#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T sqr(T t) {     return t * t;   }   inline void files() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int n, a[100100];   int main() {     files();     int l = 0, r = 0;     int ans = 0;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 3; i <= n; i++) {       if (a[i] == a[i - 1] + a[i - 2]) {         if (l == 0) l = max(1, i - 2);         r = i;         ans = max(ans, r - l + 1);       } else {         l = 0;         r = 0;       }     }     ans = max(ans, min(n, 2));     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   void nhap() { cin >> n >> m >> k; }   long long tinh(long long x) {     if (x > k) return -1e19 + 10;     long long r = n / (x + 1);     long long h = k - x;     long long d = m / (h + 1);     return r * d;   }   void xuli() {     if (n - 1 + m - 1 < k) {       cout << -1;       return;     }     long long kq = -1e19 + 10;     for (int i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         kq = max(kq, tinh(1ll * i - 1));         kq = max(kq, tinh(n / i - 1));       }     }     swap(n, m);     for (int i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         kq = max(kq, tinh(1ll * i - 1));         kq = max(kq, tinh(n / i - 1));       }     }     cout << kq;   }   int main() {     nhap();     xuli();   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 5;   long long n, k, sum, l, x, m, i, a, b[N];   vector<long long> ans;   int main() {     cin >> n;     if (n == 1) {       cin >> a;       cout << a;       return 0;     }     for (long long i = 0; i < n; i++) {       cin >> a;       b[i] = a + i;     }     sort(b, b + n);     for (long long i = 0; i < n; i++) {       ans.push_back(b[i] - i);       if (b[i] == b[i + 1]) return cout <<  :(  << endl, 0;     }     for (long long i = 0; i < n; i++) {       cout << ans[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char str[200005];     gets(str);     vector<char> v;     if (strlen(str) > 1) {       v.push_back(str[0]);       v.push_back(str[1]);     } else {       cout << str;       return 0;     }     int l = strlen(str);     int len;     for (int i = 2; i < l; i++) {       len = v.size();       if (str[i] == v[len - 1] && str[i] == v[len - 2]) continue;       if (v[len - 3] == v[len - 2] && str[i] == v[len - 1])         continue;       else         v.push_back(str[i]);     }     len = v.size();     for (int i = 0; i < len; i++) printf( %c , v[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100500];   int v[100500];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     v[0] = -1;     int ans = 0;     for (int i = 0; i < n; i++) {       int l = 0, r = ans + 1;       while (r - l > 1) {         int j = (l + r) / 2;         if (v[j] < a[i])           l = j;         else           r = j;       }       v[l + 1] = a[i];       if (l + 1 > ans) ans = l + 1;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T sq(T n) {     return n * n;   }   template <class T>   T gcd(T a, T b) {     return (b != 0 ? gcd<T>(b, a % b) : a);   }   template <class T>   T lcm(T a, T b) {     return (a / gcd<T>(a, b) * b);   }   template <class T>   T power(T N, T P) {     return (P == 0) ? 1 : N * power(N, P - 1);   }   int A[5000001], len;   long long dp[5000001];   int convert(char c) {     if (c >=  a  && c <=  z )       return (int)(c - 87);     else if (c >=  0  && c <=  9 )       return (int)(c - 48);     else       return (int)(c - 29);   }   int main(int argc, char *argv[]) {     string S;     int i;     long long k1, k2, v = 1, res = 1;     cin >> S;     len = S.length();     for (i = 0; i <= len - 1; i++) A[i] = convert(S[i]);     dp[0] = 1;     k1 = A[0];     k2 = A[0];     for (i = 1; i <= len - 1; i++) {       v *= 5;       k1 += (v * A[i]);       k2 = 5 * k2 + A[i];       if (k1 == k2) dp[i] = dp[(i + 1) / 2 - 1] + 1;       res += dp[i];     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m;   long long a[10001], f[10001];   int main() {     int d, x, y;     scanf( %I64d %I64d , &n, &m);     f[0] = f[1] = 1;     for (int i = 2; i <= n; i++) f[i] = f[i - 1] + f[i - 2], f[i] %= 1000000000LL;     for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]);     for (int i = 1; i <= m; i++) {       scanf( %I64d , &d);       if (d == 1) {         scanf( %I64d %I64d , &x, &y);         a[x] = y;       } else {         long long ans = 0;         scanf( %I64d %I64d , &x, &y);         for (int i = x; i <= y; i++) ans += f[i - x] * a[i], ans %= 1000000000LL;         printf( %I64d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   FILE *in = stdin, *out = stdout;   using namespace std;   int n;   vector<int> son[5005];   int tot;   vector<int> edge[5005];   int dy[5005][2][5005];   int leaf[5005];   int visit[5005];   void input() {     fscanf(in,  %d , &n);     for (int i = (1); i <= (n - 1); i++) {       int x, y;       fscanf(in,  %d , &x), fscanf(in,  %d , &y);       edge[x].push_back(y);       edge[y].push_back(x);     }   }   int temp[2][5005];   void go(int x) {     visit[x] = 1;     int flag = 0;     for (auto &i : edge[x]) {       if (visit[i]) continue;       go(i);       if (flag == 0) dy[x][0][0] = dy[x][1][0] = 0;       flag = 1;       for (int j = (0); j <= (leaf[x] + leaf[i]); j++)         temp[0][j] = temp[1][j] = 0x7fffffff;       for (int p1 = (0); p1 <= (1); p1++)         for (int p2 = (0); p2 <= (1); p2++)           for (int j = (0); j <= (leaf[x]); j++)             for (int k = (0); k <= (leaf[i]); k++)               if (dy[x][p1][j] != 0x7fffffff && dy[i][p2][k] != 0x7fffffff)                 temp[p1][j + k] =                     min(temp[p1][j + k],                         dy[x][p1][j] + dy[i][p2][k] + (p1 == p2 ? 0 : 1));       for (int j = (0); j <= (leaf[x] + leaf[i]); j++)         for (int k = (0); k <= (1); k++) dy[x][k][j] = temp[k][j];       leaf[x] += leaf[i];     }     if (flag == 0) {       leaf[x] = 1;       dy[x][0][0] = 0;       dy[x][1][1] = 0;       tot++;     }   }   void pro() {     for (int i = (0); i <= (n); i++)       for (int j = (0); j <= (n); j++) dy[i][0][j] = dy[i][1][j] = 0x7fffffff;     for (int i = (1); i <= (n); i++)       if (edge[i].size() > 1) {         go(i);         fprintf(out,  %d , dy[i][1][tot / 2]);         return;       }   }   int main() {     input();     if (n == 2)       fprintf(out,  1 );     else       pro();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   const int maxn = 2e5 + 5;   struct node {     int idx, p;     bool operator<(const node &b) const { return p < b.p; }   } ver[100005], hor[100005];   int vcnt, hcnt;   vector<node> V1[maxn], V2[maxn];   int tempx[100005], tempy[100005];   int ansx[100005], ansy[100005];   int main() {     int n, w, h;     cin >> n >> w >> h;     int g, p, t;     for (int i = 1; i <= n; i++) {       scanf( %d , &g);       if (g == 1) {         vcnt++;         scanf( %d%d , &p, &t);         V1[p - t + 100000].push_back({i, p});       } else {         hcnt++;         scanf( %d%d , &p, &t);         V2[p - t + 100000].push_back({i, p});       }     }     for (int i = 0; i < maxn; i++) {       sort(V1[i].begin(), V1[i].end());       sort(V2[i].begin(), V2[i].end());     }     for (int i = 0; i < maxn; i++) {       int cnt = 0;       for (int j = 0; j < V1[i].size(); j++) {         tempx[cnt] = V1[i][j].p;         tempy[cnt] = h;         cnt++;       }       for (int j = V2[i].size() - 1; j >= 0; j--) {         tempx[cnt] = w;         tempy[cnt] = V2[i][j].p;         cnt++;       }       cnt = 0;       for (int j = V2[i].size() - 1; j >= 0; j--) {         ansx[V2[i][j].idx] = tempx[cnt];         ansy[V2[i][j].idx] = tempy[cnt];         cnt++;       }       for (int j = 0; j < V1[i].size(); j++) {         ansx[V1[i][j].idx] = tempx[cnt];         ansy[V1[i][j].idx] = tempy[cnt];         cnt++;       }     }     for (int i = 1; i <= n; i++) {       printf( %d %d n , ansx[i], ansy[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[105][105], n, m, k;   int res, c;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) cin >> a[i][j];     for (int j = 1; j <= m; ++j) {       int cnt = 0;       int maxx = 0;       int now = 0;       for (int i = 1; i <= n; ++i)         if (a[i][j] == 1) {           int tmp = 0;           cnt++;           for (int h = i; h <= i + min(k, n - i + 1) - 1; ++h)             if (a[h][j] == 1) ++tmp;           if (tmp > maxx) {             maxx = tmp;             now = cnt;           }         }       res += maxx;       c += max(0, now - 1);     }     cout << res <<     << c;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long x, long long y, long long z) {     long long ret = 1;     while (y > 0) {       if (y & 1) ret = (ret * x) % z;       x = (x * x) % z;       y >>= 1;     }     return ret;   }   long long q;   map<long long, long long> getFactors(long long num) {     long long i;     map<long long, long long> answer;     for (i = 2; i * i <= num; i++) {       while (num > 1 && num % i == 0) {         answer[i]++;         num /= i;       }     }     if (num > 1) answer[num]++;     return answer;   }   int main() {     long long i, j, t;     scanf( %lld , &q);     ;     map<long long, long long> factors = getFactors(q);     long long sum = 0, xorVal = 0, flag = 0, ting;     for (auto it = factors.begin(); it != factors.end(); it++) {       long long temp = it->second;       sum += temp;     }     xorVal = factors.size();     cerr <<  sum           <<   ::   << sum <<   t           <<  flag           <<   ::   << flag <<   t           <<  xorVal           <<   ::   << xorVal <<   n ;     ;     if (sum == 2) {       cout <<  2  << endl;       return 0;     }     if (sum <= 1)       cout <<  1  << endl <<  0  << endl;     else {       long long answer = 1, cutter = 0;       for (auto it = factors.begin(); it != factors.end(); it++) {         long long siz = it->second;         for (j = 0; j < siz; j++) {           if (cutter >= 2) {             cout <<  1  << endl << answer << endl;             return 0;           }           answer = answer * (it->first);           cutter++;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       long long int arr[n];       long long int i;       for (i = 0; i <= n - 1; i++) {         cin >> arr[i];       }       long long int temp = k;       vector<long long int> v;       long long int sum = 0;       for (i = 0; i <= n - 1; i++) {         sum = sum + arr[i];         if (sum % 2 != 0 && temp > 1) {           v.push_back(i);           sum = 0;           temp--;         }       }       if (sum % 2 == 0) {         cout <<  NO               <<   n ;       } else {         v.push_back(n - 1);         cout <<  YES               <<   n ;         for (i = 0; i < v.size(); i++) {           cout << v[i] + 1 <<    ;         }         cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 111111;   const int INF = 1000000000, mod = 1000000007;   const long long LLINF = 1000000000000000000ll;   pair<string, string> a[N];   int p[N];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second;     for (int i = 0; i < n; ++i) {       cin >> p[i];       --p[i];     }     string mx =   ;     for (int j = 0; j < n; ++j) {       int i = p[j];       if (j == 0) {         mx = min(a[i].first, a[i].second);         continue;       }       if (a[i].first > a[i].second) swap(a[i].first, a[i].second);       if (a[i].first < mx) {         if (a[i].second < mx) {           puts( NO );           return 0;         }         mx = a[i].second;       } else         mx = a[i].first;     }     puts( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100010;   int n, d, m, cnta = 0, cntb = 0;   long long a[MAXN], b[MAXN];   inline bool cmp(long long x, long long y) { return x > y; }   int main() {     scanf( %d%d%d , &n, &d, &m);     for (int i = 1; i <= n; i++) {       long long x;       scanf( %lld , &x);       if (x > m)         a[++cnta] = x;       else         b[++cntb] = x;     }     sort(a + 1, a + cnta + 1, cmp);     sort(b + 1, b + cntb + 1, cmp);     for (int i = 1; i <= cnta; i++) a[i] += a[i - 1];     for (int i = 1; i <= cntb; i++) b[i] += b[i - 1];     long long ans = b[cntb];     for (int i = 1; i <= cnta; i++) {       if ((i - 1) * (d + 1) + 1 > n) break;       int ind = min(n - (i - 1) * (d + 1) - 1, cntb);       ans = max(ans, a[i] + b[ind]);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5, MOD = 1e9 + 7;   int main() {     vector<int> a(27, -1), b(27, -1), c(27, -1);     string str;     cin >> str;     for (int i = 0; i < (int)str.size(); i++) {       if (a[str[i] -  a ] == -1) {         a[str[i] -  a ] = i;         c[str[i] -  a ] = i;       } else {         b[str[i] -  a ] = max(i - a[str[i] -  a ], b[str[i] -  a ]);         a[str[i] -  a ] = i;       }     }     int x = (int)str.size() - 1;     int ans = (int)str.size() / 2 + 1;     for (int i = 0; i < 27; i++) {       if (b[i] != -1) {         b[i] = max({b[i], x - a[i] + 1, c[i] + 1});         ans = min(b[i], ans);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T, class U>   void ckmin(T &a, U b) {     if (a > b) a = b;   }   template <class T, class U>   void ckmax(T &a, U b) {     if (a < b) a = b;   }   int N, K;   pair<int, int> arr[213];   vector<pair<int, int> > blocks;   int dp[100013][2];   int tmp[100013][2];   int ans;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout << fixed << setprecision(12);     cerr << fixed << setprecision(4);     cin >> N >> K;     for (auto i = (0); i < (K); i++) {       cin >> arr[i].first >> arr[i].second;       if (i == 0 && arr[i].first > 0) {         blocks.push_back({arr[i].first, 0});       }       if (i > 0) {         blocks.push_back({arr[i].first - arr[i - 1].second, 0});       }       blocks.push_back({arr[i].second - arr[i].first, 1});     }     if (arr[K - 1].second != 2 * N) {       blocks.push_back({2 * N - arr[K - 1].second, 0});     }     for (auto i = (0); i < (N + 1); i++) {       dp[i][0] = 1000000007;       dp[i][1] = 1000000007;     }     dp[0][0] = 0;     dp[0][1] = 0;     for (pair<int, int> p : blocks) {       int sz = p.first;       if (!p.second) {         for (auto i = (N + 1) - 1; i >= (sz); i--) {           dp[i][0] = dp[i - sz][0];         }         for (auto i = (sz)-1; i >= (0); i--) {           dp[i][0] = 1000000007;         }       } else {         for (auto i = (0); i < (N + 1); i++) {           tmp[i][0] = 1000000007;           tmp[i][1] = 1000000007;         }         multiset<int> dp0, dp1;         for (auto i = (0); i < (N + 1); i++) {           dp0.insert(dp[i][0]);           dp1.insert(dp[i][1]);           ckmin(tmp[i][0], *dp0.begin() + 2);           ckmin(tmp[i][1], *dp1.begin() + 2);           ckmin(tmp[i][1], *dp0.begin() + 1);           ckmin(tmp[i][0], *dp1.begin() + 1);           if (i >= sz) {             dp0.erase(dp0.find(dp[i - sz][0]));             dp1.erase(dp1.find(dp[i - sz][1]));           }         }         for (auto i = (0); i < (N + 1); i++) {           ckmin(tmp[i][1], dp[i][1]);         }         for (auto i = (0); i < (N + 1 - sz); i++) {           ckmin(tmp[i + sz][0], dp[i][0]);         }         for (auto i = (0); i < (N + 1); i++) {           dp[i][0] = tmp[i][0];           dp[i][1] = tmp[i][1];         }       }     }     ans = min(dp[N][0], dp[N][1]);     if (ans >= 1000000007) {       cout <<  Hungry n ;       return 0;     }     cout <<  Full n  << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T bigmod(T p, T e, T M) {     long long int ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return (T)ret;   }   template <class T>   inline T modinverse(T a, T M) {     return bigmod(a, M - 2, M);   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int arr[105], cnt;   int moveee(int n) {     for (int i = 3, j = 1; i <= 99; i += 2, j++)       if (n == i) return j;     return -1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     ;     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> arr[i];     int mov = moveee(n);     if (mov == -1) return cout << -1 << endl, 0;     for (int i = mov; i >= 1; i--) {       int a = i, b = i << 1, c = b + 1;       int maxi = max(arr[b], arr[c]);       arr[a] = max(0, arr[a] - maxi);       arr[b] = max(0, arr[b] - maxi);       arr[c] = max(0, arr[c] - maxi);       cnt += maxi;     }     if (arr[1] > 0) cnt += arr[1];     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1);   const int maxn = 1e6 + 10;   const int mod = 1e9 + 7;   typedef struct p {     long long x, y;   };   p a[maxn];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %lld %lld , &a[i].x, &a[i].y);     }     int isok = 1;     if (n % 2) {       printf( NO n );       return 0;     }     for (int i = 0; i < n / 2; i++) {       int a1 = i, b1 = i + 1, a2 = (i + n / 2 + n) % n,           b2 = (i + n / 2 + n + 1) % n;       if (abs(a[a1].x - a[b1].x) != abs(a[a2].x - a[b2].x) ||           abs(a[a1].y - a[b1].y) != abs(a[a2].y - a[b2].y)) {         isok = 0;         break;       }     }     if (isok)       printf( YES n );     else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int r, c, n, k;     cin >> r >> c >> n >> k;     int x[n], y[n], res = 0, xi, yi;     for (int i = 0; i < n; i++) {       cin >> xi >> yi;       x[i] = xi - 1;       y[i] = yi - 1;     }     for (int i = 0; i < r; i++) {       for (int j = 0; j < c; j++) {         for (int i2 = i; i2 < r; i2++) {           for (int j2 = j; j2 < c; j2++) {             int violasenimg = 0;             for (int v = 0; v < n; v++) {               if (i <= x[v] && x[v] <= i2 && j <= y[v] && y[v] <= j2)                 violasenimg++;             }             if (violasenimg >= k) res++;           }         }       }     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e6 + 5;   long long v[MAX];   long long GCD(long long a, long long b) {     if (!b) return a;     if (!a) return b;     return GCD(b, a % b);   }   int main() {     long long mx = 0;     long long n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> v[i];       mx = max(v[i], mx);     }     long long G = 0;     for (int i = 1; i <= n; i++) {       G = GCD(mx - v[i], G);     }     long long ans1 = 0;     for (int i = 1; i <= n; i++) {       ans1 += (mx - v[i]) / G;     }     cout << ans1 <<     << G <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e5 + 11;   long long cs[4][N], n, dp[N][4][4];   vector<int> g[N], ord;   bool u[N];   void dfs(int v) {     u[v] = 1;     ord.push_back(v);     for (int i = 0; i < g[v].size(); i++) {       int to = g[v][i];       if (!u[to]) dfs(to);     }   }   pair<long long, vector<int> > f(int x, int y) {     long long res = 0;     vector<int> g(n + 1);     g[ord[0]] = x;     g[ord[1]] = y;     res += cs[x][ord[0]] + cs[y][ord[1]];     for (int i = 2; i < n; i++) {       int cur = ord[i];       int col = 6 - x - y;       res += cs[col][cur];       g[cur] = col;       x = y;       y = col;     }     return make_pair(res, g);   }   void solve() {     cin >> n;     for (int i = 1; i <= 3; i++)       for (int j = 1; j <= n; j++) cin >> cs[i][j];     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     int cnt = 0;     for (int i = 1; i <= n; i++)       if (g[i].size() > 2) {         cout << -1;         return;       } else if (g[i].size() == 1)         cnt++;     if (cnt != 2) {       cout << -1;       return;     }     int st = 0;     for (int i = 1; i <= n; i++)       if (g[i].size() == 1) st = i;     dfs(st);     pair<long long, vector<int> > ans = min(         min(f(1, 2), f(1, 3)), min(min(f(2, 1), f(2, 3)), min(f(3, 1), f(3, 2))));     cout << ans.first <<   n ;     for (int i = 1; i <= n; i++) cout << ans.second[i] <<    ;   }   int main() {     ;     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int tt = 1;     for (int i = 1; i <= tt; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int sum = 0;     for (int i = 0; i < n; ++i) {       int l, r;       cin >> l >> r;       sum += r - l + 1;     }     int ct = 0;     while (sum % k != 0) {       ct++;       sum++;     }     cout << ct << endl;   }


