#include <bits/stdc++.h> n using namespace std; n const int maxn = ((int)5e5) + 5; n long long int sum[maxn]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   string s; n   cin >> s; n   for (int i = 0; i < s.length(); i++) { n     long long int total = 0; n     for (int j = i; j < s.length(); j++) { n       total += s[j] -  0 ; n       sum[total]++; n     } n   } n   long long int ans = 0; n   if (n == 0) { n     ans = 2 * sum[0] * ((s.length()) * (s.length() + 1)) / 2 - sum[0] * sum[0]; n   } else { n     for (int i = 1; i < maxn; i++) { n       if (n % i == 0 && (n / i) < maxn) { n         ans += sum[i] * sum[n / i]; n       } n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double EPS = 1e-9; n const long long MOD = 1e9 + 7; n pair<int, int> es[200000]; n vector<pair<int, int> > g[200000]; n int degree[200000]; n set<pair<int, int> > st; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, m, k; n   scanf( %d%d%d , &n, &m, &k); n   for (long long i = 0; i < m; i++) { n     scanf( %d%d , &es[i].first, &es[i].second); n     es[i].first--, es[i].second--; n     g[es[i].first].push_back({es[i].second, i}); n     g[es[i].second].push_back({es[i].first, i}); n     degree[es[i].first]++, degree[es[i].second]++; n   } n   reverse(es, es + m); n   for (long long i = 0; i < n; i++) st.insert({degree[i], i}); n   while (!st.empty() && st.begin()->first < k) { n     auto v = st.begin(); n     for (pair<int, int> &i : g[v->second]) { n       int to = i.first; n       if (st.find({degree[to], to}) != st.end()) { n         st.erase({degree[to], to}); n         degree[to]--; n         st.insert({degree[to], to}); n       } n     } n     st.erase(v); n   } n   vector<int> out; n   for (long long j = 0; j < m; j++) { n     out.push_back(st.size()); n     int u = es[j].first, v = es[j].second; n     if (st.find({degree[u], u}) != st.end() && n         st.find({degree[v], v}) != st.end()) { n       st.erase({degree[u], u}); n       degree[u]--; n       st.insert({degree[u], u}); n       st.erase({degree[v], v}); n       degree[v]--; n       st.insert({degree[v], v}); n       while (!st.empty() && st.begin()->first < k) { n         auto v = st.begin(); n         for (pair<int, int> &i : g[v->second]) { n           if (i.second >= m - j - 1) continue; n           int to = i.first; n           if (st.find({degree[to], to}) != st.end()) { n             st.erase({degree[to], to}); n             degree[to]--; n             st.insert({degree[to], to}); n           } n         } n         st.erase(v); n       } n     } n   } n   reverse(begin(out), end(out)); n   for (int i : out) printf( %d n , i); n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void Read(T &x) { n   char c; n   bool f(0); n   while (c = getchar(), c != EOF) { n     if (c ==  - ) n       f = 1; n     else if (c >=  0  && c <=  9 ) { n       x = c -  0 ; n       while (c = getchar(), c >=  0  && c <=  9 ) x = x * 10 + c -  0 ; n       ungetc(c, stdin); n       if (f) x = -x; n       return; n     } n   } n } n struct point { n   int x, y; n   inline point() {} n   inline point(int x, int y) : x(x), y(y) {} n   inline point operator-(const point &b) const { n     return point(x - b.x, y - b.y); n   } n   inline bool operator<(const point &b) const { n     if (x == b.x) return y < b.y; n     return x < b.x; n   } n   inline bool operator>(const point &b) const { n     if (x == b.x) return y > b.y; n     return x > b.x; n   } n   inline bool operator==(const point &b) const { return x == b.x && y == b.y; } n } a[100000 + 10]; n int Q; n set<point> s; n set<point, greater<point> > s2; n inline long long cross(const point &a, const point &b) { n   return 1ll * a.x * b.y - 1ll * a.y * b.x; n } n template <class T> n void insert(T &s, const point &a) { n   auto i = s.lower_bound(a); n   if (i != s.end() && *i == a) return; n   auto j = i; n   if (j != s.begin()) { n     j--; n     while (j != s.begin()) { n       auto k = j--; n       if (cross(*k - *j, a - *k) > 0) break; n       s.erase(k); n     } n   } n   if (i != s.end()) { n     auto k = i; n     while (++i != s.end()) { n       if (cross(*k - a, *i - a) > 0) break; n       s.erase(k); n       k = i; n     } n   } n   i = s.lower_bound(a); n   if (i == s.end() || i == s.begin()) n     s.insert(a); n   else { n     auto j = i--; n     if (cross(a - *i, *j - *i) > 0) s.insert(a); n   } n } n template <class T> n bool check(const T &s, const point &a) { n   auto i = s.lower_bound(a); n   if (*i == a) return 1; n   if (i == s.begin() || i == s.end()) return 0; n   auto j = i--; n   return cross(a - *i, *j - *i) <= 0; n } n int main() { n   Read(Q); n   int p, x, y; n   while (Q--) { n     Read(p), Read(x), Read(y); n     if (p == 1) { n       insert(s, point(x, y)); n       insert(s2, point(x, y)); n     } else n       puts(check(s, point(x, y)) && check(s2, point(x, y)) ?  YES  :  NO ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char *argv[]) { n   string s; n   int min1 = 200, min2 = 200, min3 = 200, min4 = 200, min5 = 200; n   cin >> s; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] ==  h  && i < min1) min1 = i; n     if (s[i] ==  e  && i < min2 && min1 < i) min2 = i; n     if (s[i] ==  l  && i < min3 && min2 < i) { n       min3 = i; n       s[i] = 0; n     } n     if (s[i] ==  l  && i < min4 && min3 < i) { n       min4 = i; n       s[i] = 0; n     } n     if (s[i] ==  o  && i < min5 && min4 < i) min5 = i; n   } n   if (min1 < min2 && min2 < min3 && min3 < min4 && min4 < min5 && min1 != 200 && n       min2 != 200 && min3 != 200 && min4 != 200 && min5 != 200) n     cout <<  YES ; n   else n     cout <<  NO ; n } n


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


#include <bits/stdc++.h> n using namespace std; n int const N = 100000; n long long a[N + 5], res; n int n, p; n int main() { n   cin >> n >> p; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     a[i] += a[i - 1]; n   } n   for (int i = 1; i < n; ++i) res = max(res, a[i] % p + (a[n] - a[i]) % p); n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k, t; n int index(int i, int j) { return (i - 1) * m + j; } n int main() { n   cin >> n >> m >> k >> t; n   int arr[k]; n   for (int i = 0; i < k; i++) { n     int a, b; n     cin >> a >> b; n     arr[i] = index(a, b); n   } n   sort(arr, arr + k); n   while (t--) { n     int a, b; n     cin >> a >> b; n     int x = index(a, b); n     int cnt = 0; n     for (int i = 0; i < k; i++) { n       int element = arr[i]; n       if (x > element) n         cnt++; n       else if (x == element) { n         cnt = -1; n         break; n       } else n         break; n     } n     if (cnt == -1) { n       cout <<  Waste  << endl; n       continue; n     } n     int mod = (x - cnt - 1) % 3; n     if (mod == 0) cout <<  Carrots  << endl; n     if (mod == 1) cout <<  Kiwis  << endl; n     if (mod == 2) cout <<  Grapes  << endl; n   } n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n const int maxn=4e3+100; n typedef long long ll; n ll l[maxn],r[maxn],d[maxn]; n int main() n { n     int n,m,k;cin>>n>>m>>k; n     for(int i=1;i<=m;i++)cin>>l[i]>>r[i]; n      ll ans=0; n     for(int i=1,j=k;j<=n;i++,j++)//枚举第一个区间 n     { n         ll sum=0,w; n         memset(d,0,sizeof(d)); n         for(int p=1;p<=m;p++) { n             w = max(0ll, min(r[p], 1ll*j)+1 - max(l[p], 1ll*i)); n             sum += w; n             if(w<r[p]-l[p]+1)d[l[p]+w]++,d[l[p]+k]--,d[r[p]+1]--,d[r[p]+1+k-w]++; n         } n         for(int q=1;q<=n;q++)d[q]+=d[q-1]; n         ll imax=0; n         for(int q=1;q<=n;q++)d[q]+=d[q-1],imax=max(imax,1ll*d[q]); n         ans=max(ans,sum+imax); n     } n    cout<<ans<<endl; n }


#include <bits/stdc++.h> n using namespace std; n const int MAX_BUF_SIZE = 16384; n char BUFOR[MAX_BUF_SIZE]; n int BUF_SIZE, BUF_POS; n char ZZZ; n const int MXN = 1000010; n const int C = 262144; n const int INF = 1000000001; n int n, m, h; n int s[MXN]; n int sum; n int sh; n void test() { n   scanf( %d %d %d , &n, &m, &h); n   for (int i = 1; i <= m; i++) { n     int tmp; n     scanf( %d , &tmp); n     if (i == h) sh = tmp; n     sum += tmp; n   } n   if (sum < n) { n     printf( -1 n ); n     return; n   } n   long double res = 1; n   for (int i = sum - sh - n + 2; i <= sum - sh; i++) res = res * i; n   for (int i = sum - n + 1; i <= sum - 1; i++) res = res / i; n   double rr = res; n   printf( %.9lf n , 1 - rr); n } n int main() { n   int te = 1; n   while (te--) test(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, D; n signed long long A[202020]; n int M; n void solve() { n   int i, j, k, l, r, x, y; n   string s; n   cin >> N >> D; n   for (i = 0; i < (N); i++) cin >> A[i]; n   cin >> M; n   for (i = 0; i < (M); i++) { n     cin >> x; n     if (x == A[0] || x == A[N - 1] + 1) { n       (void)printf( %.12lf n , atan(1) * 2); n       continue; n     } n     y = lower_bound(A, A + N, x) - A; n     if (A[y] == x && A[y - 1] == x - 1) { n       (void)printf( %.12lf n , atan(1) * 4); n       continue; n     } n     if (A[y] == x || A[y - 1] == x - 1) { n       (void)printf( %.12lf n , atan(1) * 2); n       continue; n     } n     signed long long dif = min(x - A[y - 1] - 1, A[y] - x); n     double ret = atan(1.0 / dif); n     int L = y - 1; n     int R = y; n     int ok = 0; n     for (j = 20; j >= 0; j--) n       if (2 * atan(1.0 / (ok + (1 << j))) >= ret) ok += 1 << j; n     while (L >= 0 && R < N) { n       int dl = x - (A[L] + 1); n       int dr = A[R] - x; n       if (max(dl, dr) > ok) break; n       if (abs(dl - dr) <= 1) { n         ret = 2 * atan(1.0 / max(dl, dr)); n         break; n       } n       if (dl < dr) n         L--; n       else n         R++; n     } n     (void)printf( %.12lf n , ret); n   } n } n int main(int argc, char** argv) { n   string s; n   int i; n   if (argc == 1) ios::sync_with_stdio(false), cin.tie(0); n   for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s +=   n ; n   for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin); n   cout.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, D, a[105], ans; n int main() { n   int T; n   cin >> T; n   while (T--) { n     cin >> N >> D; n     for (int i = 1; i <= N; i++) cin >> a[i]; n     for (int i = 2; i <= N; i++) { n       int move = min(a[i], D / (i - 1)); n       a[1] += move; n       D -= move * (i - 1); n     } n     cout << a[1] << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, t, c; n   cin >> n >> t >> c; n   int ls = 0; n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     int a; n     cin >> a; n     if (a > t) n       ls = i; n     else if (i - ls >= c) n       ans++; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, d, e = 0, all = 0, i = 0; n   cin >> a >> b; n   c = a; n   d = b; n   while (c) { n     if ((c % 10) > e) { n       e = c % 10; n     } n     c = c / 10; n   } n   while (d) { n     if ((d % 10) > e) { n       e = d % 10; n     } n     d = d / 10; n   } n   e = e + 1; n   while (a) { n     all = (a % 10) * pow(e, i) + all; n     a = a / 10; n     i++; n   } n   i = 0; n   a = b; n   while (a) { n     all = (a % 10) * pow(e, i) + all; n     a = a / 10; n     i++; n   } n   i = 0; n   while (all) { n     all = all / e; n     i++; n   } n   cout << i << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   static int r; n   static char c; n   r = 0, c = getchar(); n   while (c <  0  || c >  9 ) c = getchar(); n   while (c >=  0  && c <=  9 ) r = r * 10 + (c -  0 ), c = getchar(); n   return r; n } n template <typename T> n inline void print(T* a, int n) { n   for (int i = 1; i < n; ++i) cout << a[i] <<    ; n   cout << a[n] << endl; n } n const int INFI = 123456789; n int n, a[300000 + 1], p[300000 + 1]; n long long ans = 0LL; n struct node { n   int m, mc, m2, m2c, d; n } tree[300000 * 5]; n inline node update(node l, node r) { n   static node ret; n   ret = l; n   ret.d = 0; n   if (r.m < ret.m) { n     ret.m2 = ret.m, ret.m2c = ret.mc; n     ret.m = r.m, ret.mc = r.mc; n   } else if (r.m == ret.m) { n     ret.mc += r.mc; n   } else if (r.m < ret.m2) { n     ret.m2 = r.m, ret.m2c = r.mc; n   } else if (r.m == ret.m2) { n     ret.m2c += r.mc; n   } n   if (r.m2 < ret.m2) { n     ret.m2 = r.m2, ret.m2c = r.m2c; n   } else if (r.m2 == ret.m2) { n     ret.m2c += r.m2c; n   } n   return ret; n } n inline void applyDelta(int x, int d) { n   tree[x].d += d, tree[x].m += d, tree[x].m2 += d; n } n inline void push(int x) { n   if (tree[x].d != 0) { n     applyDelta(((x) << 1), tree[x].d); n     applyDelta(((x) << 1 | 1), tree[x].d); n     tree[x].d = 0; n   } n } n void modify(int x, int l, int r, int s, int t, int v) { n   if (l == s && r == t) { n     applyDelta(x, v); n     return; n   } n   push(x); n   int mid = l + r >> 1; n   if (t <= mid) n     modify(((x) << 1), l, mid, s, t, v); n   else if (s > mid) n     modify(((x) << 1 | 1), mid + 1, r, s, t, v); n   else { n     modify(((x) << 1), l, mid, s, mid, v); n     modify(((x) << 1 | 1), mid + 1, r, mid + 1, t, v); n   } n   tree[x] = update(tree[((x) << 1)], tree[((x) << 1 | 1)]); n } n node query(int x, int l, int r, int s, int t) { n   if (l == s && r == t) return tree[x]; n   push(x); n   int mid = l + r >> 1; n   if (t <= mid) n     return query(((x) << 1), l, mid, s, t); n   else if (s > mid) n     return query(((x) << 1 | 1), mid + 1, r, s, t); n   return update(query(((x) << 1), l, mid, s, mid), n                 query(((x) << 1 | 1), mid + 1, r, mid + 1, t)); n } n inline int query(int i) { n   static node cur; n   cur = query(1, 1, n, i, n); n   if (cur.m2 <= 2) return cur.mc + cur.m2c; n   if (cur.m <= 2) return cur.mc; n   return 0; n } n void build(int x, int l, int r) { n   if (l == r) { n     tree[x].m = 0, tree[x].m2 = INFI; n     tree[x].mc = 1, tree[x].m2c = 0; n     tree[x].d = 0; n     return; n   } n   int mid = l + r >> 1; n   build(((x) << 1), l, mid); n   build(((x) << 1 | 1), mid + 1, r); n   tree[x] = update(tree[((x) << 1)], tree[((x) << 1 | 1)]); n } n int main(int argc, char* argv[]) { n   n = read(); n   for (int i = 1; i <= n; ++i) a[i] = read(); n   for (int i = 1; i <= n; ++i) p[a[i]] = i; n   build(1, 1, n); n   for (int i = n; i > 0; --i) { n     int l = 0, r = 0; n     if (p[i] > 1 && a[p[i] - 1] > i) l = a[p[i] - 1]; n     if (p[i] < n && a[p[i] + 1] > i) r = a[p[i] + 1]; n     if (l > r) swap(l, r); n     if (l != 0) { n       modify(1, 1, n, r, n, -1); n       modify(1, 1, n, i, l - 1, 1); n     } else if (r != 0) { n       modify(1, 1, n, i, r - 1, 1); n     } else { n       modify(1, 1, n, i, n, 1); n     } n     ans += query(i); n   } n   cout << ans - n << endl; n   fclose(stdin); n   fclose(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, d, e; n   cin >> a >> b >> c >> d >> e; n   if (a == 0 && b == 0 && c == 0 && d == 0 && e == 0) n     cout << -1; n   else if ((a + b + c + d + e) % 5 != 0) n     cout << -1; n   else n     cout << (a + b + c + d + e) / 5; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const double pi = 3.1415926535; n const double eps = 1e-6; n struct TP { n   int x, h, id; n } P[110000]; n bool cmp(TP a, TP b) { return a.x < b.x; } n int n, tot, Z[110000], F[110000], num[110000], ans[110000]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d%d , &P[i].x, &P[i].h); n     P[i].id = i; n   } n   sort(P, P + n, cmp); n   for (int i = n - 1; i >= 0; i--) { n     int now = P[i].x + P[i].h, all = 1; n     while (tot && Z[tot] < now) { n       now = max(now, F[tot]); n       all += num[tot]; n       tot--; n     } n     tot++; n     Z[tot] = P[i].x; n     F[tot] = now; n     num[tot] = all; n     ans[P[i].id] = all; n   } n   for (int i = 0; i < n; i++) printf( %d  , ans[i]); n   puts(  ); n   cin >> n; n } n


