#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n const int MAXN = 2500; n struct P { n   int x, y; n   P() {} n   P(int x, int y) : x(x), y(y) {} n }; n long long operator^(const P& a, const P& b) { n   return (long long)a.x * b.y - (long long)a.y * b.x; n } n P operator-(const P& a, const P& b) { return P(a.x - b.x, a.y - b.y); } n bool operator<(const P& a, const P& b) { n   bool apos = a.y > 0 || a.y == 0 && a.x > 0; n   bool bpos = b.y > 0 || b.y == 0 && b.x > 0; n   if (apos != bpos) return apos; n   return (a ^ b) > 0; n } n int n; n P p[MAXN]; n long long C[MAXN + 1][5 + 1]; n P q[2 * (MAXN - 1)]; n int nq; n long long solve() { n   for (int i = (0); i <= (n); ++i) n     for (int j = (0); j <= (5); ++j) C[i][j] = 0; n   for (int i = (0); i <= (n); ++i) { n     C[i][0] = 1; n     for (int j = (1); j <= (min(5, i)); ++j) n       C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; n   } n   long long cnttot = C[n][5]; n   long long cntside = 0; n   for (int i = (0); i < (n); ++i) { n     nq = 0; n     for (int j = (0); j < (n); ++j) n       if (j != i) q[nq++] = p[j] - p[i]; n     sort(q, q + nq); n     for (int j = (0); j < (nq); ++j) q[nq + j] = q[j]; n     int to = 0; n     for (int at = (0); at < (nq); ++at) { n       to = max(to, at + 1); n       while (to - at < nq && (q[at] ^ q[to]) > 0) ++to; n       int cur = to - at - 1; n       cntside += C[cur][3]; n     } n   } n   return 5 * cnttot - cntside; n } n void run() { n   scanf( %d , &n); n   for (int i = (0); i < (n); ++i) scanf( %d%d , &p[i].x, &p[i].y); n   printf( %lld n , solve()); n } n int main() { n   run(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double p[22], f[(1 << 20) + 10], ans[22]; n int n, m; n int main() { n   int cnt = 0; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) { n     scanf( %lf , &p[i]); n     if (p[i] > 1e-7) cnt++; n   } n   if (cnt <= m) { n     for (int i = 1; i <= n; i++) n       if (p[i] > 1e-7) n         printf( 1  ); n       else n         printf( 0  ); n     return 0; n   } n   int ss = (1 << n) - 1; n   f[0] = 1; n   for (int i = 0; i <= ss; i++) { n     cnt = 0; n     for (int j = 1; j <= n; j++) n       if (i & (1 << (j - 1))) cnt++; n     if (cnt > m) continue; n     if (cnt == m) { n       for (int j = 1; j <= n; j++) n         if (i & (1 << (j - 1))) ans[j] += f[i]; n       continue; n     } n     double t = 1; n     for (int j = 1; j <= n; j++) n       if (i & (1 << (j - 1))) t -= p[j]; n     for (int j = 1; j <= n; j++) { n       if (i & (1 << (j - 1))) continue; n       f[i + (1 << (j - 1))] += f[i] * p[j] / t; n     } n   } n   for (int i = 1; i <= n; i++) printf( %.7lf  , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[100002]; n int b[100002]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d , a + i); n   int ret = 0; n   for (int i = n - 1; i >= 0; i--) { n     int mx = 1; n     for (int j = 1; j * j <= a[i]; j++) n       if (a[i] % j == 0) { n         mx = max(mx, 1 + b[a[i] / j]); n         mx = max(mx, 1 + b[j]); n       } n     for (int j = 1; j * j <= a[i]; j++) n       if (a[i] % j == 0) { n         if (j != 1) b[j] = max(b[j], mx); n         b[a[i] / j] = max(b[a[i] / j], mx); n       } n     ret = max(ret, mx); n   } n   cout << ret << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n; n   cin >> n; n   int count[2] = {0, 0}; n   bool all_even = 1; n   for (int i = 0; i < n; i++) { n     static string s; n     cin >> s; n     if (static_cast<int>(s.size()) & 1) all_even = 0; n     for (const char &c : s) count[c -  0 ]++; n   } n   if (all_even && (count[0] & 1) && (count[1] & 1)) n     cout << n - 1; n   else n     cout << n; n   cout <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0); n   int t = 1; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n typedef long long ll; n typedef pair<int,int> PII; n const int maxn=1111111,mod=998244353; n #define MP make_pair n #define PB push_back n #define lson o<<1,l,mid n #define rson o<<1|1,mid+1,r n #define FOR(i,a,b) for(int i=(a);i<=(b);i++) n #define ROF(i,a,b) for(int i=(a);i>=(b);i--) n #define MEM(x,v) memset(x,v,sizeof(x)) n inline ll read(){ n  char ch=getchar();ll x=0,f=0; n  while(ch< 0  || ch> 9 ) f|=ch== - ,ch=getchar(); n  while(ch>= 0  && ch<= 9 ) x=x*10+ch- 0 ,ch=getchar(); n  return f?-x:x; n } n int n,m,deg[maxn],p[maxn],q[maxn],rem,que[maxn],h,r,el,head[maxn],to[maxn],nxt[maxn]; n bool in[maxn]; n set<PII,greater<PII> > s; n set<int> nvis,e[maxn]; n inline void add(int u,int v){ n  e[u].insert(v); n } n inline void add2(int u,int v){ n // printf( add(%d,%d) n ,u,v); n  to[++el]=v;nxt[el]=head[u];head[u]=el; n } n void clear(){ n  FOR(i,1,n) deg[i]=p[i]=q[i]=head[i]=in[i]=0; n  s.clear(); n  nvis.clear(); n  FOR(i,1,n) e[i].clear(); n  FOR(i,1,el) to[i]=nxt[i]=0; n  el=0; n } n bool dfs(int u,int f){ n  int son=0,cnt=0; n  for(int i=head[u];i;i=nxt[i]){ n   int v=to[i]; n   if(dfs(v,u)) cnt++; n   else son=v; n  } n // printf( u=%d,cnt=%d n ,u,cnt); n  if(cnt){ n   for(int i=head[u];i;i=nxt[i]){ n    int v=to[i]; n    if(!in[v]) continue; n    p[v]=rem; n    q[v]=--rem; n   } n   q[u]=rem+cnt; n   p[u]=rem--; n   return in[u]=false; n  } n  else if(!f){ n   assert(son); n //  puts( in ); n   p[u]=q[u]=rem--; n   swap(p[u],p[son]); n   return in[u]=false; n  } n  else return in[u]=true; n } n void bfs(int s){ n  que[h=r=1]=s; n  while(h<=r){ n   int u=que[h++]; n   for(set<int>::iterator it=nvis.begin();it!=nvis.end();){ n    int v=*it; n //   printf( try %d to %d n ,u,v); n    if(e[u].find(v)!=e[u].end()){it++;continue;} n    set<int>::iterator it1=it++; n    nvis.erase(it1); n    que[++r]=v; n    add2(u,v); n   } n  } n  dfs(s,0); n /* set<int>::iterator it=nvis.begin(); n  int son=0; n  if(!vec[u].empty()){ n   p[u]=rem; n   FOR(i,0,(int)vec[u].size()-1) p[vec[u][i]]=rem-i-1; n   FOR(i,0,(int)vec[u].size()-1) q[vec[u][i]]=rem-i; n   q[u]=rem-=vec[u].size(); n   return false; n  } n  else if(rt){ n   assert(son); n   p[u]=q[u]=rem--; n   swap(q[u],q[son]); n   return false; n  } n  else return true;*/ n } n void solve(){ n  n=read();m=read(); n  FOR(i,1,m){ n   int u=read(),v=read(); n   add(u,v);add(v,u); n   deg[u]++;deg[v]++; n  } n  FOR(i,1,n) s.insert(MP(deg[i],i)); n  rem=n; n  while(!s.empty() && s.begin()->first==(int)s.size()-1){ n   int u=s.begin()->second; n   s.erase(s.begin()); n //  printf( erase %d n ,u); n   p[u]=q[u]=rem--; n   for(set<int>::iterator it=e[u].begin();it!=e[u].end();it++){ n    int v=*it; n    s.erase(MP(deg[v],v)); n    s.insert(MP(--deg[v],v)); n    e[v].erase(u); n   } n   e[u].clear(); n   deg[u]=0; n  } n  FOR(i,1,n) if(!p[i]) nvis.insert(i); n  FOR(i,1,n) if(!p[i]){ n   nvis.erase(i); n   bfs(i); n  } n  FOR(i,1,n) printf( %d  ,p[i]); n  puts(  ); n  FOR(i,1,n) printf( %d  ,q[i]); n  puts(  ); n  clear(); n } n int main(){ n  int T=read(); n  while(T--) solve(); n }