#include <bits/stdc++.h>   using namespace std;   char buff[100010];   int calc() {     scanf( %s , buff);     int mask = 0;     int len = strlen(buff);     for (int i = 0; i < len; ++i) mask |= 1 << (buff[i] -  a );     return mask;   }   int main() {     int n;     scanf( %d , &n);     int mask = (1 << 26) - 1;     bool flag = false;     int cnt = 0;     for (int i = 0; i < n; ++i) {       scanf( %s , buff);       char op = buff[0];       if (!flag) {         if (op ==  ! ) {           mask &= calc();         } else if (op ==  . ) {           mask &= ~calc();         } else {           mask &= ~calc();         }         if (mask == (mask & -mask)) flag = true;       } else {         if (op ==  ! ) {           if (mask & calc()) cnt++;         } else if (op ==  . ) {           calc();         } else {           if (calc() != mask) cnt++;         }       }     }     printf( %d n , cnt);     return 0;   }


#include <bits/stdc++.h>   const int N = 1e5 + 5;   char str[N];   int n, s[N];   long long f[N][11], ans;   inline int nex(int i, int j) { return (9 + i * (i - 1) / 2 + j + 1) % 11; }   int main() {     scanf( %s , str + 1);     n = strlen(str + 1);     for (int i = 1; i <= n; ++i) s[i] = str[i] -  0 ;     for (int i = 1; i <= n; ++i)       if (s[i]) ++f[i][s[i]];     for (int i = 1; i <= n; ++i)       for (int j = 0; j <= 10; ++j) {         if (s[i] < j) f[i][nex(j, s[i])] += f[i - 1][j];       }     for (int i = 1; i <= n; ++i)       for (int j = 0; j <= 10; ++j) ans += f[i][j];     printf( %I64d n , ans);     return 0;   }