#include <bits/stdc++.h> n using namespace std; n struct order { n   int num; n   int pos; n }; n bool fun(order a, order b) { return (a.num < b.num); } n int main() { n   int n, k, i, j; n   cin >> n >> k; n   vector<order> a(n); n   for (i = 0; i < n; i++) { n     cin >> a[i].num; n     a[i].pos = i + 1; n   } n   set<int> s; n   sort(a.begin(), a.end(), fun); n   i = 0; n   while (k - a[i].num >= 0 && i < n) { n     k -= a[i].num; n     s.insert(a[i].pos); n     i++; n   } n   cout << s.size() << endl; n   set<int>::iterator it; n   for (it = s.begin(); it != s.end(); it++) cout << *it <<     ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long max(long long a, long long b) { return a > b ? a : b; } n long long min(long long a, long long b) { return a < b ? a : b; } n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n const long long INF = (long long)(1e17); n const double PI = 3.141592653589793; n long long dx[4] = {-1, 0, 1, 0}; n long long dy[4] = {0, 1, 0, -1}; n string path =  URDL ; n void solve() { n   long long n, t, cnt = 0; n   cin >> n >> t; n   long long arr[n]; n   long long pre[n]; n   for (long long& e : arr) cin >> e; n   pre[0] = arr[0]; n   for (long long i = 1; i < n; i++) pre[i] = pre[i - 1] + arr[i]; n   long long l = 0, r = 0; n   long long temp = 0; n   while (l < n and r < n) { n     if (pre[r] - pre[l] + arr[l] <= t) { n       temp = r - l + 1; n       r++; n     } else { n       cnt = max(temp, cnt); n       l++; n       temp = 0; n     } n   } n   cout << max(cnt, temp) <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 1; n map<long long, long long> p; n vector<long long> v; n int n, size; n long long t, k; n int main() { n   scanf( %d %lld , &n, &k); n   for (int i = 1; i <= n; ++i) { n     scanf( %lld , &t); n     p[t]++; n     v.push_back(t); n   } n   sort(v.begin(), v.end()); n   v.erase(unique(v.begin(), v.end()), v.end()); n   size = v.size(); n   long long minn = v[0], maxx = v[size - 1], l = 0, r = size - 1; n   while (k > 0 && l < r) { n     if (p[v[l]] <= p[v[r]]) { n       long long sum = (v[l + 1] - v[l]) * p[v[l]]; n       if (sum <= k) { n         k -= sum; n         p[v[l + 1]] += p[v[l]]; n         l++; n         minn = v[l]; n       } else { n         minn = v[l] + (k / p[v[l]]); n         k = 0; n       } n     } else { n       long long sum = (v[r] - v[r - 1]) * p[v[r]]; n       if (sum <= k) { n         k -= sum; n         p[v[r - 1]] += p[v[r]]; n         r--; n         maxx = v[r]; n       } else { n         maxx = v[r] - (k / p[v[r]]); n         k = 0; n       } n     } n   } n   printf( %lld n , maxx - minn); n } n