#include <bits/stdc++.h> n using namespace std; n long long n, x, k, lb, ub, ans = -1; n void init() { n   long long l, r; n   scanf( %lld%lld%lld%lld , &n, &l, &r, &k); n   x = (r >= l ? r - l + 1 : r + n - l + 1) % n; n } n void solve() { n   for (long long i = k, j, r; i; i = j) { n     j = k / (k / i + 1); n     r = k / i; n     ub = min(2 * n, i); n     lb = max(n, j + 1); n     ub = min(ub, min((2 * n + k - 2 * x + 1) / (r + 1), (k - x) / r)); n     lb = max(lb, (k - 2 * x + r - 1) / r); n     if (ub >= lb) ans = max(ans, ub); n   } n   if (x <= k && k <= x * 2) ans = max(ans, n + min(k - x, x - 1) + n - x + 1); n   if (!x && k == n) ans = max(ans, n + 1); n   printf( %lld n , ~ans ? ans - n : ans); n } n int main() { n   init(); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 7; n const long long INFL = 1e18 + 123; n const double PI = atan2(0, -1); n mt19937 tw(960172); n long long rnd(long long x, long long y) { n   static uniform_int_distribution<long long> d; n   return d(tw) % (y - x + 1) + x; n } n int cur_sum, deleted_sum; n vector<tuple<int, int, int>> back, front; n void init() { n   cur_sum = 0; n   deleted_sum = 0; n   back.clear(); n   front.clear(); n } n int get_min_back() { n   if (((int)(back).size())) { n     return get<2>(back.back()); n   } n   return INF; n } n int get_min_front() { n   if (((int)(front).size())) { n     return get<2>(front.back()); n   } n   return INF; n } n void add(int val) { n   cur_sum += val; n   back.push_back({val, cur_sum, min(cur_sum, get_min_back())}); n } n void pop() { n   assert(((int)(back).size()) || ((int)(front).size())); n   if (!((int)(front).size())) { n     while (((int)(back).size())) { n       int val, sum, tmp; n       tie(val, sum, tmp) = back.back(); n       back.pop_back(); n       front.push_back({val, sum, min(sum, get_min_front())}); n     } n   } n   deleted_sum += get<0>(front.back()); n   front.pop_back(); n } n int get_min() { return min(get_min_front(), get_min_back()) - deleted_sum; } n void solve() { n   int n, l; n   cin >> n >> l; n   vector<int> boys, girls; n   for (int i = 0; i < n; ++i) { n     int num; n     cin >> num; n     boys.push_back(num); n     boys.push_back(num + l); n   } n   for (int i = 0; i < n; ++i) { n     int num; n     cin >> num; n     girls.push_back(num - l); n     girls.push_back(num); n     girls.push_back(num + l); n   } n   sort(boys.begin(), boys.end()); n   sort(girls.begin(), girls.end()); n   int lg = -1, rg = l / 2; n   while (rg - lg > 1) { n     int mid = (lg + rg) / 2; n     init(); n     bool flag = true; n     int c1 = 0, c2 = 0, c3 = 0; n     while (girls[c2] - mid <= boys[c1]) { n       ++c2; n     } n     c3 = c2; n     while (c3) { n       if (boys[0] - girls[c3 - 1] <= mid) { n         --c3; n       } else { n         break; n       } n     } n     int c0 = c2; n     for (int i = 0; i < n; ++i) { n       while (girls[c3] < boys[i] - mid) { n         ++c3; n       } n       while (girls[c0] - mid <= boys[i]) { n         ++c0; n       } n       c2 = max(c2, c0); n       while (true) { n         if (girls[c2] - mid <= boys[c1]) { n           if (c2 == c3 + n) { n             break; n           } n           add(1); n           ++c2; n         } else { n           if (boys[c1] + mid >= boys[i] + l - mid) { n             break; n           } n           add(-1); n           ++c1; n         } n       } n       if (c0 - c3 + get_min() < 0) { n         flag = false; n         break; n       } n       if (i == n - 1) { n         break; n       } n       int tmp = deleted_sum; n       pop(); n       --tmp; n       assert(tmp == deleted_sum); n       while ((((int)(front).size()) || ((int)(back).size())) && n              girls[c0] - mid <= boys[i + 1]) { n         pop(); n         ++tmp; n         ++c0; n       } n       assert(tmp == deleted_sum); n     } n     if (flag) { n       rg = mid; n     } else { n       lg = mid; n     } n   } n   cout << rg <<   n ; n } n int main() { n   cerr << fixed << setprecision(15); n   cout << fixed << setprecision(15); n   ios::sync_with_stdio(false); n   int tests = 1; n   for (int it = 1; it <= tests; ++it) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e9; n const int M = 1e9; n int ix, iy, fx, fy; n map<pair<int, int>, int> pres; n map<pair<int, int>, int> dist; n map<pair<int, int>, bool> vis; n int dx[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1}; n int dy[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1}; n bool check(int x, int y) { n   if (x >= 1 && x <= 1e9 && y >= 1 && y <= 1e9) { n     if (pres[make_pair(x, y)]) return true; n     return false; n   } n   return false; n } n void bfs(int x, int y) { n   queue<pair<int, int> > q; n   pair<int, int> tmp; n   q.push(make_pair(x, y)); n   while (q.size() > 0) { n     tmp = q.front(); n     q.pop(); n     for (int i = 0; i < 9; ++i) { n       int x1 = tmp.first + dx[i]; n       int y1 = tmp.second + dy[i]; n       if (check(x1, y1) && vis[make_pair(x1, y1)] == 0) { n         vis[make_pair(x1, y1)] = 1; n         dist[make_pair(x1, y1)] = dist[tmp] + 1; n         q.push(make_pair(x1, y1)); n       } n     } n   } n } n int main() { n   cin >> ix >> iy >> fx >> fy; n   int Q; n   cin >> Q; n   int x, y, z; n   for (int q = 1; q <= Q; ++q) { n     scanf( %d%d%d , &x, &y, &z); n     for (int i = y; i <= z; ++i) { n       pres[make_pair(x, i)] = 1; n     } n   } n   dist[make_pair(ix, iy)] = 0; n   dist[make_pair(fx, fy)] = 1e9; n   vis[make_pair(ix, iy)] = 1; n   bfs(ix, iy); n   int res = dist[make_pair(fx, fy)]; n   if (res >= 1e9) res = -1; n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   std::ios::sync_with_stdio(false); n   double n, m; n   char ch; n   cin >> n >> ch >> m; n   if (n >= 12) n -= 12; n   double ans1, ans2; n   ans2 = 6 * m; n   ans1 = n * 30 + 0.5 * m; n   cout << ans1 <<     << ans2 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long getInt() { n   long long ret; n   char tmpc; n   bool sign = 0; n   while (tmpc = getchar(), !isdigit(tmpc)) sign = (tmpc ==  - ); n   ret = tmpc -  0 ; n   while (tmpc = getchar(), isdigit(tmpc)) ret = ret * 10 + tmpc -  0 ; n   if (sign) ret *= -1; n   return ret; n } n const int mx = 1e5 + 10; n int n, ans, dp[2][mx]; n int main() { n   n = getInt(); n   vector<int> in(n + 2); n   for (int i = 1; i <= n; i++) { n     in[i] = getInt(); n     dp[0][i] = min(in[i], dp[0][i - 1] + 1); n   } n   for (int i = n; i >= 1; i--) { n     dp[1][i] = min(in[i], dp[1][i + 1] + 1); n     ans = max(ans, min(dp[0][i], dp[1][i])); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, f, a, b; n   vector<pair<long long int, long long int> > v; n   cin >> n >> f; n   int i; n   for (i = 0; i < n; i++) { n     cin >> a >> b; n     v.push_back(make_pair(a, b)); n   } n   long long int ans = 0; n   vector<long long int> t; n   for (i = 0; i < n; i++) { n     ans = ans + min(v[i].first, v[i].second); n     long long int mins = n         min(v[i].first * 2, v[i].second) - min(v[i].first, v[i].second); n     t.push_back(mins); n   } n   sort(t.begin(), t.end()); n   for (i = n - 1; i >= 0; i--) { n     if (t[i] > 0 && f != 0) { n       ans = ans + t[i]; n       f--; n     } n     if (f == 0) break; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using ll = long long; n int n, a, v[10005]; n ll d[1000005], ans; n char s[10005]; n int main() { n   scanf( %d , &a); n   scanf( %s , s + 1); n   n = std::strlen(s + 1); n   int lim = n * 10; n   for (int i = 1; i <= n; ++i) v[i] = v[i - 1] + s[i] -  0 ; n   for (int l = 1; l <= n; ++l) n     for (int r = l; r <= n; ++r) { n       d[v[r] - v[l - 1]]++; n     } n   if (a == 0) { n     ans = d[0] * (ll)n * (n + 1) - d[0] * d[0]; n   } else { n     for (int i = 1; i * i <= a; ++i) { n       if (a % i) continue; n       int j = a / i; n       if (i <= lim && j <= lim) ans += d[i] * d[j] * (1 + (i != j)); n     } n   } n   printf( %lld , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n const long long int MOD = 1e9 + 7; n const long long int INV2 = 500000004; n int A[N][4]; n int main(int argc, char const *argv[]) { n   cin.sync_with_stdio(0); n   cin.tie(0); n   int n, m; n   cin >> n >> m; n   int v = 1; n   for (int i = 1; i <= n; i++) { n     A[i][0] = v++; n     A[i][3] = v++; n   } n   for (int i = 1; i <= n; i++) { n     A[i][1] = v++; n     A[i][2] = v++; n   } n   for (int i = 1; i <= n; i++) { n     if (A[i][1] <= m) cout << A[i][1] <<    ; n     if (A[i][0] <= m) cout << A[i][0] <<    ; n     if (A[i][2] <= m) cout << A[i][2] <<    ; n     if (A[i][3] <= m) cout << A[i][3] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<string> split(const string& s, const string& delim =    ) { n   vector<string> res; n   string t; n   for (int i = 0; i != s.size(); i++) { n     if (delim.find(s[i]) != string::npos) { n       if (!t.empty()) { n         res.push_back(t); n         t =   ; n       } n     } else { n       t += s[i]; n     } n   } n   if (!t.empty()) { n     res.push_back(t); n   } n   return res; n } n vector<int> splitInt(const string& s, const string& delim =    ) { n   vector<string> tok = split(s, delim); n   vector<int> res; n   for (int i = 0; i != tok.size(); i++) res.push_back(atoi(tok[i].c_str())); n   return res; n } n template <typename T> n void print(T a) { n   cerr << a; n } n static void print(long long a) { cerr << a <<  L ; } n static void print(string a) { cerr <<     << a <<    ; } n template <typename T> n void print(vector<T> a) { n   cerr <<  { ; n   for (int i = 0; i != a.size(); i++) { n     if (i != 0) cerr <<  ,  ; n     print(a[i]); n   } n   cerr <<  }  << endl; n } n int main() { n   int n, m; n   while (cin >> n >> m) { n     int res = 0; n     if (n <= 1 || m <= 1) res = m * n; n     if (n == 2 || m == 2) { n       int x = max(m, n); n       res = max(res, x / 4 * 4 + min((x % 4) * 2, 4)); n     } n     int x = m * n / 2; n     int y = m * n - x; n     res = max(max(res, x), y); n     res = min(res, m * n); n     cout << res << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long double s, a, b, c; n int main() { n   cin >> s >> a >> b >> c; n   if (a + b + c == 0) { n     cout << 0 <<     << 0 <<     << 0 << endl; n     return 0; n   } n   long double x = s * a / (a + b + c); n   long double y = s * b / (a + b + c); n   long double z = s * c / (a + b + c); n   printf( %.10lf %.10lf %.10lf n , (double)x, (double)y, (double)z); n   return 0; n } n