#include<bits/stdc++.h>   #define llu unsigned long long     #define ll long long    #define l1 int   #define u_m unordered_map   #define M map   #define answer cout<<ans<<endl;   #define Sum cout<<sum<<endl;   #define sort1(s) sort(s.begin(),s.end())   #define pb(x) push_back(x)   #define yes cout<< YES <<endl;   #define no cout<< NO <<endl;   using namespace std;   /*    vector<vector<int>> v(101,vector<int>());   vector<bool> b(101,false);   vector<int> ans(101);       ll power(ll x, ll y)     {         ll res = 1;               while (y > 0)         {             if (y & 1)                 res = (res*x)%mod;             y = y/2;             x = (x*x)%mod;       }         return res%mod;     }   int dfs(int p,int k)   {       a[p]=true;       int i,j=1;       for(i=0;i<v[p].size();i++)       {           if(a[v[p][i]]==false)           {               if(k==4)               {                   ans[v[p][i]]=5;                   a[v[p][i]]=true;                   j=dfs(v[p][i],5);               }               else               {                   ans[v[p][i]]=4;                   a[v[p][i]]=true;                   j=dfs(v[p][i],4);               }           }       }       return j;   }   ll prime(ll n)   {       ll mx=n+1;//cout<<mx<<endl;       for(ll i=2;i*i<=n;i++)       {           if(n%i==0 && n/i!=i)           {               mx=min(mx,(n/i) + i);               //cout<<mx<<endl;           }       }       return mx;   }   ll modinv(ll x)   {       return power(x,mod-2)%mod;       }   void swap(ll *xp, ll *yp)    {        ll temp = *xp;        *xp = *yp;        *yp = temp;    }   void print(vector<ll> v)   {       ll i,j,n=v.size();       for(i=0;i<n;i++)       {           cout<<v[i]<<   ;       }       cout<<endl;   }   bool sortcol( const vector<int>& v1,                   const vector<int>& v2 ) {     return v1[1] < v2[1];    }        bool sortcol1( const vector<int>& v1,                   const vector<int>& v2 ) {     return v1[0] < v2[0];    }   void scan(vll &v,ll n)   {       for(ll i=0;i<n;i++)       cin>>v[i];   }   ll gcd(ll a, ll b)    {        if (b == 0)            return a;        return gcd(b, a % b);     }   ll lcm(ll a,ll b)   {       return (a*b)/gcd(a,b);   }   */       int main()   {       ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);       /*l1 t;       cin>>t;       while(t--)*/       {        ll n;        cin>>n;        if(n==1)        {         cout<<4;         return 0;        }        if(n%2==0)        {         n=(n/2 + 1)*(n/2 + 1);        }        else        {         n=2*(n/2 + 1)*(n/2 + 2);        }        cout<<n;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   template <class T>   inline void gn(T &first) {     char c, sg = 0;     while (c = getchar(), (c >  9  || c <  0 ) && c !=  - )       ;     for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ;          c = getchar())       first = (first << 1) + (first << 3) + c -  0 ;     if (sg) first = -first;   }   template <class T, class T1>   inline void gn(T &first, T1 &second) {     gn(first);     gn(second);   }   template <class T, class T1, class T2>   inline void gn(T &first, T1 &second, T2 &z) {     gn(first);     gn(second);     gn(z);   }   template <class T>   inline void print(T first) {     if (first < 0) {       putchar( - );       return print(-first);     }     if (first < 10) {       putchar( 0  + first);       return;     }     print(first / 10);     putchar(first % 10 +  0 );   }   template <class T>   inline void printsp(T first) {     print(first);     putchar(   );   }   template <class T>   inline void println(T first) {     print(first);     putchar(  n );   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   struct Node {     int sz, val;     Node *ls, *rs, *fa;   } buf[1111111];   int used;   struct Splay_Tree {     Node *root, *NIL, *minf, *pinf;     Node *create_node(int first = 0) {       Node *node = &buf[used++];       node->sz = 1;       node->val = first;       node->ls = node->rs = node->fa = NIL;       return node;     }     void init() {       used = 0;       NIL = create_node(0);       NIL->sz = 0;       Node *first = create_node(-0x3f3f3f3f);       Node *second = create_node(0x3f3f3f3f);       first->rs = second;       second->fa = first;       root = first;       minf = first;       pinf = second;       update(first);     }     void update(Node *first) { first->sz = first->ls->sz + first->rs->sz + 1; }     void zig(Node *first) {       Node *second = first->rs, *p = first->fa;       first->rs = second->ls;       second->ls->fa = first;       second->ls = first;       first->fa = second;       second->fa = p;       if (p == NIL)         root = second;       else if (p->ls == first)         p->ls = second;       else         p->rs = second;       update(first);     }     void zag(Node *first) {       Node *second = first->ls, *p = first->fa;       first->ls = second->rs;       second->rs->fa = first;       second->rs = first;       first->fa = second;       second->fa = p;       if (p == NIL)         root = second;       else if (p->rs == first)         p->rs = second;       else         p->ls = second;       update(first);     }     void splay(Node *first, Node *g) {       Node *second, *z;       while (first->fa != g) {         second = first->fa;         z = second->fa;         if (z == g) {           if (first == second->rs)             zig(second);           else             zag(second);         } else if (second == z->rs) {           if (first == second->rs)             zig(z), zig(second);           else             zag(second), zig(z);         } else {           if (first == second->rs)             zig(second), zag(z);           else             zag(z), zag(second);         }       }       update(first);     }     Node *find(Node *first, int k) {       if (k <= first->ls->sz) return find(first->ls, k);       if (k == first->ls->sz + 1) return first;       return find(first->rs, k - first->ls->sz - 1);     }     Node *next(Node *first, int val) {       if (first == NIL) return first;       if (first->val > val) {         Node *ans = next(first->ls, val);         if (ans == NIL) ans = first;         return ans;       } else         return next(first->rs, val);     }     Node *prev(Node *first, int val) {       if (first == NIL) return first;       if (first->val < val) {         Node *ans = prev(first->rs, val);         if (ans == NIL) ans = first;         return ans;       } else         return prev(first->ls, val);     }     Node *insert(int val) {       Node *first = create_node(val);       Node *z = prev(root, val);       Node *second = next(root, val);       splay(z, NIL);       splay(second, z);       first->fa = second;       second->ls = first;       update(second);       update(z);       return first;     }     void removeFront(int val) {       Node *first = minf;       Node *second = next(root, val);       splay(first, NIL);       splay(second, first);       second->ls = NIL;       update(second);       update(first);     }     void removeBack(int val) {       Node *first = pinf;       Node *second = prev(root, val);       splay(first, NIL);       splay(second, first);       second->rs = NIL;       update(second);       update(first);     }     void remove(int k) {       Node *z = find(root, k), *second = find(root, k + 2);       splay(z, NIL);       splay(second, z);       second->ls = NIL;       update(second);       update(z);     }     void remove(Node *first) {       splay(first, NIL);       remove(first->ls->sz);     }     void dup(Node *first) {       if (first == NIL) return;       dup(first->ls);       printf( %d  , first->val);       dup(first->rs);     }   } tree;   int N, s1, s2;   int first[111111];   bool possible(int d) {     tree.init();     tree.insert(s1);     int cur = s2;     for (int i = 0; i < N; i++) {       if (abs(cur - first[i]) <= d) tree.insert(cur);       tree.removeFront(max(first[i] - d - 1, -0x3f3f3f3f + 1));       tree.removeBack(min(first[i] + d + 1, 0x3f3f3f3f - 1));       if (tree.root->sz == 2) {         return false;       }       cur = first[i];     }     return true;   }   int main() {     gn(N, s1, s2);     for (int i = 0; i < N; i++) gn(first[i]);     int high = 1000000000, low = abs(s1 - s2);     while (high > low + 1) {       int mid = (high + low) / 2;       if (possible(mid))         high = mid;       else         low = mid;     }     if (possible(low))       printf( %d n , low);     else       printf( %d n , high);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<string> sx;   vector<string> vx;   int ft;   void generate(char str[], int k, int l) {     if (k < 0) {       str[l] =   0 ;       bool status = true;       for (int i = 0; i < strlen(str); i++) {         for (int j = i + 1; j < strlen(str); j++) {           if (str[i] == str[j]) {             status = false;             break;           }         }         if (status == false) break;       }       if (status) {         vx.push_back(string(str));       }       return;     } else {       for (int i = 0; i <= 9; i++) {         str[l] = i +  0 ;         generate(str, k - 1, l + 1);       }     }   }   set<string> check(string sno, int a, int b, set<string> fx) {     set<string> px;     for (int i = 0; i < vx.size(); i++) {       int c = 0, d = 0;       for (int j = 0; j < 4; j++) {         if (vx[i][j] == sno[j])           c++;         else {           for (int k = 0; k < 4; k++)             if (vx[i][j] == sno[k]) {               d++;               break;             }         }       }       if (c == a && b == d) {         if (ft == 0 || fx.find(vx[i]) != fx.end()) px.insert(vx[i]);       }     }     ft = 1;     return px;   }   int main() {     char str[10];     generate(str, 3, 0);     set<string> fx;     ft = 0;     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       char inp[100];       getchar();       scanf( %[^ n] , inp);       string sno =   ;       int b, c;       b = c = -1;       bool stat = false;       for (int i = 0; i < strlen(inp); i++) {         if (inp[i] ==    )           stat = true;         else {           if (!stat)             sno += inp[i];           else if (b == -1)             b = inp[i] -  0 ;           else if (c == -1)             c = inp[i] -  0 ;         }       }       fx = check(sno, b, c, fx);     }     if (fx.size() == 1) {       string req = *(fx.begin());       cout << req << endl;     } else if (fx.size() > 1)       cout <<  Need more data  << endl;     else if (fx.size() == 0)       cout <<  Incorrect data  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<pair<int, int> > road;     for (int a = (0); a < (m); a++) {       int p, q;       cin >> p >> q;       if (p > q) swap(p, q);       road.push_back(make_pair(p, q));     }     int field[101][101];     for (int a = (0); a < (101); a++)       for (int b = (0); b < (101); b++) field[a][b] = 10000;     for (int a = (0); a < (m); a++)       for (int b = (0); b < (m); b++) {         int p = road[b].first;         int q = road[b].second;         int r = road[a].first;         int s = road[a].second;         if (p != r && p != s & q != r && q != s) {           int count = 0;           if (p < r && r < q) count++;           if (p < s && s < q) count++;           if (count == 1) {             field[a + 1][b + 1] = 1;             field[b + 1][a + 1] = 1;           }         }       }     int check[101];     for (int j = 1; j <= m; j++)       for (int i = 1; i <= m; i++)         for (int k = 1; k <= m; k++)           field[i][k] = min(field[i][k], field[i][j] + field[j][k]);     int flag = 0;     for (int a = 1; a <= m; a++)       if (field[a][a] % 2 == 1) flag = 1;     if (flag == 1)       cout <<  Impossible  << endl;     else {       int out[101];       for (int a = (0); a < (101); a++) out[a] = -1;       for (int a = 1; a <= m; a++)         if (out[a] == -1) {           out[a] = 0;           for (int b = 1; b <= m; b++)             if (field[a][b] < 200) {               out[b] = field[a][b] % 2;             }         }       int fflag = 0;       for (int a = 1; a <= m; a++)         for (int b = 1; b <= m; b++) {           if (field[a][b] == 1)             if (out[a] + out[b] != 1) fflag = 1;         }       if (fflag == 1)         cout <<  Impossible  << endl;       else {         for (int a = 1; a <= m; a++) {           if (out[a] == 0)             cout <<  o ;           else             cout <<  i ;         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e6 + 00;   const long long inf = 1e9 + 800;   long long a[maxn];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, r, sum = 0;     ;     cin >> n >> r;     for (long long i = 0; i < (1 << n); i++) {       cin >> a[i];       sum += a[i];     }     cout << fixed << setprecision(10);     for (long long i = 0; i < r; i++) {       cout << (long double)sum / (1 << n) << endl;       long long p, v;       cin >> p >> v;       sum -= a[p];       a[p] = v;       sum += a[p];     }     cout << (long double)sum / (1 << n) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double EPS = 1e-11;   void fast() { std::ios_base::sync_with_stdio(0); }   int n;   vector<int> arr;   string s;   vector<vector<int>> dp;   int calc(int i, int state) {     if (i == n) return 0;     int &ret = dp[i][state];     if (ret != -1) {       return ret;     }     if (state == 1) return ret = calc(i + 1, 1) + arr[i];     if (s[i] ==  0 ) return ret = calc(i + 1, 0);     int x = calc(i + 1, 0) + arr[i];     int y = calc(i + 1, 1);     return ret = max(x, y);   }   int main() {     scanf( %d , &n);     arr.resize(n);     dp.resize(n);     for (int i = 0; i < n; i++) dp[i].resize(2, -1);     for (int &i : arr) scanf( %d , &i);     cin >> s;     reverse(arr.begin(), arr.end());     reverse(s.begin(), s.end());     printf( %d n , calc(0, 0));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int head[100005], fa[100005], a[100005];   struct edge {     int to, next;   } edges[200005];   int em;   void addedge(int u, int v) {     edges[em].next = head[u];     edges[em].to = v;     head[u] = em++;     edges[em].next = head[v];     edges[em].to = u;     head[v] = em++;   }   void dfs(int x, int f) {     fa[x] = f;     for (int e = head[x]; e != -1; e = edges[e].next) {       int v = edges[e].to;       if (v != f) {         dfs(v, x);       }     }   }   int gcd(int a, int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int main() {     int n, q;     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int m = n - 1;     memset(head, -1, sizeof(head));     while (m--) {       int x, y;       scanf( %d%d , &x, &y);       addedge(x, y);     }     dfs(1, -1);     while (q--) {       int qq;       scanf( %d , &qq);       if (qq == 1) {         int v;         scanf( %d , &v);         int in = -1;         int tmp = fa[v];         while (tmp != -1) {           int g = gcd(a[tmp], a[v]);           if (g > 1) {             in = tmp;             break;           }           tmp = fa[tmp];         }         printf( %d n , in);       } else if (qq == 2) {         int v, w;         scanf( %d%d , &v, &w);         a[v] = w;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     string second;     cin >> n >> second;     string t = second;     bool ok = 1;     vector<int> vec;     for (int i = 0; i < n; i++) {       if (second[i] ==  W ) continue;       if (i + 1 < n && second[i + 1] == second[i]) {         vec.push_back(i);         second[i] = second[i + 1] =  W ;         continue;       }       bool foo = 1;       int to = -1;       for (int j = i + 1; j < n; j++)         if (second[j] == second[i]) {           to = j;           break;         }       for (int j = i + 1; j < to; j++)         if (second[j] == second[i]) foo = 0;       if (to == -1) foo = 0;       if (foo) {         for (int j = i; j < to; j++) {           vec.push_back(j);           second[j] =  W ;         }         second[to] =  W ;         continue;       }       ok = 0;       break;     }     if (ok) {       cout << (int)vec.size() << endl;       for (auto i : vec) cout << i + 1 <<    ;       cout << endl;       return 0;     }     ok = 1;     vec.clear();     second = t;     for (int i = 0; i < n; i++) {       if (second[i] ==  B ) continue;       if (i + 1 < n && second[i + 1] == second[i]) {         vec.push_back(i);         second[i] = second[i + 1] =  B ;         continue;       }       bool foo = 1;       int to = -1;       for (int j = i + 1; j < n; j++)         if (second[j] == second[i]) {           to = j;           break;         }       for (int j = i + 1; j < to; j++)         if (second[j] == second[i]) foo = 0;       if (to == -1) foo = 0;       if (foo) {         for (int j = i; j < to; j++) {           vec.push_back(j);           second[j] =  B ;         }         second[to] =  B ;         continue;       }       ok = 0;       break;     }     if (ok) {       cout << (int)vec.size() << endl;       for (auto i : vec) cout << i + 1 <<    ;       cout << endl;       return 0;     }     cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   const int oo = 0x3f3f3f3f;   using namespace std;   inline int read() {     int x = 0, f = 1, hhh = getchar();     while (!isdigit(hhh)) {       if (hhh ==  - ) f = -1;       hhh = getchar();     }     while (isdigit(hhh)) {       x = x * 10 + hhh -  0 ;       hhh = getchar();     }     return x * f;   }   const int c[] = {0, 1, 2, 3, 4, 6, 12};   const int r[] = {0, 12, 6, 4, 3, 2, 1};   char a[100][100];   bool ans[10];   int main() {     int T = read();     while (T--) {       memset(a, 0, sizeof(a));       memset(ans, false, sizeof(ans));       string s;       cin >> s;       for (int cas = (1); cas <= (6); ++cas) {         int now = 0;         for (int i = (1); i <= (c[cas]); ++i)           for (int j = (1); j <= (r[cas]); ++j) {             a[i][j] = s[now++];           }         for (int i = (1); i <= (r[cas]); ++i) {           bool flag = false;           for (int j = (1); j <= (c[cas]); ++j) {             if (a[j][i] ==  O ) {               flag = true;               break;             }           }           if (!flag) {             ans[cas] = true;             break;           }         }       }       int ret = 0;       for (int i = (1); i <= (6); ++i) ret += (ans[i] == true);       printf( %d  , ret);       for (int i = (1); i <= (6); ++i)         if (ans[i] == true) printf( %dx%d  , c[i], r[i]);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f, oo = inf;   inline long long read() {     register long long x = 0, f = 1;     register char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     return x * f;   }   inline void write(long long x) {     if (x < 0) x = -x, putchar( - );     if (x >= 10) write(x / 10);     putchar(x % 10 +  0 );   }   inline void writeln(long long x) {     write(x);     puts(  );   }   const int Mod = 1e9 + 7;   inline int ppow(int a, int b) {     int ans = 1;     for (; b; b >>= 1, a = 1ll * a * a % Mod)       if (b & 1) ans = 1ll * ans * a % Mod;     return ans;   }   const int maxnode = 323333;   struct ACautomto {     struct node {       int nxt[26], fail, v, end;     } T[maxnode];     int tot;     int front, rear, q[maxnode], root[22];     ACautomto() {       tot = 0;       memset(T, 0, sizeof(T));     }     inline void merge(int o1, int o2) {       T[o2].end |= T[o1].end;       for (register int i = (0); i < (26); ++i) {         if (!T[o1].nxt[i])           continue;         else if (!T[o2].nxt[i])           T[o2].nxt[i] = T[o1].nxt[i];         else           merge(T[o1].nxt[i], T[o2].nxt[i]);       }     }     inline void insert(int o, char s[]) {       for (int i = 0; s[i]; ++i) {         if (!T[o].nxt[s[i] -  a ]) T[o].nxt[s[i] -  a ] = ++tot;         o = T[o].nxt[s[i] -  a ];       }       ++T[o].end;     }     inline void build(int rt) {       int u, v, p;       front = rear = 0;       q[rear++] = rt;       while (front < rear) {         u = q[front++];         for (register int i = (0); i < (26); ++i)           if (T[u].nxt[i]) {             v = T[u].nxt[i], p = T[u].fail;             while (p && !T[p].nxt[i]) p = T[p].fail;             T[v].fail = p ? T[p].nxt[i] : rt;             T[v].v = T[v].end + T[T[v].fail].v;             q[rear++] = v;           }       }     }     inline int query(int rt, char s[]) {       int ans = 0, o = rt;       for (int i = 0; s[i]; ++i) {         while (o && !T[o].nxt[s[i] -  a ]) o = T[o].fail;         if (o == 0) o = rt;         o = T[o].nxt[s[i] -  a ];         ans += T[o].v;       }       return ans;     }     inline void add(char s[]) {       int rt = ++tot;       insert(rt, s);       for (int i = 0; i < 20; ++i) {         if (!root[i]) {           root[i] = rt;           build(root[i]);           return;         } else {           merge(root[i], rt);           root[i] = 0;         }       }     }     inline int get(char s[]) {       int ans = 0;       for (int i = 0; i < 20; ++i) ans += query(root[i], s);       return ans;     }   } add, del;   char s[300005];   int main() {     int T = read();     while (T--) {       int op = read();       scanf( %s , s);       if (op == 1) {         add.add(s);       } else if (op == 2) {         del.add(s);       } else {         writeln(add.get(s) - del.get(s));       }       fflush(stdout);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   struct sl {     int SC, LC, TS, TL;     double p;   } a[1005];   struct csl {     long double score, tim;   } f[1005][1561], ans;   double a1, a2, p;   int n, m, z, x, y;   inline bool cmp(sl x, sl y) {     return x.TL * x.p * (1 - y.p) < y.TL * y.p * (1 - x.p);   }   inline csl Max(csl x, int l, int k, int t) {     csl y;     y.score = y.tim = 0;     if (t == 1) {       y.score = f[l - 1][k - a[l].TS].score + a[l].SC;       y.tim = f[l - 1][k - a[l].TS].tim + a[l].TS;     } else {       y.score = f[l - 1][k - a[l].TS - a[l].TL].score + a[l].SC +                 a[l].LC * (1 - a[l].p);       y.tim = a[l].p * (f[l - 1][k - a[l].TS - a[l].TL].tim + a[l].TS) +               k * (1 - a[l].p);     }     if (x.score + eps < y.score ||         (abs(x.score - y.score) < eps && x.tim > y.tim))       return y;     else       return x;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) {       scanf( %d%d%d%d%lf , &a[i].SC, &a[i].LC, &a[i].TS, &a[i].TL, &a[i].p);     }     sort(a + 1, a + n + 1, cmp);     for (int i = 1; i <= n; ++i) {       for (int j = 0; j <= m; ++j) {         f[i][j] = f[i - 1][j];         if (j >= a[i].TS) f[i][j] = Max(f[i][j], i, j, 1);         if (j >= a[i].TS + a[i].TL) f[i][j] = Max(f[i][j], i, j, 2);       }     }     for (int i = 0; i <= m; ++i)       if (ans.score + eps < f[n][i].score ||           (abs(ans.score - f[n][i].score) < eps && ans.tim > f[n][i].tim))         ans = f[n][i];     printf( %.10lf %.10lf , (double)ans.score, (double)ans.tim);   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int maxn = 205;   int fail[maxn + 5];   int nxt[maxn + 5][maxn + 5];   long long dp[maxn + 5][maxn + 5][maxn + 5];   char s[maxn + 5];   int n, len;   void Get_fail() {     fail[0] = -1;     int j = 0, k = -1;     while (j <= len) {       if (k == -1 || s[j] == s[k])         fail[++j] = ++k;       else         k = fail[k];     }   }   void Get_nxt() {     for (int i = 0; i <= len; i++) {       for (int j = 0; j <= 1; j++) {         if (i == len)           nxt[i + 1][j] = len;         else {           char ch = (j == 0 ?  )  :  ( );           int r = i;           while (r >= 0 && s[r] != ch) r = fail[r];           if (s[r] == ch || r == -1) r++;           nxt[i + 1][j] = r;         }       }     }   }   long long DP() {     dp[0][0][0] = 1;     for (int i = 0; i <= 2 * n; i++) {       for (int j = 0; j <= min(i, n); j++) {         for (int k = 0; k <= len; k++) {           for (int p = 0; p <= 1; p++) {             if (dp[i][j][k] == 0) continue;             int nj = j - (p == 0 ? 1 : -1);             if (nj >= 0 && nj <= n) {               int nk = nxt[k + 1][p];               dp[i + 1][nj][nk] = (dp[i + 1][nj][nk] + dp[i][j][k]) % mod;             }           }         }       }     }     return dp[2 * n][0][len];   }   void Init() {     len = strlen(s);     Get_fail();     Get_nxt();   }   int main() {     scanf( %d , &n);     scanf( %s , s);     Init();     printf( %lld n , DP());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N;   vector<int> rating;   void reading() {     cin >> N;     rating.resize(N);     for (int i = 0; i < N; i++) cin >> rating[i];   }   void processing() {     for (int i = 0; i < N; i++) {       int res = 0;       for (int j = 0; j < N; j++)         if (rating[i] < rating[j]) res++;       cout << res + 1 <<    ;     }   }   int main() {     reading();     processing();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXW = 1000000;   const int INF = 0x3f3f3f3f;   const int MOD = 1000000007;   const char test[] =  test n ;   int in();   int tr[100010];   int ls[100010];   int n, m, k;   int hav[100010];   int lowbit(int x) { return (-x) & x; }   void updata(int in, int val) {     while (in <= n) {       if (val > tr[in]) {         tr[in] = val;       }       in += lowbit(in);     }   }   int ask(int to) {     int mx = 0;     while (to) {       mx = max(mx, tr[to]);       to -= lowbit(to);     }     return mx;   }   int main() {     cin >> n >> m;     hav[1]++;     hav[m + 1]--;     for (int i = 0; i < n; ++i) {       int u, v;       cin >> u >> v;       hav[u]++;       hav[v + 1]--;     }     for (int i = 1; i <= m; ++i) {       hav[i] += hav[i - 1];       int val = ask(hav[i]) + 1;       updata(hav[i], val);       ls[i] = val;     }     memset(tr, 0, sizeof tr);     int ans = 0;     for (int i = m; i > 0; --i) {       int val = ask(hav[i]) + 1;       updata(hav[i], val);       ans = max(ans, ls[i] + val - 1);     }     cout << ans;     return 0;   }   int in() {     int input;     scanf( %d , &input);     return input;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long ans = 0;     for (int i = (0); i < (n); ++i) {       long long t, T, x, cost;       cin >> t >> T >> x >> cost;       if (t >= T) {         ans += cost + m * x;         continue;       }       long long aux1 = cost;       if (m > (T - t)) aux1 += m * x;       long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1;       aux2 *= cost;       ans += min(aux1, aux2);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream &operator<<(ostream &o, vector<T> &vec) {     cout <<  [ ;     for (int i = 0; i < ((int)(vec).size()); i++) {       if (i) cout <<  ,  ;       cout << vec[i];     }     cout <<  ] ;     return o;   }   template <typename T1, typename T2>   ostream &operator<<(ostream &o, pair<T1, T2> &pair) {     cout <<  (  << pair.first <<  ,   << pair.second <<  ) ;     return o;   }   const long long MX = 312312;   const long long SQMX = 1000;   const long long MD = 1000000007;   long long N;   vector<long long> ip;   bool isp[MX];   vector<long long> prime;   long long sm[MX], tmp[MX];   long long C[MX];   long long fac[MX];   long long ps[MX];   long long fp(long long a, long long b) {     if (!b) return 1 % MD;     long long ret = fp(a * a % MD, b / 2);     if (b & 1) ret = ret * a % MD;     return ret;   }   inline long long rev(long long a) { return fp(a, MD - 2); }   void pre() {     fill(isp + 2, isp + MX, true);     for (long long i = 0; i < MX; i++) {       if (isp[i]) {         prime.push_back(i);         for (long long j = i + i; j < MX; j += i) {           isp[j] = false;         }       }     }     fac[0] = 1;     for (long long i = 1; i <= N - 1; i++) fac[i] = fac[i - 1] * i % MD;     for (long long i = 0; i <= N - 1; i++)       C[i] = fac[N - 1] * rev(fac[i]) % MD * rev(fac[N - i - 1]) % MD;     for (long long i = 0; i <= N - 1; i++) {       ps[i + 1] = ps[i] + C[i];     }   }   int32_t main() {     cin >> N;     pre();     ip.resize(N);     for (long long i = 0; i < N; i++) {       cin >> ip[i];     }     long long ans = 0;     for (long long i = 0; i < ((long long)(prime).size()); i++) {       long long p = prime[i];       if (p > SQMX) break;       fill(tmp, tmp + N, 0);       for (long long j = 0; j < N; j++) {         long long t = 0, &a = ip[j];         while (a % p == 0) {           a /= p;           t++;         }         tmp[j] = t;       }       sort(tmp, tmp + N);       for (long long j = 0; j < N; j++) sm[j] += tmp[j];     }     sort(ip.begin(), ip.end());     for (long long i = 0, j = 0; i < N; i = j) {       while (ip[j] == ip[i]) j++;       if (ip[i] == 1) continue;       long long c = j - i;       for (long long k = 0; k < c; k++) {         sm[N - k - 1]++;       }     }     for (long long j = 0; j < N; j++) {       long long f1 = ps[j] - ps[0], f2 = ps[N] - ps[j + 1];       long long f = f1 - f2;       f = (f + MD) % MD;       ans += f * sm[j];       ans %= MD;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   int dx[4] = {-1, 0, 1, 0};   int dy[4] = {0, -1, 0, 1};   int n;   int map[2010][2010];   int vis[2010][2010];   int as, ac;   int go(int x, int y) {     vis[y][x] = 1;     int r = 1;     for (int i = 0; i < 4; ++i) {       int nx = x + dx[i], ny = y + dy[i];       if (map[ny][nx] == 0 || vis[ny][nx] == 1) continue;       r += go(nx, ny);     }     return r;   }   int chk(int x, int y, int r) {     int ok = 1;     for (int i = y; i < y + r && ok == 1; ++i)       for (int j = x; j < x + r && ok == 1; ++j)         if (map[i][j] != 1) ok = 0;     return ok == 1;   }   int main(void) {     scanf( %d , &n);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) scanf( %d , &map[i][j]);     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         if (map[i][j] == 0 || vis[i][j] == 1) continue;         int nd = go(j, i);         int r = (int)sqrt(nd);         if (nd != r * r)           ++ac;         else {           if (chk(j, i, r) == 1)             ++as;           else             ++ac;         }       }     }     printf( %d %d n , ac, as);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 6e3 + 5;   const int mod = 1e9 + 7;   const int inf = 0x3f3f3f3f;   int main() {     int t, n, k;     char x;     cin >> t;     while (t--) {       cin >> n >> k;       for (int i = 0; i < n % k; i++) {         cout <<  a ;       }       for (int i = 0; i < k; i++) {         x =  a  + i;         for (int j = 0; j < n / k; j++) {           cout << x;         }       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, first[200050], nxt[200050], to[200050], tot;   void add(int x, int y) { nxt[++tot] = first[x], first[x] = tot, to[tot] = y; }   double w[200050], ans, sum[200050];   int fa[200050];   void dfs(int u, int f) {     ans += w[f] * (1 - w[u]);     for (int i = first[u]; i; i = nxt[i]) {       int t = to[i];       if (t == f) continue;       fa[t] = u;       sum[u] += (1 - w[t]);       dfs(t, u);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %lf , &w[i]);     }     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       x++;       y++;       add(x, y);       add(y, x);     }     w[0] = 1;     dfs(1, 0);     scanf( %d , &m);     while (m--) {       int u;       double v;       scanf( %d%lf , &u, &v);       u++;       ans -= (1 - w[u]) * w[fa[u]];       ans -= w[u] * sum[u];       sum[fa[u]] -= (1 - w[u]);       w[u] = v;       sum[fa[u]] += (1 - w[u]);       ans += w[u] * sum[u];       ans += (1 - w[u]) * w[fa[u]];       printf( %0.5lf n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const long long INF = 1e17, LINF = 1e12;   int n, m, q, x, y;   vector<int> g[N], s[N];   int top[N], p[N], dp[N], son[N], sz, d[N];   int tin1[N], tin2[N], tout[N], timer, num[N];   pair<long long, int> og[N];   pair<long long, int> t[4 * N];   long long ob[4 * N];   void dfs(int v, int pr = 0, int depth = 0) {     d[v] = depth;     p[v] = pr;     dp[v] = 1;     for (int to : g[v]) {       if (to != pr) {         dfs(to, v, depth + 1);         dp[v] += dp[to];         if (dp[to] > dp[son[v]]) {           son[v] = to;         }       }     }   }   void hld(int v, int pr = 0) {     tin1[v] = ++timer;     og[timer] = make_pair(INF, 0);     for (auto it : s[v]) {       timer++;       og[timer] = make_pair(it, it);       num[it] = timer;     }     tin2[v] = timer;     if (son[v]) {       top[son[v]] = top[v];       hld(son[v], v);     }     for (int to : g[v]) {       if (to != pr && to != son[v]) {         top[to] = to;         hld(to, v);       }     }     tout[v] = timer;   }   void build(int v, int l, int r) {     if (l == r) {       t[v] = og[l];       return;     }     int mid = (r + l) >> 1;     build(v + v, l, mid);     build(v + v + 1, mid + 1, r);     t[v] = min(t[v + v], t[v + v + 1]);   }   inline void push(int v) {     if (ob[v]) {       ob[v + v] += ob[v];       ob[v + v + 1] += ob[v];       t[v + v].first += ob[v];       t[v + v + 1].first += ob[v];       ob[v] = 0;     }   }   void update(int v, int l, int r, int tl, int tr, long long val) {     if (l > r || l > tr || tl > r) {       return;     }     if (tl <= l && r <= tr) {       t[v].first += val;       ob[v] += val;       return;     }     push(v);     int mid = (r + l) >> 1;     update(v + v, l, mid, tl, tr, val);     update(v + v + 1, mid + 1, r, tl, tr, val);     t[v] = min(t[v + v], t[v + v + 1]);   }   pair<long long, int> get(int v, int l, int r, int tl, int tr) {     if (l > r || l > tr || tl > r) {       return make_pair(INF, 0);     }     if (tl <= l && r <= tr) {       return t[v];     }     push(v);     int mid = (r + l) >> 1;     return min(get(v + v, l, mid, tl, tr), get(v + v + 1, mid + 1, r, tl, tr));   }   pair<long long, int> get(int x, int y) {     pair<long long, int> mn = make_pair(INF, 1e9);     while (top[x] != top[y]) {       if (d[top[x]] > d[top[y]]) {         mn = min(mn, get(1, 1, timer, tin1[top[x]], tin2[x]));         x = p[top[x]];       } else {         mn = min(mn, get(1, 1, timer, tin1[top[y]], tin2[y]));         y = p[top[y]];       }     }     if (d[x] > d[y]) {       swap(x, y);     }     mn = min(mn, get(1, 1, timer, tin1[x], tin2[y]));     return mn;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> q;     for (int i = 1; i < n; i++) {       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     for (int i = 1; i <= m; i++) {       cin >> x;       s[x].push_back(i);     }     dfs(1);     top[1] = 1;     hld(1);     build(1, 1, timer);     while (q--) {       int t;       cin >> t;       if (t == 1) {         int x, y, k;         cin >> x >> y >> k;         vector<int> ans;         while (k) {           auto it = get(x, y);           if (it.first >= INF) {             break;           }           k--;           ans.push_back(it.second);           update(1, 1, timer, num[it.second], num[it.second], INF);         }         cout << ans.size() <<    ;         for (auto it : ans) {           cout << it <<    ;         }         cout <<   n ;       } else {         int x, y;         cin >> x >> y;         update(1, 1, timer, tin1[x], tout[x], y);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)1e5 + 5;   int x[3];   int y[3];   int buf;   int main() {     buf = 0;     cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2];     for (long long i = 0; i < 3; ++i) {       if (x[i] < y[i]) {         buf = x[i];         x[i] = y[i];         y[i] = buf;       }     }     int n = max(x[0], x[1]);     n = max(n, x[2]);     bool eq = (x[0] == x[1] && x[1] == x[2]);     if (eq && x[0] == (y[0] + y[1] + y[2])) {       cout << n <<   n ;       for (long long i = 0; i < 3; ++i) {         for (long long j = 0; j < y[i]; ++j) {           for (long long p = 0; p < n; ++p) {             cout << (char)(65 + i);           }           cout <<   n ;         }       }       return 0;     }     int max = 0;     int med = 1;     int min = 2;     if (n == x[1]) {       max = 1;       med = 0;     }     if (n == x[2]) {       max = 2;       min = 0;       med = 1;     }     if (n - y[max] == x[med] && n - y[max] == x[min] && n == y[med] + y[min]) {       cout << n <<   n ;       for (long long j = 0; j < y[max]; ++j) {         for (long long p = 0; p < n; ++p) {           cout << (char)(65 + max);         }         cout <<   n ;       }       for (long long j = 0; j < n - y[max]; ++j) {         for (long long p = 0; p < y[med]; ++p) {           cout << (char)(65 + med);         }         for (long long p = 0; p < y[min]; ++p) {           cout << (char)(65 + min);         }         cout <<   n ;       }       return 0;     }     if (n - y[max] == y[med] && n - y[max] == y[min] && n == x[med] + x[min]) {       cout << n <<   n ;       for (long long j = 0; j < y[max]; ++j) {         for (long long p = 0; p < n; ++p) {           cout << (char)(65 + max);         }         cout <<   n ;       }       for (long long j = 0; j < n - y[max]; ++j) {         for (long long p = 0; p < x[med]; ++p) {           cout << (char)(65 + med);         }         for (long long p = 0; p < x[min]; ++p) {           cout << (char)(65 + min);         }         cout <<   n ;       }       return 0;     }     if (n - y[max] == y[med] && n - y[max] == x[min] && n == x[med] + y[min]) {       cout << n <<   n ;       for (long long j = 0; j < y[max]; ++j) {         for (long long p = 0; p < n; ++p) {           cout << (char)(65 + max);         }         cout <<   n ;       }       for (long long j = 0; j < n - y[max]; ++j) {         for (long long p = 0; p < x[med]; ++p) {           cout << (char)(65 + med);         }         for (long long p = 0; p < y[min]; ++p) {           cout << (char)(65 + min);         }         cout <<   n ;       }       return 0;     }     if (n - y[max] == x[med] && n - y[max] == y[min] && n == y[med] + x[min]) {       cout << n <<   n ;       for (long long j = 0; j < y[max]; ++j) {         for (long long p = 0; p < n; ++p) {           cout << (char)(65 + max);         }         cout <<   n ;       }       for (long long j = 0; j < n - y[max]; ++j) {         for (long long p = 0; p < y[med]; ++p) {           cout << (char)(65 + med);         }         for (long long p = 0; p < x[min]; ++p) {           cout << (char)(65 + min);         }         cout <<   n ;       }       return 0;     }     cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x[200005];   int main() {     memset(x, 0, sizeof(x));     int n = 0;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &x[i]);     }     sort(x, x + n);     double eps = 1e-10, l = 0.0, r = (double)(x[n - 1] - x[0]) / 6.0;     int p1 = 0, p2 = 0;     while (r - l > eps) {       double mid = l + (r - l) / 2.0;       p1 = upper_bound(x, x + n, x[0] + 2 * mid) - x;       if (p1 == n) {         r = mid;         continue;       }       p2 = upper_bound(x, x + n, x[p1] + 2 * mid) - x;       if (p2 == n || (double)(x[n - 1] - x[p2]) <= 2 * mid - eps) {         r = mid;       } else {         l = mid;       }     }     double tmp = x[0] + 2 * l;     int idx = lower_bound(x, x + n, (int)(tmp - 1)) - x;     for (; idx < n; ++idx) {       if (x[idx] > x[0] + (int)(2 * l + 0.1)) {         break;       }     }     printf( %.6lf n , l);     printf( %.6lf %.6lf %.6lf , (double)x[0] + l, (double)x[idx] + l,            (double)x[n - 1] - l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[400006];   vector<int> dis;   int main() {     int i, j, m, n, c, x, l, y, t, bytes;     cin >> n >> bytes;     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     int total = 1;     for (i = 1; i < n; i++) {       while (i < n && a[i] == a[i - 1]) {         total++;         i++;       }       dis.push_back(total);       total = 1;     }     if (a[n - 1] != a[n - 2]) dis.push_back(1);     bytes *= 8;     int bits = bytes / n;     if (bits > 31) {       cout << 0;       return 0;     }     total = pow(2, bits);     if (total >= dis.size()) {       cout << 0;       return 0;     }     int ans = 0;     int temp = 0;     for (i = 1; i < dis.size(); i++) {       dis[i] += dis[i - 1];     }     ans = dis[total - 1];     for (i = total; i < dis.size(); i++) {       ans = max(ans, dis[i] - dis[i - total]);     }     cout << n - ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e4 + 5;   int n, f[N];   struct node {     int t, d, p, id;     bool operator<(const node& other) const { return d < other.d; }   } a[N];   vector<int> g[N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++)       scanf( %d %d %d , &a[i].t, &a[i].d, &a[i].p), a[i].id = i;     sort(a + 1, a + 1 + n);     for (int i = 1; i <= n; i++) {       for (int j = a[i].d - 1; j >= a[i].t; j--) {         if (f[j - a[i].t] + a[i].p > f[j]) {           f[j] = f[j - a[i].t] + a[i].p;           g[j].clear();           g[j] = g[j - a[i].t];           g[j].push_back(a[i].id);         }       }     }     int ans = 0;     for (int i = 1; i <= 2000; i++)       if (f[i] > f[ans]) ans = i;     printf( %d n , f[ans]);     int len = g[ans].size();     printf( %d n , len);     for (int i = 0; i < len; i++) printf( %d  , g[ans][i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 0x3f3f3f3f;   const int N = 3e5 + 10;   const long long mod = 1e9 + 7;   const double PI = acos(-1);   inline long long mm(long long x, long long p) {     return x >= p ? x -= p : ((x < 0) ? x += p : x);   }   inline long long ab(long long x) { return x < 0 ? -x : x; }   char s[N];   int main() {     int n, x, y;     long long cnt = 0;     scanf( %d%d%d , &n, &x, &y);     scanf( %s , s);     bool flag = true;     for (int i = 0; i < n; ++i) {       if (s[i] ==  1 )         flag = true;       else {         if (flag) cnt++;         flag = false;       }     }     if (cnt)       printf( %lld n , min(cnt * y, (cnt - 1) * x + y));     else       puts( 0 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long limit = 1e9 + 7;   bool cmp(long long a, long long b) { return a > b; }   long long myceil(long long a, long long b) { return a / b + bool(a % b); }   long long mylog(long long num, long long base) {     long long ans = 0;     while (num) {       ans++;       num /= base;     }     return ans - 1;   }   long long Pow(long long a, long long b) {     long long ans = 1, mul = a;     while (b) {       if (b & 1) ans = (ans * mul) % limit;       mul = (mul * mul) % limit;       b /= 2;     }     return ans;   }   template <typename T>   ostream &operator<<(ostream &os, vector<T> &v) {     int n = v.size();     for (int i = 0; i < n; i++) os << v[i] <<    ;     os << endl;     return os;   }   template <typename T>   istream &operator>>(istream &is, vector<T> &v) {     int n = v.size();     for (int i = 0; i < n; i++) is >> v[i];     return is;   }   string lps(string s) {     int n = s.length();     int lps[n];     lps[0] = 0;     int len = 0;     int i = 1;     while (i < n) {       if (s[i] == s[len]) {         len++;         lps[i] = len;         i++;       } else {         if (len != 0) {           len = lps[len - 1];         } else {           lps[i] = 0;           i++;         }       }     }     int res = lps[n - 1];     return s.substr(0, res);   }   vector<int> primes;   long long fact[100005], inv[100005];   ;   void pre() {     fact[0] = 1;     inv[0] = 1;     for (int i = 1; i < 100005; i++) fact[i] = (fact[i - 1] * i) % limit;     for (int i = 1; i < 100005; i++)       inv[i] = (inv[i - 1] * Pow(i, limit - 2)) % limit;   }   long long comb(long long n, long long r) {     long long ans = fact[n];     ans *= inv[n - r];     ans %= limit;     ans *= inv[r];     ans %= limit;     return ans;   }   int main() {     int t = 1;     cin >> t;     for (int test = 1; test < t + 1; test++) {       long long n, k;       cin >> n >> k;       if ((n - (k - 1) * (k - 1)) >= (2 * k - 1) && (n - (k - 1) * (k - 1)) % 2)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int n;   int seat[100];   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> seat[i];     int sum = 0;     for (int i = 0; i < n; i++) sum += seat[i];     vector<int> ans;     ans.push_back(0);     int curSum = seat[0];     for (int i = 1; i < n; i++) {       if (seat[i] * 2 <= seat[0]) {         ans.push_back(i);         curSum += seat[i];       }     }     if (curSum > sum / 2) {       cout << ans.size() <<   n ;       for (int i = 0; i < ans.size(); i++) cout << ans[i] + 1 <<    ;     } else       cout << 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, a[200010], m = INT_MAX;     string s;     cin >> n >> s;     for (int i = 0; i < n; i++) cin >> a[i];     long long int j = -1;     for (long long int i = 0; i < s.length(); i++) {       if (s[i] ==  R )         j = i;       else {         if (j != -1) {           long long int temp = abs(a[i] - a[j]) / 2;           if (temp < m) m = temp;         }       }     }     if (m == INT_MAX)       cout << -1;     else       cout << m;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   void solve() {     int n, p, k;     cin >> n >> p >> k;     auto f = [&](int x) -> int {       return ((ll)x * x % p * x % p * x % p - (ll)k * x % p + p) % p;     };     map<int, int> cnt;     for (int _ = 0; _ < n; _++) {       int x;       cin >> x;       cnt[f(x)]++;     }     ll res = 0;     for (auto& kp : cnt) {       int i = kp.second;       res += (ll)i * (i - 1) / 2;     }     cout << res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1 << 16;   map<pair<int, int>, int> dp[maxn];   int n, c[20], r[20], b[20], ed, rrr, bbb, ans = 0x3f3f3f3f;   int main() {     cin >> n;     getchar();     for (int i = 1; i <= n; i++) {       char ch;       cin >> ch >> r[i] >> b[i];       if (ch ==  R ) c[i] = 1;     }     ed = (1 << n) - 1;     dp[0][pair<int, int>(0, 0)] = 0;     for (int i = 0; i <= ed; i++) {       int rr = 0, bb = 0;       for (int t = 0; t < n; t++)         if (i & (1 << t)) ++(c[t + 1] ? rr : bb);       for (int j = 0; j < n; j++) {         if (i & (1 << j)) continue;         for (auto it : dp[i]) {           int next = i | (1 << j), need = 0;           if (it.first.first < max(r[j + 1] - rr, 0))             need = max(need, r[j + 1] - rr - it.first.first);           if (it.first.second < max(b[j + 1] - bb, 0))             need = max(need, b[j + 1] - bb - it.first.second);           int rmr = it.first.first + need - max(r[j + 1] - rr, 0),               rmb = it.first.second + need - max(b[j + 1] - bb, 0);           if (!dp[next].count(pair<int, int>(rmr, rmb)))             dp[next][pair<int, int>(rmr, rmb)] = 0x3f3f3f3f;           dp[next][pair<int, int>(rmr, rmb)] =               min(dp[next][pair<int, int>(rmr, rmb)], it.second + need);         }       }     }     for (auto it : dp[ed]) ans = min(ans, it.second);     cout << ans + n << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char p[120], A[10100][120], B[10100][120], res[120];   int SA[110], SB[110], Z[110], Pre[110];   int SS[110], Suf[110];   void Do(int n) {     int i, j;     printf( ? %d %d n , 1, n);     fflush(stdout);     for (i = 0; i < n * (n + 1) / 2; i++) {       scanf( %s , A[i]);       int c = 0;       for (j = 0; A[i][j]; j++) c += A[i][j] -  a ;       int L = j;       SA[L] += c;     }     printf( ? %d %d n , 1, n - 1);     fflush(stdout);     for (i = 0; i < n * (n - 1) / 2; i++) {       scanf( %s , B[i]);       int c = 0;       for (j = 0; B[i][j]; j++) c += B[i][j] -  a ;       int L = j;       SB[L] += c;     }     for (i = 1; i <= n; i++) {       Z[i] = SA[i] - SB[i];       res[n - i] = Z[i] - Z[i - 1] +  a ;     }   }   int main() {     int i, j, k;     int n;     scanf( %d , &n);     if (n == 1) {       printf( ? %d %d n , 1, n);       fflush(stdout);       scanf( %s , p);       printf( ! %s n , p);       fflush(stdout);       return 0;     }     if (n == 2) {       printf( ? %d %d n , 1, 1);       fflush(stdout);       scanf( %s , p);       res[0] = p[0];       printf( ? %d %d n , 2, 2);       fflush(stdout);       scanf( %s , p);       res[1] = p[0];       res[2] = 0;       printf( ! %s n , res);       return 0;     }     Do((n + 1) / 2);     printf( ? %d %d n , 1, n);     fflush(stdout);     for (i = 0; i < (n + 1) / 2; i++) {       Pre[i + 1] = Pre[i] + res[i] -  a ;     }     for (i = 0; i < n * (n + 1) / 2; i++) {       scanf( %s , A[i]);       int c = 0;       for (j = 0; A[i][j]; j++) c += A[i][j] -  a ;       int L = j;       SS[L] += c;     }     int tot = SS[n];     for (i = 1; i <= n / 2; i++) {       int z = SS[n - i];       for (j = 1; j < i; j++) {         int s = 0;         for (k = 0; k < i - j; k++) {           s += res[n - k - 1] -  a ;         }         z -= tot - (s + Pre[j]);       }       z -= (tot - Pre[i]);       Suf[i] = tot - z;       res[n - i] = Suf[i] - Suf[i - 1] +  a ;     }     printf( ! %s n , res);     fflush(stdout);   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* na, Arg1&& arg1, Args&&... args) {     const char* c = strchr(na + 1,  , );     cerr.write(na, c - na) <<   :   << arg1 <<   ,  ;     __f(c + 1, args...);   }   const double pi = acos(-1.0);   const double eps = 1e-8;   const int inf = 1e9;   const long long INF = 1e18;   const int mod = 1e9 + 7;   const int N = 3e5 + 5;   void solve() {     int len, q;     cin >> len >> q;     string s;     cin >> s;     s =  #  + s;     int ans = 0;     for (int i = 1; i <= len;) {       if (s[i] ==  . ) {         int j = i;         while (j <= len && s[j] ==  . ) j++;         ans += (j - i - 1);         i = j;       } else {         i++;       }     }     while (q--) {       int pos;       string ch;       cin >> pos >> ch;       if (s[pos] !=  .  && ch[0] ==  . ) {         if (pos - 1 >= 1 && s[pos - 1] ==  . ) ans++;         if (pos + 1 <= len && s[pos + 1] ==  . ) ans++;         s[pos] =  . ;       } else if (s[pos] ==  .  && ch[0] !=  . ) {         if (pos - 1 >= 1 && s[pos - 1] ==  . ) ans--;         if (pos + 1 <= len && s[pos + 1] ==  . ) ans--;         s[pos] = ch[0];       }       cout << ans <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t = 1;     for (int tc = 1; tc <= t; tc++) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double Pi = acos(-1.0);   inline int cmp(double x, double y = 0, double tol = 1e-8) {     return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;   }   struct point {     double x, y;     point(double x = 0, double y = 0) : x(x), y(y) {}     point operator+(point q) { return point(x + q.x, y + q.y); }     point operator-(point q) { return point(x - q.x, y - q.y); }     point operator*(double t) { return point(x * t, y * t); }     point operator/(double t) { return point(x / t, y / t); }     double operator*(point q) { return x * q.x + y * q.y; }     double operator%(point q) { return x * q.y - y * q.x; }     double mod() { return sqrt(x * x + y * y); }     point rotate(double t) {       return point(x * cos(t) - y * sin(t), x * sin(t) + y * cos(t));     }     int cmp(point q) const {       if (int t = ::cmp(x, q.x)) return t;       return ::cmp(y, q.y);     }     bool operator==(point q) const { return cmp(q) == 0; }     bool operator!=(point q) const { return cmp(q) != 0; }     bool operator<(point q) const { return cmp(q) < 0; }     static point pivot;   };   point point::pivot;   double poly_area(vector<point>& T) {     double s = 0;     int n = T.size();     for (int i = 0; i < n; i++) s += T[i] % T[(i + 1) % n];     return s / 2;   }   point line_intersect(point p, point q, point r, point s) {     point a = q - p, b = s - r, c = point(p % q, r % s);     return point(point(a.x, b.x) % c, point(a.y, b.y) % c) / (a % b);   }   vector<point> halfplane(vector<point>& p, pair<point, point> semiplano) {     vector<point> q;     point p1 = semiplano.first, p2 = semiplano.second;     int n = p.size();     for (int i = 0; i < n; i++) {       double c = (p2 - p1) % (p[i] - p1);       double d = (p2 - p1) % (p[(i + 1) % n] - p1);       if (cmp(c) >= 0) q.push_back(p[i]);       if (cmp(c * d) < 0)         q.push_back(line_intersect(p1, p2, p[i], p[(i + 1) % n]));     }     return q;   }   vector<point> semi_plano_cruzado(vector<pair<point, point> > semiplano) {     vector<point> p;     p.push_back(point(-1e9, -1e9));     p.push_back(point(-1e9, +1e9));     p.push_back(point(+1e9, +1e9));     p.push_back(point(+1e9, -1e9));     int n = semiplano.size();     for (int i = 0; i < n; i++) {       p = halfplane(p, semiplano[i]);       if (p.size() == 0) break;     }     return p;   }   int main() {     double w, h, a;     cin >> w >> h >> a;     double gama = atan(w / h);     double beta = atan(h / w);     vector<point> p, q;     p.push_back(point(-0.5 * w, -0.5 * h));     p.push_back(point(-0.5 * w, 0.5 * h));     p.push_back(point(0.5 * w, 0.5 * h));     p.push_back(point(0.5 * w, -0.5 * h));     a = a * Pi / 180;     double teta = 0.5 * Pi + a - gama - beta;     q.push_back(point(-0.5 * w, -0.5 * h));     q.push_back(point(-0.5 * w, 0.5 * h));     q.push_back(point(0.5 * w, 0.5 * h));     q.push_back(point(0.5 * w, -0.5 * h));     for (int i = 0; i < 4; i++) q[i] = q[i].rotate(teta);     for (int i = 0; i < 4; i++) {       p = halfplane(p, make_pair(q[(i + 1) % 4], q[i]));     }     printf( %.9lf n , fabs(poly_area(p)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s1;   long long arr2[2000006];   long long dsu(long long x) { return arr2[x] == x ? x : arr2[x] = dsu(arr2[x]); }   int main() {     char ans[2000006];     long long n, t1, t2, t3, t4, t5;     cin >> n;     for (int i = 0; i < 2000006; i++) {       ans[i] =  a ;       arr2[i] = i;     }     t3 = 0;     while (n--) {       cin >> s1;       t1 = s1.length();       cin >> t2;       while (t2--) {         cin >> t4;         t4--;         if (t3 < t4 + t1 - 1) t3 = t4 + t1 - 1;         for (int i = dsu(t4); i < t4 + t1;) {           ans[i] = s1[i - t4];           arr2[i] = i + 1;           i = dsu(i);         }       }     }     t5 = 0;     while (1) {       cout << ans[t5++];       if (t5 > t3) break;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   inline long long int rl() {     long long int res = 0, neg = 0;     char c = getchar();     while ((c <  0  || c >  9 ) && c !=  - ) c = getchar();     if (c ==  - ) neg = 1, c = getchar();     while (c >=  0  && c <=  9 ) {       res = (res << 1) + (res << 3) + c - 48;       c = getchar();     }     return neg ? -res : res;   }   inline void read(string &s) {     s =   ;     char c = getchar();     while (c !=   n ) {       s += c;       c = getchar();     }   }   int main() {     vector<std::vector<char> > a(9);     for (int i = 0; i < 9; ++i) {       for (int j = 0; j < 9; ++j) {         char c;         cin >> c;         a[i].push_back(c);       }     }     long long int x = rl() - 1, y = rl() - 1;     int i;     for (i = 3 * (x % 3); i < 3 * (x % 3 + 1); ++i)       for (int j = 3 * (y % 3); j < 3 * (y % 3 + 1); ++j) {         if (a[i][j] ==  . ) goto exit;       }   exit:;     if (i == 3 * (x % 3 + 1)) {       for (int i = 0; i < 9; ++i) {         for (int j = 0; j < 9; ++j) {           if (a[i][j] ==  . )             cout <<  ! ;           else             cout << a[i][j];           if (j % 3 == 2 && j != 8) cout <<    ;         }         cout <<   n ;         if (i % 3 == 2 && i != 8) cout <<   n ;       }     } else {       for (i = 3 * (x % 3); i < 3 * (x % 3 + 1); ++i)         for (int j = 3 * (y % 3); j < 3 * (y % 3 + 1); ++j) {           if (a[i][j] ==  . ) a[i][j] =  ! ;         }       for (int i = 0; i < 9; ++i) {         for (int j = 0; j < 9; ++j) {           cout << a[i][j];           if (j % 3 == 2 && j != 8) cout <<    ;         }         cout <<   n ;         if (i % 3 == 2 && i != 8) cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const int MOD = 1e9 + 7;   vector<string> vec_splitter(string s) {     s +=  , ;     vector<string> res;     while (!s.empty()) {       res.push_back(s.substr(0, s.find( , )));       s = s.substr(s.find( , ) + 1);     }     return res;   }   void debug_out(vector<string> __attribute__((unused)) args,                  __attribute__((unused)) int idx,                  __attribute__((unused)) int LINE_NUM) {     cerr <<   n ;   }   template <typename Head, typename... Tail>   void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {     if (idx > 0)       cerr <<  ,  ;     else       cerr <<  Line(  << LINE_NUM <<  )  ;     stringstream ss;     ss << H;     cerr << args[idx] <<   =   << ss.str();     debug_out(args, idx + 1, LINE_NUM, T...);   }   void run() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   long long gcd(long long n1, long long n2) {     if (n2 != 0)       return gcd(n2, n1 % n2);     else       return n1;   }   bool checkPalindrome(string s) {     int n = s.size();     for (int i = 0; i < n / 2; i++) {       if (s[i] != s[n - i - 1]) return false;     }     return true;   }   long long digSum(long long n) {     long long sum = 0;     while (n > 0) {       sum += n % 10;       n /= 10;     }     return sum;   }   bool compare(pair<int, int> a, pair<int, int> b) {     if (a.first == a.second)       return true;     else if (b.first == b.second)       return false;     else {       int adiff = a.second - a.first;       int bdiff = b.second - b.first;       if (adiff > bdiff)         return false;       else         return true;     }   }   int main() {     run();     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       vector<int> v(n + 1);       for (int i = 1; i <= n; i++) {         cin >> v[i];       }       sort(v.begin(), v.end());       long long ans = 0;       int ind = n - 2 * k;       int half = ind + k;       for (int i = 1; i <= ind; i++) {         ans += v[i];       }       for (int i = ind + 1; i <= half; i++) {         ans = ans + (v[i] / v[i + k]);       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   const long long pri = 1e9 + 7;   long long myPow(long long a, long long b) {     long long ret = 1;     while (b != 0) {       if (b % 2 != 0) {         ret = (ret * a) % pri;       }       a = (a * a) % pri;       b /= 2;     }     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     long long precision = numeric_limits<double>::digits10;     cin >> n >> m >> k;     if (k == -1 && (n + m) % 2 != 0)       cout << 0 <<   n ;     else {       long long ans = myPow(2, m - 1);       ans = myPow(ans, n - 1);       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   int main() {     int x, y;     scanf( %d%d , &x, &y);     int r2 = x * x + y * y;     int r = floor(sqrt(static_cast<double>(r2)));     if (r * r < r2 && (r + 1) * (r + 1) > r2 &&         (r % 2 == 1 && x * y > 0 || r % 2 == 0 && x * y < 0)) {       printf( white n );     } else {       printf( black n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 250005;   vector<int> g[maxn];   int pa[maxn];   int v[maxn];   int dep[maxn];   vector<int> leaf;   int n, m, k;   void build(int now) {     int x = 0, y = 0;     for (auto &i : g[now]) {       if (i == pa[now]) {         continue;       } else if (x == 0) {         x = i;       } else {         y = i;       }     }     vector<int> ans;     if ((dep[now] - dep[x] + 1) % 3) {       ans.push_back(now);       while (ans.back() != x) {         ans.push_back(pa[ans.back()]);       }     } else if ((dep[now] - dep[y] + 1) % 3) {       ans.push_back(now);       while (ans.back() != y) {         ans.push_back(pa[ans.back()]);       }     } else {       if (dep[x] < dep[y]) {         swap(x, y);       }       ans.push_back(now);       ans.push_back(x);       while (ans.back() != y) {         ans.push_back(pa[ans.back()]);       }     }     cout << ans.size() <<   n ;     for (auto &i : ans) {       cout << i <<    ;     }     cout <<   n ;   }   void dfs(int now) {     v[now] = 1;     int f = 0;     if (dep[now] * k >= n) {       cout <<  PATH n ;       vector<int> ans{now};       while (ans.back() != 1) {         ans.push_back(pa[ans.back()]);       }       cout << ans.size() <<   n ;       for (auto &i : ans) {         cout << i <<    ;       }       cout <<   n ;       exit(0);     }     for (auto &i : g[now]) {       if (v[i]) {         continue;       }       dep[i] = dep[now] + 1;       pa[i] = now;       dfs(i);       f = 1;     }     if (!f) {       leaf.push_back(now);     }   }   void go() {     cin >> n >> m >> k;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     dep[1] = 1;     dfs(1);     cout <<  CYCLES n ;     for (int i = 0; i < k; i++) {       build(leaf[i]);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int c = 0;     int t;     if (!c) {       t = 1;     } else {       cin >> t;     }     while (t--) {       go();     }   }