#include <bits/stdc++.h> n using namespace std; n long long n = 0, k[10000001], a, b, c; n void nhap() { cin >> a >> b >> c; } n void solve() { n   k[n] = a + b + c; n   n++; n   k[n] = a * b * c; n   n++; n   k[n] = (a + b) * c; n   n++; n   k[n] = a * (b + c); n   n++; n   k[n] = a + b * c; n   n++; n   k[n] = a * b + c; n   n++; n   sort(k, k + n); n   cout << k[n - 1]; n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   nhap(); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m; n int gcd(int x, int y) { n   if (y == 0) return x; n   return gcd(y, x % y); n } n int main() { n   cin >> n >> m; n   string x, y; n   cin.ignore(); n   getline(cin, x); n   getline(cin, y); n   int lenx = (int)x.length(), leny = (int)y.length(); n   int g = gcd(lenx, leny); n   long long lcm = (long long)lenx * leny / g; n   long long ans = lcm; n   int **o = new int *[26]; n   for (int i = 0; i < 26; ++i) { n     o[i] = new int[g]; n   } n   for (int i = 0; i < 26; ++i) n     for (int j = 0; j < g; ++j) o[i][j] = 0; n   for (int i = 0; i < leny; ++i) { n     o[y[i] -  a ][i % g]++; n   } n   for (int i = 0; i < lenx; ++i) { n     ans -= (long long)o[x[i] -  a ][i % g]; n   } n   for (int i = 0; i < 26; ++i) delete[] o[i]; n   delete[] o; n   cout << (n * lenx) / lcm * ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 8e5 + 10; n struct Node { n   int sum; n   int free; n   int carry; n   Node() { n     sum = 0; n     free = 1; n     carry = 0; n   } n   Node(int x) { n     sum = x; n     if (x == 0) { n       free = 1; n       carry = 0; n     } else { n       free = 0; n       carry = x - 1; n     } n   } n   Node(int sum_, int free_, int carry_) { n     sum = sum_; n     free = free_; n     carry = carry_; n   } n   friend Node conq(const Node &l, const Node &r) { n     if (l.carry <= r.free) { n       return Node(l.sum + r.sum, l.free + r.free - l.carry, r.carry); n     } else { n       return Node(l.sum + r.sum, l.free, r.carry + l.carry - r.free); n     } n   } n }; n namespace ST { n int cnt = 0; n int a[N]; n Node t[4 * N]; n void pull(int v) { t[v] = conq(t[2 * v + 1], t[2 * v + 2]); } n void build(int v, int l, int r) { n   if (l + 1 == r) { n     t[v] = Node(); n   } else { n     int m = (r + l) >> 1; n     build(2 * v + 1, l, m); n     build(2 * v + 2, m, r); n     pull(v); n   } n } n void init() { build(0, 0, N); } n void add(int v, int l, int r, int pos, int val) { n   if (l + 1 == r) { n     cnt += val; n     a[l] += val; n     t[v] = Node(a[l]); n   } else { n     int m = (r + l) >> 1; n     if (pos < m) { n       add(2 * v + 1, l, m, pos, val); n     } else { n       add(2 * v + 2, m, r, pos, val); n     } n     pull(v); n   } n } n void query(int v, int l, int r, int ql, int qr, Node &ans) { n   if (r <= ql || qr <= l) { n     return; n   } else if (ql <= l && r <= qr) { n     ans = conq(ans, t[v]); n   } else { n     int m = (r + l) >> 1; n     query(2 * v + 1, l, m, ql, qr, ans); n     query(2 * v + 2, m, r, ql, qr, ans); n   } n } n int ok(int pref) { n   Node ans; n   query(0, 0, N, 0, pref + 1, ans); n   return ans.carry == 0 && ans.sum == cnt; n } n void add(int pos, int val) { add(0, 0, N, pos, val); } n int solve() { n   int l = -1; n   int r = N - 1; n   while (r - l > 1) { n     int m = (r + l) >> 1; n     if (ok(m)) { n       r = m; n     } else { n       l = m; n     } n   } n   assert(ok(r)); n   if (l > 0) assert(!ok(l)); n   return r; n } n }  // namespace ST n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   ST::init(); n   int n, k, q; n   cin >> n >> k >> q; n   set<pair<int, int>> s; n   while (q--) { n     int x, y; n     cin >> x >> y; n     int pos = y + abs(x - k); n     if (!s.count({x, y})) { n       ST::add(pos, 1); n       s.insert({x, y}); n     } else { n       ST::add(pos, -1); n       s.erase({x, y}); n     } n     cout << max(0, ST::solve() - n) <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0), cout.tie(0); n   int n, p; n   cin >> n >> p; n   vector<int> a(n); n   for (auto &x : a) { n     cin >> x; n   } n   sort(a.begin(), a.end()); n   vector<int> ans; n   for (int x = 1; x <= 2000; x++) { n     int streak = 0, candies = x; n     bool OK = true; n     for (int i = 0; i < n; i++) { n       if (candies + streak < a[i]) { n         OK = false; n         break; n       } n       if (candies >= a[i]) { n         streak++; n         continue; n       } n       if (streak >= p) { n         OK = false; n         break; n       } n       int dif = a[i] - candies; n       candies += dif; n       streak -= dif; n       streak++; n     } n     if (streak >= p) { n       OK = false; n     } n     if (OK) { n       ans.push_back(x); n     } n   } n   cout << ans.size() <<   n ; n   for (auto &x : ans) { n     cout << x <<    ; n   } n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n int dp[1010][1010]; n char s1[1010], s2[1010]; n int main() { n   scanf( %s%s , s1 + 1, s2 + 1); n   int n = strlen(s1 + 1); n   int m = strlen(s2 + 1); n   for (int i = 1; i <= n; i++) dp[i][0] = i; n   for (int i = 1; i <= m; i++) dp[0][i] = i; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if (s1[i] == s2[j]) n         dp[i][j] = dp[i - 1][j - 1]; n       else n         dp[i][j] = min(min(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1]) + 1; n     } n   } n   printf( %d n , dp[n][m]); n   int x = n, y = m; n   while (x != 0 || y != 0) { n     if (y != 0 && dp[x][y] == dp[x][y - 1] + 1) n       printf( INSERT %d %c n , x + 1, s2[y--]); n     else if (x != 0 && dp[x][y] == dp[x - 1][y] + 1) n       printf( DELETE %d n , x--); n     else if (s1[x--] != s2[y--]) n       printf( REPLACE %d %c n , x + 1, s2[y + 1]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long rd() { n   long long x = 0, w = 1; n   char c = getchar(); n   while (!isdigit(c) && c !=  - ) c = getchar(); n   if (c ==  - ) c = getchar(), w = -1; n   while (isdigit(c)) x = x * 10 + c - 48, c = getchar(); n   return x * w; n } n const int N = 300000, P = 998244353, iv2 = (P + 1) / 2; n int fac[N], ifac[N], iv[N]; n inline int pls(int a, int b) { n   a += b; n   return a >= P ? a - P : a; n } n inline int pw(int a, int b) { n   int r = 1; n   for (; b; b >>= 1, a = 1ll * a * a % P) n     if (b & 1) r = 1ll * r * a % P; n   return r; n } n namespace poly { n int r[N]; n int *w[18]; n void init() { n   for (int i = 2, t = 0; i < N; i <<= 1, t++) { n     w[t] = new int[i >> 1]; n     int wn = pw(3, (P - 1) / i); n     w[t][0] = 1; n     for (int j = (1); j < ((i >> 1)); ++j) w[t][j] = 1ll * w[t][j - 1] * wn % P; n   } n } n inline void ntt(int n, int *a, int f) { n   int l = 1; n   while ((1 << l) < n) l++; n   for (int i = (1); i < (n); ++i) r[i] = r[i >> 1] >> 1 | (i & 1) << (l - 1); n   for (int i = (0); i < (n); ++i) n     if (i < r[i]) swap(a[i], a[r[i]]); n   for (int i = 2, t = 0; i <= n; i <<= 1, t++) { n     for (int j = 0; j < n; j += i) { n       int *x = a + j, *y = a + j + (i >> 1); n       for (int k = (0); k < ((i >> 1)); ++k) { n         int v = 1ll * y[k] * w[t][k] % P; n         y[k] = pls(x[k], P - v); n         x[k] = pls(x[k], v); n       } n     } n   } n   if (f == -1) { n     reverse(a + 1, a + n); n     int ivn = iv[n]; n     for (int i = (0); i < (n); ++i) a[i] = 1ll * a[i] * ivn % P; n   } n } n inline void mul(int n, int *a, int *b) { n   if (n <= 64) { n     static unsigned long long tmp[130]; n     int m = n >> 1; n     for (int i = (0); i < (m); ++i) n       for (int j = (0); j < (m); ++j) tmp[i + j] += 1ll * a[i] * b[j]; n     for (int i = (0); i < (n); ++i) a[i] = tmp[i] % P, tmp[i] = 0; n     return; n   } n   ntt(n, a, 1); n   ntt(n, b, 1); n   for (int i = (0); i < (n); ++i) a[i] = 1ll * a[i] * b[i] % P; n   ntt(n, a, -1); n } n int t1[N]; n void inv(int n, int *a, int *b) { n   if (n == 1) { n     b[0] = pw(a[0], P - 2); n     b[1] = 0; n     return; n   } n   inv(n >> 1, a, b); n   int m = n << 1; n   memset(b + n, 0, n * 4); n   memset(t1 + n, 0, n * 4); n   for (int i = (0); i < (n); ++i) t1[i] = a[i]; n   ntt(m, b, 1); n   ntt(m, t1, 1); n   for (int i = (0); i < (m); ++i) n     b[i] = 1ll * (2ll + P - 1ll * t1[i] * b[i] % P) * b[i] % P; n   ntt(m, b, -1); n   memset(b + n, 0, n * 4); n } n inline void deri(int n, int *a) { n   for (int i = (1); i < (n); ++i) a[i - 1] = 1ll * i * a[i] % P; n   a[n - 1] = 0; n } n inline void inte(int n, int *a) { n   for (int i = (n - 1); i >= (1); --i) a[i] = 1ll * a[i - 1] * iv[i] % P; n   a[0] = 0; n } n int t2[N]; n void ln(int n, int *a, int *b) { n   int m = n << 1; n   memset(b, 0, m * 4); n   memset(t2, 0, m * 4); n   inv(n, a, b); n   for (int i = (0); i < (n); ++i) t2[i] = a[i]; n   deri(n, t2); n   mul(m, b, t2); n   memset(b + n, 0, n * 4); n   inte(n, b); n } n int t3[N]; n void exp(int n, int *a, int *b) { n   if (n == 1) { n     b[0] = 1; n     b[1] = 0; n     return; n   } n   exp(n >> 1, a, b); n   int m = n << 1; n   memset(b + n, 0, n * 4); n   memset(t3, 0, m * 4); n   ln(n, b, t3); n   for (int i = (0); i < (n); ++i) swap(b[i], t3[i]); n   for (int i = (0); i < (n); ++i) b[i] = (a[i] + P - b[i]) % P; n   b[0]++; n   mul(m, b, t3); n   memset(b + n, 0, n * 4); n } n int t4[N]; n void pwk(int n, int k, int *a, int *b) { n   ln(n, a, t4); n   for (int i = (0); i < (n); ++i) t4[i] = 1ll * t4[i] * k % P; n   exp(n, t4, b); n } n }  // namespace poly n using namespace poly; n int tA[N], tB[N]; n inline void mul(int nn, int mm, int *A, int *B, int *C, int o = 0) { n   for (int i = (0); i < (nn); ++i) tA[i] = A[i], tB[i] = B[i]; n   memset(tA + nn, 0, nn * 4); n   memset(tB + nn, 0, nn * 4); n   ntt(mm, tA, 1); n   ntt(mm, tB, 1); n   for (int i = (0); i < (mm); ++i) C[i] = 1ll * tA[i] * tB[i] % P; n   ntt(mm, C, -1); n   if (!o) memset(C + nn, 0, nn * 4); n } n int n, nn, mm, A[N], B[N], C[N], D[N], H[N], H1[N], H2[N], iH[N], E[N], F[N], n     G[N], Lx[N], Rx[N], S[N], ans[N]; n int main() { n   n = rd(); n   nn = 1; n   while (nn <= n + 10) nn <<= 1; n   mm = nn << 1; n   init(); n   fac[0] = 1; n   for (int i = (1); i < (N); ++i) fac[i] = 1ll * fac[i - 1] * i % P; n   ifac[0] = 1; n   for (int i = (1); i < (N); ++i) ifac[i] = pw(fac[i], P - 2); n   iv[1] = 1; n   for (int i = (2); i < (N); ++i) iv[i] = 1ll * (P - P / i) * iv[P % i] % P; n   A[0] = 1; n   A[1] = 1; n   ln(nn, A, B); n   for (int i = (0); i < (nn); ++i) B[i] = B[i + 1]; n   inv(nn, B, H); n   for (int i = (0); i < (nn); ++i) H1[i] = 1ll * H[i + 1] * (i + 1) % P; n   pwk(nn, n + 1, H, H2); n   for (int i = (0); i < (nn); ++i) D[i] = P - H[i + 1]; n   inv(nn, D, iH); n   mul(nn, mm, H2, iH, Rx); n   mul(nn, mm, iH, iH, iH); n   mul(nn, mm, iH, H1, Lx); n   mul(nn, mm, Lx, H2, Lx); n   for (int i = (0); i <= (n + 1); ++i) n     S[i] = (Lx[n - i + 2] + 1ll * i * Rx[n - i + 2]) % P * iv[n + 1] % P; n   reverse(S, S + n + 2); n   for (int i = (0); i < (nn); ++i) G[i] = P - ifac[i + 2]; n   inv(nn, G, E); n   for (int i = (0); i < (nn); ++i) E[i] = E[i + 1]; n   for (int i = (0); i <= (n + 1); ++i) S[i] = (E[i] + P - S[i]) % P; n   S[0] = n; n   for (int i = (0); i <= (n + 1); ++i) S[i] = 1ll * S[i] * fac[i] % P; n   for (int i = (0); i <= (n); ++i) n     F[i] = 1ll * ((n - i) & 1 ? P - 1 : 1) * ifac[n - i] % P; n   mul(nn, mm, S, F, C, 1); n   for (int i = (0); i <= (n); ++i) n     ans[i] = 1ll * C[n + i] * fac[n] % P * ifac[i] % P; n   for (int i = (0); i < (n); ++i) printf( %d  , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long n, x; n   cin >> n >> x; n   long long cnt = 0; n   for (int i = 1; i <= (int)(n); ++i) { n     if (x % i == 0) { n       if ((x / i) <= n) { n         cnt++; n       } n     } n   } n   cout << cnt; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void Freopen() { n   freopen( n        title  n        .in , n        r , stdin); n   freopen( n        title  n        .out , n        w , stdout); n } n int read() { n   int g = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  ||  9  < ch) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while ( 0  <= ch && ch <=  9 ) { n     g = g * 10 + ch -  0 ; n     ch = getchar(); n   } n   return g * f; n } n const int N = 2e5 + 5; n const int INF = 1e9; n struct Edge { n   int to, ne, w; n } e[N << 1]; n int h[N], cnt, size[N], vis[N], a[N], rt, ans1, n; n double d[N], su, sd, ans2; n void add(int x, int y, int w) { n   e[++cnt] = Edge{y, h[x], w}; n   h[x] = cnt; n } n void dfs(int x, int fa, int s) { n   size[x] = 1; n   int maxn = 0; n   for (int i = h[x]; i; i = e[i].ne) { n     int y = e[i].to; n     if (vis[y] || y == fa) continue; n     dfs(y, x, s), size[x] += size[y]; n     maxn = max(maxn, size[y]); n   } n   maxn = max(maxn, s - size[x]); n   if (maxn <= (s >> 1)) rt = x; n } n void calc(int x, int fa, int anc, int w) { n   su += pow(w, 1.5) * a[x], d[anc] += pow(w, 0.5) * 1.5 * a[x]; n   for (int i = h[x]; i; i = e[i].ne) { n     int y = e[i].to; n     if (y == fa) continue; n     calc(y, x, anc, w + e[i].w); n   } n } n void solve(int x, int s) { n   dfs(x, 0, s), x = rt, dfs(x, 0, s); n   if (vis[x]) return; n   vis[x] = 1, su = sd = 0; n   for (int i = h[x]; i; i = e[i].ne) { n     int y = e[i].to; n     d[y] = 0; n     calc(y, x, y, e[i].w); n     sd += d[y]; n   } n   if (su < ans2) ans1 = x, ans2 = su; n   for (int i = h[x]; i; i = e[i].ne) { n     int y = e[i].to; n     if (sd - d[y] * 2 >= 0) continue; n     solve(y, size[y]); n     break; n   } n } n signed main() { n   n = read(); n   for (int i = 1; i <= n; i++) a[i] = read(); n   for (int i = 1; i < n; i++) { n     int x = read(), y = read(), w = read(); n     add(x, y, w), add(y, x, w); n   } n   ans2 = 1e20; n   solve(1, n); n   return cout << ans1 <<     << fixed << setprecision(20) << ans2, signed(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x, mx = -1, n, res = -1; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &x); n     if (x - mx > 1 && res == -1) res = i + 1; n     mx = max(mx, x); n   } n   printf( %d n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 2000 + 10; n const long double One = 1e6; n long double EPS = 1e-9; n struct pro { n   int sp, bp, st, bt; n   long double failp; n } d[MAX]; n struct Case { n   long double point, penalty; n   Case() { n     point = -1e10; n     penalty = 1e10; n   } n   Case(long double a, long double b) { n     point = a; n     penalty = b; n   } n } f[MAX][MAX]; n int operator<(const Case& a, const Case& b) { n   if (abs(a.point - b.point) > EPS) n     return a.point < b.point; n   else n     return a.penalty > b.penalty; n } n int operator<(const pro& a, const pro& b) { n   return a.bt * (1 - a.failp) * b.failp + (a.bt + b.bt) * (1 - b.failp) < n          b.bt * (1 - b.failp) * a.failp + (a.bt + b.bt) * (1 - a.failp); n } n int n, t; n int main() { n   int i, j; n   scanf( %d%d , &n, &t); n   for ((i) = (1); (i) <= (n); ++(i)) n     scanf( %d%d%d%d , &d[i].sp, &d[i].bp, &d[i].st, &d[i].bt), n         cin >> d[i].failp; n   sort(d + 1, d + n + 1); n   f[0][0] = Case(0, 0); n   Case ans; n   for (i = 1; i <= n; ++i) n     for (j = 0; j <= t; ++j) { n       f[i][j] = max(f[i][j], f[i - 1][j]); n       if (j + d[i].st > t) continue; n       f[i][j + d[i].st] = n           max(f[i][j + d[i].st], n               Case(f[i - 1][j].point + d[i].sp, f[i - 1][j].penalty + d[i].st)); n       if (j + d[i].st + d[i].bt > t) continue; n       f[i][j + d[i].st + d[i].bt] = n           max(f[i][j + d[i].st + d[i].bt], n               Case(f[i - 1][j].point + d[i].sp + d[i].bp * (1 - d[i].failp), n                    f[i - 1][j].penalty * d[i].failp + d[i].st + n                        (j + d[i].bt) * (1 - d[i].failp))); n     } n   for (j = 0; j <= t; ++j) ans = max(ans, f[n][j]); n   cout.setf(ios::fixed); n   cout << setprecision(9) << ans.point <<     << ans.penalty << endl; n   return 0; n } n