#include <bits/stdc++.h> n  n using namespace std; n  n typedef unsigned long long ll; n typedef long double ld; n typedef vector<ll> vl; n typedef vector<int> vi; n typedef vector<vector<int>> vvi; n typedef vector<vector<ll>> vvl; n typedef vector<ll, vector<ll>> vll; n #define ln   n  n #define mp make_pair n #define pb push_back n #define st first n #define nd second n #define all(x) (x).begin(), (x).end() n #define sz(x) ((ll)(x).size()) n  n void solve() n { n   ll n; n   cin >> n; n  n   if (n % 2 != 0) n   { n     cout <<  NO  << ln; n     return; n   } n  n   ll j = n; n  n   while (j % 2 == 0) n   { n     j = j / 2; n   } n  n   if (j == 1) n   { n     cout <<  YES  << ln; n     return; n   } n  n   ll sq = sqrt(j); n   if (sq * sq == j) n   { n     cout <<  YES  << ln; n     return; n   } n  n   cout <<  NO  << ln; n } n  n int main() n { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n  n   int test; n   cin >> test; n   for (int i = 1; i <= test; i++) n     solve(); n  n   return 0; n }


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100010; n int v[maxn], b[maxn]; n int n, k; n long long base, sum; n int cmp(const int &i, const int &j) { return i > j; } n int main() { n   while (scanf( %d %d , &n, &k) != EOF) { n     scanf( %I64d , &base); n     sum = 0; n     for (int i = 0; i < n; i++) { n       scanf( %d , &v[i]); n       if (i != n - 1) b[i] = v[i]; n     } n     sort(b, b + n - 1, cmp); n     int ans = n; n     for (int i = 0; i < k; i++) sum += b[i]; n     for (int i = 0; i < n; i++) { n       int s = lower_bound(b, b + n - 1, v[i], cmp) - b; n       long long now = sum; n       if (s >= k) { n         now += v[i]; n         now -= b[k - 1]; n       } n       if (now > base) { n         ans = i + 1; n         break; n       } n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int x, int y) { n   int i, z; n   while (y != 0) { n     z = x % y; n     x = y; n     y = z; n   } n   return x; n } n int a[110]; n int b[110]; n int main() { n   int n, m, i, j, k, count = 0, s = 0; n   scanf( %d%d , &n, &m); n   for (i = 0; i <= n; i++) scanf( %d , &a[i]); n   for (i = 0; i <= m; i++) scanf( %d , &b[i]); n   for (i = 0; i < n; i++) { n     if (a[i] != 0) { n       n = n - i; n       break; n     } n   } n   for (j = 0; j < m; j++) { n     if (b[j] != 0) { n       m = m - j; n       break; n     } n   } n   if (a[i] < 0 && n != 0) count++; n   if (b[j] < 0 && m != 0) count++; n   for (k = i; k <= n; k++) { n     if (a[k] < 0 && k != n) a[k] = fabs(a[k]); n     if (a[k] < 0 && k == n) { n       a[k] = fabs(a[k]); n       s++; n     } n   } n   for (k = j; k <= m; k++) { n     if (b[k] < 0 && k != m) b[k] = fabs(b[k]); n     if (b[k] < 0 && k == m) { n       b[k] = fabs(b[k]); n       s++; n     } n   } n   if (m > n) { n     printf( 0/1 n ); n     return 0; n   } n   if (count % 2 == 1) printf( - ); n   if (n > m) n     printf( Infinity n ); n   else if (n == m && n != 0 && b[j] % a[i] == 0) n     printf( 1/%d n , b[j] / a[i]); n   else if (n == m && n != 0) n     printf( %d/%d n , a[i] / gcd(a[i], b[j]), b[j] / gcd(a[i], b[j])); n   else if (n == 0 && m == 0 && s % 2 == 0) n     printf( %d/%d n , a[n] / gcd(a[n], b[m]), b[m] / gcd(a[n], b[m])); n   else if (n == 0 && m == 0 && s % 2 == 1) n     printf( -%d/%d n , a[n] / gcd(a[n], b[m]), b[m] / gcd(a[n], b[m])); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long pw(long long base, long long e) { n   return e ? pw(base * base, e / 2) * (e % 2 ? base : 1) : 1; n } n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long to_int(string s) { n   long long ret = 0; n   for (int i = 0; i <= s.size(); i++) { n     ret += pw(10, s.size() - i - 1) * (long long)(s[i] -  0 ); n   } n   return ret; n } n const int maxn = 1e5 + 10, mod = 1e9 + 7; n const long long INF = 1e9; n long long n; n long long f(long long x) { return (n - x) / (2 * x); } n int main() { n   cin >> n; n   n--; n   long long ans = 0; n   for (int i = 0; i <= log2(n); i++) { n     ans += pw(2, i) * (f(pw(2, i)) + 1); n   } n   return cout << ans <<   n , 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1); n const long long mod = 1e9 + 7; n const long long N = 2e5 + 5, K = 105; n const int si = (1 << 20); n const long long add = 1e4; n const long long M = 100 + 5; n const double INFdb = 1e10; n int t; n int n; n vector<int> a[N]; n priority_queue<int, vector<int>, greater<int> > pq; n void reset() { n   for (int i = 0; i < n; ++i) a[i].clear(); n   while (!pq.empty()) pq.pop(); n } n void solve() { n   cin >> n; n   reset(); n   for (int i = 0; i < n; ++i) { n     int m, c; n     cin >> m >> c; n     a[m].push_back(c); n   } n   long long sum = 0; n   int used = 0; n   int smartNum = n; n   for (int i = n - 1; i >= 0; --i) { n     for (int x : a[i]) pq.push(x); n     smartNum -= (int)a[i].size(); n     while (smartNum + used < i && !pq.empty()) { n       sum += pq.top(); n       pq.pop(); n       ++used; n     } n   } n   cout << sum <<   n ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(0); n   cin >> t; n   while (t--) { n     solve(); n   } n   cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int l[100500]; n int r[100500]; n int val[100500]; n int t[400500]; n int t2[400500]; n int mas[100500]; n int INF = 0; n void build(int v, int tl, int tr) { n   if (tl == tr) n     t[v] = 0; n   else { n     int mid = (tl + tr) >> 1; n     build(v << 1, tl, mid); n     build((v << 1) + 1, mid + 1, tr); n     t[v] = 0; n   } n } n void update(int v, int tl, int tr, int ql, int qr, int nval) { n   if (ql > qr) return; n   if (tl == ql && tr == qr) { n     t[v] = t[v] | nval; n   } else { n     int mid = (tl + tr) >> 1; n     update(v << 1, tl, mid, ql, min(qr, mid), nval); n     update((v << 1) + 1, mid + 1, tr, max(ql, mid + 1), qr, nval); n   } n } n void dfs(int v, int tl, int tr, int curr) { n   if (tl == tr) { n     mas[tl] = curr | t[v]; n   } else { n     int mid = (tl + tr) >> 1; n     dfs(v << 1, tl, mid, curr | t[v]); n     dfs((v << 1) + 1, mid + 1, tr, curr | t[v]); n   } n } n void build2(int v, int tl, int tr) { n   if (tl == tr) { n     t[v] = mas[tl]; n   } else { n     int mid = (tl + tr) >> 1; n     build2(v << 1, tl, mid); n     build2((v << 1) + 1, mid + 1, tr); n     t[v] = t[v << 1] & t[(v << 1) + 1]; n   } n } n int query(int v, int tl, int tr, int ql, int qr) { n   if (ql > qr) return INF; n   if (tl == ql && tr == qr) { n     return t[v]; n   } else { n     int mid = (tl + tr) >> 1; n     return query(v << 1, tl, mid, ql, min(qr, mid)) & n            query((v << 1) + 1, mid + 1, tr, max(ql, mid + 1), qr); n   } n } n int main() { n   for (int i = 29; i >= 0; i--) { n     INF += (1 << i); n   } n   cin >> n >> m; n   build(1, 1, n); n   for (int i = 0; i < m; i++) { n     cin >> l[i] >> r[i] >> val[i]; n     update(1, 1, n, l[i], r[i], val[i]); n   } n   dfs(1, 1, n, 0); n   build2(1, 1, n); n   for (int i = 0; i < m; i++) { n     if (query(1, 1, n, l[i], r[i]) != val[i]) { n       cout <<  NO ; n       return 0; n     } n   } n   cout <<  YES n ; n   for (int i = 1; i <= n; i++) cout << mas[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, d, f; n   cin >> n; n   if (n % 3 == 2) n     d = n / 3 + 1; n   else n     d = n / 3; n   f = d / 12; n   d = d % 12; n   cout << f <<     << d << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline void read(T &x) { n   x = 0; n   char c = getchar(), f = 0; n   for (; c <  0  || c >  9 ; c = getchar()) n     if (c ==  - ) f = 1; n   for (; c >=  0  && c <=  9 ; c = getchar()) n     x = (x << 1) + (x << 3) + (c ^ 48); n   if (f) x = -x; n } n int n, m, K, a[2000005][5]; n char ch[2000005]; n long long N, M; n inline void solve() { n   read(n); n   if (n % 3 == 0) n     printf( %d %d n , n / 3, n / 3); n   else if (n % 3 == 1) n     printf( %d %d n , n / 3 + 1, n / 3); n   else n     printf( %d %d n , n / 3, n / 3 + 1); n } n int main() { n   int Ca; n   for (read(Ca); Ca--;) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2000; n vector<array<int, 2>> que; n int degree[N][N], n, m; n string grid[N]; n bool valid(int i, int j) { n   return i >= 0 && i < n && j >= 0 && j < m && grid[i][j] ==  . ; n } n void update(int i, int j) { n   if (i >= 0 && i < n && j >= 0 && j < m) { n     degree[i][j] = 0; n   } n   if (valid(i - 1, j) && ++degree[i - 1][j] == 3) { n     que.push_back({i - 1, j}); n   } n   if (valid(i + 1, j) && ++degree[i + 1][j] == 3) { n     que.push_back({i + 1, j}); n   } n   if (valid(i, j - 1) && ++degree[i][j - 1] == 3) { n     que.push_back({i, j - 1}); n   } n   if (valid(i, j + 1) && ++degree[i][j + 1] == 3) { n     que.push_back({i, j + 1}); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cin >> n >> m; n   for (int i = 0; i < n; ++i) { n     cin >> grid[i]; n   } n   for (int i = 0; i < n; ++i) { n     update(i, -1), update(i, m); n   } n   for (int i = 0; i < m; ++i) { n     update(-1, i), update(n, i); n   } n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       if (grid[i][j] ==  * ) { n         update(i, j); n       } n     } n   } n   while (!que.empty()) { n     auto [i, j] = que.back(); n     que.pop_back(); n     if (degree[i][j] == 0) { n       continue; n     } else if (degree[i][j] == 4) { n       cout <<  Not unique n ; n       exit(0); n     } n     if (valid(i - 1, j)) { n       grid[i - 1][j] =  ^ , grid[i][j] =  v ; n       update(i - 1, j); n     } else if (valid(i + 1, j)) { n       grid[i][j] =  ^ , grid[i + 1][j] =  v ; n       update(i + 1, j); n     } else if (valid(i, j - 1)) { n       grid[i][j - 1] =  < , grid[i][j] =  > ; n       update(i, j - 1); n     } else { n       grid[i][j] =  < , grid[i][j + 1] =  > ; n       update(i, j + 1); n     } n     update(i, j); n   } n   for (int i = 0; i < n; ++i) { n     if (count(grid[i].begin(), grid[i].end(),  . ) > 0) { n       cout <<  Not unique n ; n       exit(0); n     } n   } n   for (int i = 0; i < n; ++i) { n     cout << grid[i] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n set<string> st; n set<string>::iterator it1; n vector<int> dp2(20000, 0), dp3(20000, 0); n void solve(string s, int i, string prev) { n   if (i < 1) return; n   if (i == 1) { n     string a = s.substr(i - 1, 2); n     if (a != prev) n       st.insert(a); n     else n       return; n   } else { n     string temp; n     string a = s.substr(i - 1, 2); n     string b = s.substr(i - 2, 3); n     if (a != prev && !dp2[i]) { n       dp2[i] = 1; n       temp = a; n       solve(s, i - 2, temp); n     } n     if (b != prev && !dp3[i]) { n       dp3[i] = 1; n       temp = b; n       solve(s, i - 3, temp); n     } n   } n   return; n } n int main() { n   string str; n   cin >> str; n   if (str.size() < 7) { n     cout << 0; n     return 0; n   } n   string s(str.begin() + 5, str.end()); n   int n = s.size(); n   solve(s, n - 1,   ); n   for (int i = 0; i < n; i++) { n     if (dp2[i]) st.insert(s.substr(i - 1, 2)); n     if (dp3[i]) st.insert(s.substr(i - 2, 3)); n   } n   cout << st.size() << endl; n   it1 = st.begin(); n   for (; it1 != st.end(); it1++) cout << *it1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, i, X[200005], poz, nr0; n long long A[200005], B[200005], val, t; n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> t; n   for (i = 1; i <= n; i++) cin >> A[i]; n   for (i = 1; i <= n; i++) { n     cin >> X[i]; n     if (X[i] < X[i - 1]) { n       cout <<  No n ; n       return 0; n     } n     if (X[i] < i) { n       cout <<  No n ; n       return 0; n     } n     if (X[i - 1] != X[i] && X[i - 1] != (i - 1)) { n       cout <<  No n ; n       return 0; n     } n   } n   A[n + 1] = A[n] + 1000000001; n   for (i = 1; i <= n; i++) B[X[i]] = A[X[i] + 1] + t - 1; n   val = B[n] - 1; n   for (i = n - 1; i >= 1; i--) { n     if (B[i] != 0) n       val = B[i]; n     else { n       if (val < A[i + 1] + t) { n         cout <<  No n ; n         return 0; n       } n     } n     B[i] = val; n     val--; n   } n   cout <<  Yes n ; n   for (i = 1; i <= n; i++) cout << B[i] <<    ; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = (int)1e5 + 22; n vector<vector<int> > cr; n int N, M; n vector<vector<int> > qq; n int A[MAXN], prv[MAXN], nxt[MAXN], lst[MAXN]; n struct Fenwick { n   int n; n   vector<long long> t, w; n   void init(int _n) { n     n = _n; n     t.resize(n, 0); n     w.resize(n, 0); n   } n   long long sum(int r) { n     long long ans = 0; n     for (; r >= 0; r = (r & (r + 1)) - 1) ans += t[r]; n     return ans; n   } n   void inc(int i, long long d) { n     w[i] += d; n     for (; i < n; i = (i | (i + 1))) t[i] += d; n   } n   long long sum(int l, int r) { n     if (l > r) return 0; n     return sum(r) - sum(l - 1); n   } n }; n void updateCR(int v, int l, int r, int x) { n   cr[v].push_back(prv[x]); n   if (r - l == 1) return; n   int mid = (l + r) / 2; n   if (x < mid) n     updateCR(2 * v + 1, l, mid, x); n   else n     updateCR(2 * v + 2, mid, r, x); n } n vector<Fenwick> T; n void build(int v, int l, int r) { n   cr[v].push_back(-1); n   sort(cr[v].begin(), cr[v].end()); n   cr[v].resize(unique(cr[v].begin(), cr[v].end()) - cr[v].begin()); n   T[v].init((int)cr[v].size()); n   for (int i = l; i < r; i++) { n     int pos = lower_bound(cr[v].begin(), cr[v].end(), prv[i]) - cr[v].begin(); n     assert(cr[v][pos] == prv[i]); n     T[v].inc(pos, i - prv[i]); n   } n   if (r - l == 1) return; n   int mid = (l + r) / 2; n   build(2 * v + 1, l, mid); n   build(2 * v + 2, mid, r); n } n long long get(int v, int l, int r, int ql, int qr) { n   if (ql >= r || qr <= l) return 0; n   if (ql <= l && r <= qr) { n     int pos = lower_bound(cr[v].begin(), cr[v].end(), ql) - cr[v].begin(); n     int sz = (int)cr[v].size(); n     return T[v].sum(pos, sz - 1); n   } n   int mid = (l + r) / 2; n   long long a, b; n   a = get(2 * v + 1, l, mid, ql, qr); n   b = get(2 * v + 2, mid, r, ql, qr); n   return a + b; n } n void update(int v, int l, int r, int x, int d) { n   int pos = lower_bound(cr[v].begin(), cr[v].end(), prv[x]) - cr[v].begin(); n   assert(pos < (int)cr[v].size()); n   if (cr[v][pos] != prv[x]) cerr << cr[v][pos] <<     << prv[x] << endl; n   assert(cr[v][pos] == prv[x]); n   T[v].inc(pos, d * (x - prv[x])); n   if (r - l == 1) return; n   int mid = (l + r) / 2; n   if (x < mid) n     update(2 * v + 1, l, mid, x, d); n   else n     update(2 * v + 2, mid, r, x, d); n } n void input() { n   cin >> N >> M; n   memset(lst, -1, sizeof(lst)); n   memset(nxt, -1, sizeof(nxt)); n   cr.resize(4 * N); n   vector<set<int> > st; n   st.resize(N + 1); n   vector<int> B; n   for (int i = 0; i < N; i++) { n     cin >> A[i]; n     B.push_back(A[i]); n     st[A[i]].insert(i); n     prv[i] = lst[A[i]]; n     if (prv[i] >= 0) nxt[prv[i]] = i; n     updateCR(0, 0, N, i); n     lst[A[i]] = i; n   } n   int type, a, b; n   for (int i = 0; i < M; i++) { n     cin >> type >> a >> b; n     --type, --a; n     qq.push_back({type, a, b}); n     if (!type) { n       if (prv[a] >= 0) nxt[prv[a]] = nxt[a]; n       if (nxt[a] >= 0) { n         prv[nxt[a]] = prv[a]; n         updateCR(0, 0, N, nxt[a]); n       } n       st[B[a]].erase(a); n       B[a] = b; n       st[B[a]].insert(a); n       auto it = st[B[a]].lower_bound(a); n       if (it != st[B[a]].begin()) { n         --it; n         nxt[*it] = a; n         prv[a] = *it; n         ++it; n       } else n         prv[a] = -1; n       updateCR(0, 0, N, a); n       ++it; n       if (it != st[B[a]].end()) { n         prv[*it] = a; n         nxt[a] = *it; n         updateCR(0, 0, N, nxt[a]); n       } else n         nxt[a] = -1; n     } n   } n } n void solve() { n   memset(lst, -1, sizeof(lst)); n   memset(nxt, -1, sizeof(nxt)); n   vector<set<int> > st; n   st.resize(N + 1); n   vector<int> B; n   for (int i = 0; i < N; i++) { n     B.push_back(A[i]); n     st[A[i]].insert(i); n     prv[i] = lst[A[i]]; n     if (prv[i] >= 0) nxt[prv[i]] = i; n     lst[A[i]] = i; n   } n   T.resize(4 * N); n   build(0, 0, N); n   int type, a, b; n   for (int i = 0; i < M; i++) { n     type = qq[i][0]; n     a = qq[i][1]; n     b = qq[i][2]; n     if (type) n       cout << get(0, 0, N, a, b) <<   n ; n     else { n       update(0, 0, N, a, -1); n       if (prv[a] >= 0) { n         nxt[prv[a]] = nxt[a]; n       } n       if (nxt[a] >= 0) { n         update(0, 0, N, nxt[a], -1); n         prv[nxt[a]] = prv[a]; n         update(0, 0, N, nxt[a], 1); n       } n       st[B[a]].erase(a); n       B[a] = b; n       st[B[a]].insert(a); n       auto it = st[B[a]].lower_bound(a); n       ++it; n       if (it != st[B[a]].end()) { n         nxt[a] = *it; n         update(0, 0, N, nxt[a], -1); n         prv[*it] = a; n         update(0, 0, N, nxt[a], 1); n       } else n         nxt[a] = -1; n       --it; n       if (it != st[B[a]].begin()) { n         --it; n         nxt[*it] = a; n         prv[a] = *it; n         ++it; n       } else n         prv[a] = -1; n       update(0, 0, N, a, 1); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   input(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, A; n vector<int> X; n int main(void) { n   cin.sync_with_stdio(0); n   cin >> N; n   int Curr = 0, __Cnt = 0; n   for (int i = 0; i < N; i++) { n     cin >> A; n     if (A < 0) { n       if (__Cnt == 2) { n         __Cnt = 0; n         X.push_back(Curr); n         Curr = 0; n       } n       __Cnt++; n     } n     Curr++; n   } n   if (Curr) X.push_back(Curr); n   int Cnt = X.size(); n   cout << Cnt << endl; n   for (int i = 0; i < Cnt; i++) { n     if (i) cout <<    ; n     cout << X[i]; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x, p, q, count = 0; n   cin >> n; n   vector<int> v; n   vector<int>::iterator it; n   for (int i = 0; i < n; i++) { n     cin >> x; n     v.push_back(x); n   } n   for (int i = 0; i < n; i++) { n     p = i; n     for (int j = i + 1; j < n; j++) { n       if (v[p] == v[j]) { n         v[p] = 0; n         p = j; n       } n     } n   } n   for (it = v.begin(); it != v.end(); it++) { n     if ((*it) != 0) count++; n   } n   cout << count << endl; n   for (it = v.begin(); it != v.end(); it++) { n     if ((*it) != 0) cout << *it <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int> > g(7); n vector<int> vis(7); n int cycles = 0; n int nds = 0; n bool allvis() { n   for (int i = 1; i <= 5; i++) n     if (!vis[i]) return false; n   return true; n } n bool dfs(int node, int par, int cnt) { n   if (vis[node]) { n     cycles++; n     nds = cnt; n     return true; n   } n   vis[node] = 1; n   for (int i = 0; i < g[node].size(); i++) { n     int child = g[node][i]; n     if (child != par) { n       if (dfs(child, node, cnt + 1)) return true; n     } n   } n   return false; n } n int main() { n   int m; n   while (cin >> m) { n     g.clear(); n     g.resize(7); n     vis.clear(); n     vis.resize(7); n     cycles = 0; n     nds = 0; n     int a, b; n     for (int i = 0; i < m; i++) { n       cin >> a >> b; n       g[a].push_back(b); n       g[b].push_back(a); n     } n     int tmp = 0; n     for (int i = 1; i <= 5; i++) { n       if (g[i].size() < 2) tmp++; n     } n     dfs(1, 0, 0); n     if (cycles == 1 && nds == 5 && m == 5) n       cout <<  FAIL  << endl; n     else n       cout <<  WIN  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int TESTS = 1; n   while (TESTS--) { n     vector<pair<int, int>> v; n     int i, a, b, index = 0, dp[1000005] = {0}, ans = INT_MIN, n; n     cin >> n; n     for (long long int i = 0; i < n; i++) { n       cin >> a >> b; n       v.push_back({a, b}); n     } n     sort((v).begin(), (v).end()); n     for (i = 0; i < n; i++) { n       while (index != v[i].first) { n         dp[index] = dp[max(0, index - 1)]; n         index++; n       } n       if (index - v[i].second - 1 < 0) n         dp[index] = 1; n       else n         dp[index] = dp[index - v[i].second - 1] + 1; n       ans = max(ans, dp[index]); n       index++; n     } n     cout << n - ans; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = INT_MAX / 2, NINF = INT_MIN / 2; n const long double PI = acos(-1.0); n void prepareIO() { n   if (strlen(  ) != 0) { n     freopen( n            n          .in , n          r , stdin); n     freopen( n            n          .out , n          w , stdout); n   } n } n void debout() {} n template <typename Head, typename... Tail> n void debout(Head H, Tail... T) {} n void stressout() {} n template <typename Head, typename... Tail> n void stressout(Head H, Tail... T) {} n void solve1(); n int main() { n   prepareIO(); n   solve1(); n   fprintf(stderr,  %.6lf n , (double)clock() / CLOCKS_PER_SEC); n   return 0; n } n struct T { n   int to, cnt, pos; n }; n const int N = 1010; n int a[N], mark[N]; n void solve1() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   int ans = 0, cnt = 0; n   int to = 1; n   int pos = 0; n   while (cnt < n) { n     if (a[pos] <= cnt && mark[pos] == false) { n       mark[pos] = 1; n       cnt++; n       continue; n     } n     if (to == 1) { n       if (pos == n - 1) { n         ans++; n         to ^= 1; n         continue; n       } n       pos++; n     } else { n       if (pos == 0) { n         ans++; n         to ^= 1; n         continue; n       } n       pos--; n     } n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n namespace output { n void __(short x) { cout << x; } n void __(unsigned x) { cout << x; } n void __(int x) { cout << x; } n void __(long long x) { cout << x; } n void __(unsigned long long x) { cout << x; } n void __(double x) { cout << x; } n void __(long double x) { cout << x; } n void __(char x) { cout << x; } n void __(const char* x) { cout << x; } n void __(const string& x) { cout << x; } n void __(bool x) { cout << (x ?  true  :  false ); } n template <class S, class T> n void __(const pair<S, T>& x) { n   __(1 ?  (  :   ), __(x.first), __(1 ?  ,   :    ), __(x.second), n       __(1 ?  )  :   ); n } n template <class T> n void __(const vector<T>& x) { n   __(1 ?  {  :   ); n   bool _ = 0; n   for (const auto& v : x) __(_ ? 1 ?  ,   :     :   ), __(v), _ = 1; n   __(1 ?  }  :   ); n } n template <class T> n void __(const set<T>& x) { n   __(1 ?  {  :   ); n   bool _ = 0; n   for (const auto& v : x) __(_ ? 1 ?  ,   :     :   ), __(v), _ = 1; n   __(1 ?  }  :   ); n } n template <class T> n void __(const multiset<T>& x) { n   __(1 ?  {  :   ); n   bool _ = 0; n   for (const auto& v : x) __(_ ? 1 ?  ,   :     :   ), __(v), _ = 1; n   __(1 ?  }  :   ); n } n template <class S, class T> n void __(const map<S, T>& x) { n   __(1 ?  {  :   ); n   bool _ = 0; n   for (const auto& v : x) __(_ ? 1 ?  ,   :     :   ), __(v), _ = 1; n   __(1 ?  }  :   ); n } n void pr() { cout <<   n ; } n template <class S, class... T> n void pr(const S& a, const T&... b) { n   __(a); n   if (sizeof...(b)) __(   ); n   pr(b...); n } n }  // namespace output n using namespace output; n const int MN = 2e5 + 5; n int N, i, x, y, w, vs[MN], st[MN], ring[MN]; n long long nxt[MN], ans[MN], sz[MN], dis[MN], len, idk[MN]; n vector<pair<int, int> > adj[MN]; n stack<int> s; n vector<int> cyc; n void detect(int n, int p) { n   vs[n] = 1; n   st[n] = 1; n   s.push(n); n   for (auto v : adj[n]) { n     if (v.first == p) continue; n     if (!vs[v.first]) detect(v.first, n); n     if (st[v.first]) { n       while (s.size() && s.top() != v.first) { n         cyc.push_back(s.top()); n         s.pop(); n       } n       cyc.push_back(s.top()); n       s.pop(); n     } n   } n   st[n] = 0; n   if (s.size() && s.top() == n) s.pop(); n } n void dfs(int n, int p) { n   sz[n] = 1; n   for (auto v : adj[n]) { n     if (v.first == p || ring[v.first]) continue; n     dfs(v.first, n); n     sz[n] += sz[v.first]; n     ans[n] += 1LL * v.second * sz[v.first]; n     ans[n] += ans[v.first]; n   } n } n void dfs2(int n, int p, long long up) { n   long long acc = 0; n   for (auto v : adj[n]) { n     if (v.first == p) { n       up += 1LL * v.second * (N - sz[n]); n       ans[n] += up; n       continue; n     } n     if (ring[v.first]) continue; n     acc += ans[v.first] + 1LL * v.second * sz[v.first]; n   } n   for (auto v : adj[n]) { n     if (v.first == p || ring[v.first]) continue; n     dfs2(v.first, n, up + acc - ans[v.first] - 1LL * v.second * sz[v.first]); n   } n } n void prop(int n, int p, long long val) { n   ans[n] += val; n   for (auto v : adj[n]) { n     if (v.first == p || ring[v.first]) continue; n     prop(v.first, n, val); n   } n } n int main() { n   for (scanf( %d , &N), i = 1; i <= N; i++) { n     scanf( %d%d%d , &x, &y, &w); n     adj[x].push_back({y, w}); n     adj[y].push_back({x, w}); n   } n   detect(1, 0); n   for (auto v : cyc) ring[v] = 1; n   len = 0; n   for (i = 1; i < (int)cyc.size(); i++) { n     for (auto v : adj[cyc[i]]) { n       if (v.first == cyc[i - 1]) { n         dis[cyc[i]] = dis[v.first] + v.second; n         idk[cyc[i]] = v.second; n         nxt[cyc[i - 1]] = v.second; n         len += v.second; n         break; n       } n     } n   } n   for (auto v : adj[cyc[0]]) { n     if (v.first == cyc.back()) { n       len += v.second; n       nxt[cyc.back()] = v.second; n       idk[cyc[0]] = v.second; n       break; n     } n   } n   long long sigma = 0; n   for (auto v : cyc) { n     dfs(v, 0); n     dfs2(v, 0, 0); n     sigma += ans[v]; n   } n   for (auto v : cyc) { n     prop(v, 0, sigma - ans[v]); n   } n   long long ls = sz[cyc[0]], rs = 0, lsm = 0, rsm = 0, j, dist = idk[cyc[0]]; n   for (i = (int)cyc.size() - 1; i > 0; i--) { n     rs += sz[cyc[i]]; n     rsm += dist * sz[cyc[i]]; n     dist += idk[cyc[i]]; n   } n   dist = 0; n   for (i = j = 0; i < (int)cyc.size(); i++) { n     while ((dist + nxt[cyc[j]]) * 2 <= len) { n       dist += nxt[cyc[j]]; n       j = (j + 1) % cyc.size(); n       long long dis2 = len - dist; n       rs -= sz[cyc[j]]; n       rsm -= 1LL * dis2 * sz[cyc[j]]; n       ls += sz[cyc[j]]; n       lsm += 1LL * dist * sz[cyc[j]]; n     } n     ls -= sz[cyc[i]]; n     rs += sz[cyc[i]]; n     long long cur = lsm + rsm; n     prop(cyc[i], 0, cur); n     if (i + 1 != cyc.size()) { n       long long nxt = dis[cyc[i + 1]] - dis[cyc[i]]; n       lsm -= ls * nxt; n       rsm += rs * nxt; n       dist -= nxt; n     } n   } n   for (i = 1; i <= N; i++) printf( %lld  , ans[i]); n   pr(); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int a, i, b, k, temp; n   while (~scanf( %d , &a) && a >= 0) { n     temp = 0; n     while (a) { n       b = a; n       k = 0; n       while (b > 0) { n         if (k < b % 10) k = b % 10; n         b = b / 10; n       } n       a -= k; n       temp++; n     } n     printf( %d n , temp); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int delta[1000000], cnt[1000000]; n int main() { n   int n, m, dx, dy; n   cin >> n >> m >> dx >> dy; n   int x = 0, y = 0; n   delta[0] = 0; n   for (int i = 1; i < n; ++i) { n     x = (x + dx) % n; n     y = (y + dy) % n; n     delta[x] = y; n   } n   for (int i = 0; i < n; ++i) cnt[i] = 0; n   for (int i = 0; i < m; ++i) { n     cin >> x >> y; n     ++cnt[(y + n - delta[x]) % n]; n   } n   int ans = 0; n   for (int i = 0; i < n; ++i) n     if (cnt[ans] < cnt[i]) ans = i; n   cout << 0 <<     << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000000009; n const double PI = acos(-1.0); n const double eps = 1e-8; n const int MAXN = 0; n const int MAXM = 0; n long long n, k, t, b, z; n int main() { n   z = 1; n   int ans = 0; n   cin >> k >> b >> n >> t; n   while (z <= t) { n     ans++; n     z = z * k + b; n   } n   if (z == t) n     ans = n - ans; n   else { n     ans--; n     ans = n - ans; n   } n   cout << max(0, ans) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long l, i = 0, n, d, t; n   cin >> d >> n; n   if (d != 1 && n == 0) { n     cout <<  No solution n ; n     return 0; n   } n   cout << n; n   for (t = 1; t <= d - 1; t++) cout << 0; n   cout << 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   int a, b, c, d; n   int n; n   cin >> a >> b >> c >> d >> n; n   vector<int> v(n); n   for (int i = 0; i < n; i++) { n     cin >> v[i]; n   } n   cout <<  YES n ; n   int row = max(b, d); n   int col = a + c; n   char ans[row][col]; n   for (int i = 0; i < row; i++) { n     for (int j = 0; j < col; j++) { n       ans[i][j] =  . ; n     } n   } n   int x, y, yc; n   int dir; n   if (d % 2 == 1) { n     y = a + c - 1; n     yc = a; n     x = d - 1; n     dir = -1; n   } else { n     y = a; n     yc = a + c - 1; n     x = d - 1; n     dir = 1; n   } n   int ind = 0; n   for (int i = x; i >= 0; i--) { n     for (int j = y; j < a + c and j > a - 1; j += dir) { n       if (v[ind]) { n         ans[i][j] =  a  + ind; n         v[ind]--; n       } else { n         ind++; n         j -= dir; n       } n     } n     dir = (dir == 1) ? -1 : 1; n     swap(y, yc); n   } n   dir = -1; n   y = a - 1; n   yc = 0; n   for (int i = 0; i < b; i++) { n     for (int j = y; j < a and j >= 0; j += dir) { n       if (v[ind]) { n         ans[i][j] =  a  + ind; n         v[ind]--; n       } else { n         ind++; n         j -= dir; n       } n     } n     dir = (dir == 1) ? -1 : 1; n     swap(y, yc); n   } n   for (int i = 0; i < row; i++) { n     for (int j = 0; j < col; j++) { n       cout << ans[i][j]; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n double dp[110][110][110] = {0}; n double c[110][110] = {0}; n int a[110], n, m; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; ++i) scanf( %d , &a[i]); n   for (int i = 0; i <= n + m; ++i) c[i][0] = 1; n   for (int i = 1; i <= n + m; ++i) n     for (int j = 1; j <= i; ++j) c[i][j] = c[i - 1][j - 1] + c[i - 1][j]; n   for (int i = 0; i <= m; ++i) dp[i][0][0] = 1; n   for (int i = 1; i <= m; ++i) n     for (int j = 1; j <= n; ++j) n       for (int k = 0; k <= j; ++k) { n         int l = max(a[i] * (k - 1) + 1, 0), r = a[i] * k; n         for (int w = 0; w <= k; ++w) n           for (int p = l; p <= min(r, j); ++p) n             dp[i][j][k] += dp[i - 1][j - p][w] * c[n - j + p][p]; n         for (int p = 0; p <= min(l - 1, j); ++p) n           dp[i][j][k] += dp[i - 1][j - p][k] * c[n - j + p][p]; n       } n   double ans = 0; n   for (int i = 1; i <= n; ++i) ans += dp[m][n][i] * i; n   for (int i = 1; i <= n; ++i) ans /= (double)m; n   printf( %.10lf , ans); n   return 0; n } n


#pragma GCC target ( avx2 ) n #pragma GCC optimize ( O3 ) n #pragma GCC optimize ( unroll-loops ) n  n #include<bits/stdc++.h> n using namespace std; n  n // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n // int rnd(int x, int y) {return (rng() % (y-x +1)) + x;}; n  n #define ll long long n #define pb push_back n #define eb emplace_back n #define mp make_pair n #define lb lower_bound n #define ub upper_bound n #define ins insert n #define ull unsigned long long n #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) n #define ff first n #define ss second n #define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); n #define nl   n  n #define sz(a) (int)(a).size() n #define all(a) (a).begin(),(a).end() n #define fl(a,x) memset(a,x,sizeof(a)); n #define pt(a,x) cout << get<x>(a) <<     ; n #define mt make_tuple n #define vec vector n #define mxe max_element n #define mne max_element n #define present(c, x) (c.find(x) != c.end()) n #define printall(a) for(auto i : a) cout << i <<     ; cout << nl ; n  n #define int long long n  n typedef vector<int> vii; n typedef vector<ll> vll; n typedef pair<int,int> pii; n typedef pair<ll,ll> pll; n typedef vector<pii> vpi; n typedef vector<pll> vpl; n typedef vector<vii> vvi; n typedef vector<vll> vvl; n  n #define error(args...) { string _s = #args; replace(_s.begin(), _s.end(),  , ,    ); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); } n  n void err(istream_iterator<string> it) {} n template<typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) { n     cout << *it <<   =   << a << endl; n     err(++it, args...); n } n  n const int mod = (int) 1e9 + 7 ; n const int MOD = (int) 998244353 ; n const ll INF = (ll) 1e18; n  n inline int add(int a, int b) {return (a + b >= mod ? a + b - mod : a + b);} n inline int mul(int a, int b) {return (ll) a * b % mod ; } n  n void solve() { n  n     int n; cin >> n ; n     string s; cin >> s;  n     int ans = 0 ;  n     int id = 0 , cnt = 0 ;  n     int x = count(all(s),  * ) ;  n     rep(i,0,n) { n         cnt += (s[i] ==  * ) ;  n         if(cnt == (x+1)/2) { n             id = i ;  n             break ; n         } n     } n     cnt = 0 ;  n     for(int i = id + 1 ; i < n ; ++i) { n         if(s[i] !=  * ) continue ;  n         ans += i - id - 1 - cnt ;  n         ++cnt ;  n     } n     cnt = 0 ;  n     for(int i = id - 1 ; i >= 0 ; --i) { n         if(s[i] !=  * ) continue ;  n         ans += id - i - 1 - cnt ;  n         ++cnt ;  n     } n     cout << ans << nl ; n }    n  n int32_t main() { n  n     fast; n     int t; cin >> t ; rep(i,0,t)  n         solve() ; n     // cout <<  Time elapsed:   << 1.0 * clock() / CLOCKS_PER_SEC <<   s. n ; n     return 0; n }


#include <bits/stdc++.h> n const double eps = (1e-9); n using namespace std; n int dcmp(long double a, long double b) { n   return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1; n } n int getBit(int num, int idx) { return ((num >> idx) & 1) == 1; } n int setBit1(int num, int idx) { return num | (1 << idx); } n long long setBit0(long long num, int idx) { return num & ~(1ll << idx); } n long long flipBit(int num, int idx) { return num ^ (1 << idx); } n void FS() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n int countNumBit1(int mask) { n   int ret = 0; n   while (mask) { n     mask &= (mask - 1); n     ++ret; n   } n   return ret; n } n const int N = 100009; n int arr[N]; n int main() { n   int n; n   cin >> n; n   int mx = -1; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n     if (arr[i] > mx) { n       mx = arr[i]; n     } n   } n   int mxlen = 1; n   int cnt = 0, str = -1, en = 0; n   for (int i = 0; i < n; i++) { n     if (arr[i] == mx) { n       if (str == -1) str = i; n       en = i; n     } else { n       if (str != -1) mxlen = max(mxlen, en - str + 1); n       str = -1; n     } n   } n   if (str != -1) mxlen = max(mxlen, en - str + 1); n   cout << mxlen << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n pair<long long, long long> ps[300010]; n long long x; n int main() { n   cin >> x; n   if (x == 1) { n     puts( 1 n1 1 ); n     return 0; n   } n   ps[0].first = 1, ps[0].second = x; n   bool f1 = 0; n   long long c = 2, f2 = 0; n   int t = 1; n   while (1) { n     long long re = x - 1ll * c * (c - 1) * (2 * c - 1) / 6; n     long long p = 1ll * c * (c - 1) / 2; n     re += 1ll * c * p; n     long long m1 = re % (1ll * c * c - p); n     long long m = re / (1ll * c * c - p); n     if (c > m) break; n     if (!m1) { n       if (c == m) n         f2 = c; n       else n         ps[t++] = make_pair(c, m); n     } n     c++; n   } n   if (f2) n     cout << (2 * t + 1) << endl; n   else n     cout << (2 * t) << endl; n   for (int i = 0; i < t; i++) { n     cout << ps[i].first <<     << ps[i].second << endl; n   } n   if (f2) cout << f2 <<     << f2 << endl; n   for (int i = t - 1; i >= 0; i--) { n     cout << ps[i].second <<     << ps[i].first << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[20]; n long long b[20]; n int getbit(long long x) { n   int ret = 0; n   while (x) { n     x /= 10; n     ++ret; n   } n   return ret; n } n int main() { n   a[1] = 9; n   b[1] = 9; n   for (int i = 2; i <= 18; ++i) b[i] = b[i - 1] * 10 + 9; n   for (int i = 2; i <= 18; ++i) a[i] = a[i - 1] * 10; n   long long w, m, k; n   while (cin >> w >> m >> k) { n     long long num = getbit(m); n     long long cnt = b[num] - m + 1; n     long long ans = 0; n     if (w <= num * k * cnt || (num * k * cnt) <= 0) { n       ans = w / (num * k); n     } else { n       ans = cnt; n       w -= cnt * num * k; n       for (int i = num + 1; w > 0; ++i) { n         if (w <= a[i] * i * k || a[i] * i * k <= 0) { n           ans += w / (i * k); n           break; n         } else { n           ans += a[i]; n           w -= a[i] * k * i; n         } n       } n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 514; n int mat[MAX][MAX]; n int aib[MAX][MAX]; n int n, m; n int dx[] = {1, 0}; n int dy[] = {0, 1}; n inline int inside(int x, int y) { n   return x <= n and y <= m and x >= 1 and y >= 1; n } n int jos[MAX][MAX]; n int dreapta[MAX][MAX]; n int main() { n   ios ::sync_with_stdio(false); n   cin >> n >> m; n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       char c; n       cin >> c; n       if (c ==  # ) ++mat[i][j]; n     } n   } n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       for (int k = 0; k <= 1; ++k) { n         if (inside(i + dx[k], j + dy[k])) { n           if (mat[i][j] == 0 and mat[i + dx[k]][j + dy[k]] == 0) { n             aib[i][j]++; n             if (k == 0) { n               jos[i][j]++; n             } else { n               dreapta[i][j]++; n             } n           } n         } n       } n       aib[i][j] += aib[i - 1][j]; n       aib[i][j] += aib[i][j - 1]; n       aib[i][j] -= aib[i - 1][j - 1]; n       jos[i][j] += jos[i][j - 1]; n       dreapta[i][j] += dreapta[i - 1][j]; n     } n   } n   int q; n   cin >> q; n   while (q--) { n     int a, b, c, d; n     cin >> a >> b >> c >> d; n     int dr = dreapta[c][d] - dreapta[a - 1][d]; n     int jj = jos[c][d] - jos[c][b - 1]; n     cout << aib[c][d] - aib[c][b - 1] - aib[a - 1][d] + aib[a - 1][b - 1] - dr - n                 jj n          <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> adj[205]; n bool vis[205]; n long long dp[205]; n void dfs(long long v) { n   vis[v] = true; n   for (long long first : adj[v]) { n     if (!vis[first]) { n       dfs(first); n       dp[v] = max(dp[first] + 1, dp[v]); n     } n   } n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   map<string, long long> m; n   long long curr = 2; n   m[ polycarp ] = 1; n   for (long long i = 0; i < n; i++) { n     string s1, s2, s3; n     cin >> s1 >> s2 >> s3; n     for (char &c : s1) c = tolower(c); n     for (char &c : s3) c = tolower(c); n     if (!m[s1]) m[s1] = curr++; n     if (!m[s3]) m[s3] = curr++; n     adj[m[s3]].emplace_back(m[s1]); n   } n   dfs(1); n   cout << dp[1] + 1; n } n


#include <bits/stdc++.h> n int main() { n   long long a, b; n   scanf( %I64d %I64d , &a, &b); n   printf( %I64d n , (6LL * a - 1LL) * b); n   for (long long i = 1; i <= a; i++) { n     printf( %I64d %I64d %I64d %I64d n , (6LL * i - 5LL) * b, n            (6LL * i - 4LL) * b, (6LL * i - 3LL) * b, (6LL * i - 1LL) * b); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   double x, r1 = 0, p1 = 0, p2 = 999999999999, a, b; n   cin >> n; n   while (n--) { n     cin >> x; n     r1 = max(r1, x); n   } n   cin >> n; n   while (n--) { n     cin >> x; n     p1 = max(p1, x); n   } n   cin >> n; n   while (n--) { n     cin >> x; n     p2 = min(p2, x); n   } n   cin >> a >> b; n   x = b * p1; n   double up = x * r1 * r1, down = a * p2 + x; n   cout << setprecision(10) << sqrt(up / down); 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     printf( %d , i); n     for (int j = 1; j < n; j++) { n       int tmp = (i + j) % n; n       if (tmp == 0) tmp = n; n       printf(  %d , j * n + tmp); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct caca { n   long long a, b; n }; n caca v[7005]; n bool ok[7005]; n bool cmp(caca a, caca b) { return a.a < b.a; } n int main() { n   cin.tie(0)->sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> v[i].a; n   for (int i = 1; i <= n; i++) cin >> v[i].b; n   sort(v + 1, v + n + 1, cmp); n   v[0].a = -1; n   v[n + 1].a = -1; n   for (int i = 1; i <= n; i++) { n     if (v[i].a == v[i - 1].a || v[i].a == v[i + 1].a) { n       ok[i] = 1; n       for (int j = 1; j <= n; j++) { n         if ((v[i].a & v[j].a) == v[j].a) { n           ok[j] = 1; n         } n       } n     } n   } n   long long sol = 0; n   for (int i = 1; i <= n; i++) { n     if (ok[i]) { n       sol += v[i].b; n     } n   } n   cout << sol; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100 + 10; n int n, m; n int SG[N << 1]; n  n int main() { n     int T; n     for(scanf( %d , &T); T--; ) { n         scanf( %d%d , &n, &m); n         memset(SG, 0, (n + m) << 2); n         for(int i = 0; i < n; i++) { n             for(int j = 0; j < m; j++) { n                 int x; n                 scanf( %d , &x); n                 SG[i + j] ^= x; n             } n         } n         int flag = 0; n         for(int i = 0; i <= n + m - 2; i++) if(SG[i]) flag = 1; n         if(flag) printf( Ashish n ); n         else printf( Jeel n ); n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   string s; n   cin >> s; n   long long int n = s.length(), i; n   stack<char> a; n   for (i = 0; i < n; i++) { n     if (a.empty()) n       a.push(s[i]); n     else { n       if (a.top() == s[i]) n         a.pop(); n       else n         a.push(s[i]); n     } n   } n   if (a.size() != 0) n     cout <<  No ; n   else n     cout <<  Yes ; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9; n const int N = 122231; n int n, k; n vector<int> g[N]; n int used[N]; n int done[150][150][150]; n int memo[150][150][150]; n vector<int> sons[N]; n int max_dep[N]; n void dfs(int v) { n   used[v] = 1; n   max_dep[v] = 0; n   for (int i = 0; i < g[v].size(); i++) { n     int to = g[v][i]; n     if (used[to]) continue; n     sons[v].push_back(to); n     dfs(to); n     max_dep[v] = max(max_dep[v], max_dep[to] + 1); n   } n } n int solve(int v, int top1, int covered_pref) { n   if (done[v][top1][covered_pref]) return memo[v][top1][covered_pref]; n   done[v][top1][covered_pref] = 1; n   if (top1 == 100) { n     memo[v][top1][covered_pref] = (covered_pref > max_dep[v]); n     return memo[v][top1][covered_pref]; n   } n   if (top1 > k && covered_pref == 0) { n     memo[v][top1][covered_pref] = 0; n     return 0; n   } n   long long ways[2], nways[2]; n   ways[0] = ways[1] = nways[0] = nways[1] = 0; n   if (top1 == 0) { n     ways[1] = 1; n   } else { n     ways[0] = 1; n   } n   for (int i = 0; i < sons[v].size(); i++) { n     int to = sons[v][i]; n     for (int j = 0; j < 2; j++) nways[j] = 0; n     int new_pref = max(covered_pref - 1, k - top1); n     if (new_pref < 0) new_pref = 0; n     for (int dep_there = 0; dep_there <= 100; dep_there++) { n       int is_ok_dep = 1; n       if (dep_there + 1 < top1) is_ok_dep = 0; n       if (dep_there == 100) { n         if (new_pref <= max_dep[to]) is_ok_dep = 0; n       } else { n         int covered2 = dep_there - k; n         if (covered2 > new_pref) is_ok_dep = 0; n       } n       if (is_ok_dep == 0) continue; n       if (solve(to, dep_there, new_pref) == 0) continue; n       for (int j = 0; j < 2; j++) { n         nways[j | ((dep_there + 1) == top1)] = n             1ll * nways[j | ((dep_there + 1) == top1)] + n             1ll * ways[j] * solve(to, dep_there, new_pref) % 1000000007; n         nways[j | ((dep_there + 1) == top1)] %= 1000000007; n       } n     } n     for (int j = 0; j < 2; j++) { n       ways[j] = nways[j]; n     } n   } n   memo[v][top1][covered_pref] = ways[1]; n   return memo[v][top1][covered_pref]; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n >> k; n   for (int i = 1; i < n; i++) { n     int a, b; n     cin >> a >> b; n     g[a].push_back(b); n     g[b].push_back(a); n   } n   int root = 1; n   dfs(root); n   int res = 0; n   for (int i = 0; i <= k; i++) { n     res += solve(root, i, 0); n     res %= 1000000007; n   } n   cout << res << endl; n   cin.get(); n   cin.get(); n   return 0; n } n


#include <bits/stdc++.h> n const int INF = 1 << 29; n using namespace std; n void put(int i) { n   cout << (i == 0 ? 0 : i); n   exit(0); n } n int main() { n   std::ios_base::sync_with_stdio(false); n   std::cin.tie(NULL); n   ; n   int n, x, y; n   cin >> n; n   vector<int> v(n), sum(n); n   for (int i = 0; i < n; ++i) { n     cin >> v[i]; n     if (!i) n       sum[i] = v[i]; n     else n       sum[i] = sum[i - 1] + v[i]; n   } n   cin >> x >> y; n   for (int i = 1; i < n; ++i) { n     int p1 = sum[i - 1]; n     int p2 = sum[n - 1] - sum[i - 1]; n     if (p1 >= x && p1 <= y && p2 >= x && p2 <= y) put(i + 1); n   } n   put(0); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200010, M = 400010, mod = 1e9 + 7; n int n, m, k; n int h[N], e[M], ne[M], idx; n int a[N], b[N], ans[N]; n int ind[N], oud[N], cnt; n bool stn[N], stm[M]; n struct Edge { n   int a, b; n } edge[M]; n void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; } n queue<int> q; n void delet_node() { n   while (!q.empty()) { n     int t = q.front(); n     q.pop(); n     for (int i = h[t]; ~i; i = ne[i]) { n       if (stm[i]) continue; n       int j = e[i]; n       ind[j]--; n       if (ind[j] < k && !stn[j]) { n         q.push(j), stn[j] = 1, cnt--; n       } n     } n   } n } n void topsort() { n   for (int i = 1; i <= n; i++) { n     if (ind[i] < k) q.push(i), cnt--, stn[i] = 1; n   } n   delet_node(); n   for (int i = m; i >= 1; i--) { n     ans[i] = cnt; n     int a = edge[i].a, b = edge[i].b; n     if (!stn[a] && !stn[b]) ind[a]--, ind[b]--; n     stm[--idx] = 1, stm[--idx] = 1; n     if (ind[a] < k && !stn[a]) q.push(a), stn[a] = 1, cnt--; n     if (ind[b] < k && !stn[b]) q.push(b), stn[b] = 1, cnt--; n     delet_node(); n   } n   for (int i = 1; i <= m; i++) cout << ans[i] << endl; n } n int main() { n   memset(h, -1, sizeof h); n   scanf( %d%d%d , &n, &m, &k); n   cnt = n; n   for (int i = 1; i <= m; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     edge[i] = {a, b}; n     add(a, b), add(b, a); n     ind[a]++, ind[b]++; n   } n   topsort(); n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> g[200009]; n int c[200009]; n set<int> col[200009]; n int main() { n   int n, m; n   scanf( %d , &n); n   scanf( %d , &m); n   int fans = 1e6; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &c[i]); n     fans = min(fans, c[i]); n   } n   for (int i = 0; i < m; i++) { n     int x, y; n     scanf( %d , &x); n     scanf( %d , &y); n     g[x].push_back(y); n     g[y].push_back(x); n   } n   for (int i = 1; i <= n; i++) { n     int id = c[i]; n     for (int j = 0; j < g[i].size(); j++) { n       if (c[g[i][j]] != id) { n         col[id].insert(c[g[i][j]]); n       } n     } n   } n   int maxx = -1, maxid = -1; n   for (int i = 1; i <= 100000; i++) { n     int sz = col[i].size(); n     if (maxx < sz) { n       maxx = sz; n       maxid = i; n     } n   } n   if (maxx == 0) { n     maxid = fans; n   } n   printf( %d n , maxid); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using lli = long long int; n using pii = pair<int, int>; n using vi = vector<int>; n using vb = vector<bool>; n using vvi = vector<vector<int>>; n using vlli = vector<long long int>; n using vpii = vector<pair<int, int>>; n const int N = 500005; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n lli n, m, k, u, v, x, ans, curr, T; n vlli c(N); n lli fast_exp(lli base, lli exp) { n   lli res = 1; n   base = base % 1000000007; n   while (exp > 0) { n     if (exp % 2) res = (res * base) % 1000000007; n     base = (base * base) % 1000000007; n     exp /= 2; n   } n   return res % 1000000007; n } n template <class T> n struct DSU { n   map<T, T> par; n   T comp_sz = n; n   T get(T u) { n     if (par.find(u) == par.end()) return u; n     return par[u] = get(par[u]); n   } n   void unite(T x, T y) { n     T X = get(x), Y = get(y); n     if (X == Y) return; n     par[X] = Y; n     --comp_sz; n   } n }; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m >> k; n   map<lli, DSU<lli>> virus; n   for (int i = 1; i <= n; i++) cin >> c[i]; n   for (int i = 1; i <= m; i++) { n     cin >> u >> v; n     x = c[u] ^ c[v]; n     virus[x].unite(u, v); n   } n   ans = ((fast_exp(2, k) - virus.size() + 1000000007) * fast_exp(2, n)) % n         1000000007; n   for (auto i : virus) { n     curr = (i.second).comp_sz; n     ans = (ans + fast_exp(2, curr)) % 1000000007; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n const double eps = pi / 180.0; n int main() { n   int t; n   cin >> t; n   while (t--) { n     double n; n     cin >> n; n     double angle = 180.0 / n; n     double first = 1.0 / 2.0 / sin(angle / 2.0 * eps); n     double a1 = 180.0 / n * round(n / 4.0); n     double a2 = 90 - a1; n     double ans = first * (sin(a1 * eps) + sin(a2 * eps)) / sin(45.0 * eps); n     printf( %.9lf n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   set<char> c; n   int mul = 0; n   long long ans = 1; n   bool f = false; n   string s; n   cin >> s; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] ==  ? ) n       ans *= 10; n     else if (s[i] >= 65 && s[i] <= 74) n       c.insert(s[i]); n   } n   if (s[0] >= 65 && s[0] <= 74 || s[0] ==  ? ) f = true; n   for (int i = 0; i < c.size(); i++) ans *= (10 - i); n   if (f == true) ans *= 0.9; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool f[1005]; n vector<int> x[1005]; n vector<int> y[1005]; n int dx[4] = {1, 1, -1, -1}; n int dy[4] = {1, -1, 1, -1}; n int main() { n   for (int i = 1; i <= 1000; i++) { n     for (int j = 1; j <= 1000; j++) { n       int p = i * i + j * j; n       int u = (int)(sqrt(p)); n       if (u * u == p && u <= 1000) { n         f[u] = 1; n         x[u].push_back(i); n         y[u].push_back(j); n       } n     } n   } n   int a, b; n   scanf( %d%d , &a, &b); n   if (f[a] && f[b]) { n     for (int r = 0; r < x[a].size(); r++) n       for (int s = 0; s < x[b].size(); s++) { n         int u = x[a][r], v = y[a][r]; n         for (int i = 0; i < 4; i++) { n           int p = u * dx[i]; n           int q = v * dy[i]; n           if (x[b][s] * p + y[b][s] * q == 0 && n               (x[b][s] != p && y[b][s] != q)) { n             printf( YES n ); n             printf( 0 0 n ); n             printf( %d %d n , x[b][s], y[b][s]); n             printf( %d %d n , p, q); n             return 0; n           } n         } n         swap(u, v); n         for (int i = 0; i < 4; i++) { n           int p = u * dx[i]; n           int q = v * dy[i]; n           if (x[b][s] * p + y[b][s] * q == 0 && n               (x[b][s] != p && y[b][s] != q)) { n             printf( YES n ); n             printf( 0 0 n ); n             printf( %d %d n , x[b][s], y[b][s]); n             printf( %d %d n , p, q); n             return 0; n           } n         } n       } n     printf( NO n ); n   } else n     printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int m, k, n, s; n   cin >> m >> k >> n >> s; n   int len = m - k * (n - 1); n   vector<int> a(m); n   for (auto& i : a) { n     cin >> i; n   } n   int bad = 0; n   vector<int> cnt(5e5 + 1); n   for (int i = 0; i < s; ++i) { n     int b; n     cin >> b; n     bad += !cnt[b]; n     ++cnt[b]; n   } n   bool ok = false; n   vector<int> ans; n   for (int i = 0; i < m; ++i) { n     --cnt[a[i]]; n     bad -= !cnt[a[i]]; n     int j = i - len + 1; n     if (j >= 0) { n       if (!bad && j % k == 0) { n         for (int l = j; len - int(ans.size()) > k; ++l) { n           if (cnt[a[l]] < 0) { n             ans.push_back(l); n             ++cnt[a[l]]; n           } n         } n         ok = true; n         break; n       } n       bad += !cnt[a[j]]; n       ++cnt[a[j]]; n     } n   } n   if (!ok) { n     cout << -1 <<   n ; n   } else { n     cout << ans.size() <<   n ; n     for (auto i : ans) { n       cout << i + 1 <<    ; n     } n   } n } n


#include <bits/stdc++.h> n const int maxn = 5e5 + 5; n const int logn = 21; n const int lim = 2e1; n const int maxq = 5e5 + 5; n struct w { n   int l, r, id; n   friend bool operator<(w now, w oth) { return now.r < oth.r; } n } qu[maxq]; n int b[logn], p[logn]; n void insert(int gave, int id) { n   for (int i = lim; i >= 0; i--) { n     if (!(gave >> i & 1)) continue; n     if (!b[i]) { n       b[i] = gave; n       p[i] = id; n       return; n     } n     if (p[i] < id) { n       std::swap(p[i], id); n       std::swap(b[i], gave); n     } n     gave ^= b[i]; n   } n   return; n } n int tian(int lef) { n   int r = 0; n   for (int i = lim; i >= 0; i--) n     if (p[i] >= lef) r = std::max(r, r ^ b[i]); n   return r; n } n int o[maxq]; n int n, q; n int v[maxn]; n signed main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , v + i); n   scanf( %d , &q); n   for (int i = 1; i <= q; i++) { n     scanf( %d%d , &qu[i].l, &qu[i].r); n     qu[i].id = i; n   } n   std::sort(qu + 1, qu + q + 1); n   int nr = 0; n   for (int i = 1; i <= q; i++) { n     while (nr < qu[i].r) { n       nr++; n       insert(v[nr], nr); n     } n     o[qu[i].id] = tian(qu[i].l); n   } n   for (int i = 1; i <= q; i++) printf( %d n , o[i]); n   return 0; n } n


#include <queue> n #include <vector> n #include <stdio.h> n #include <stdlib.h> n  n #define DEBUG printf( Passing [%s] in Line %d n  , __FUNCTION__ , __LINE__) ; n  n const int MAX_N = (1 << 11) + 10 , MAX_M = 10 + 5 , MAX_E = (1 << 22) + 10 , INF = 0x3f3f3f3f ; n  n struct Link { n  int num , cap , cost ; n  Link *next , *reg ; n }list[MAX_E] ; n  n std::queue<int> q ; n std::vector<int> ans ; n  n char s[MAX_N][MAX_M] ; n Link *head[MAX_N] , *id[MAX_N] ; n bool st[MAX_N] , ud[MAX_M] , vis[MAX_N] ; n int n , m , tot , cur , pt[MAX_N][2] , lt[MAX_N] ; n int S , T , pre[MAX_N] , dis[MAX_N] , flow[MAX_N] ; n  n void ins(int x , int y , int f , int c) { n  list[cur].num = y ; n  list[cur].cap = f ; n  list[cur].cost = c ; n  list[cur].reg = &list[cur + 1] ; n  list[cur].next = head[x] ; n  head[x] = &list[cur++] ; n  n  list[cur].num = x ; n  list[cur].cap = 0 ; n  list[cur].cost = -c ; n  list[cur].reg = &list[cur - 1] ; n  list[cur].next = head[y] ; n  head[y] = &list[cur++] ; n } n  n /// n  n bool spfa() { n  for (int i = 0 ; i <= tot ; ++i) dis[i] = INF , vis[i] = 0 ; n  vis[S] = 1 ; dis[S] = 0 ; flow[S] = INF ; q.push(S) ; n  n  while (!q.empty()) { n   int x = q.front() ; vis[x] = 0 ; q.pop() ; n  n   for (Link *h = head[x] ; h ; h = h->next) { n    int nx = h->num ; n    if (dis[nx] <= dis[x] + h->cost || !h->cap) continue ; n  n    flow[nx] = std::min(flow[x] , h->cap) ; n    dis[nx] = dis[x] + h->cost ; n    pre[nx] = x ; id[nx] = h ; n  n    if (!vis[nx]) {vis[nx] = 1 ; q.push(nx) ;} n   } n  } n  n  return dis[T] < INF ; n } n  n void dinic() { n  while (spfa()) { n   int x = T ; n   for (; x != S ; x = pre[x]) { n    id[x]->cap -= flow[T] ; n    id[x]->reg->cap += flow[T] ; n   } n  } n } n  n /// n  n int main() { n  scanf( %d %d  , &m , &n) ; n  for (int i = 1 ; i <= n ; ++i) scanf( %s  , s[i]) ; n  n  /// n  n  for (int i = 1 ; i <= n ; ++i) pt[i][0] = ++tot , pt[i][1] = ++tot ; n  S = 0 ; T = ++tot ; n  n  for (int i = 1 ; i <= n ; ++i) { n   int cnt = 1 ; n   for (int j = 0 ; j < m ; ++j) if (s[i][j] ==  1 ) ++cnt ; n  n   for (int j = 1 ; j <= n ; ++j) { n    if (i == j) continue ; n  n    bool ok = 1 ; n    for (int k = 0 ; k < m ; ++k) if (s[i][k] ==  1  && s[j][k] ==  0 ) ok = 0 ; n    if (ok) ins(pt[i][0] , pt[j][1] , 1 , -cnt) ; n   } n  } n  n  for (int i = 1 ; i <= n ; ++i) n   ins(S , pt[i][0] , 1 , 0) , ins(pt[i][1] , T , 1 , 0) ; n  n  /// n  n  dinic() ; n  for (int i = 1 ; i <= n ; ++i) { n   int x = pt[i][0] ; n   for (Link *h = head[x] ; h ; h = h->next) { n    int nx = h->num ; n    if (h->cap || !nx) continue ; n  n    nx >>= 1 ; n    lt[(x + 1) >> 1] = nx ; st[nx] = 1 ; n   } n  } n  n  /// n  n  for (int i = 1 ; i <= n ; ++i) n   if (!st[i]) { n    for (int j = 0 ; j < m ; ++j) ud[j] = 0 ; n    for (int j = i ; j ; j = lt[j]) n     for (int k = 0 ; k < m ; ++k) n      if (s[j][k] ==  1  && !ud[k]) ans.push_back(k) , ud[k] = 1 ; n    ans.push_back(-1) ; n   } n  n  int m = ans.size() - 1 ; n  printf( %d n  , m) ; n  for (int i = 0 ; i < m ; ++i) { n   int x = ans[i] ; n   if (x == -1) printf( R  ) ; n   else printf( %d   , x) ; n  } n  printf(  n ) ; n  n  return 0 ; n }


#include <bits/stdc++.h> n using namespace std; n template <class t> n t mag(t a) { n   return a > 0 ? a : -a; n } n template <class T> n T cdiv(T num, T den) { n   return (num / den) + (num % den > 0); n } n std::ifstream term( /dev/tty ); n std::string tempstring; n using ll = int_fast64_t; n using ii = pair<ll, ll>; n using vi = vector<int>; n using vl = vector<ll>; n using vii = vector<ii>; n int tc = 1; n const ll sij = 40001000; n const ll mod = 1000000007ll; n ll n, m; n bool vis[1510][1510]; n string vec[1510]; n int mx[] = {0, 0, -1, 1}, my[] = {-1, 1, 0, 0}; n ii st; n ll msk[1510][1510], msy[1510][1510]; n int esc(int tcase) { n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     cin >> vec[i]; n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (vec[i][j] ==  S ) { n         st = {i, j}; n       } n     } n   } n   st.first = st.first + n * mod; n   st.second = st.second + m * mod; n   msk[st.first % n][st.second % m] = st.first; n   msy[st.first % n][st.second % m] = st.second; n   queue<ii> q; n   q.push(st); n   while (!q.empty()) { n     ii cr = q.front(); n     q.pop(); n     for (int i = 0; i < 4; i++) { n       ll gx = cr.first + mx[i], gy = cr.second + my[i]; n       if (vec[gx % n][gy % m] ==  # ) continue; n       if (msk[gx % n][gy % m] == 0) { n         q.push({gx, gy}); n         msk[gx % n][gy % m] = gx; n         msy[gx % n][gy % m] = gy; n         continue; n       } n       if (msk[gx % n][gy % m] != gx or msy[gx % n][gy % m] != gy) { n         cout <<  Yes ; n         return 0; n       } n     } n   } n   cout <<  No ; n   return 0; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   for (int i = 1; i <= tc; i++) esc(i); n } n


#include <bits/stdc++.h> n using namespace std; n char ch, B[1 << 20], *S = B, *T = B; n long long aa, bb; n long long rd() { n   while (ch = (S == T && (T = (S = B) + fread(B, 1, 1 << 20, stdin), S == T) n                    ? 0 n                    : *S++), n          !(ch >=  0  && ch <=  9 ) && ch !=  - ) n     ; n   ch ==  -  ? aa = bb = 0 : (aa = ch -  0 , bb = 1); n   while (ch = (S == T && (T = (S = B) + fread(B, 1, 1 << 20, stdin), S == T) n                    ? 0 n                    : *S++), n          (ch >=  0  && ch <=  9 )) n     aa = aa * 10 + ch -  0 ; n   return bb ? aa : -aa; n } n const long long MAXN = 1e5 + 10; n long long n, k, ans, b[MAXN], tr[MAXN]; n struct Node { n   long long pos, l, r, q, len; n } a[MAXN]; n bool cmp1(Node a, Node b) { return a.len > b.len; } n bool cmp2(Node a, Node b) { return a.q < b.q; } n inline void add(long long x, long long c) { n   while (x <= n) { n     tr[x] += c; n     x += (x & (-x)); n   } n } n long long sum(long long x) { n   long long ret = 0; n   while (x) { n     ret += tr[x]; n     x -= (x & (-x)); n   } n   return ret; n } n long long query(long long l, long long r) { return sum(r) - sum(l - 1); } n inline void cdq(long long l, long long r) { n   if (l == r) return; n   long long mid = (l + r) >> 1; n   cdq(l, mid); n   cdq(mid + 1, r); n   long long L = l, R = l - 1; n   for (register long long i = mid + 1; i <= r; ++i) { n     while (L <= mid && a[i].q - a[L].q > k) { n       add(a[L].pos, -1); n       ++L; n     } n     while (R < mid && a[R + 1].q - a[i].q <= k) { n       ++R; n       add(a[R].pos, 1); n     } n     ans += query(a[i].l, a[i].r); n   } n   for (register long long i = L; i <= R; ++i) add(a[i].pos, -1); n   sort(a + l, a + r + 1, cmp2); n } n inline void work() { n   n = rd(); n   k = rd(); n   for (register long long i = 1; i <= n; ++i) { n     a[i].pos = rd(); n     a[i].len = rd(); n     a[i].q = rd(); n     b[i] = a[i].pos; n   } n   sort(b + 1, b + n + 1); n   long long cnt = unique(b + 1, b + n + 1) - b - 1; n   for (register long long i = 1; i <= n; ++i) { n     a[i].l = lower_bound(b + 1, b + cnt + 1, a[i].pos - a[i].len) - b; n     a[i].r = upper_bound(b + 1, b + cnt + 1, a[i].pos + a[i].len) - b - 1; n     a[i].pos = lower_bound(b + 1, b + cnt + 1, a[i].pos) - b; n   } n   sort(a + 1, a + n + 1, cmp1); n   cdq(1, n); n   printf( %lld n , ans); n } n signed main() { n   work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void splitstr(const string &s, vector<T> &out) { n   istringstream in(s); n   out.clear(); n   copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out)); n } n template <class T> n T gcd(T a, T b) { n   return b ? gcd(b, a % b) : a; n } n static void redirect(int argc, const char **argv) { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   if (argc > 1) { n     static filebuf f; n     f.open(argv[1], ios::in); n     cin.rdbuf(&f); n     if (!cin) { n       cerr <<  Failed to open    << argv[1] <<     << endl; n       exit(1); n     } n   } n   if (argc > 2) { n     static filebuf f; n     f.open(argv[2], ios::out | ios::trunc); n     cout.rdbuf(&f); n     if (!cout) { n       cerr <<  Failed to open    << argv[2] <<     << endl; n     } n   } n } n static void no() { n   cout <<  -1 n ; n   exit(0); n } n static void check_dist(const vector<int> &dist, n                        const vector<vector<int>> &edges, int cur, int parent, n                        int depth) { n   if (dist[cur] != depth) no(); n   for (int v : edges[cur]) n     if (v != parent) check_dist(dist, edges, v, cur, depth + 1); n } n int main(int argc, const char **argv) { n   redirect(argc, argv); n   int N, K; n   cin >> N >> K; n   vector<vector<int>> dist(K, vector<int>(N)); n   vector<int> opos(K, -1); n   for (int i = 0; i < K; i++) n     for (int j = 0; j < N; j++) { n       cin >> dist[i][j]; n       if (dist[i][j] == 0) opos[i] = j; n     } n   if (count(begin(opos), end(opos), -1)) no(); n   int root = opos[0]; n   vector<int> parent(N, -1); n   parent[root] = -2; n   vector<vector<int>> order(K); n   for (int i = 1; i < K; i++) { n     if (dist[i][root] == 0) no(); n     order[i].resize(dist[i][root] + 1, -1); n     for (int j = 0; j < N; j++) n       if (dist[i][j] + dist[0][j] == dist[i][root]) order[i][dist[0][j]] = j; n     if (order[i][0] != root) no(); n     for (int j = 1; j < ((long long)(order[i]).size()); j++) { n       int v = order[i][j]; n       if (v == -1) no(); n       if (parent[v] != -1 && parent[v] != order[i][j - 1]) no(); n       parent[v] = order[i][j - 1]; n     } n   } n   vector<vector<pair<int, int>>> down(N); n   for (int i = 0; i < N; i++) n     if (parent[i] == -1) { n       int hi = -1; n       int v = root; n       int d = dist[0][i]; n       pair<int, int> best(0, 0); n       for (int j = 1; j < K; j++) { n         int a = dist[0][i] + dist[j][root] - dist[j][i]; n         if (a < 0 || a > 2 * dist[j][root] || (a & 1)) no(); n         a /= 2; n         if (a > hi) { n           hi = a; n           v = order[j][a]; n           d = dist[0][i] - a; n         } n       } n       down[v].emplace_back(d, i); n     } n   vector<int> lvl; n   for (int i = 0; i < N; i++) { n     if (down[i].empty()) continue; n     sort(begin(down[i]), end(down[i])); n     lvl.clear(); n     lvl.push_back(i); n     for (const auto &entry : down[i]) { n       int d = entry.first; n       int v = entry.second; n       if (d > ((long long)(lvl).size())) n         no(); n       else { n         parent[v] = lvl[d - 1]; n         if (d == ((long long)(lvl).size())) lvl.push_back(v); n       } n     } n   } n   vector<vector<int>> edges(N); n   for (int i = 0; i < N; i++) { n     if (parent[i] == -1) n       no(); n     else if (parent[i] >= 0) { n       edges[parent[i]].push_back(i); n       edges[i].push_back(parent[i]); n     } n   } n   for (int i = 0; i < K; i++) check_dist(dist[i], edges, opos[i], -1, 0); n   for (int i = 0; i < N; i++) n     if (parent[i] >= 0) cout << i + 1 <<     << parent[i] + 1 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, i, sum1, sum2, sum3; n   scanf( %d , &n); n   sum1 = 0; n   for (i = 0; i < n; i++) { n     int a; n     scanf( %d , &a); n     sum1 ^= a; n   } n   sum2 = 0; n   for (i = 0; i < n - 1; i++) { n     int b; n     scanf( %d , &b); n     sum2 ^= b; n   } n   sum3 = 0; n   for (i = 0; i < n - 2; i++) { n     int c; n     scanf( %d , &c); n     sum3 ^= c; n   } n   printf( %d n%d n , sum1 ^ sum2, sum2 ^ sum3); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = ~0U >> 1; n const long long INF = ~0ULL >> 1; n template <class T> n inline void read(T &n) { n   char c; n   int flag = 1; n   for (c = getchar(); !(c >=  0  && c <=  9  || c ==  - ); c = getchar()) n     ; n   if (c ==  - ) n     flag = -1, n = 0; n   else n     n = c -  0 ; n   for (c = getchar(); c >=  0  && c <=  9 ; c = getchar()) n = n * 10 + c -  0 ; n   n *= flag; n } n int v[100][100], d[100][100]; n char str[10000]; n int n; n void p0() { n   for (int j = 1; j <= 4; j += 3) n     for (int i = 1; i <= 4; i += 2) n       if (!v[i][j] && !v[i + 1][j]) { n         v[i][j] = v[i + 1][j] = 1; n         printf( %d %d n , i, j); n         return; n       } n   assert(0); n } n void p1() { n   for (int i = 1; i <= 4; i++) n     if (!v[i][2] && !v[i][3]) { n       v[i][2] = v[i][3] = 1; n       printf( %d %d n , i, 2); n       return; n     } n   assert(0); n } n int main(int argc, char *argv[]) { n   scanf( %s , str); n   n = strlen(str); n   for (int i = (0); i < (n); ++i) { n     if (str[i] ==  0 ) { n       p0(); n     } else { n       p1(); n     } n     for (int x = (1); x <= (4); ++x) n       for (int y = (1); y <= (4); ++y) { n         d[x][y] = false; n         bool ok = true; n         for (int z = (1); z <= (4); ++z) n           if (!v[x][z]) ok = false; n         if (ok) d[x][y] = true; n         ok = true; n         for (int z = (1); z <= (4); ++z) n           if (!v[z][y]) ok = false; n         if (ok) d[x][y] = true; n       } n     for (int x = (1); x <= (4); ++x) n       for (int y = (1); y <= (4); ++y) n         if (d[x][y]) v[x][y] = 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n int main() { n   cin >> s; n   s =     + s; n   int dem = 0; n   for (int i = 1; i <= s.size() - 1; i++) { n     if (s[i] < 97 && (s[i] -  0 ) % 2 != 0) n       dem++; n     else if (s[i] ==  a  || s[i] ==  e  || s[i] ==  i  || s[i] ==  o  || n              s[i] ==  u ) n       dem++; n   } n   cout << dem; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, i, j, k, l; n long long p[10004], ans; n int main() { n   cin >> n >> m >> k; n   for (int i_ = 0; i_ < n; ++i_) cin >> p[i_]; n   ; n   ans = 0; n   if (n & 1) { n     if (m >= n / 2 + 1) { n       int mn = 2e9; n       for (i = 0; i < n; i += 2) mn = ((mn) < (p[i]) ? (mn) : (p[i])); n       l = m / (n / 2 + 1); n       ans = ((mn) < (l * k) ? (mn) : (l * k)); n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int x, int y) { n   if (x) n     return (gcd(y % x, x)); n   else n     return y; n } n int main() { n   int a, b, n; n   cin >> a >> b >> n; n   for (int i = 0; i < 1000; i++) { n     int x = gcd(a, n); n     if (x <= n) n       n -= x; n     else { n       cout << 1; n       return 0; n     } n     x = gcd(b, n); n     if (x <= n) n       n -= x; n     else { n       cout << 0; n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1001010; n int a[maxn]; n void solve() { n   int n; n   cin >> n; n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n   } n   int cnt = 0; n   for (int i = 0; i < n and a[i] >= i; ++i, ++cnt) { n   } n   for (int i = n - 1; i >= 0 and a[i] >= n - 1 - i; --i, ++cnt) { n   } n   cout << (cnt > n ?  Yes  :  No ) << endl; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int mark[201000 << 2]; n int A[201000], n, m; n struct ST { n   int val[2], las, len; n   void update(ST a, ST b) { n     b.val[1] -= a.las; n     b.val[0] += a.las; n     if (b.len & 1) n       b.las -= a.las; n     else n       b.las += a.las; n     val[0] = min(a.val[0], b.val[a.len & 1]); n     val[1] = min(a.val[1], b.val[(a.len & 1) ^ 1]); n     las = b.las; n     len = a.len + b.len; n     return; n   } n } node[201000 << 2]; n void build(int u, int L, int R) { n   if (L == R) { n     node[u].val[0] = 0; n     node[u].val[1] = node[u].las = A[L]; n     node[u].len = 1; n     return; n   } n   build((u << 1), L, ((L + R) >> 1)); n   build(((u << 1) | 1), (((L + R) >> 1) + 1), R); n   node[u].update(node[(u << 1)], node[((u << 1) | 1)]); n } n void down(int u, int L, int R) { n   if (!mark[u]) return; n   node[u].val[1] += mark[u]; n   if (node[u].len & 1) node[u].las += mark[u]; n   if (L < R) mark[(u << 1)] += mark[u], mark[((u << 1) | 1)] += mark[u]; n   mark[u] = 0; n   return; n } n void change(int u, int L, int R, int l, int r, int k) { n   down(u, L, R); n   if (L == l && R == r) { n     mark[u] += k; n     down(u, L, R); n     return; n   } n   if (r < (((L + R) >> 1) + 1)) n     down(((u << 1) | 1), (((L + R) >> 1) + 1), R), n         change((u << 1), L, ((L + R) >> 1), l, r, k); n   else if (l > ((L + R) >> 1)) n     down((u << 1), L, ((L + R) >> 1)), n         change(((u << 1) | 1), (((L + R) >> 1) + 1), R, l, r, k); n   else { n     change((u << 1), L, ((L + R) >> 1), l, ((L + R) >> 1), k); n     change(((u << 1) | 1), (((L + R) >> 1) + 1), R, (((L + R) >> 1) + 1), r, k); n   } n   node[u].update(node[(u << 1)], node[((u << 1) | 1)]); n } n ST query(int u, int L, int R, int l, int r) { n   down(u, L, R); n   if (L == l && R == r) return node[u]; n   if (r < (((L + R) >> 1) + 1)) n     return query((u << 1), L, ((L + R) >> 1), l, r); n   else if (l > ((L + R) >> 1)) n     return query(((u << 1) | 1), (((L + R) >> 1) + 1), R, l, r); n   else { n     ST a = query((u << 1), L, ((L + R) >> 1), l, ((L + R) >> 1)); n     ST b = n         query(((u << 1) | 1), (((L + R) >> 1) + 1), R, (((L + R) >> 1) + 1), r); n     a.update(a, b); n     return a; n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &A[i]); n   build(1, 1, n); n   for (scanf( %d , &m); m; m--) { n     int t, L, R, k; n     scanf( %d %d %d , &t, &L, &R); n     L++, R++; n     if (t == 1) { n       scanf( %d , &k); n       change(1, 1, n, L, R, k); n     } else { n       ST ans = query(1, 1, n, L, R); n       if (ans.val[0] >= 0 && ans.val[1] >= 1 && ans.las - (ans.len & 1) == 0) n         printf( 1 n ); n       else n         printf( 0 n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a[101]; n   bool f = 1; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] == 1) f = 0; n   } n   if (f) n     puts( EASY ); n   else n     puts( HARD ); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 7; n const int inf = INT_MAX; n const long long inff = 1e18; n const long long mod = 1e9 + 7; n long long n, p, k; n long long a[maxn]; n set<long long> s; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> p >> k; n   for (long long i = 1; i <= n; i++) { n     cin >> a[i]; n     long long now = a[i]; n     a[i] = a[i] * a[i] % p * a[i] % p * a[i] % p; n     a[i] = (a[i] + p - k * now % p) % p; n     s.insert(a[i]); n   } n   sort(a + 1, a + n + 1); n   long long ans = 0; n   for (long long i : s) { n     long long now = n         upper_bound(a + 1, a + n + 1, i) - lower_bound(a + 1, a + n + 1, i); n     ans = (ans + now * (now - 1) / 2); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1000 * 1000 * 1000 + 7; n struct suffix_array { n   vector<int> sa; n   vector<int> lcp; n   vector<vector<int>> st; n   vector<int> log2; n   vector<int> c; n   string str; n   int n; n   void sort_pairs(vector<pair<pair<int, int>, int>>& a) { n     vector<int> beg(n + 20); n     for (int i = 0; i < n; i++) { n       beg[a[i].first.second + 1]++; n     } n     for (int i = 0; i < beg.size() - 1; i++) { n       beg[i + 1] += beg[i]; n     } n     vector<pair<pair<int, int>, int>> sorted(n); n     for (int i = 0; i < n; i++) { n       sorted[beg[a[i].first.second]] = a[i]; n       beg[a[i].first.second]++; n     } n     beg.assign(beg.size(), 0); n     for (int i = 0; i < n; i++) { n       beg[sorted[i].first.first + 1]++; n     } n     for (int i = 0; i < beg.size() - 1; i++) { n       beg[i + 1] += beg[i]; n     } n     for (int i = 0; i < n; i++) { n       a[beg[sorted[i].first.first]] = sorted[i]; n       beg[sorted[i].first.first]++; n     } n   } n   suffix_array(string s) { n     s +=  $ ; n     n = s.length(); n     str = s; n     c.assign(n, 0); n     for (int i = 0; i < n; i++) { n       if (s[i] >=  0  && s[i] <=  9 ) { n         c[i] = (int)(s[i] -  0  + 1); n       } else { n         c[i] = 0; n       } n     } n     vector<pair<pair<int, int>, int>> pairs(n); n     for (int j = 0; (1 << (j - 1)) < n; j++) { n       for (int i = 0; i < n; i++) { n         pairs[i] = {{c[i], c[(i + (1 << j)) % n]}, i}; n       } n       sort_pairs(pairs); n       int cc = 0; n       c[pairs[0].second] = cc; n       for (int i = 1; i < n; i++) { n         if (pairs[i].first != pairs[i - 1].first) cc++; n         c[pairs[i].second] = cc; n       } n     } n     sa.assign(n, 0); n     for (int i = 0; i < n; i++) { n       sa[c[i]] = i; n     } n     lcp.assign(n, 0); n     int k = 0; n     for (int i = 0; i < n; i++) { n       int a = i; n       if (c[i] == n - 1) { n         k = 0; n         continue; n       } n       int b = sa[c[i] + 1]; n       if (k > 0) k--; n       while (max(a + k, b + k) < n && s[a + k] == s[b + k]) { n         k++; n       } n       lcp[c[i]] = k; n     } n     log2.assign(n + 1, 0); n     log2[1] = 0; n     for (int i = 2; i <= n; i++) { n       log2[i] = log2[i / 2] + 1; n     } n     st.assign(log2[n] + 1, vector<int>(n)); n     for (int i = 0; i < n; i++) { n       st[0][i] = lcp[i]; n     } n     for (int j = 1; j < st.size(); j++) { n       for (int i = 0; i + (1 << j) <= n; i++) { n         st[j][i] = min(st[j - 1][i], st[j - 1][i + (1 << (j - 1))]); n       } n     } n   } n   int compare(int i, int len_i, int j, int len_j) { n     if (i == j && len_i == len_j) return 0; n     int pos_i = i; n     int pos_j = j; n     i = c[i]; n     j = c[j]; n     if (i > j) swap(i, j); n     j--; n     int l = log2[j - i + 1]; n     int lcp_ans = min(st[l][i], st[l][j - (1 << l) + 1]); n     int len = min(len_i, len_j); n     lcp_ans = min(lcp_ans, len); n     if (lcp_ans == len) { n       if (len_i == len_j) { n         return 0; n       } else if (len_i > len_j) { n         return 1; n       } else { n         return -1; n       } n     } else if (str[pos_i + lcp_ans] > str[pos_j + lcp_ans]) { n       return 1; n     } else { n       return -1; n     } n   } n }; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   string s; n   cin >> s; n   suffix_array sa(s); n   vector<vector<int>> dp(n + 1, vector<int>(n + 1)); n   vector<vector<int>> sums(n + 1, vector<int>(n + 1)); n   dp[0][0] = 1; n   dp[1][1] = 1; n   sums[0].assign(n + 1, 1); n   for (int i = 1; i <= n; i++) { n     sums[1][i] = 1; n   } n   for (int i = 2; i <= n; i++) { n     for (int j = 1; j <= i; j++) { n       if (s[i - j] ==  0 ) { n         dp[i][j] = 0; n         sums[i][j] = sums[i][j - 1]; n         continue; n       } n       if (j <= i - j && sa.compare(i - j, j, i - j - j, j) > 0) { n         dp[i][j] += dp[i - j][j]; n         dp[i][j] %= mod; n       } n       dp[i][j] += sums[i - j][j - 1]; n       dp[i][j] %= mod; n     } n     for (int j = 1; j <= n; j++) { n       sums[i][j] = sums[i][j - 1] + dp[i][j]; n       sums[i][j] %= mod; n     } n   } n   long long ans = 0; n   for (int i = 0; i <= n; i++) { n     ans += dp[n][i]; n     ans %= mod; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n typedef struct { n   int dollar; n   int cent; n } money; n money q[110]; n int w[110]; n int main() { n   int i, j, n, m, k = 0, l = 0; n   scanf( %d%d , &n, &m); n   for (i = 1; i <= n; i++) scanf( %d%d , &q[i].dollar, &q[i].cent); n   for (i = 1; i <= n; i++) { n     if (q[i].dollar < m || (q[i].dollar == m && q[i].cent == 0)) { n       if (!k) k = 1; n       if (q[i].cent == 0) n         continue; n       else n         l = (l > 100 - q[i].cent) ? l : 100 - q[i].cent; n     } n   } n   if (!k) n     printf( -1 n ); n   else n     printf( %d n , l); n   return 0; n } n