#include <bits/stdc++.h>   using namespace std;   const int KMAX = 8;   const int NMAX = 2505;   char mat[NMAX][NMAX];   int psm[NMAX][NMAX], pt1[KMAX], pt2[KMAX];   inline int sum(int x1, int y1, int x2, int y2) {     return psm[x2][y2] - psm[x2][y1 - 1] - psm[x1 - 1][y2] + psm[x1 - 1][y1 - 1];   }   long long solve(int x1, int y1, int x2, int y2, int k) {     if (x1 == x2 and y1 == y2) return sum(x1, y1, x2, y2) == k;     long long ans;     if (x2 - x1 <= y2 - y1) {       int ym = (y1 + y2) / 2;       ans = solve(x1, y1, x2, ym, k) + solve(x1, ym + 1, x2, y2, k);       for (int i = x1; i <= x2; ++i) {         for (int k1 = 0; k1 <= k; ++k1) pt1[k1] = y1, pt2[k1] = y2;         for (int j = i; j <= x2; ++j) {           for (int k1 = 0; k1 <= k; ++k1) {             while (pt1[k1] <= ym and sum(i, pt1[k1], j, ym) > k1) ++pt1[k1];             while (pt2[k1] > ym and sum(i, ym + 1, j, pt2[k1]) > k1) --pt2[k1];           }           for (int k1 = 0; k1 <= k; ++k1)             ans += 1LL * (((k1 > 0) ? pt1[k1 - 1] : (ym + 1)) - pt1[k1]) *                    (pt2[k - k1] - ((k - k1 > 0) ? pt2[k - k1 - 1] : ym));         }       }     } else {       int xm = (x1 + x2) / 2;       ans = solve(x1, y1, xm, y2, k) + solve(xm + 1, y1, x2, y2, k);       for (int i = y1; i <= y2; ++i) {         for (int k1 = 0; k1 <= k; ++k1) pt1[k1] = x1, pt2[k1] = x2;         for (int j = i; j <= y2; ++j) {           for (int k1 = 0; k1 <= k; ++k1) {             while (pt1[k1] <= xm and sum(pt1[k1], i, xm, j) > k1) ++pt1[k1];             while (pt2[k1] > xm and sum(xm + 1, i, pt2[k1], j) > k1) --pt2[k1];           }           for (int k1 = 0; k1 <= k; ++k1)             ans += 1LL * (((k1 > 0) ? pt1[k1 - 1] : (xm + 1)) - pt1[k1]) *                    (pt2[k - k1] - ((k - k1 > 0) ? pt2[k - k1 - 1] : xm));         }       }     }     return ans;   }   int main(void) {     int n, m, k;     scanf( %d %d %d , &n, &m, &k);     for (int i = 1; i <= n; ++i) {       scanf( %s , mat[i] + 1);       for (int j = 1; j <= m; ++j)         psm[i][j] =             psm[i - 1][j] + psm[i][j - 1] - psm[i - 1][j - 1] + (mat[i][j] -  0 );     }     printf( %I64d n , solve(1, 1, n, m, k));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 205;   const int INF = 0x3f3f3f3f;   string a, b;   int dp[MAX][MAX][405];   int call(int x, int y, int s) {     if (x >= a.size() and y >= b.size()) return s;     if (dp[x][y][s] != -1) return dp[x][y][s];     int ret = INF;     if (x < a.size() and y < b.size() and a[x] == b[y]) {       if (a[x] ==  ( ) {         ret = min(ret, 1 + call(x + 1, y + 1, s + 1));       } else {         if (s) {           ret = min(ret, 1 + call(x + 1, y + 1, s - 1));         } else {           ret = min(ret, 2 + call(x + 1, y + 1, s));         }       }     } else {       if (x < a.size()) {         if (a[x] ==  ( ) {           ret = min(ret, 1 + call(x + 1, y, s + 1));         } else {           if (s) {             ret = min(ret, 1 + call(x + 1, y, s - 1));           } else {             ret = min(ret, 2 + call(x + 1, y, s));           }         }       }       if (y < b.size()) {         if (b[y] ==  ( ) {           ret = min(ret, 1 + call(x, y + 1, s + 1));         } else {           if (s) {             ret = min(ret, 1 + call(x, y + 1, s - 1));           } else {             ret = min(ret, 2 + call(x, y + 1, s));           }         }       }     }     return dp[x][y][s] = ret;   }   void go(int x, int y, int s) {     if (x >= a.size() and y >= b.size()) {       for (int i = 0; i < s; i++) cout <<  ) ;       cout << endl;       return;     }     int ret = call(x, y, s);     if (x < a.size() and y < b.size() and a[x] == b[y]) {       if (a[x] ==  ( ) {         if (ret == 1 + call(x + 1, y + 1, s + 1)) {           cout <<  ( ;           go(x + 1, y + 1, s + 1);           return;         }       } else {         if (s) {           if (ret == 1 + call(x + 1, y + 1, s - 1)) {             cout <<  ) ;             go(x + 1, y + 1, s - 1);             return;           }         } else {           if (ret == 2 + call(x + 1, y + 1, s)) {             cout <<  () ;             go(x + 1, y + 1, s);             return;           }         }       }     } else {       if (x < a.size()) {         if (a[x] ==  ( ) {           if (ret == 1 + call(x + 1, y, s + 1)) {             cout <<  ( ;             go(x + 1, y, s + 1);             return;           }         } else {           if (s) {             if (ret == 1 + call(x + 1, y, s - 1)) {               cout <<  ) ;               go(x + 1, y, s - 1);               return;             }           } else {             if (ret == 2 + call(x + 1, y, s)) {               cout <<  () ;               go(x + 1, y, s);               return;             }           }         }       }       if (y < b.size()) {         if (b[y] ==  ( ) {           if (ret == 1 + call(x, y + 1, s + 1)) {             cout <<  ( ;             go(x, y + 1, s + 1);             return;           }         } else {           if (s) {             if (ret == 1 + call(x, y + 1, s - 1)) {               cout <<  ) ;               go(x, y + 1, s - 1);               return;             }           } else {             if (ret == 2 + call(x, y + 1, s)) {               cout <<  () ;               go(x, y + 1, s);               return;             }           }         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> a >> b;     memset(dp, -1, sizeof(dp));     go(0, 0, 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e8;   long long inf = 1e15;   long long n, m, k, ans, x;   long long t[2003], c[2003];   long long dp[2003][4003];   long long f(long long x, long long y) {     long long &ret = dp[x][y];     if (ret != -1) return ret;     if (x == n + 1 && y < 2000) return inf;     if (x == n + 1) return 0;     long long yy = y + t[x];     yy = min(yy, 4000LL);     ret = c[x] + f(x + 1, yy);     ret = min(ret, f(x + 1, y - 1));     return ret;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(dp, -1, sizeof dp);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> t[i] >> c[i];     }     cout << f(1, 2000);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T, class L>   bool smax(T &x, L y) {     return x < y ? (x = y, 1) : 0;   }   template <class T, class L>   bool smin(T &x, L y) {     return x > y ? (x = y, 1) : 0;   }   const int maxn = 15e3 + 17, maxk = 1e3 + 17, mod = 1e9 + 7, base = 1e7 + 19,             lg = 17, maxq = 3e4 + 17;   vector<int> iman[maxq << 2];   int n, k, nq, q, dp[lg][maxk], w[maxn], v[maxn], ans[maxq], po[maxk];   void majid(int st, int en, int idx, int l = 0, int r = q, int id = 1) {     if (st <= l && r <= en) {       iman[id].push_back(idx);       return;     }     if (en <= l || r <= st) return;     int mid = l + r >> 1;     majid(st, en, idx, l, mid, id << 1), majid(st, en, idx, mid, r, id << 1 | 1);   }   void hamid(int l = 0, int r = q, int id = 1, int h = 1) {     memcpy(dp[h], dp[h - 1], sizeof dp[h]);     for (auto idx : iman[id])       for (int wi = k - w[idx]; wi >= 0; wi--)         smax(dp[h][wi + w[idx]], dp[h][wi] + v[idx]);     partial_sum(dp[h], dp[h] + k + 1, dp[h],                 [](int &x, int &y) { return max(x, y); });     if (r - l < 2) {       for (int i = 1; i <= k; i++)         ans[l] = (ans[l] + (long long)po[i - 1] * dp[h][i]) % mod;       return;     }     int mid = l + r >> 1;     hamid(l, mid, id << 1, h + 1), hamid(mid, r, id << 1 | 1, h + 1);   }   int st[maxn], en[maxn];   int main() {     ios::sync_with_stdio(0), cin.tie(0);     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> v[i] >> w[i];     po[0] = 1;     for (int i = 1; i <= k; i++) po[i] = (long long)po[i - 1] * base % mod;     memset(en, 63, sizeof en);     cin >> nq;     for (int t, x; nq--;) {       cin >> t;       if (t == 1)         cin >> v[n] >> w[n], st[n++] = q;       else if (t == 2)         cin >> x, en[x - 1] = q;       else         q++;     }     for (int i = 0; i < n; i++) majid(st[i], min(q, en[i]), i);     hamid();     for (int i = 0; i < q; i++) cout << ans[i] <<   n ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   void solve() {     string s;     cin >> s;     int n = s.size();     if (s[0] ==  b  && s[n - 1] ==  a ) {       s[0] =  a ;     } else if (s[0] ==  a  && s[n - 1] ==  b ) {       s[n - 1] =  a ;     }     cout << s <<   n ;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     int n;     cin >> n;     vector<char> c(n);     vector<int> id(n);     map<int, bool> state, exist;     for (int i = 0; i < n; i++) cin >> c[i] >> id[i];     for (int i = 0; i < n; i++) {       if (c[i] ==  + )         exist[id[i]] = true;       else {         if (exist[id[i]])           exist[id[i]] = false;         else           state[id[i]] = true;       }     }     int ans = state.size();     for (int i = 0; i < n; i++) {       if (c[i] ==  + )         state[id[i]] = true;       else {         state.erase(id[i]);       }       ans = max(ans, int(state.size()));     }     cout << ans;     return 0;   }