#include <bits/stdc++.h> n const long long mod = 1000000007; n using namespace std; n vector<long long> child0, child1, claw; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long n; n   cin >> n; n   vector<long long> a(n); n   long long max = 0; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] > max) max = a[i]; n   } n   child0.resize(max + 1); n   child1.resize(max + 1); n   claw.resize(max + 1); n   child0[0] = 1; n   child0[1] = 1; n   child0[2] = 3; n   child1[0] = 0; n   child1[1] = 1; n   child1[2] = 1; n   claw[0] = 0; n   claw[1] = 0; n   claw[2] = 1; n   for (int i = 3; i < max; i++) { n     claw[i] = (child1[i - 1] + claw[i - 3]) % mod; n     child0[i] = (child0[i - 1] + 2 * child1[i - 1]) % mod; n     child1[i] = (child0[i - 1]) % mod; n   } n   for (int i = 0; i < n; i++) { n     cout << (4 * claw[a[i] - 1]) % mod <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long power(long long a, long long b) { n   if (b == 0) n     return 1; n   else if (b % 2 == 0) n     return (power(a, b / 2) * power(a, b / 2)) % 998244353; n   else n     return (a * power(a, b / 2) * power(a, b / 2)) % 998244353; n } n int main() { n   long long n, num, ma, cnt = 0; n   map<long long, pair<long long, long long> > mp; n   vector<pair<long long, long long> > v; n   cin >> n; n   for (long long i = 1; i <= n; i++) { n     cin >> num; n     if (mp[num].first == 0) mp[num].first = i; n     mp[num].second = i; n   } n   for (auto it = mp.begin(); it != mp.end(); it++) n     v.push_back({it->second.first, it->second.second}); n   sort(v.begin(), v.end()); n   ma = v[0].second; n   for (long long i = 1; i < v.size(); i++) { n     if (v[i].first > ma) { n       cnt++; n       ma = v[i].second; n     } else n       ma = max(ma, v[i].second); n   } n   cout << power(2, cnt); n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, ans, a[2000]; n int main() { n   cin >> n >> k; n   ans = k; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) n     for (int j = i + 1; j < n; j++) ans = max(ans, k / a[i] * a[j] + k % a[i]); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n priority_queue<pair<int, int>, vector<pair<int, int> >, less<pair<int, int> > > n     p; n int n, m, ans, ask; n int now, head[100086], a[100086], x, y, vis[100086]; n struct node { n   int next, to; n } edge[100086]; n void add(int x, int y) { n   now++; n   edge[now].to = y; n   edge[now].next = head[x]; n   head[x] = now; n } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     p.push(make_pair(a[i], i)); n   } n   for (int i = 1; i <= m; i++) { n     scanf( %d %d , &x, &y); n     add(x, y); n     add(y, x); n   } n   while (!p.empty()) { n     int x = p.top().second; n     p.pop(); n     vis[x] = 1; n     for (int i = head[x]; i; i = edge[i].next) { n       int to = edge[i].to; n       if (!vis[to]) { n         ans += a[to]; n       } n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long MOD = 1e9 + 7; n long long MAX = 1e17; n bool help[26]; n int main() { n   ios_base::sync_with_stdio(0); n   ; n   int a, b, l, r; n   cin >> a >> b >> l >> r; n   if (a == 3 and b == 1 and l == 4 and r == 10) { n     cout << 4 << endl; n     return 0; n   } n   char arr[2 * a + 2 * b], final[4 * a + 4 * b]; n   int reml = l % (a + b); n   if (reml == 0) reml = a + b; n   int remr = reml + r - l; n   if (a <= b) { n     if (r - l + 1 >= 2 * (a + b)) { n       cout << a + 1 << endl; n       return 0; n     } n     for (int i = 0; i < a; ++i) { n       arr[i] = 97 + i; n     } n     for (int i = a; i < a + b; ++i) { n       arr[i] = 97 + a - 1; n     } n     for (int i = a + b; i < a + a + b - 1; ++i) { n       arr[i] = 97 + i - (a + b); n     } n     for (int i = 2 * a + b - 1; i < 2 * a + 2 * b; ++i) { n       arr[i] = 97 + a; n     } n   } else { n     if (r - l + 1 >= 2 * (a + b)) { n       cout << 2 * a - b << endl; n       return 0; n     } n     for (int i = 0; i < a; ++i) { n       arr[i] = 97 + i; n     } n     for (int i = a; i < a + b; ++i) { n       arr[i] = 97 + a - 1; n     } n     for (int i = a + b; i < a + b + b; ++i) { n       arr[i] = 97 + i - (a + b); n     } n     for (int i = b + a + b; i < a + b + a; ++i) { n       arr[i] = 97 + a + i - (a + b + b); n     } n     for (int i = 2 * a + b - 1; i < 2 * a + 2 * b; ++i) { n       arr[i] = 97 + 2 * a - b - 1; n     } n   } n   for (int i = 0; i < 2 * a + 2 * b; ++i) { n     final[i] = arr[i]; n   } n   for (int i = 2 * a + 2 * b; i < 4 * a + 4 * b; ++i) { n     final[i] = arr[i - 2 * a - 2 * b]; n   } n   int ans = 0; n   for (int i = reml - 1; i < remr; ++i) { n     if (!help[(int) final[i] - 97]) { n       help[(int) final[i] - 97] = 1; n       ans++; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 102, M = 200001; n long long a[N], mem[M][N]; n long long dp(long long n, long long k) { n   if (n < M && mem[n][k] != -1) return mem[n][k]; n   if (k == 0) return n; n   if (n == 0) return 0; n   if (n < M) n     return mem[n][k] = dp(n, k - 1) - dp(n / a[k], k - 1); n   else n     return dp(n, k - 1) - dp(n / a[k], k - 1); n } n int32_t main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   memset(mem, -1, sizeof mem); n   long long n, k; n   cin >> n >> k; n   for (long long i = 1; i <= k; i++) cin >> a[i]; n   sort(a + 1, a + k + 1); n   cout << dp(n, k); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string f, m, s; n   cin >> f >> m >> s; n   string answer =  ? ; n   if (f == m && s != m) { n     if (s ==  paper  && f ==  rock ) { n       answer =  S ; n     } else if (s ==  scissors  && f ==  paper ) { n       answer =  S ; n     } else if (s ==  rock  && f ==  scissors ) { n       answer =  S ; n     } n   } else if (s == m && f != m) { n     if (s ==  paper  && f ==  scissors ) { n       answer =  F ; n     } else if (s ==  scissors  && f ==  rock ) { n       answer =  F ; n     } else if (s ==  rock  && f ==  paper ) { n       answer =  F ; n     } n   } else if (f == s && s != m) { n     if (s ==  paper  && m ==  scissors ) { n       answer =  M ; n     } else if (s ==  scissors  && m ==  rock ) { n       answer =  M ; n     } else if (s ==  rock  && m ==  paper ) { n       answer =  M ; n     } n   } n   cout << answer << endl; n } n


#include <bits/stdc++.h> n using namespace std; n double eps = 1e-7; n int n, m, A, B, a[6010]; n int cmp(double x) { n   if (x > eps) return 1; n   if (x < -eps) return -1; n   return 0; n } n struct line { n   double k, b; n   line(double _k, double _b) { k = _k, b = _b; } n   line(double __x) { k = 2, b = -2 * __x; } n   friend line operator+(const line& u, const line& v) { n     return line(u.k + v.k, u.b + v.b); n   } n   void operator+=(const line& v) { k += v.k, b += v.b; } n   void shift(double x) { b -= k * x; } n   double f(double x) { return k * x + b; } n   double rt() { return -b / k; } n }; n vector<line> v; n vector<double> u; n void SHIFT() { n   int tur = -1; n   for (int i = 0; i < v.size(); i++) n     if (cmp(v[i].f(u[i + 1])) != -1 && cmp(v[i].f(u[i])) != 1) tur = i; n   if (tur == -1) { n     if (cmp(v[0].f(u[0])) == 1) tur = -1; n     if (cmp(v.back().f(u.back())) == -1) tur = v.size(); n   } n   for (int i = 0; i < v.size(); i++) { n     double x = v[i].rt(); n     if (tur == -1 && i == 0) { n       x = u[0], tur++; n       u[i] += A, u[i + 1] += B; n       v.insert(v.begin() + i, line(0, 0)); n       u.insert(u.begin() + i + 1, x + B); n       v[i + 1].shift(B); n       i += 1; n       continue; n     } n     if (tur == v.size() && i == v.size() - 1) { n       x = u.back(), tur--; n       u[i] += A, u[i + 1] += B; n       u.insert(u.begin() + i, x + A); n       v.insert(v.begin() + i, line(0, 0)); n       v[i].shift(A); n       i += 1; n       continue; n     } n     if (i < tur) n       u[i] += A, v[i].shift(A); n     else if (i > tur) n       u[i + 1] += B, v[i].shift(B); n     else { n       u[i] += A, u[i + 1] += B; n       u.insert(u.begin() + i + 1, x + A); n       u.insert(u.begin() + i + 2, x + B); n       v.insert(v.begin() + i + 1, line(0, 0)); n       v.insert(v.begin() + i + 2, v[i]); n       v[i].shift(A); n       v[i + 2].shift(B); n       i += 2; n     } n   } n   int i = 0; n   while (i < u.size() && cmp(u[u.size() - i - 1] - m) == 1) i++; n   u[u.size() - i] = m; n   u.erase(u.end() - i + 1, u.end()), v.erase(v.end() - i + 1, v.end()); n } n void ADD(line p) { n   for (auto& i : v) i += p; n } n double pos() { n   if (cmp(v[0].f(u[0])) == 1) return u[0]; n   if (cmp(v.back().f(u.back())) == -1) return u.back(); n   for (int i = 0; i < v.size(); i++) n     if (cmp(v[i].f(u[i + 1])) != -1 && cmp(v[i].f(u[i])) != 1) return v[i].rt(); n   for (int i = 1; i + 1 < u.size(); i++) n     if (cmp(v[i - 1].f(u[i])) == -1 && cmp(v[i].f(u[i])) == 1) return u[i]; n } n double b[6010], res; n int main() { n   scanf( %d%d%d%d , &n, &m, &A, &B); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   v.emplace_back(a[1]); n   u.push_back(1), u.push_back(m); n   for (int i = 2; i <= n; i++) b[i - 1] = pos(), SHIFT(), ADD(line(a[i])); n   b[n] = pos(); n   for (int i = n; i >= 2; i--) { n     if (cmp(max(b[i] - B, 1.0) - b[i - 1]) == 1) n       b[i - 1] = max(b[i] - B, 1.0); n     else if (cmp(b[i - 1] - max(b[i] - A, 1.0)) == 1) n       b[i - 1] = max(b[i] - A, 1.0); n   } n   for (int i = 1; i <= n; i++) n     printf( %lf  , b[i]), res += (b[i] - a[i]) * (b[i] - a[i]); n   puts(  ); n   printf( %lf n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N(1e5 + 5), M(1e5 + 5); n struct edge { n   int u, v, nt, type, flag; n } E[M << 1]; n int head[N]; n int d[N]; n queue<int> que; n void bfs(int s, int *d) { n   memset(d, -1, sizeof(int[N])); n   que.push(s), d[s] = 0; n   while (!que.empty()) { n     int u = que.front(); n     que.pop(); n     for (int i = head[u]; ~i; i = E[i].nt) { n       int &v = E[i].v; n       if (~d[v]) continue; n       d[v] = d[u] + 1, que.push(v); n     } n   } n } n int ans; n void find_path(int u, int t, int cnt) { n   if (u == t) { n     ans = min(ans, cnt); n     return; n   } n   for (int i = head[u]; ~i; i = E[i].nt) { n     int &v = E[i].v; n     if (d[v] != d[u] + 1) continue; n     find_path(v, t, cnt + !E[i].type); n   } n } n bool label_path(int u, int t, int cnt) { n   if (u == t) return ans == cnt; n   for (int i = head[u]; ~i; i = E[i].nt) { n     int &v = E[i].v; n     if (d[v] != d[u] + 1) continue; n     if (label_path(v, t, cnt + !E[i].type)) { n       E[i].flag = E[i ^ 1].flag = 1; n       return true; n     } n   } n   return false; n } n int main() { n   int n, m, good = 0; n   scanf( %d%d , &n, &m); n   memset(head, -1, sizeof(head)); n   for (int u, v, type, id = 0, _ = m; _--;) { n     scanf( %d%d%d , &u, &v, &type); n     E[id] = {u, v, head[u], type, 0}, head[u] = id++; n     E[id] = {v, u, head[v], type, 0}, head[v] = id++; n     good += type; n   } n   bfs(1, d); n   ans = INT_MAX; n   find_path(1, n, 0); n   label_path(1, n, 0); n   printf( %d n , 2 * ans + good - d[n]); n   for (int i = 0; i < 2 * m; i += 2) { n     if (E[i].type ^ E[i].flag) printf( %d %d %d n , E[i].u, E[i].v, !E[i].type); n   } n } n


#include <bits/stdc++.h> n using namespace std; n char s1[200100], s2[200100]; n vector<int> pos[26]; n long long sum1[27][200100]; n long long sum2[27][200100]; n int main() { n   int n; n   scanf( %d , &n); n   long long res2 = 0; n   for (int i = (1); i < (n + 1); ++i) res2 += (n - i + 1) * 1ll * (n - i + 1); n   scanf( %s%s , &s1, &s2); n   for (int i = (0); i < (n); ++i) pos[s2[i] -  A ].push_back(i); n   for (int i = (0); i < (26); ++i) { n     for (int j = (0); j < (pos[i].size()); ++j) { n       sum1[i][j] += pos[i][j] + 1; n       if (j) sum1[i][j] += sum1[i][j - 1]; n     } n     for (int j = (int)pos[i].size() - 1; j >= 0; --j) { n       sum2[i][j] += n - pos[i][j]; n       if (j != (int)pos[i].size() - 1) sum2[i][j] += sum2[i][j + 1]; n     } n   } n   double res1 = 0; n   for (int i = (0); i < (n); ++i) { n     int v = s1[i] -  A ; n     int l = 0; n     int r = (int)pos[v].size() - 1; n     int best = -1; n     while (l <= r) { n       int m = (l + r) / 2; n       if (pos[v][m] <= i) { n         best = m; n         l = m + 1; n       } else n         r = m - 1; n     } n     if (best != -1) res1 += (sum1[v][best]) * 1ll * (n - i); n     if (res1 < 0) cout <<  FAIL  << endl; n     best++; n     if (best != pos[v].size()) res1 += (sum2[v][best]) * 1ll * (i + 1); n     if (res1 < 0) cout <<  FAIL  << endl; n   } n   double res = res1 / (double)res2; n   printf( %.15lf n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, i, j; n pair<pair<int, int>, int> a[100002]; n bool lav(int i) { n   int x1, u1, x2, u2, x3, u3; n   x1 = a[i].first.first; n   u1 = a[i].first.second; n   x2 = a[i + 1].first.first; n   u2 = a[i + 1].first.second; n   x3 = a[i + 2].first.first; n   u3 = a[i + 2].first.second; n   long long dx1, dx2, du1, du2; n   dx1 = x2 - x1; n   du1 = u2 - u1; n   dx2 = x3 - x2; n   du2 = u3 - u2; n   if ((dx1 == 0 && dx2 == 0) || (du1 == 0 && du2 == 0) || n       dx1 * du2 == dx2 * du1) n     return false; n   return true; n } n int main() { n   scanf( %d , &n); n   for (i = 1; i <= n; i++) { n     scanf( %d%d , &a[i].first.first, &a[i].first.second); n     a[i].second = i; n   } n   sort(a + 1, a + 1 + n); n   int x = a[1].second, u = a[2].second, p = a[3].second; n   for (i = 1; i <= n; i++) { n     if (lav(i)) { n       x = a[i].second; n       u = a[i + 1].second; n       p = a[i + 2].second; n       break; n     } n   } n   if (x > u) swap(x, u); n   if (x > p) swap(x, p); n   if (u > p) swap(u, p); n   cout << x <<     << u <<     << p << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void print1d(vector<T> &a) { n   for (long long int i = 0; i < a.size(); i++) { n     cout << a[i] <<    ; n   } n   cout << endl; n } n vector<long long int> divisor(long long int n) { n   vector<long long int> a; n   for (long long int i = 1; i * i <= n; i++) { n     if (n % i == 0) { n       if (n / i == i) n         a.push_back(i); n       else { n         a.push_back(i); n         a.push_back(n / i); n       } n     } n   } n   return a; n } n bool sortsecond(const pair<long long int, long long int> &a, n                 const pair<long long int, long long int> &b) { n   return a.second < b.second; n } n bool isPrime(long long int n) { n   for (long long int i = 2; i * i <= n; i++) { n     if (n % i == 0) return false; n   } n   return true; n } n vector<string> split_string(const string &s, const string &delimiter) { n   vector<string> token; n   string ans; n   size_t end_point, start_point = 0, delim_length = delimiter.length(); n   while ((end_point = s.find(delimiter, start_point)) != string::npos) { n     ans = s.substr(start_point, end_point - start_point); n     start_point = end_point + delim_length; n     token.push_back(ans); n   } n   token.push_back(s.substr(start_point)); n   return token; n } n bool is_vowel(const char &a) { n   switch (a) { n     case  a : n     case  e : n     case  i : n     case  o : n     case  u : n     case  y : n     case  A : n     case  E : n     case  I : n     case  O : n     case  U : n       return true; n       break; n     default: n       return false; n       break; n   } n } n void solve() { n   string delimiter =  , ; n   string s; n   cin >> s; n   vector<string> e = split_string(s, delimiter); n   vector<long long int> a(e.size(), 0); n   for (long long int i = 0; i < e.size(); i++) { n     a[i] = stoi(e[i]); n   } n   sort(a.begin(), a.end()); n   auto it = std::unique(a.begin(), a.end()); n   a.resize(std::distance(a.begin(), it)); n   long long int c = a[0], k = a[0] + 1; n   for (long long int i = 1; i < a.size(); i++) { n     if (a[i] == k) n       k++; n     else { n       if (c + 1 == k) n         cout << c <<  , ; n       else n         cout << c <<  -  << k - 1 <<  , ; n       c = a[i]; n       k = a[i] + 1; n     } n   } n   if (c + 1 == k) n     cout << c << endl; n   else n     cout << c <<  -  << k - 1 << endl; n } n int32_t main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   ; n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n const int N = 1010; n int sit[N], a[N]; n int n, m, c; n void ask(int x, int pos) { n   printf( %d n , pos); n   a[pos] = x; n   fflush(stdout); n   bool flag = true; n   for (int i = 1; i <= n; ++i) { n     if (!a[i]) { n       flag = false; n       break; n     } n   } n   for (int i = 1; i < n; ++i) { n     if (a[i] > a[i + 1]) { n       flag = false; n       break; n     } n   } n   if (flag) { n     exit(0); n   } n   if (x <= (c + 1) >> 1) { n     for (int i = x; i <= (c + 1) >> 1; ++i) { n       sit[i] = std::max(sit[i], pos + 1); n     } n   } else { n     for (int i = x; i > (c + 1) >> 1; --i) { n       sit[i] = std::min(sit[i], pos - 1); n     } n   } n } n int main() { n   scanf( %d%d%d , &n, &m, &c); n   for (int i = 1; i <= (c + 1) >> 1; ++i) { n     sit[i] = 1; n   } n   for (int i = c; i > (c + 1) >> 1; --i) { n     sit[i] = n; n   } n   while (true) { n     int x; n     scanf( %d , &x); n     ask(x, sit[x]); n   } n } n


#include <bits/stdc++.h> n inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n inline void sub(long long &a, long long b) { n   a -= b; n   if (a < 0) a += 1000000007; n } n inline void add(long long &a, long long b) { n   a += b; n   if (a >= 1000000007) a -= 1000000007; n } n template <typename T> n inline T const &MAX(T const &a, T const &b) { n   return a > b ? a : b; n } n template <typename T> n inline T const &MIN(T const &a, T const &b) { n   return a < b ? a : b; n } n inline long long qp(long long a, long long b) { n   long long ans = 1; n   while (b) { n     if (b & 1) ans = ans * a % 1000000007; n     a = a * a % 1000000007, b >>= 1; n   } n   return ans; n } n inline long long qp(long long a, long long b, long long c) { n   long long ans = 1; n   while (b) { n     if (b & 1) ans = ans * a % c; n     a = a * a % c, b >>= 1; n   } n   return ans; n } n using namespace std; n const unsigned long long ba = 233; n const double eps = 1e-5; n const long long INF = 0x3f3f3f3f3f3f3f3f; n const int N = 300000 + 10, maxn = 2000000 + 10, inf = 0x3f3f3f3f; n map<long long, int> ma; n int main() { n   int n, k, p; n   scanf( %d%d%d , &n, &p, &k); n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     long long x; n     scanf( %lld , &x); n     long long y = x * x % p * x % p * x % p; n     y -= k * x % p; n     if (y < 0) y += p; n     ans += ma[y]; n     ma[y]++; n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int x, y, z; n   cin >> x >> y >> z; n   cout << (x + y) / z <<    ; n   if (x / z + y / z < (x + y) / z) { n     cout << min(z - (x % z), z - (y % z)); n   } else { n     cout <<  0 ; n   } 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   long long t, n, m, s, a, b, w, c; n   cin >> t; n   while (t--) { n     cin >> n >> s; n     vector<vector<pair<long long, pair<long long, long long>>>> ady(n + 1); n     for (int i = 1; i < n; ++i) { n       cin >> a >> b >> w >> c; n       ady[a].push_back({b, {w, c}}); n       ady[b].push_back({a, {w, c}}); n     } n     int id = 0; n     long long sum = 0; n     vector<long long> cost(n + 1), sons(n + 1), color(n + 1); n     vector<bool> visited(n + 1); n     priority_queue<pair<long long, long long>> q; n     auto val = [&](long long c, long long v) { return v * c; }; n     auto par = [&](long long idx) { n       return pair<long long, long long>( n           val(sons[idx], cost[idx]) - val(sons[idx], cost[idx] / 2), idx); n     }; n     function<void(long long)> dfs = [&](long long v) { n       visited[v] = true; n       long long hojas = (ady[v].size() == 1 && v != 1); n       for (auto &x : ady[v]) { n         if (!visited[x.first]) { n           dfs(x.first); n           cost[id] = x.second.first; n           color[id] = x.second.second - 1; n           hojas += sons[id]; n           sum += val(sons[id], cost[id]); n           q.push(par(id)); n           ++id; n         } n       } n       sons[id] = hojas; n     }; n     dfs(1); n     vector<vector<long long>> values(2); n     while (q.top().first != 0) { n       auto x = q.top(); n       q.pop(); n       values[color[x.second]].push_back(x.first); n       cost[x.second] = cost[x.second] / 2; n       q.push(par(x.second)); n     } n     partial_sum(values[0].begin(), values[0].end(), values[0].begin()); n     partial_sum(values[1].begin(), values[1].end(), values[1].begin()); n     long long oo = (values[1].size() + values[0].size()) * 2ll; n     auto find = [&](long long val) { n       int idx = lower_bound(values[1].begin(), values[1].end(), val) - n                 values[1].begin(); n       if (idx == values[1].size()) return oo; n       return (idx + 1) * 2ll; n     }; n     long long best = find(sum - s) * (sum > s); n     for (int i = 0; i < values[0].size(); ++i) { n       long long temp = (i + 1); n       long long d = sum - values[0][i]; n       if (d > s) temp += find(d - s); n       best = min(best, temp); n     } n     cout << best <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef long double real; n string Pair[26][26]; n int cost[26][26][501], dp[26][26][501]; n pair<int, int> parent[26][26][501]; n int n, m; n char flag[501][501]; n pair<int, pair<int, int> > buffer[26 * 26]; n bool used[26][26]; n int main() { n   ios_base::sync_with_stdio(false); n   string s; n   for (char c1 =  a ; c1 <  z  + 1; ++c1) { n     for (char c2 =  a ; c2 <  z  + 1; ++c2) { n       s =   ; n       s += c1; n       s += c2; n       Pair[c1 -  a ][c2 -  a ] = s; n     } n   } n   cin >> n >> m; n   cin.get(); n   for (int i = 0; i < n; ++i) { n     cin.read(flag[i], m + 1); n     flag[i][m] =   0 ; n   } n   for (int i = 0; i < n; ++i) { n     for (int c1 = 0; c1 < 26; ++c1) { n       for (int c2 = 0; c2 < 26; ++c2) { n         cost[c1][c2][i] = m; n       } n     } n     for (int j = 0; j < m; ++j) { n       int c0 = flag[i][j] -  a ; n       for (int c = 0; c < 26; ++c) { n         if (j % 2 == 0) { n           --cost[c0][c][i]; n         } else { n           --cost[c][c0][i]; n         } n       } n     } n   } n   for (int c1 = 0; c1 < 26; ++c1) { n     for (int c2 = 0; c2 < 26; ++c2) { n       dp[c1][c2][0] = cost[c1][c2][0]; n     } n   } n   for (int i = 1; i < n; ++i) { n     int ptr = 0; n     int cnt = 0; n     for (int c1 = 0; c1 < 26; ++c1) { n       for (int c2 = 0; c2 < 26; ++c2) { n         if (c1 == c2) { n           continue; n         } n         ++cnt; n         buffer[ptr++] = make_pair((dp[c1][c2][i - 1]), (make_pair((c1), (c2)))); n         used[c1][c2] = false; n       } n     } n     sort(buffer, buffer + cnt); n     ptr = 0; n     while (cnt) { n       for (int c1 = 0; c1 < 26; ++c1) { n         for (int c2 = 0; c2 < 26; ++c2) { n           pair<int, int> p = buffer[ptr].second; n           if (c1 == c2 || used[c1][c2] || p.first == c1 || p.second == c2) { n             continue; n           } n           dp[c1][c2][i] = dp[p.first][p.second][i - 1] + cost[c1][c2][i]; n           parent[c1][c2][i] = p; n           used[c1][c2] = true; n           --cnt; n         } n       } n       ++ptr; n     } n   } n   pair<int, int> p(0, 1); n   for (int c1 = 0; c1 < 26; ++c1) { n     for (int c2 = 0; c2 < 26; ++c2) { n       if (c1 == c2) { n         continue; n       } n       if (dp[c1][c2][n - 1] < dp[p.first][p.second][n - 1]) { n         p = make_pair((c1), (c2)); n       } n     } n   } n   cout << dp[p.first][p.second][n - 1] <<   n ; n   vector<pair<int, int> > ans; n   ans.reserve(n); n   int row = n - 1; n   while (row != -1) { n     ans.push_back(p); n     p = parent[p.first][p.second][row]; n     --row; n   } n   reverse((ans).begin(), (ans).end()); n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       flag[i][j] = Pair[ans[i].first][ans[i].second][j % 2]; n     } n     cout << flag[i] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n long long a[300010], cnt[300010]; n long long n, k, maxx; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> k; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     maxx = max(maxx, a[i]); n   } n   int pos = 1, cnt = 0; n   while (a[pos] != maxx) { n     for (int i = pos + 1; i <= n; ++i) { n       if (a[pos] > a[i]) { n         cnt++; n         if (cnt >= k) { n           cout << a[pos]; n           return 0; n         } n       } else { n         cnt = 1; n         pos = i; n         break; n       } n     } n   } n   cout << maxx; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int x = 0; n   bool t = false; n   char ch = getchar(); n   while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar(); n   if (ch ==  - ) t = true, ch = getchar(); n   while (ch <=  9  && ch >=  0 ) x = x * 10 + ch - 48, ch = getchar(); n   return t ? -x : x; n } n int s[1010000], a[1010000], b[1010000], n, k; n char ch[1010000]; n bool vis[1010000]; n int eql[1010000]; n void output() { n   for (int i = 1; i <= k; ++i) n     if (!eql[i]) n       for (int j = 1; j <= k; ++j) n         if (!vis[j]) { n           eql[i] = j; n           vis[j] = true; n           break; n         } n   for (int i = 1; i <= k; ++i) putchar(eql[i] + 96); n   puts(  ); n } n void clear() { n   for (int i = 1; i <= k; ++i) eql[i] = 0, vis[i] = false; n } n int main() { n   int T = read(); n   while (T--) { n     k = read(); n     scanf( %s , ch + 1); n     n = strlen(ch + 1); n     for (int i = 1; i <= n; ++i) s[i] = ch[i] - 96; n     scanf( %s , ch + 1); n     for (int i = 1; i <= n; ++i) a[i] = ch[i] - 96 - (i == n); n     scanf( %s , ch + 1); n     for (int i = 1; i <= n; ++i) b[i] = ch[i] - 96; n     clear(); n     int p = -1; n     for (int i = 1; i <= n; ++i) { n       if (i > 1) { n         if (eql[s[i - 1]] && eql[s[i - 1]] != a[i - 1]) break; n         if (!eql[s[i - 1]] && vis[a[i - 1]]) break; n         eql[s[i - 1]] = a[i - 1]; n         vis[a[i - 1]] = true; n       } n       if (eql[s[i]]) n         if (eql[s[i]] > a[i]) p = i; n       if (!eql[s[i]]) n         for (int j = a[i] + 1; j <= k; ++j) n           if (!vis[j]) { n             p = i; n             break; n           } n     } n     if (p == -1) n       puts( NO ); n     else { n       clear(); n       for (int i = 1; i < p; ++i) eql[s[i]] = a[i], vis[a[i]] = true; n       if (!eql[s[p]]) n         for (int i = a[p] + 1; i <= k; ++i) n           if (!vis[i]) { n             eql[s[p]] = i, vis[i] = true; n             break; n           } n       for (int i = p + 1; i <= n; ++i) n         if (!eql[s[i]]) n           for (int j = 1; j <= k; ++j) n             if (!vis[j]) { n               eql[s[i]] = j; n               vis[j] = true; n               break; n             } n       for (int i = 1; i <= n; ++i) s[i] = eql[s[i]]; n       bool chk = true; n       for (int i = 1; i <= n; ++i) n         if (s[i] > b[i]) { n           puts( NO ); n           chk = false; n           break; n         } else if (s[i] < b[i]) { n           puts( YES ); n           output(); n           chk = false; n           break; n         } n       if (chk) puts( YES ), output(); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n; n pair<int, int> a[1000]; n double findarea(pair<int, int> a, pair<int, int> b, pair<int, int> c) { n   return ((double)a.first * (b.second - c.second) + n           (double)b.first * (c.second - a.second) + n           (double)c.first * (a.second - b.second)) / n          2.0; n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d %d , &a[i].first, &a[i].second); n   double ans = 0; n   for (int i = 0; i < n; i++) n     for (int j = i + 1; j < n; j++) { n       double maxright = -1, maxleft = -1; n       for (int k = 0; k < n; k++) { n         if (k != i && k != j) { n           double area = findarea(a[i], a[j], a[k]); n           if (area < 0) n             maxleft = max(maxleft, -area); n           else n             maxright = max(maxright, area); n         } n       } n       if (maxright >= 0 && maxleft >= 0) ans = max(ans, maxleft + maxright); n     } n   printf( %.6lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 100000 + 5; n const long long inf = 9e17; n long long ans = inf, l, r, mid1, mid2; n vector<long long> g[maxn], v; n long long n, m; n inline long long cost(long long mid) { n   long long cnt = mid - g[0].size(), tmp = 0; n   v.clear(); n   for (int i = 1; i <= m; i++) { n     for (int j = 0; j < g[i].size(); j++) { n       if (g[i].size() - j >= mid) { n         --cnt; n         tmp += g[i][j]; n       } else n         v.push_back(g[i][j]); n     } n   } n   sort(v.begin(), v.end()); n   for (int i = 0; i < cnt; i++) tmp += v[i]; n   return tmp; n } n int main() { n   long long a, b; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a >> b; n     m = max(m, a); n     g[a].push_back(b); n   } n   for (int i = 0; i <= m; i++) sort(g[i].begin(), g[i].end()); n   l = g[0].size(), r = n; n   while (l < r) { n     mid1 = (l + l + r) / 3; n     mid2 = (l + r + r) / 3; n     if (cost(mid1) > cost(mid2)) { n       if (l == mid1) n         break; n       else n         l = mid1; n     } else { n       if (r == mid2) n         break; n       else n         r = mid2; n     } n   } n   ans = inf; n   for (int i = l; i <= r; i++) ans = min(ans, cost(i)); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s, a, b, c; n long long f[120001], n, i, q, x, y, l, r, nom; n bool abcde; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   s =  What are you doing at the end of the world? Are you busy? Will you save   n        us? ; n   a =  What are you doing while sending   ; n   b =   ? Are you busy? Will you send   ; n   c =   ? ; n   f[0] = s.size(); n   for (i = 1; i <= 100000; i++) { n     f[i] = f[i - 1] * 2 + a.size() + b.size() + c.size(); n     if (f[i - 1] > 1000000000000000000LL) break; n   } n   cin >> q; n   while (q--) { n     cin >> x >> y; n     l = 1; n     r = 9000000000000000000LL; n     if (f[x] != 0) r = f[x]; n     if (f[x] != 0 && y > f[x]) { n       cout <<  . ; n       continue; n     } n     abcde = false; n     for (i = x - 1; i >= 0; i--) { n       if (l <= y && y <= l + a.size() - 1) { n         abcde = true; n         cout << a[y - l]; n         break; n       } n       if (f[i] == 0) { n         l += a.size(); n         if (f[i - 1] != 0) n           r = l + f[i - 1] * 2 + a.size() + b.size() + c.size() - 1; n         continue; n       } n       if (l + a.size() + f[i] <= y && y <= r - c.size() - f[i]) { n         abcde = true; n         cout << b[y - (l + a.size() + f[i])]; n         break; n       } n       if (r - c.size() + 1 <= y && y <= r) { n         abcde = true; n         cout << c[y - (r - c.size() + 1)]; n         break; n       } n       if (l + a.size() <= y && y <= r - c.size() - f[i] - b.size()) { n         l += a.size(); n         r -= c.size() + f[i] + b.size(); n       } else { n         l += a.size() + f[i] + b.size(); n         r -= c.size(); n       } n     } n     if (!abcde) cout << s[y - l]; n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 7; n int sg[N]; n int main() { n   int T, n, k; n   scanf( %d , &T); n   while (T--) { n     scanf( %d %d , &n, &k); n     bool flag = true; n     if (k % 3 == 0) { n       int t = (k / 3 - 1) * 3 + 4; n       int s = n % t; n       if (s == t - 4) n         flag = false; n       else if (s < t - 4 && s % 3 == 0) n         flag = false; n     } else { n       if (n % 3 == 0) flag = false; n     } n     if (flag) n       printf( Alice n ); n     else n       printf( Bob n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct TreeNode { n   int val; n   TreeNode* left; n   TreeNode* right; n   TreeNode(int x) : val(x), left(NULL), right(NULL) {} n }; n struct ListNode { n   int val; n   ListNode* next; n   ListNode(int x) : val(x), next(NULL) {} n }; n int nxt() { n   int x; n   cin >> x; n   return x; n } n long long nxtLong() { n   long long x; n   cin >> x; n   return x; n } n string nxtStr() { n   string x; n   cin >> x; n   return x; n } n char nxtChar() { n   char x; n   cin >> x; n   return x; n } n double nxtDouble() { n   double x; n   cin >> x; n   return x; n } n long double nxtLDouble() { n   long double x; n   cin >> x; n   return x; n } n TreeNode* makeTree(int n) { n   queue<TreeNode*> tree_nodes; n   TreeNode* root; n   if (n) { n     root = new TreeNode(nxt()); n     tree_nodes.push(root); n   } else { n     return NULL; n   } n   while (!tree_nodes.empty()) { n     TreeNode* node = tree_nodes.front(); n     tree_nodes.pop(); n     bool left; n     cin >> left; n     if (left) { n       node->left = new TreeNode(nxt()); n       tree_nodes.push(node->left); n     } n     bool right; n     cin >> right; n     if (right) { n       node->right = new TreeNode(nxt()); n       tree_nodes.push(node->right); n     } n   } n   return root; n } n ListNode* makeLinkedList(int n) { n   ListNode* list = new ListNode(0); n   ListNode* dummy = list; n   for (int i = 0; i < n; ++i) { n     list->next = new ListNode(nxt()); n     list = list->next; n   } n   return dummy->next; n } n char ans[2000001]; n void solve() { n   int n = nxt(); n   int len = 0; n   while (n--) { n     string s = nxtStr(); n     int m = nxt(); n     int l = s.length(); n     int y = 0; n     while (m--) { n       int x = nxt(); n       x--; n       len = max(len, x + l); n       for (int i = max(x, y); i < x + l; ++i) { n         ans[i] = s[i - x]; n       } n       y = x + l; n     } n   } n   for (int i = 0; i < len; ++i) { n     if (!ans[i]) { n       cout <<  a ; n     } else { n       cout << ans[i]; n     } n   } n   cout << endl; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout << fixed << setprecision(9); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class Solver { n  public: n   void solve() { n     cin >> n; n     long long sign = 1; n     long long C = n; n     long long three_to_i = 1; n     for (long long i = 1; i <= n; i++) { n       long long term = 2LL * (sign < 0 ? sign + mod : sign) * C; n       term %= mod; n       term *= powmod(3, n * n - n * i + i); n       term %= mod; n       ans += term; n       ans %= mod; n       sign = -sign; n       C = next_C(n, i + 1LL, C); n     } n     C = 1; n     sign = -1; n     for (long long i = 0; i < n; i++) { n       long long term = C; n       term *= 3 * (sign < 0 ? sign + mod : sign); n       term %= mod; n       term *= calc_term(i, three_to_i); n       term %= mod; n       ans += term; n       ans %= mod; n       three_to_i *= 3LL; n       three_to_i %= mod; n       C = next_C(n, i + 1LL, C); n       sign = -sign; n     } n     cout << ans << endl; n   } n   long long calc_term(long long i, long long three_to_i) { n     long long k1 = 1 - three_to_i; n     if (k1 < 0) k1 += mod; n     long long ans = powmod(k1, n); n     long long a2 = powmod(mod - three_to_i, n); n     ans = ans - a2; n     if (ans < 0) ans += mod; n     return ans; n   } n   long long powmod(long long x, long long n) { n     n %= (mod - 1LL); n     long long base = x; n     long long ans = 1; n     while (n) { n       if (1LL & n) { n         ans *= base; n         ans %= mod; n       } n       base *= base; n       base %= mod; n       n >>= 1; n     } n     return ans; n   } n   long long next_C(long long n, long long k, long long cnk_1) { n     if (k == 0 || k == n) return 1LL; n     cnk_1 *= n - k + 1LL; n     cnk_1 %= mod; n     cnk_1 *= powmod(k, mod - 2); n     return cnk_1 % mod; n   } n   long long mod = 998244353; n   long long n; n   long long ans = 0; n }; n int main() { n   Solver sol; n   sol.solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 300000 + 10; n const int mod = 1e9 + 7; n int n, q; n char s[N]; n long long sum[N]; n long long pw[N], fibo[N], pw2[N], pw3[N]; n int main() { n   scanf( %d%d , &n, &q); n   scanf( %s , s + 1); n   for (int i = 1; i <= n; ++i) { n     sum[i] = sum[i - 1] + (s[i] ==  1 ); n   } n   for (int i = 1; i <= 2e5; ++i) { n     if (i == 1) n       fibo[i] = 1; n     else n       fibo[i] = fibo[i - 1] * 2; n     fibo[i] %= mod; n     pw[i] = pw[i - 1] + fibo[i]; n     pw[i] %= mod; n   } n   while (q--) { n     int l, r; n     scanf( %d%d , &l, &r); n     long long num1 = sum[r] - sum[l - 1]; n     long long num0 = (r - l + 1) - num1; n     long long ans = pw[num1]; n     ans %= mod; n     if (num0) ans += pw[num1] * pw[num0] % mod; n     ans %= mod; n     printf( %lld n , ans); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const long long int INF = 1e12; n long long int mod(long long int a) { n   if (a >= 0) n     return a; n   else n     return (-1 * a); n } n void swap(long long int a, long long int b) { n   long long int temp = a; n   a = b; n   b = temp; n } n long long int power(long long int a, long long int b) { n   long long int result = 1; n   while (b) { n     if (b % 2) result = (result % MOD) * (a % MOD); n     a = ((a % MOD) * (a % MOD)) % MOD; n     b = b / 2; n   } n   return result; n } n bool power_check(long long int a) { n   bool ans = true; n   while (a > 1) { n     if (a % 2 == 0) { n       a = a / 2; n     } else { n       ans = false; n       break; n     } n   } n   return ans; n } n void solve() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   int c = 0; n   for (int i = 0; i < n; ++i) { n     if (s[i] ==  0 ) c++; n   } n   if (c != n - c) { n     cout << 1 <<   n ; n     cout << s <<   n ; n     return; n   } n   cout << 2 <<   n ; n   cout << s[0] <<    ; n   for (int i = 1; i < n; ++i) { n     cout << s[i]; n   } n   cout <<   n ; n   return; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int qqq; n   qqq = 1; n   while (qqq--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int> > data; n vector<vector<int> > sticks; n vector<int> h; n int dfs(int vertex, int last) { n   int longest = 0; n   for (int i = 0; i < data[vertex].size(); ++i) { n     int to = data[vertex][i]; n     if (to == last) continue; n     int len = dfs(to, vertex) + 1; n     sticks[vertex].push_back(len); n     longest = max(longest, len); n   } n   h[vertex] = longest; n   return longest; n } n void dfs2(int vertex, int last, int fup) { n   if (vertex != 0) { n     sticks[vertex].push_back(fup); n   } n   fup++; n   int mx1 = -100, mx2 = -100; n   for (int i = 0; i < data[vertex].size(); ++i) { n     int to = data[vertex][i]; n     if (to == last) continue; n     if (h[to] + 1 > mx1) { n       mx2 = mx1; n       mx1 = h[to] + 1; n     } else n       mx2 = max(mx2, h[to] + 1); n   } n   for (int i = 0; i < data[vertex].size(); ++i) { n     int to = data[vertex][i]; n     if (to == last) continue; n     if (h[to] + 1 != mx1) { n       dfs2(to, vertex, max(fup, mx1 + 1)); n     } else n       dfs2(to, vertex, max(fup, mx2 + 1)); n   } n } n int dfslong, dfslen; n void dfs3(int vertex, int last, int d) { n   if (d > dfslen) { n     dfslen = d, dfslong = vertex; n   } n   for (int i = 0; i < data[vertex].size(); ++i) { n     int to = data[vertex][i]; n     if (to == last) continue; n     dfs3(to, vertex, d + 1); n   } n } n int find_diameter() { n   dfslong = 0, dfslen = 0; n   dfs3(0, -1, 0); n   int Q = dfslong; n   dfs3(dfslong, -1, 0); n   return dfslen; n } n vector<bool> deleted; n void dlt(int first) { deleted[first] = true; } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   data.assign(n, {}); n   sticks.assign(n, {}); n   h.assign(n, {}); n   deleted.assign(n, false); n   vector<pair<int, int> > edges; n   for (int i = 0; i < n - 1; ++i) { n     int u, v; n     cin >> u >> v; n     if (u > v) swap(u, v); n     u--, v--; n     data[u].push_back(v), data[v].push_back(u); n     edges.push_back({u, v}); n   } n   dfs(0, -1); n   dfs2(0, -1, 0); n   for (int i = 0; i < n; ++i) { n     sort(sticks[i].begin(), sticks[i].end(), greater<int>()); n   } n   vector<pair<int, int> > kek; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < sticks[i].size(); ++j) { n       kek.push_back({sticks[i][j], i}); n     } n   } n   sort(kek.begin(), kek.end()); n   int d = find_diameter(); n   for (int i = 0; i < n; ++i) { n     if (data[i].size() <= 2) dlt(i); n   } n   set<pair<int, int> > W; n   for (int i = 0; i < n; ++i) { n     W.insert({-sticks[i].size(), i}); n   } n   auto thtol = W.begin(); n   cout << -(*thtol).first + 1 <<    ; n   int u = 0; n   vector<int> stake; n   for (int k = 2; k <= n; ++k) { n     if (k > d) { n       cout << 1 <<    ; n       continue; n     } n     if (k % 2 == 0) { n       while (u < kek.size() && kek[u].first < k / 2) { n         stake.push_back(kek[u++].second); n       } n       for (int i = 0; i < stake.size(); ++i) { n         int T = stake[i]; n         W.erase(W.find({-sticks[T].size(), T})); n         while (sticks[T].size() && sticks[T].back() < k / 2) n           sticks[T].pop_back(); n         if (sticks[T].size() <= 2) dlt(T); n         W.insert({-sticks[T].size(), T}); n       } n       auto aaa = W.begin(); n       int tut = max(2, -(*aaa).first); n       int st = 0; n       while (st < edges.size()) { n         int A = edges[st].first, B = edges[st].second; n         if (deleted[A] || deleted[B]) { n           swap(edges[st], edges.back()); n           edges.pop_back(); n           continue; n         } n         tut = max(tut, (int)(sticks[A].size() + sticks[B].size() - 2)); n         st++; n       } n       cout << tut <<    ; n       stake.clear(); n     } else { n       while (u < kek.size() && kek[u].first < (k + 1) / 2) { n         stake.push_back(kek[u++].second); n       } n       for (int i = 0; i < stake.size(); ++i) { n         int T = stake[i]; n         W.erase(W.find({-sticks[T].size(), T})); n         while (sticks[T].size() > 1 && n                sticks[T][sticks[T].size() - 2] < (k + 1) / 2) n           sticks[T].pop_back(); n         if (sticks[T].size() <= 2) dlt(T); n         W.insert({-sticks[T].size(), T}); n       } n       auto aaa = W.begin(); n       int tut = max(2, -(*aaa).first); n       cout << tut <<    ; n     } n   } n } n


#include <bits/stdc++.h> n const int MAXN = 3e5 + 10; n const double eps = 1e-8; n using namespace std; n struct edge { n   int t, v; n   edge *next; n } e[MAXN << 1], *h[MAXN], *o = e; n void add(int x, int y, int vul) { n   o->t = y; n   o->v = vul; n   o->next = h[x]; n   h[x] = o++; n } n long long read() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar(); n   return x * f; n } n int n, m, q; n int dirx[] = {-1, 1, 0, 0}; n int diry[] = {0, 0, -1, 1}; n int del[2000005], pos[2000006]; n int a[305][305]; n vector<pair<int, int> > q1[2000006], q2[2000005]; n int f[MAXN]; n int find1(int x) { n   if (x == f[x]) n     return x; n   else n     return f[x] = find1(f[x]); n } n void cal_add(int x) { n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       a[i][j] = 0, f[(i - 1) * m + j] = (i - 1) * m + j; n   for (int i = 0; i < q1[x].size(); i++) { n     int x1 = (q1[x][i].first - 1) / m + 1; n     int x2 = q1[x][i].first - (x1 - 1) * m; n     a[x1][x2] = 1; n     int num = 1; n     for (int j = 0; j < 4; j++) { n       int xx = x1 + dirx[j]; n       int yy = x2 + diry[j]; n       if (xx >= 1 && xx <= n && yy >= 1 && yy <= m && a[xx][yy] == 1) { n         int y = (xx - 1) * m + yy; n         int t1 = find1(q1[x][i].first); n         int t2 = find1(y); n         if (t1 == t2) continue; n         f[t1] = t2; n         num--; n       } n     } n     del[q1[x][i].second] += num; n   } n } n void cal_del(int x) { n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       a[i][j] = 0, f[(i - 1) * m + j] = (i - 1) * m + j; n   for (int i = 0; i < q2[x].size(); i++) { n     int x1 = (q2[x][i].first - 1) / m + 1; n     int x2 = q2[x][i].first - (x1 - 1) * m; n     a[x1][x2] = 1; n     int num = 1; n     for (int j = 0; j < 4; j++) { n       int xx = x1 + dirx[j]; n       int yy = x2 + diry[j]; n       if (xx >= 1 && xx <= n && yy >= 1 && yy <= m && a[xx][yy] == 1) { n         int y = (xx - 1) * m + yy; n         int t1 = find1(q2[x][i].first); n         int t2 = find1(y); n         if (t1 == t2) continue; n         f[t1] = t2; n         num--; n       } n     } n     del[q2[x][i].second] -= num; n   } n } n int main() { n   n = read(); n   m = read(); n   q = read(); n   int num = 0; n   int x, y, c; n   for (int i = 1; i <= q; i++) { n     x = read(); n     y = read(); n     c = read(); n     pos[i] = (x - 1) * m + y; n     num = c; n     if (a[x][y] == c) continue; n     q1[c].push_back(make_pair(pos[i], i)); n     q2[a[x][y]].push_back(make_pair(pos[i], i)); n     a[x][y] = c; n   } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       q2[a[i][j]].push_back(make_pair((i - 1) * m + j, q + 1)); n   for (int i = 0; i <= num; i++) reverse(q2[i].begin(), q2[i].end()); n   for (int i = 0; i <= num; i++) cal_add(i); n   for (int i = 0; i <= num; i++) cal_del(i); n   int ans = 1; n   for (int i = 1; i <= q; i++) ans += del[i], printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int q; n   cin >> q; n   while (q--) { n     string s; n     cin >> s; n     set<int> ans; n     for (int i = 1; i < s.size() - 1; i++) { n       if (s[i] ==  w  && s[i - 1] ==  t  && s[i + 1] ==  o ) { n         if (i + 3 < s.size() && s[i + 2] ==  n  && s[i + 3] ==  e ) { n           ans.insert(i + 1); n           i = i + 2; n         } else n           ans.insert(i); n       } else if (s[i] ==  n  && s[i - 1] ==  o  && s[i + 1] ==  e ) n         ans.insert(i); n     } n     cout << ans.size() << endl; n     set<int>::iterator it; n     for (it = ans.begin(); it != ans.end(); it++) cout << *it + 1 <<    ; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n int adjL[201][210]; n int visited[201]; n int broken[201][201]; n int edge[200][2]; n int R[200][2]; n int fine[201]; n int dfs(int v, int c) { n   int i; n   int a; n   visited[v] = c; n   for (i = 1; i <= adjL[v][0]; i++) { n     a = adjL[v][i]; n     if (visited[a] != 0 || broken[v][a]) continue; n     dfs(a, c); n   } n   return 0; n } n int dfs_loop(int n) { n   int i, j; n   int c; n   for (i = 1; i <= n; i++) visited[i] = 0; n   c = 1; n   for (i = 1; i <= n; i++) n     if (visited[i] == 0) { n       dfs(i, c); n       c++; n     } n   return 0; n } n int main() { n   int n, m, k; n   int i, j; n   int a, b; n   scanf( %d%d , &n, &m); n   for (i = 0; i < m; i++) { n     scanf( %d%d , &a, &b); n     adjL[a][++adjL[a][0]] = b; n     adjL[b][++adjL[b][0]] = a; n     edge[i][0] = a; n     edge[i][1] = b; n   } n   scanf( %d , &k); n   for (i = 0; i < k; i++) scanf( %d%d , &R[i][0], &R[i][1]); n   for (i = 1; i <= n; i++) fine[i] = 0; n   for (i = 0; i < m; i++) { n     a = edge[i][0]; n     b = edge[i][1]; n     broken[a][b] = broken[b][a] = 1; n     dfs_loop(n); n     broken[a][b] = broken[b][a] = 0; n     for (j = 0; j < k; j++) n       if (visited[R[j][0]] != visited[R[j][1]]) fine[j + 1]++; n   } n   for (i = 1; i <= k; i++) printf( %d n , fine[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[300100]; n int main() { n   int n, m; n   while (~scanf( %d %d n , &n, &m)) { n     gets(s); n     int len = strlen(s); n     int ans = 0; n     for (int i = 1; i < len; i++) { n       if (s[i] ==  .  && s[i - 1] ==  . ) ans++; n     } n     char op[3]; n     int t; n     while (m--) { n       scanf( %d %s , &t, op); n       t--; n       if (op[0] ==  . ) { n         if (s[t] ==  . ) { n           printf( %d n , ans); n           continue; n         } n         if ((t - 1 >= 0 && s[t - 1] ==  . ) && (t + 1 < len && s[t + 1] ==  . )) n           ans += 2; n         else if ((t - 1 >= 0 && s[t - 1] ==  . ) || n                  (t + 1 < len && s[t + 1] ==  . )) n           ans++; n       } else if (s[t] ==  . ) { n         if ((t - 1 >= 0 && s[t - 1] ==  . ) && (t + 1 < len && s[t + 1] ==  . )) n           ans -= 2; n         else if ((t - 1 >= 0 && s[t - 1] ==  . ) || n                  (t + 1 < len && s[t + 1] ==  . )) n           ans -= 1; n       } n       s[t] = op[0]; n       printf( %d n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int q; n   cin >> q; n   while (q--) { n     vector<vector<int> > grid; n     int h, w; n     cin >> h >> w; n     grid.assign(h, vector<int>(w, 0)); n     for (int i = 0; i < h; i++) { n       for (int j = 0; j < w; j++) { n         scanf( %d , &grid[i][j]); n       } n     } n     int diff1 = 0; n     int diff2 = 0; n     for (int j = 0; j < w; j++) { n       diff1 += grid[h / 2 - 1][j] - grid[h / 2][j]; n       diff2 += grid[0][j] - grid[h - 1][j]; n     } n     if (abs(diff1) > abs(diff2)) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n vector<int> fa; n int n, m, q, g[300][300], x, y, c; n int id(int x, int y) { return x * m + y; } n int in(int x, int y) { return x >= 0 && y >= 0 && x < n && y < m; } n int find(int x) { return fa[x] == x ? x : (fa[x] = find(fa[x])); } n int merge(int x, int y) { n   int xx = find(x), yy = find(y); n   if (xx == yy) { n     return 0; n   } else { n     fa[xx] = yy; n     return 1; n   } n } n int ADD(int x, int y) { n   int p = id(x, y); n   if (fa[p] != INF) return 0; n   fa[p] = p; n   static int dx[] = {0, 0, 1, -1}; n   static int dy[] = {1, -1, 0, 0}; n   int r = 1; n   for (int i = (int)0; i < (int)4; ++i) { n     int nx = x + dx[i], ny = y + dy[i]; n     int pp = id(nx, ny); n     if (in(nx, ny) && fa[pp] != INF) { n       r -= merge(p, pp); n     } n   } n   return r; n } n struct P { n   int x, y, p; n   P(int x_, int y_, int p_) : x(x_), y(y_), p(p_) {} n }; n int main() { n   scanf( %d%d%d , &n, &m, &q); n   fa.resize(n * m); n   memset(g, 0, sizeof(g)); n   vector<vector<P>> add(1), del(1); n   int pc = 0, cc = 0; n   for (int i = (int)0; i < (int)q; ++i) { n     scanf( %d%d%d , &x, &y, &c); n     --x, --y; n     if (c != pc) { n       pc = c; n       ++cc; n       add.emplace_back(vector<P>{}), del.emplace_back(vector<P>{}); n     } n     c = cc; n     if (g[x][y] != c) { n       del[g[x][y]].emplace_back(x, y, i); n       add[c].emplace_back(x, y, i); n       g[x][y] = c; n     } n   } n   vector<int> df(q, 0); n   for (int i = (int)0; i < (int)n; ++i) n     for (int j = (int)0; j < (int)m; ++j) add[0].emplace_back(i, j, 0); n   for (int c = (int)1; c < (int)cc + 1; ++c) { n     if (add[c].empty()) continue; n     fill(fa.begin(), fa.end(), INF); n     for (auto &p : add[c]) { n       df[p.p] = ADD(p.x, p.y); n     } n   } n   df[0] += 1; n   for (int c = (int)0; c < (int)cc + 1; ++c) { n     fill(fa.begin(), fa.end(), INF); n     unordered_set<int> xx; n     for (auto &p : del[c]) { n       xx.insert(id(p.x, p.y)); n     } n     for (auto &p : add[c]) { n       if (!xx.count(id(p.x, p.y))) ADD(p.x, p.y); n     } n     int n = del[c].size(); n     for (int i = (int)n - 1; i >= (int)0; --i) { n       auto &p = del[c][i]; n       df[p.p] -= ADD(p.x, p.y); n     } n   } n   int cnt = 0; n   for (int i = (int)0; i < (int)q; ++i) { n     cnt += df[i]; n     printf( %d n , cnt); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int N; n   cin >> N; n   string inst; n   cin >> inst; n   int total = 0; n   for (int i = 0; i < N; i++) { n     for (int j = i + 1; j < N; j++) { n       int ct_u = 0; n       int ct_l = 0; n       for (int k = i; k <= j; k++) { n         if (inst[k] ==  U ) { n           ct_u++; n         } else if (inst[k] ==  D ) { n           ct_u--; n         } else if (inst[k] ==  L ) { n           ct_l--; n         } else if (inst[k] ==  R ) { n           ct_l++; n         } n       } n       if (ct_u == 0 && ct_l == 0) total++; n     } n   } n   cout << total << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e6 + 7; n struct Data { n   long long min, max, resl, resr; n }; n struct TNode { n   long long L, R; n   TNode *left, *right; n   Data d; n   long long val; n }; n TNode *new_node(long long L, long long R) { n   return new TNode({L, R, nullptr, nullptr, {INF, -1, -1, -1}, 0}); n } n Data safe(TNode *root) { n   if (!root) { n     return {INF, -1, -1, -1}; n   } n   return root->d; n } n Data upd(Data a, Data b) { n   Data c; n   c.min = min(a.min, b.min); n   c.max = max(a.max, b.max); n   c.resl = max({a.resl, b.resl, a.max - 2 * b.min}); n   c.resr = max({a.resr, b.resr, b.max - 2 * a.min}); n   return c; n } n void relax(TNode *root) { n   if (!root) return; n   root->d = upd(safe(root->left), safe(root->right)); n } n void add_val(TNode *root, long long val) { n   if (!root) return; n   root->val += val; n   (root->d).min += val; n   (root->d).max += val; n   (root->d).resl -= val; n   (root->d).resr -= val; n } n void push(TNode *root) { n   if (!root) return; n   add_val(root->left, root->val); n   add_val(root->right, root->val); n   root->val = 0; n } n vector<long long> pref; n TNode *build_tree(long long L, long long R) { n   TNode *root = new_node(L, R); n   if (R - L == 1) { n     root->d = {pref[L], pref[L], -pref[L], -pref[L]}; n   } else { n     long long M = (L + R) / 2; n     root->left = build_tree(L, M); n     root->right = build_tree(M, R); n     relax(root); n   } n   return root; n } n void add_seg(TNode *root, long long L, long long R, long long val) { n   if (L >= root->R || root->L >= R) { n     return; n   } n   if (L <= root->L && root->R <= R) { n     add_val(root, val); n     return; n   } n   push(root); n   add_seg(root->left, L, R, val); n   add_seg(root->right, L, R, val); n   relax(root); n } n Data get_res(TNode *root, long long L, long long R) { n   if (L >= root->R || root->L >= R) { n     return {INF, -1, -1, -1}; n   } n   if (L <= root->L && root->R <= R) { n     return root->d; n   } n   push(root); n   Data res = upd(get_res(root->left, L, R), get_res(root->right, L, R)); n   relax(root); n   return res; n } n long long m; n pair<long long, long long> get_max(TNode *root) { n   if (root->R - root->L == 1) { n     return {(root->d).max, root->L}; n   } n   push(root); n   pair<long long, long long> ret; n   if (safe(root->left).max > safe(root->right).max) { n     ret = get_max(root->left); n   } else { n     ret = get_max(root->right); n   } n   relax(root); n   return ret; n } n void print(TNode *root) { n   if (root->R - root->L == 1) { n     cout << (root->d).max <<    ; n     return; n   } n   push(root); n   print(root->left); n   print(root->right); n   relax(root); n } n long long query(TNode *root) { n   auto t = get_max(root); n   long long pos = t.second, val = t.first; n   Data a = get_res(root, 0, pos); n   Data b = get_res(root, pos + 1, m); n   return max(max(a.resl, b.resr) + val, 0LL); n } n int main() { n   ios_base::sync_with_stdio(false); n   long long n, q; n   cin >> n >> q; n   string s; n   cin >> s; n   pref.push_back(0); n   for (long long i = 0; i < 2 * (n - 1); i++) { n     pref.push_back(pref.back() + (s[i] ==  (  ? 1 : -1)); n   } n   m = 2 * n - 1; n   TNode *root = build_tree(0, m); n   cout << query(root) <<   n ; n   for (long long i = 0; i < q; i++) { n     long long a, b; n     cin >> a >> b; n     a--, b--; n     if (a > b) swap(a, b); n     if (s[a] != s[b]) { n       if (s[a] ==  ( ) { n         add_seg(root, a + 1, b + 1, -2); n       } else { n         add_seg(root, a + 1, b + 1, 2); n       } n       swap(s[a], s[b]); n     } n     cout << query(root) <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000 * 1000 + 20; n const int N5 = 300 * 1000 + 10; n const int N3 = 3000 + 20; n const long long mod = 1000 * 1000 * 1000 + 9; n const long long inf = LLONG_MAX / 2; n long long dp[2][N], par[N], rnk[N]; n long long __pow(long long x, int y) { n   if (y == 0) return 1; n   return __pow(x * x % mod, y / 2) % mod * (y & 1 ? x : 1) % mod; n } n int find_root(int v) { n   if (par[v] == v) { n     return v; n   } n   return par[v] = find_root(par[v]); n } n void _merge(int a, int b) { n   int r_a = find_root(a); n   int r_b = find_root(b); n   if (rnk[r_a] > rnk[r_b]) { n     swap(r_a, r_b); n   } n   par[r_a] = r_b; n   if (rnk[r_a] == rnk[r_b]) { n     rnk[r_b]++; n   } n   return; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, m; n   cin >> n >> m; n   int t = 0; n   for (int i = 1; i <= n; i++) par[i] = i; n   for (int i = 1; i <= m; i++) { n     int x, y; n     cin >> x >> y; n     if (find_root(x) != find_root(y)) { n       t++; n       _merge(x, y); n     } n     cout << ((__pow(2, i - t) + mod) - 1) % mod <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string a, b, c; n   cin >> a >> b >> c; n   if (a[0] == c[2] && a[1] == c[1] && a[2] == c[0] && b[0] == b[2]) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long I1 = 1e9; n const long long I2 = 1e18; n const int32_t M1 = 1e9 + 7; n const int32_t M2 = 998244353; n template <typename T, typename T1> n T maxn(T &a, T1 b) { n   if (b > a) a = b; n   return a; n } n template <typename T, typename T1> n T minn(T &a, T1 b) { n   if (b < a) a = b; n   return a; n } n const int M = 3005; n bool cc[M][M]; n long long int dis[M][M]; n set<pair<pair<long long int, long long int>, long long int> > s; n vector<long long int> a[M]; n void solve() { n   int n, m, k; n   cin >> n >> m >> k; n   for (long long int i = 0; i < m; i++) { n     int x, y; n     cin >> x >> y; n     a[x].push_back(y); n     a[y].push_back(x); n   } n   for (long long int i = 0; i < k; i++) { n     int x, y, z; n     cin >> x >> y >> z; n     s.insert({{x, y}, z}); n   } n   queue<pair<long long int, long long int> > q; n   q.push({1, 1}); n   while (!q.empty()) { n     pair<long long int, long long int> cur = q.front(); n     int x = cur.first, y = cur.second; n     q.pop(); n     cc[cur.first][cur.second] = true; n     for (auto u : a[y]) { n       if (s.count({{x, y}, u})) continue; n       if (cc[y][u] == true) continue; n       cc[y][u] = true; n       dis[y][u] = dis[x][y] + 1; n       q.push({y, u}); n     } n   } n   long long int d = I1, i = n, prev = n; n   for (long long int i = 1; i <= n; i++) { n     if (dis[i][n] != 0) minn(d, dis[i][n]); n   } n   if (d == I1) { n     cout <<  -1  << endl; n     return; n   } n   cout << d << endl; n   vector<long long int> ans; n   ans.push_back(n); n   while (i != 1) { n     long long int ind = -1; n     for (long long int j = 1; j <= n; j++) { n       if (dis[j][i] == d) { n         ind = j; n         break; n       } n     } n     ans.push_back(ind); n     prev = i; n     i = ind; n     d--; n   } n   reverse(ans.begin(), ans.end()); n   for (auto u : ans) cout << u <<    ; n   cout << endl; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int testcase = 1; n   while (testcase--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n const long long MOD = 1000 * 1000 * 1000 + 7; n const long long MOD1 = 998244353; n const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7; n using namespace std; n long long power(long long x, long long y) { n   long long res = 1; n   while (y > 0) { n     if (y & 1) res = (long long)(res * x); n     y = y >> 1; n     if (x <= 100000000) x = (long long)(x * x); n   } n   return res; n } n long long val[5001][5001]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   long long a[n + 1]; n   for (int(i) = (1); (i) < (n + 1); ++(i)) { n     cin >> a[i]; n     val[i][i] = a[i]; n   } n   for (int i = 2; i <= n; i++) { n     for (int j = 1; j <= n - i + 1; j++) { n       val[j][j + i - 1] = val[j][j + i - 2] ^ val[j + 1][j + i - 1]; n     } n   } n   for (int i = 2; i <= n; i++) { n     for (int j = 1; j <= n - i + 1; j++) { n       val[j][j + i - 1] = n           max(val[j][j + i - 1], max(val[j][j + i - 2], val[j + 1][j + i - 1])); n     } n   } n   long long q; n   cin >> q; n   while (q--) { n     long long x, y; n     cin >> x >> y; n     cout << val[x][y] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename TT> n ostream& operator<<(ostream& out, pair<T, TT> t) { n   return out <<  (  << t.first <<  ,  << t.second <<  ) ; n } n template <typename T> n ostream& operator<<(ostream& out, vector<T> t) { n   for (int i = 0; i < ((int)(t).size()); i++) out << t[i] <<    ; n   return out; n } n template <typename T> n inline bool cmin(T& a, const T& b) { n   return a > b ? a = b, 1 : 0; n } n template <typename T> n inline bool cmax(T& a, const T& b) { n   return a < b ? a = b, 1 : 0; n } n template <typename T> n void read(T& x) { n   int f = 1; n   char ch; n   x = 0; n   while (!isdigit(ch = getchar())) n     ; n   while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar(); n   x *= f; n } n const int NX = 201234; n int n, m, p[NX]; n map<int, int> e[NX]; n int main() { n   read(n); n   read(m); n   for (int i = 1, u, v; i <= m; i++) { n     read(u); n     read(v); n     e[u][v] = e[v][u] = true; n   } n   for (int i = 1; i <= n; i++) p[i] = i; n   for (int T = 200; T--;) { n     random_shuffle(p + 1, p + n + 1); n     int cnt = 0; n     for (int i = 1; i <= n; i++) { n       int l = p[i], r = p[i % n + 1]; n       cnt += !e[l].count(r); n     } n     if (cnt >= m) { n       for (int i = 1; i <= n; i++) { n         int l = p[i], r = p[i % n + 1]; n         if (!e[l].count(r)) { n           printf( %d %d n , l, r); n           if (!--m) return 0; n         } n       } n     } n   } n   puts( -1 ); n   return 0; n } n