#include <bits/stdc++.h>   using namespace std;   string rows[1000];   int dist[1000][1000];   bool disc[1000][1000];   int r, c;   void bfs(int row, int col) {     queue<pair<int, int> > q;     q.push(make_pair(row, col));     while (!q.empty()) {       pair<int, int> cur = q.front();       disc[cur.first][cur.second] = true;       q.pop();       if (cur.first > 0 && !disc[cur.first - 1][cur.second] &&           rows[cur.first - 1][cur.second] !=  T ) {         dist[cur.first - 1][cur.second] = dist[cur.first][cur.second] + 1;         disc[cur.first - 1][cur.second] = true;         q.push(make_pair(cur.first - 1, cur.second));       }       if (cur.first < r - 1 && !disc[cur.first + 1][cur.second] &&           rows[cur.first + 1][cur.second] !=  T ) {         dist[cur.first + 1][cur.second] = dist[cur.first][cur.second] + 1;         disc[cur.first + 1][cur.second] = true;         q.push(make_pair(cur.first + 1, cur.second));       }       if (cur.second < c - 1 && !disc[cur.first][cur.second + 1] &&           rows[cur.first][cur.second + 1] !=  T ) {         dist[cur.first][cur.second + 1] = dist[cur.first][cur.second] + 1;         disc[cur.first][cur.second + 1] = true;         q.push(make_pair(cur.first, cur.second + 1));       }       if (cur.second > 0 && !disc[cur.first][cur.second - 1] &&           rows[cur.first][cur.second - 1] !=  T ) {         dist[cur.first][cur.second - 1] = dist[cur.first][cur.second] + 1;         disc[cur.first][cur.second - 1] = true;         q.push(make_pair(cur.first, cur.second - 1));       }     }   }   int main(void) {     cin >> r >> c;     for (int i = 0; i < r; i++) cin >> rows[i];     memset(disc, 0, sizeof(disc));     for (int i = 0; i < r; i++)       for (int j = 0; j < c; j++)         if (rows[i][j] ==  E ) bfs(i, j);     pair<int, int> start;     for (int i = 0; i < r; i++) {       for (int j = 0; j < c; j++) {         if (rows[i][j] ==  S ) {           start.first = i;           start.second = j;         }       }     }     int kiek = 0;     for (int i = 0; i < r; i++) {       for (int j = 0; j < c; j++) {         if (isdigit(rows[i][j]) &&             dist[i][j] <= dist[start.first][start.second] && disc[i][j]) {           kiek += int(rows[i][j] -  0 );         }       }     }     cout << kiek << endl;   }


#include <bits/stdc++.h>   using namespace std;   constexpr int mod = (int)998244353;   long long mod_mul(long long a, long long b) {     a = a % mod;     b = b % mod;     return (((a * b) % mod) + mod) % mod;   }   long long mod_add(long long a, long long b) {     a = a % mod;     b = b % mod;     return (((a + b) % mod) + mod) % mod;   }   long long binpow(long long a, long long b, long long mod) {     long long res = 1;     a %= mod;     while (b > 0) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return res;   }   long long binmul(long long a, long long b) {     long long res = 0;     a %= mod;     while (b > 0) {       if (b & 1) res = (res + a) % mod;       a = (a + a) % mod;       b >>= 1;     }     return res;   }   long long area(pair<int, int> a, pair<int, int> b, pair<int, int> c) {     return abs(a.first * b.second + b.first * c.second + c.first * a.second -                a.second * b.first - b.second * c.first - c.second * a.first);   }   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   long long min(long long a, long long b) {     if (a < b) {       return a;     }     return b;   }   long long max(long long a, long long b) {     if (a > b) {       return a;     }     return b;   }   double intlog(long long n, long long base) {     return (double)log(n) / log(base);   }   long long t, m, temp, temp2, root, q, k, i, j, r, u, v, w, n, l, p;   template <typename A>   ostream &operator<<(ostream &cout, vector<A> const &v);   template <typename A, typename B>   ostream &operator<<(ostream &cout, pair<A, B> const &p) {     return cout <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename A>   ostream &operator<<(ostream &cout, vector<A> const &v) {     cout <<  [ ;     for (int i = 0; i < v.size(); i++) {       if (i) cout <<  ,  ;       cout << v[i];     }     return cout <<  ] ;   }   template <typename A, typename B>   istream &operator>>(istream &cin, pair<A, B> &p) {     cin >> p.first;     return cin >> p.second;   }   long long mid;   int solve(int i, int x, vector<long long> &a, vector<vector<int> > &dp) {     if (x < 0 || x > mid) {       return 0;     }     if (i == (int)a.size()) {       return 1;     }     int &res = dp[i][x];     if (res != -1) return res;     if (dp[i][x] != -1) return dp[i][x];     int ans = 0;     ans = ans | solve(i + 1, x - a[i], a, dp);     ans = ans | solve(i + 1, x + a[i], a, dp);     return res = ans;   }   bool solve(int mid, vector<long long> &a) {     vector<bool> dp(mid + 1, 1);     for (int i = 0; i < (int)a.size(); i++) {       vector<bool> temp(mid + 1, 0);       bool flag = 0;       for (j = 0; j <= mid; j++) {         if (j + a[i] <= mid) {           temp[j] = temp[j] || dp[j + a[i]];         }         if (j - a[i] >= 0) {           temp[j] = temp[j] || dp[j - a[i]];         }         flag = flag || temp[j];       }       if (flag == 0) return 0;       dp = temp;     }     return 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> t;     while (t--) {       cin >> n;       vector<long long> a(n);       for (i = 0; i < n; i++) {         cin >> a[i];       }       int l = 1;       int r = 2000;       long long res = 2000;       while (l <= r) {         mid = (r - l) / 2 + l;         if (solve(mid, a)) {           r = mid - 1;           res = min(res, mid);         } else {           l = mid + 1;         }       }       cout << res <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   bool flag = 0;   int work(int a, int n, int p) {     int t = a * 1ll * n / p;     if (!t) {       if (!flag) return a;       return max(a, p - a * n);     }     flag = 1;     int a1, n1, p1;     a1 = min(p % a, a - (p % a));     n1 = t;     p1 = a;     if (a * 1ll * n % p < a * 1ll * (p / a - 1)) n1--;     return work(a1, n1, p1);   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       int a, n, p, h;       scanf( %d%d%d%d , &a, &n, &p, &h);       flag = 0;       if (work(a % p, n, p) <= h)         printf( YES n );       else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>      using namespace std;      #define all(x) (x).begin(), (x).end()   #define fast ios::sync_with_stdio(false);cin.tie(0);   typedef long long ll;   typedef long double ld;   typedef unsigned long long ull;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());      map<pair<int,int>,bool> e[3];      int main(){    fast    vector<int> n(4);    for(int i=0;i<4;i++)cin>>n[i];    vector<vector<int>> c(4);    for(int i=0;i<4;i++){     c[i].resize(n[i]);     for(int j=0;j<n[i];j++)cin>>c[i][j];    }    for(int i=0;i<3;i++){     int m;     cin>>m;     for(int j=0;j<m;j++){      int a,b;      cin>>a>>b;      a--;b--;      // cerr << i <<     << a <<     << b <<   n ;      e[i][{a,b}] = true;     }    }    vector<pair<ll,int>> dp,nxt;    for(int i=0;i<n[3];i++)dp.push_back({c[3][i],i});    for(int lvl=2;lvl>=0;lvl--){     sort(all(dp));     for(int i=0;i<n[lvl];i++){      for(int j=0;j<dp.size();j++){       if(e[lvl][{i,dp[j].second}])continue;       nxt.push_back({c[lvl][i] + dp[j].first , i});       break;      }     }     dp = nxt;     nxt.clear();      }    sort(all(dp));    if(dp.empty())cout << -1 <<   n ;    else cout << dp[0].first <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 1e5 + 5;   const int maxM = 1e6 + 5;   const long long INF = 1e18;   const long long MOD = 1e9 + 7;   long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }   long long sq(long long x) { return (x * x) % MOD; }   long long modP(long long a, long long b) {     return (!b ? 1 : (sq(modP(a, b / 2)) * (b % 2 ? a : 1)) % MOD);   }   bool on[maxN];   int n, id[maxM], TIME;   int f[maxM], sz = 0;   int Q[maxM], lt, rt;   int st[maxM], fn[maxM];   int trie[maxM][26];   long long fen[maxM];   string s[maxN], str;   vector<int> G[maxM];   void SHAHO() {     for (int i = 1; i <= n; i++) {       int curr = 0;       for (auto ch : s[i]) {         int c = ch -  a ;         if (!trie[curr][c]) trie[curr][c] = ++sz;         curr = trie[curr][c];       }       id[i] = curr;     }     for (int i = 0; i < 26; i++)       if (trie[0][i]) Q[rt++] = trie[0][i];     while (lt != rt) {       int v = Q[lt++];       for (int i = 0; i < 26; i++) {         if (trie[v][i]) {           Q[rt++] = trie[v][i];           f[trie[v][i]] = trie[f[v]][i];         } else           trie[v][i] = trie[f[v]][i];       }     }     return;   }   void DFS(int v) {     st[v] = TIME++;     for (auto u : G[v]) DFS(u);     fn[v] = TIME;     return;   }   void add(int p, int x) {     for (; p < maxM; p += p & -p) fen[p] += x;     return;   }   long long fetch(int p) {     long long res = 0;     for (; p > 0; p -= p & -p) res += fen[p];     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int q;     cin >> q >> n;     for (int i = 1; i <= n; i++) cin >> s[i], on[i] = 1;     SHAHO();     for (int i = 0; i <= sz; i++)       if (i != f[i]) G[f[i]].push_back(i);     DFS(0);     for (int i = 1; i <= n; i++) {       add(st[id[i]], +1);       add(fn[id[i]], -1);     }     int v;     while (q--) {       char t;       cin >> t;       if (t ==  ? ) {         cin >> str;         v = 0;         long long ans = 0;         for (auto ch : str) {           v = trie[v][ch -  a ];           ans += fetch(st[v]);         }         cout << ans <<   n ;         continue;       }       cin >> v;       if (t ==  + ) {         add(st[id[v]], 1 - on[v]);         add(fn[id[v]], on[v] - 1);         on[v] = 1;       } else {         add(st[id[v]], -on[v]);         add(fn[id[v]], +on[v]);         on[v] = 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   const int prime[8] = {2, 3, 5, 7, 11, 13, 17, 19};   long long mul(long long x, long long y, long long mo) {     long long ret = 1;     while (y) {       if (y % 2 == 1) ret = ret * x % mo;       x = x * x % mo;       y /= 2;     }     return ret;   }   bool is_prime(int n) {     for (int i = 0; i <= 7; i++) {       if (n == prime[i]) return 1;       if (mul(prime[i], n - 1, n) != 1) return 0;     }     return 1;   }   int main() {     scanf( %d , &n);     if (n == 1) {       puts( YES );       puts( 1 );       return 0;     }     if (n == 4) {       puts( YES );       puts( 1 );       puts( 3 );       puts( 2 );       puts( 4 );       return 0;     }     if (!is_prime(n)) {       puts( NO );       return 0;     }     puts( YES );     puts( 1 );     for (int i = 2; i <= n; i++) {       long long now = i * mul(i - 1, n - 2, n) % n;       if (now == 0) now = n;       printf( %I64d n , now);     }     return 0;   }


#include <bits/stdc++.h>   const double INF = 1e18, eps = 1e-18;   double a, b, c, x_1, y_1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6, ans;   double sqr(double x) { return x * x; }   double dis(double x_1, double y_1, double x2, double y2) {     return sqrt(sqr(x2 - x_1) + sqr(y_1 - y2));   }   int main() {     scanf( %lf%lf%lf%lf%lf%lf%lf , &a, &b, &c, &x_1, &y_1, &x6, &y6);     if (std::abs(a - 0) > eps && std::abs(b - 0) > eps)       y2 = y_1, x2 = (-b * y2 - c) / a;     else       y2 = x2 = INF;     if (std::abs(a - 0) > eps && std::abs(b - 0) > eps)       x3 = x_1, y3 = (-a * x3 - c) / b;     else       x3 = y3 = INF;     if (std::abs(a - 0) > eps && std::abs(b - 0) > eps)       y4 = y6, x4 = (-b * y4 - c) / a;     else       x4 = y4 = INF;     if (std::abs(a - 0) > eps && std::abs(b - 0) > eps)       x5 = x6, y5 = (-a * x5 - c) / b;     else       x5 = y5 = INF;     ans = std::min(         std::min(             std::min(                 dis(x_1, y_1, x2, y2) + dis(x2, y2, x4, y4) + dis(x4, y4, x6, y6),                 dis(x_1, y_1, x2, y2) + dis(x2, y2, x5, y5) +                     dis(x5, y5, x6, y6)),             dis(x_1, y_1, x3, y3) + dis(x3, y3, x4, y4) + dis(x4, y4, x6, y6)),         dis(x_1, y_1, x3, y3) + dis(x3, y3, x5, y5) + dis(x5, y5, x6, y6));     ans = std::min(ans, std::abs(x6 - x_1) + std::abs(y6 - y_1));     printf( %.10lf , ans);     return 0;   }


#include <bits/stdc++.h>   struct Node;   Node* null;   struct Node {     Node* insert(int l, int r, int k) {       if (k < l || r < k) {         return this;       }       if (l == r) {         return new Node{count + 1, null, null};       }       int m = l + r >> 1;       return new Node{count + 1, left->insert(l, m, k),                       right->insert(m + 1, r, k)};     }     int count;     Node *left, *right;   };   int query(Node* p, Node* q, int l, int r, int limit) {     if (q->count - p->count <= limit) {       return INT_MAX;     }     if (l == r) {       return l;     }     int m = l + r >> 1;     return std::min(query(p->left, q->left, l, m, limit),                     query(p->right, q->right, m + 1, r, limit));   }   const int N = 300000;   Node* tree[N + 1];   int main() {     null = new Node{0, nullptr, nullptr};     null->left = null->right = null;     int n, q;     while (scanf( %d%d , &n, &q) == 2) {       tree[0] = null;       for (int i = 1, a; i <= n; ++i) {         scanf( %d , &a);         tree[i] = tree[i - 1]->insert(1, n, a);       }       while (q--) {         int l, r, k;         scanf( %d%d%d , &l, &r, &k);         int limit = (r - l + 1) / k;         int result = query(tree[l - 1], tree[r], 1, n, limit);         printf( %d n , result == INT_MAX ? -1 : result);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int T, n, m, u, v, sum, ans;   int col[N];   bool vis[N];   int cnt, head[N];   struct edge {     int next, to;   } e[N << 1];   inline void add(int u, int v) {     cnt++;     e[cnt].next = head[u];     e[cnt].to = v;     head[u] = cnt;   }   queue<int> q;   int main() {     scanf( %d , &T);     while (T--) {       scanf( %d%d , &n, &m);       cnt = 0;       for (register int i = 1; i <= n; ++i) head[i] = 0;       for (register int i = 1; i <= m; ++i)         scanf( %d%d , &u, &v), add(u, v), add(v, u);       for (register int i = 1; i <= n; ++i) vis[i] = false;       col[1] = 1;       vis[1] = true;       q.push(1);       while (q.size()) {         u = q.front();         q.pop();         for (register int i = head[u]; i; i = e[i].next)           if (!vis[e[i].to]) {             col[e[i].to] = col[u] ^ 1;             vis[e[i].to] = true;             q.push(e[i].to);           }       }       sum = 0;       for (register int i = 1; i <= n; ++i) sum += col[i];       ans = min(sum, n - sum);       printf( %d n , ans);       if (ans == sum) {         for (register int i = 1; i <= n; ++i)           if (col[i]) printf( %d  , i);       } else {         for (register int i = 1; i <= n; ++i)           if (!col[i]) printf( %d  , i);       }       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, d, a, b, p[100005], x[100005], y[100005], c, ans[100005];   long long cmp(long long A, long long B) {     return x[A] * a + y[A] * b < x[B] * a + y[B] * b;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> d;     cin >> a >> b;     for (long long i = 1; i <= n; i++) cin >> x[i] >> y[i], p[i] = i;     sort(p + 1, p + 1 + n, cmp);     for (long long i = 1; i <= n; i++)       if (d >= x[p[i]] * a + y[p[i]] * b)         d -= x[p[i]] * a + y[p[i]] * b, ans[++c] = p[i];     cout << c << endl;     for (int i = 1; i <= c; i++) cout << ans[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   bool mark = false;   int main() {     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  0  && mark == false) {         mark = true;         continue;       }       if (mark == false && i == s.size() - 1) return 0;       cout << s[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   struct trie {     int cnt, whole;     trie *next[26];     trie() {       cnt = 0;       for (int i = 0; i < 26; ++i) next[i] = NULL;     }   } *root = new trie();   void ins(char *s) {     trie *p = root;     for (int i = 0; s[i]; ++i) {       int c = s[i] -  a ;       if (p->next[c] == NULL) p->next[c] = new trie();       p = p->next[c];     }     p->cnt++;   }   vector<int> *dp(trie *p, int dep) {     int pos = -1, cnt = 0;     for (int i = 0; i < 26; ++i) {       if (p->next[i] != NULL) {         pos = i;         cnt++;       }     }     if (cnt == 0) {       vector<int> *ret = new vector<int>(p->cnt + 1);       for (int i = 0; i <= p->cnt; ++i) (*ret)[i] = i * (i - 1) * dep / 2;       return ret;     } else if (cnt == 1 && p->whole == p->next[pos]->whole) {       return dp(p->next[pos], dep + 1);     } else {       vector<int> *ret = new vector<int>(p->whole + 1, 0);       for (int i = 0; i <= p->cnt; ++i) (*ret)[i] = i * (i - 1) * dep / 2;       int lim = p->cnt;       for (int i = 0; i < 26; ++i) {         if (p->next[i] != NULL) {           vector<int> *tmp = dp(p->next[i], dep + 1);           for (int j = lim; j >= 0; --j)             for (int k = 1;                  k < (int)tmp->size() && j + k <= lim + p->next[i]->whole; ++k)               (*ret)[j + k] =                   max((*ret)[j + k], (*ret)[j] + (*tmp)[k] + (j * k * dep));           lim += p->next[i]->whole;         }       }       return ret;     }   }   int dfs(trie *p) {     p->whole = p->cnt;     for (int i = 0; i < 26; ++i)       if (p->next[i] != NULL) p->whole += dfs(p->next[i]);     return p->whole;   }   int main() {     char s[512];     scanf( %d%d , &n, &k);     for (int i = 0; i < n; ++i) {       scanf( %s , s);       ins(s);     }     dfs(root);     printf( %d n , (*dp(root, 0))[k]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   function<void(void)> ____ = []() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   };   const int MAXN = 4e5 + 7;   int n;   pair<int, int> A[MAXN];   struct Disjoint_Set_Union {     int fa[MAXN], sz[MAXN];     void clear() {       for (int i = 1; i < MAXN; i++) fa[i] = i, sz[i] = 0;     }     int findx(int x) { return x == fa[x] ? x : fa[x] = findx(fa[x]); }     void merge(int x, int y) {       x = findx(x), y = findx(y);       if (x != y) sz[y] += sz[x], fa[x] = y;     }   } dsu;   struct SegmentTree {     int root[MAXN], sz[MAXN << 4], tot, ls[MAXN << 4], rs[MAXN << 4];     long long sig[MAXN << 4], sum[MAXN << 4];     void pushup(int rt) {       sz[rt] = sz[ls[rt]] + sz[rs[rt]];       sig[rt] = sig[ls[rt]] + sig[rs[rt]];       sum[rt] = sig[ls[rt]] * sz[rs[rt]] + sum[ls[rt]] + sum[rs[rt]];     }     void modify(int &rt, int pos, int L, int R) {       rt = ++tot;       if (L + 1 == R) {         sz[rt]++;         sig[rt] += pos;         return;       }       int mid = (L + R) >> 1;       if (pos < mid)         modify(ls[rt], pos, L, mid);       else         modify(rs[rt], pos, mid, R);       pushup(rt);     }     int merge(int u, int v, int L, int R) {       if (!u or !v) return u ^ v;       if (L + 1 == R) {         sz[u] += sz[v];         sig[u] += sig[v];         return u;       }       int mid = (L + R) >> 1;       ls[u] = merge(ls[u], ls[v], L, mid);       rs[u] = merge(rs[u], rs[v], mid, R);       pushup(u);       return u;     }   } seg;   void solve() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d %d , &A[i].first, &A[i].second);     dsu.clear();     long long ret = 0;     for (int i = 1; i <= n; i++) {       int a = A[i].first, b = A[i].second;       ret -= 1ll * a * b;       int rt = dsu.findx(a);       int pos = rt + dsu.sz[rt];       dsu.sz[pos] = 1;       seg.modify(seg.root[pos], b, 1, n + 1);       if (pos == rt and pos != 1 and dsu.sz[pos - 1]) rt = dsu.findx(rt - 1);       if (pos != rt) {         ret -= seg.sum[seg.root[rt]];         ret -= rt * seg.sig[seg.root[rt]];         dsu.merge(pos, rt);         seg.root[rt] = seg.merge(seg.root[rt], seg.root[pos], 1, n + 1);       }       if (dsu.sz[pos + 1]) {         ret -= seg.sum[seg.root[pos + 1]];         ret -= (pos + 1) * seg.sig[seg.root[pos + 1]];         dsu.merge(pos + 1, rt);         seg.root[rt] = seg.merge(seg.root[rt], seg.root[pos + 1], 1, n + 1);       }       ret += seg.sum[seg.root[rt]];       ret += rt * seg.sig[seg.root[rt]];       cout << ret <<   n ;     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const int maxn = 300009;   long long fac[maxn], invfac[maxn], A[33], B[33], in[maxn], idx[maxn];   vector<int> L[maxn], R[maxn];   int n, m;   long long mpw(long long a, long long b) {     long long c = 1;     while (b) {       if (b & 1ll) c = c * a % mod;       a = a * a % mod;       b >>= 1;     }     return c;   }   void init() {     fac[0] = 1;     for (int i = 1; i < maxn; ++i) fac[i] = fac[i - 1] * i % mod;     invfac[maxn - 1] = mpw(fac[maxn - 1], mod - 2);     for (int i = maxn - 2; i >= 0; --i) invfac[i] = invfac[i + 1] * (i + 1) % mod;   }   long long C(int a, int b) {     if (a < b || b < 0) return 0;     return fac[a] * invfac[b] % mod * invfac[a - b] % mod;   };   int main() {     ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);     cin >> n >> m;     vector<std::vector<int>> add(n + 1), del(n + 1);     for (int i = 1; i <= n; ++i) {       int l, r;       cin >> l >> r;       L[l].push_back(i);       R[r].push_back(i);       add[l].push_back(i - 1);       del[r].push_back(i - 1);     }     int idxtot = 0, cc = 0;     memset(idx, -1, sizeof idx);     std::vector<int> a(m), b(m);     std::vector<int> id(n, -1);     for (int i = 0; i < m; ++i) {       cin >> A[i] >> B[i];       a[i] = A[i] - 1;       b[i] = B[i] - 1;       if (idx[A[i]] == -1) idx[A[i]] = idxtot++;       if (idx[B[i]] == -1) idx[B[i]] = idxtot++;       if (id[a[i]] == -1) id[a[i]] = cc++;       if (id[b[i]] == -1) id[b[i]] = cc++;     }     init();     long long premask = 0, tot = 0, masktot = 0, curmask = 0, res = 0;     vector<long long> cnt(m + 1);     cnt[0] = 1;     std::vector<int> ways(m + 1);     std::vector<int> in2(n);     ways[0] = 1;     long long mask = 0;     int tot2 = 0, tp = 0;     int ans = 0;     for (int i = 1; i <= n; ++i) {       for (int j : L[i]) {         in[j] = 1;         if (idx[j] == -1)           tot++;         else           masktot++;       }       for (auto x : add[i]) {         in2[x] = 1;         ++(id[x] == -1 ? tot2 : tp);       }       curmask = 0;       for (int j = 0; j < m; ++j) {         if (in[A[j]]) curmask |= 1ll << idx[A[j]];         if (in[B[j]]) curmask |= 1ll << idx[B[j]];       }       long long nMask = 0;       for (int j = 0; j < m; ++j) {         if (in2[a[j]]) nMask |= 1ll << id[a[j]];         if (in2[b[j]]) nMask |= 1ll << id[b[j]];       }       if (nMask != curmask) {         cout << 1 <<   n ;         return 0;       }       if (mask != premask) {         cout << 3;         return 0;       }       if (tp != masktot) {         cout << 4;         return 0;       }       if (nMask != mask) {         mask = nMask;         std::fill(ways.begin(), ways.end(), 0);         std::function<void(int, int64_t, int)> dfs1 = [&](int x, int64_t s,                                                           int coef) {           if (x == m) {             int p = __builtin_popcountll(s);             for (int j = 0; j <= m; ++j)               ways[j] = (ways[j] + 1ll * coef * C(tp - p, j - p)) % mod;             return;           }           if (in2[a[x]] && in2[b[x]])             dfs1(x + 1, s | 1ll << id[a[x]] | 1ll << id[b[x]], mod - coef);           dfs1(x + 1, s, coef);         };         dfs1(0, 0, 1);       }       if (premask != curmask) {         for (int j = 0; j <= m; ++j) cnt[j] = 0;         std::function<void(int, int64_t, int)> dfs1 = [&](int x, int64_t s,                                                           int coef) {           if (x == m) {             int p = __builtin_popcountll(s);             for (int j = 0; j <= m; ++j)               cnt[j] = (cnt[j] + 1ll * coef * C(tp - p, j - p)) % mod;             return;           }           if (in[A[x]] && in[B[x]])             dfs1(x + 1, s | 1ll << idx[A[x]] | 1ll << idx[B[x]], mod - coef);           dfs1(x + 1, s, coef);         };         dfs1(0, 0, 1);       }       premask = curmask;       for (int j = 0; j <= m; ++j)         if (cnt[j] != ways[j]) {           for (int x = 0; x < n; ++x) assert(in[x + 1] == in2[x]);           cout << 2;           return 0;         }       for (int j = 0; j <= m; ++j)         ans = (ans + 1ll * ways[j] * C(tot2, i - j)) % mod;       for (int j = 0; j <= m; ++j)         res = (res + cnt[j] * C(tot, i - j) % mod) % mod;       assert(ans == res);       for (int j : R[i]) {         in[j] = 0;         if (idx[j] == -1)           tot--;         else           masktot--;       }       for (auto x : del[i]) {         in2[x] = 0;         --(id[x] == -1 ? tot2 : tp);       }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e+18;   int main() {     cin.tie(0);     ios::sync_with_stdio(0);     int n, c = 0;     cin >> n;     while (n != 0) {       string str = to_string(n);       int maxi = 0;       for (int i = 0; i < str.size(); i++) {         if ((str[i] -  0 ) > maxi) {           maxi = str[i] -  0 ;         }       }       n -= maxi;       c++;     }     cout << c <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   struct Point {     int x, y;     Point() {}     Point(int a, int b) {       x = a;       y = b;     }   };   double hypt(Point A, Point B) {     return sqrt((B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y));   }   int main() {     int k, n;     cin >> n >> k;     vector<Point> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i].x >> v[i].y;     }     double ans = 0;     for (int i = 1; i < n; i++) {       ans += hypt(v[i], v[i - 1]);     }     ans *= k;     ans /= 50;     printf( %.10lf , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<pair<int, int>> arr;     vector<int> t;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       t.push_back(a);       arr.push_back({a, i});     }     sort(arr.begin(), arr.end());     int i, j;     for (i = 0; i < arr.size(); i++) {       if (arr[i].second != i) break;     }     for (j = arr.size() - 1; j >= 0; j--) {       if (arr[j].second != j) break;     }     if (i == arr.size() || j < 0)       cout << 0 <<     << 0 << endl;     else {       vector<int> res;       for (int k = 0; k < i; k++) res.push_back(t[k]);       for (int k = j; k >= i; k--) res.push_back(t[k]);       for (int k = j + 1; k < n; k++) res.push_back(t[k]);       bool flag = false;       for (int k = 0; k < n - 1; k++) {         if (res[k] >= res[k + 1]) {           flag = true;           break;         }       }       if (!flag)         cout << arr[j].second + 1 <<     << arr[i].second + 1 << endl;       else         cout << 0 <<     << 0 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     long double x, y;   };   point a1, a2, a3, a4, b1, b2, b3, b4, c;   int l, r, u, d;   bool corner(point b) {     if (b.x <= r && b.x >= l && b.y <= u && b.y >= d)       return true;     else       return false;   }   pair<long double, long double> line(point a, point b) {     long double m, c;     m = ((long double)b.y - a.y) / ((long double)b.x - a.x);     c = a.y - m * a.x;     return {m, c};   }   point foot(pair<long double, long double> line) {     point p;     p.x =         (line.first * (c.y + line.second) + c.x) / (1 + line.first * line.first);     p.y = line.first * p.x + line.second;     return p;   }   bool inside(point p, pair<long double, long double> l1,               pair<long double, long double> l2) {     int k = l1.first / l2.first;     if (k == -1) {       l1.first *= -1;       l1.second *= -1;     }     if ((p.x * l1.first + l1.second - p.y) * (p.x * l2.first + l2.second - p.y) <=         0)       return true;     return false;   }   int main() {     ios::sync_with_stdio(0);     cin >> a1.x >> a1.y >> a2.x >> a2.y >> a3.x >> a3.y >> a4.x >> a4.y;     c.x = (a1.x + a2.x + a3.x + a4.x) / 4;     c.y = (a1.y + a2.y + a3.y + a4.y) / 4;     l = min(min(a1.x, a2.x), a3.x);     r = max(max(a1.x, a2.x), a3.x);     d = min(min(a1.y, a2.y), a3.y);     u = max(max(a1.y, a2.y), a3.y);     cin >> b1.x >> b1.y >> b2.x >> b2.y >> b3.x >> b3.y >> b4.x >> b4.y;     int flag = 0;     if (corner(b1) || corner(b2) || corner(b3) || corner(b4)) flag = 1;     pair<long double, long double> l1, l2, l3, l4;     l1 = line(b1, b2);     l2 = line(b2, b3);     l3 = line(b3, b4);     l4 = line(b4, b1);     long double d = (r - l) / 2 * sqrt((long double)2);     if ((inside(a1, l1, l3) && inside(a1, l2, l4)) ||         (inside(a2, l1, l3) && inside(a2, l2, l4)) ||         (inside(a3, l1, l3) && inside(a3, l2, l4)) ||         (inside(a4, l1, l3) && inside(a4, l2, l4)) ||         (inside(c, l1, l3) && inside(c, l2, l4)))       flag = 1;     if (flag)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     srand(time(NULL));     ;     int T = 1;     cin >> T;     while (T--) {       int n;       cin >> n;       cout << setprecision(10)            << cos(3.141592653589793238 / (4 * n)) /                   sin(3.141592653589793238 / (2 * n));       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int get(long long int x) {     long long int y = 1, ans = 0;     while (y < x) {       y = y * 2;       if (y <= x)         ans++;       else         break;     }     return ans;   }   int main() {     int t = 1;     cin >> t;     while (t--) {       long long int n, m, k, a = 0, b = 0, ans = 1, x = 0, y = 0;       cin >> a >> b >> m;       if (a == b) {         cout <<  1   << a <<   n ;         continue;       }       n = get(b / (a + 1));       long long int arr[51] = {};       long long int rem = b - (1ll << n) * (a + 1);       long long int cur = a + 1, sum = a;       vector<long long int> sol;       sol.push_back(n + 2);       sol.push_back(a);       for (int i = 0; i < n; i++) {         x = (1ll << (n - i - 1));         if (rem >= x) {           k = min(m - 1, rem / x);           rem -= k * x;           cur += k;         }         sol.push_back(cur);         sum += cur;         cur = sum + 1;       }       if (rem >= 0 && rem < m) {         sol.push_back(cur + rem);         for (auto i : sol) cout << i <<    ;       } else {         cout <<  -1 ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int debug_ = 0;   const int maxn = 200000;   const long long inf = 998244353;   int unum[33], dnum[33];   long long dp[33][2][2][2];   long long dfs(int pos, int u, int e, int d) {     if (pos == -1) {       return 2 - e;     }     if (dp[pos][u][e][d] != -1) {       return dp[pos][u][e][d];     }     long long& ret = dp[pos][u][e][d];     ret = 0;     for (int i = 0; i < 3; ++i) {       int x = i / 2, y = i % 2;       if (x == 1 && u && unum[pos] == 0) {         continue;       }       if (y == 1 && e) {         continue;       }       if (y == 0 && d && dnum[pos] == 1) {         continue;       }       int nu = (u && x == unum[pos]);       int ne = (e && y == x);       int nd = (d && y == dnum[pos]);       ret += dfs(pos - 1, nu, ne, nd);     }     return ret;   }   int main() {     int tes, u, d;     cin >> tes;     while (tes--) {       cin >> d >> u;       for (int i = 0; i < 31; ++i) {         dnum[i] = (d >> i) & 1;         unum[i] = (u >> i) & 1;       }       memset(dp, -1, sizeof(dp));       cout << dfs(32, 1, 1, 1) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 205, P = 1e9 + 7ll;   struct node {     long long x, y;     node operator-(const node &t) const {       node c;       c.x = x - t.x;       c.y = y - t.y;       return c;     }     long long operator*(const node &t) const { return x * t.y - y * t.x; }   } p[N];   long long n, dp[N][N];   long long search(long long x, long long y) {     long long ans = 0;     if (dp[x][y] != -1) return dp[x][y];     if (x + 1 == y) return dp[x][y] = 1;     for (int i = x + 1; i < y; i++)       if ((p[x] - p[i]) * (p[y] - p[i]) > 0)         ans = (ans + search(x, i) * search(i, y) % P) % P;     return dp[x][y] = ans;   }   int main() {     memset(dp, -1, sizeof dp);     scanf( %dll , &n);     for (int i = 1; i <= n; i++) scanf( %lld%lld , &p[i].x, &p[i].y);     p[n + 1] = p[1];     long long s = 0;     for (int i = 1; i <= n; i++) s += p[i + 1] * p[i];     if (s < 0)       for (int i = 1, j = n; i < j; swap(p[i++], p[j--]))         ;     printf( %lld , search(1, n));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long quick_pow(long long a, long long b, long long mod) {     long long ans = 1, base = a;     while (b) {       if (b & 1) (ans *= base) %= mod;       b >>= 1;       (base *= base) %= mod;     }     return ans;   }   struct node {     int pos, len;     bool operator<(const node& k) const { return pos < k.pos; }   };   const int N = 1e5 + 5;   int X[N], Y[N];   int A[N], B[N];   int main() {     int n, m;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d %d , &X[i], &Y[i]);       A[i] = X[i];       B[i] = Y[i];     }     sort(X + 1, X + n + 1);     sort(Y + 1, Y + n + 1);     m = (n + 1) >> 1;     int mid_x = X[m], mid_y = Y[m];     int dif_x = X[m + 1] - X[m], dif_y = Y[m + 1] - Y[m];     if (n & 1) {       dif_x = min(dif_x, X[m] - X[m - 1]);       dif_y = min(dif_y, Y[m] - Y[m - 1]);     }     long long ans = 0;     bool F0 = false, F1 = false, Tag = false;     for (int i = 1; i <= n; ++i) {       ans += abs(X[i] - X[m]) + abs(Y[i] - Y[m]);       F0 |= A[i] > mid_x && B[i] > mid_y;       F1 |= A[i] > mid_x && B[i] <= mid_y;       Tag |= A[i] == mid_x && B[i] == mid_y;     }     if (F0 && F1 && (~n & 1 || Tag)) ans -= min(dif_x, dif_y);     printf( %I64d n , ans << 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long parent[200001];   long long urank[200001];   void create(long long x) {     parent[x] = x;     urank[x] = 1;   }   long long find(long long x) {     if (parent[x] != x) {       parent[x] = find(parent[x]);     }     return parent[x];   }   void merge(long long x, long long y) {     long long xroot = find(x);     long long yroot = find(y);     if (urank[xroot] <= urank[yroot]) {       parent[xroot] = yroot;       urank[yroot] = urank[yroot] + urank[xroot];     } else {       parent[yroot] = xroot;       urank[xroot] = urank[xroot] + urank[yroot];     }   }   int main() {     std::ios::sync_with_stdio(false);     int T;     T = 1;     while (T--) {       int n, i, j, m;       cin >> n >> m;       long long ar[n + 1], a, b, c;       vector<pair<long long, int> > v;       vector<pair<long long, pair<int, int> > > v2;       for (i = 1; i <= n; ++i) {         create(i);         cin >> ar[i];         v.push_back({ar[i], i});       }       sort(v.begin(), v.end());       long long ans = 0;       for (i = 1; i < n; ++i) {         v2.push_back({v[0].first + v[i].first, {v[0].second, v[i].second}});       }       while (m--) {         cin >> a >> b >> c;         v2.push_back({c, {a, b}});       }       sort(v2.begin(), v2.end());       for (i = 0; i < v2.size(); ++i) {         a = find(v2[i].second.first);         b = find(v2[i].second.second);         if (a == b) continue;         ans = ans + v2[i].first;         merge(a, b);       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-9;   const long double pi = acos(-1.0);   const long long inf = 1e+9;   const long long inf64 = inf * inf;   #pragma comment(linker,  /STACK:36777216 )   template <typename T>   istream &operator>>(istream &, vector<T> &);   template <typename T>   ostream &operator<<(ostream &, const vector<T> &);   void solve() {     int m;     cin >> m;     string s;     cin >> s;     int n = s.size();     vector<int> cnt(26);     for (int i = 0; i < n; i++) cnt[s[i] -  a ]++;     for (char t =  a ; t <=  z ; t++) {       int last = -1;       bool fl = 1;       int count = 0;       for (int i = 0; i < n; i++) {         if (s[i] < t) {           if (i - last > m) {             fl = 0;             break;           }           last = i;         }         if (s[i] == t) {           int pos = -1;           int pos2 = -1;           for (int j = last + 1; j < n && j < last + 1 + m; j++) {             if (s[j] < t) pos = j;             if (s[j] == t) pos2 = j;           }           if (pos > i) {             last = pos;             i = pos;             continue;           }           if (pos2 != -1) {             i = pos2;             last = pos2;             count++;           } else {             fl = 0;             break;           }         }         if (n - last <= m) break;       }       if (fl && n - last <= m) {         string ans =   ;         for (char z =  a ; z < t; z++) ans += string(cnt[z -  a ], z);         ans += string(count, t);         cout << ans << endl;         return;       }     }   }   int main() {     solve();     return 0;   }   template <typename T>   istream &operator>>(istream &is, vector<T> &v) {     for (int i = 0; i < v.size(); ++i) is >> v[i];     return is;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (int i = 0; i < v.size(); ++i) os << v[i];     return os;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x7f7f7f7f;   int main() {     string s;     cin >> s;     int ans = 0;     stack<char> S;     for (int i = 0; i < s.length(); i++) {       if (S.empty()) {         S.push(s[i]);       } else if (S.top() == s[i]) {         ans++;         S.pop();       } else {         S.push(s[i]);       }     }     if (ans % 2 == 0)       cout <<  No  << endl;     else       cout <<  Yes  << endl;     return 0;   }


#include <bits/stdc++.h>   long long int x, y, z, i, flag, flag2, top;   long long int A[200010];   int main() {     scanf( %lld , &x);     for (i = 1; i <= x; i++) {       scanf( %lld , &A[i]);       if (A[i] == 1 && flag == 0) {         y = i + 1;         flag = 1;       }     }     for (i = y; i <= x; i++) {       if (A[i] == 0) z++;     }     for (i = 1; i <= x; i++) {       if (A[i] == 1) {         top += z;         flag2 = 1;       } else if (A[i] == 0 && flag2 == 1)         z--;     }     printf( %lld , top);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200005, INF = 1 << 31;   struct A {     int x, w;   } a[MAXN];   int b[MAXN], c[MAXN], n, d[MAXN], f[MAXN];   bool cmp(const A &x, const A &y) { return x.x < y.x; }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d%d , &a[i].x, &a[i].w);     sort(a, a + n, cmp);     memset(f, 0, sizeof f);     memset(d, 0x7f, sizeof d);     for (int i = 0; i < n; ++i) {       b[i] = a[i].x - a[i].w;       c[i] = a[i].x + a[i].w;     }     int ans = 0;     for (int i = 0; i < n; ++i) {       int t = upper_bound(d + 1, d + ans + 1, b[i]) - d - 1;       d[t + 1] = min(c[i], d[t + 1]);       if (ans == t) ans = t + 1;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10, mod = 1e9 + 7;   const long long inf = 1e18;   long long tn[20], fv[20];   long long Mul(long long a, long long b, long long md) {     long long ans = 0;     while (b) {       if (b & 1) ans = (ans + a) % md;       a = (a + a) % md;       b >>= 1;     }     return ans;   }   long long Pow(long long a, long long b, long long md) {     long long ans = 1;     while (b) {       if (b & 1) ans = Mul(ans, a, md);       a = Mul(a, a, md);       b >>= 1;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     tn[0] = fv[0] = 1;     for (int i = 1; i < 19; i++) tn[i] = tn[i - 1] * 10, fv[i] = fv[i - 1] * 5;     int q;     cin >> q;     while (q--) {       long long x;       cin >> x;       long long xx = x;       int n = 0;       while (xx > 0) n++, xx /= 10;       long long y = (-tn[17 - n] * x) % (1ll << 17);       if (y < 0) y += (1ll << 17);       if (y % 5 == 0) y += (1ll << 17);       x = tn[17 - n] * x + y;       long long ans = 0;       if (x % 5 == 2) ans = 1;       if (x % 5 == 4) ans = 2;       if (x % 5 == 3) ans = 3;       for (int i = 2; i <= 17; i++)         while (Pow(2, ans, fv[i]) != (x % fv[i]))           ans = (ans + 4ll * fv[i - 2]) % (4ll * fv[i - 1]);       ans += 4ll * fv[16];       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   template <typename T>   inline bool MIN(T &a, const T &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool MAX(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   inline int plu(int a, int b) {     return a + b >= 1000000007 ? a + b - 1000000007 : a + b;   }   inline int sub(int a, int b) { return a - b < 0 ? a - b + 1000000007 : a - b; }   inline int mul(int a, int b) { return (long long)a * b % 1000000007; }   inline int inc(int &a, int b) {     a += b;     if (a >= 1000000007) a -= 1000000007;   }   inline int dec(int &a, int b) {     a -= b;     if (a < 0) a += 1000000007;   }   using namespace std;   int n, A[200010], m;   char s1[200010], s2[200010];   int ok(int L) {     int p = 1;     for (int i = 1; i <= n; ++i)       if (A[i] <= L) {         if (s1[i] == s2[p]) ++p;         if (p > m) return 1;       }     return 0;   }   int main() {     scanf( %s%s , s1 + 1, s2 + 1);     n = strlen(s1 + 1);     m = strlen(s2 + 1);     for (int i = 1, a; i <= n; ++i) scanf( %d , &a), A[a] = n - i + 1;     int l = 1, r = n + 1;     while (l < r) {       int mid = l + r >> 1;       if (ok(mid))         r = mid;       else         l = mid + 1;     }     printf( %d n , n - l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned int inet4[100010];   int main(int argc, char* argv[]) {     ios_base::sync_with_stdio(false);     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       char* str;       int inet[4];       scanf( %d.%d.%d.%d , &inet[0], &inet[1], &inet[2], &inet[3]);       inet4[i] = 0;       for (int j = 0; j < 4; j++) inet4[i] = inet4[i] * 256 + inet[j];     }     unsigned int mask = 0x80000000;     bool flag = false;     for (int i = 1; i < 32; i++) {       set<int> hh;       for (int j = 0; j < n; j++) {         hh.insert(inet4[j] & mask);       }       if (hh.size() == m) {         int ans[4];         for (int j = 3; j >= 0; j--) {           ans[j] = mask % 256;           mask /= 256;         }         printf( %d.%d.%d.%d n , ans[0], ans[1], ans[2], ans[3]);         flag = true;         break;       }       mask = mask | (mask >> 1);     }     if (!flag) printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[114514];   int l[114514], r[114514];   bool solve(int n) {     int curr = a[1];     l[1] = a[1];     for (int i = 2; i <= n; i++) {       if (a[i] < a[i - 1]) curr -= a[i - 1] - a[i];       if (curr < 0) return false;       l[i] = curr;     }     return true;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       for (int i = 1; i <= n; i++) cin >> a[i];       if (solve(n))         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int t[95];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> t[i];     }     t[0] = 0;     int langkah;     langkah = 0;     for (int i = 1; i <= n; i++) {       int a;       a = t[i] - t[i - 1];       if (a <= 15)         langkah++;       else {         break;       }     }     if (t[langkah] + 15 >= 90)       cout << 90 << endl;     else {       cout << t[langkah] + 15 << endl;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int N, M, K, R;   char arr[102][102];   int best[102][102][1002];   int solve(int r, int c, int p) {     if (r < 0) {       if (p % K == 0) return p;       return -1 << 30;     }     if (best[r][c][p] != -1) return best[r][c][p];     int ret = -1 << 30;     if (c - 1 >= 0) ret = max(ret, solve(r - 1, c - 1, p + (arr[r][c] -  0 )));     if (c + 1 < M) ret = max(ret, solve(r - 1, c + 1, p + (arr[r][c] -  0 )));     return best[r][c][p] = ret;   }   void solve2(int r, int c, int p) {     if (r == 0) {       printf(  n );       return;     }     int ret = -1 << 30;     if (c - 1 >= 0 && best[r - 1][c - 1][p + (arr[r][c] -  0 )] == R)       printf( L ), solve2(r - 1, c - 1, p + (arr[r][c] -  0 ));     else if (c + 1 < M && best[r - 1][c + 1][p + (arr[r][c] -  0 )] == R)       printf( R ), solve2(r - 1, c + 1, p + (arr[r][c] -  0 ));     return;   }   int main() {     scanf( %d %d %d , &N, &M, &K);     K++;     for (int i = 0; i < N; i++) scanf( %s , arr[i]);     int ret = -1 << 30, ind;     memset(best, -1, sizeof(best));     for (int i = 0; i < M; i++) {       int x = solve(N - 1, i, 0);       if (x > ret) ret = x, ind = i;     }     if (ret == -1 << 30)       printf( -1 n );     else       printf( %d n , ret);     R = ret;     if (ret != -1 << 30) {       printf( %d n , ind + 1);       solve2(N - 1, ind, 0);     }   }


#include <bits/stdc++.h>   using namespace std;   int N, M, i, X, A[100005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> N >> M;     for (i = 0; i < 2 * M; i++) {       cin >> X;       A[X]++;     }     if (N == M) {       for (i = 1; 1; i++) {         if (A[i] != 2) {           break;         }         if (i == N) {           cout <<  ring topology n ;           return 0;         }       }     }     if (N - 1 == M) {       for (i = 1; i <= N; i++) {         if (A[i] == N - 1) {           cout <<  star topology n ;           return 0;         }       }       for (i = 1; 1; i++) {         if (A[i] > 2 || A[i] == 0) {           break;         }         if (i == N) {           cout <<  bus topology n ;           return 0;         }       }     }     cout <<  unknown topology n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int hour, minute, sleeph, sleepm;     char temp;     scanf( %d%c%d , &hour, &temp, &minute);     scanf( %d%c%d , &sleeph, &temp, &sleepm);     int shour, smin;     smin = minute - sleepm;     if (smin < 0) {       smin += 60;       hour--;     }     shour = hour - sleeph;     while (shour < 0) {       shour += 24;     }     if (shour < 10) cout <<  0 ;     cout << shour <<  : ;     if (smin < 10) cout <<  0 ;     cout << smin << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> x, y, z;   inline int sqr(int x) { return x * x; }   inline double dist(int i, int j) {     return sqrt(sqr(x[i] - x[j]) + sqr(y[i] - y[j]) + sqr(z[i] - z[j]));   }   int main() {     int n;     cin >> n;     x.resize(n), y.resize(n), z.resize(n);     for (int i = 0; i < n; ++i) cin >> x[i] >> y[i] >> z[i];     double shortestTime = 1e9;     for (int i = 1; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         double d = dist(0, i) + dist(i, j) + dist(j, 0);         shortestTime = min(shortestTime, d / 2);       }     }     cout << setprecision(10) << shortestTime << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long modpow(long long b, long long e, long long mod) {     long long ans = 1;     for (; e; b = b * b % mod, e /= 2)       if (e & 1) ans = ans * b % mod;     return ans;   }   const int N = 5050;   int dp[N][N][2], c[N], n;   bool vis[N][N][2];   int solve(int x, int y, int z) {     if (x < 0 || y > n || x > y) return (int)1e9;     if (x == 1 && y == n) return 0;     if (vis[x][y][z]) return dp[x][y][z];     vis[x][y][z] = true;     return dp[x][y][z] =                min(solve(x - 1, y, 0) + (c[z ? y : x] == c[x - 1] ? 0 : 1),                    solve(x, y + 1, 1) + (c[z ? y : x] == c[y + 1] ? 0 : 1));   }   int32_t main() {     cin >> n;     for (int i = 0; i < (n); ++i) cin >> c[i + 1];     int ans = (int)1e9;     for (int i = 0; i < (n); ++i) ans = min(ans, solve(i + 1, i + 1, 0));     cout << ans << endl;   }


#include<bits/stdc++.h>   using namespace std;   #define endl   n    #define ll long long   int main()   { ios_base::sync_with_stdio(false);        cin.tie(NULL);    ll t;   cin>>t;   while(t--)   { ll n;       cin>>n;   if(n<=3)   cout<<n-1<<endl;   else   {       if(n%2==0)       cout<<2<<endl;       else       {           cout<<3<<endl;       }          }         }                                     }


#include <bits/stdc++.h>   using namespace std;      #define rep(i, a) for(int i=0;i<a;i++)   #define repA(i,a,b)for(int i=a;i<b;i++)   #define l list   #define v vector   #define u_m unordered_map   typedef long long ll;   const int mxN=101,MOD=1e9+7;   void solve(){    int n,m,count=1,r=0;    cin>>n>>m;    string s;    cin>>s;    while(count>0&&r<m){     string cop=s;     count=0;     rep(i,n){      if(s[i]== 0 ){      int cr=0;      if(i-1>=0&&s[i-1]== 1 )cr++;      if(i+1<n&&s[i+1]== 1 )cr++;      if(cr==1){       cop[i]= 1 ;       count++;      }      }     }     s=cop;     r++;    }    cout<<s<<endl;   }   int main(){    ios::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);    int t;    cin>>t;    while(t--){     solve();    }   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e13;   void solve() {     long long n;     cin >> n;     vector<pair<long long, long long> > a(n);     for (long long i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = i;     }     sort(a.begin(), a.end());     long long cnt = 1, ans = 1, w = 1;     for (long long i = 1; i < n; i++) {       if (a[i].first == a[i - 1].first) continue;       w++;       if (a[i].second > a[i - 1].second)         cnt++;       else {         ans = max(ans, cnt);         cnt = 1;       }     }     ans = max(ans, cnt);     cout << w - ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long q;     cin >> q;     while (q--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int tosub = 0;     int pls = 1;     int mins = 0;     string s;     char a;     cin >> a;     while (a !=  = ) {       if (a ==  + ) {         s.push_back(a);         pls++;       } else if (a ==  - ) {         mins++;         s.push_back(a);       }       cin >> a;     }     int tmp;     cin >> tmp;     int mn = pls - mins * tmp;     int mx = pls * tmp - mins;     if (tmp < mn || tmp > mx) {       cout <<  Impossible n ;       return 0;     }     cout <<  Possible n ;     int curr = 0;     for (int i = (-1); i < (int)s.size(); ++i) {       if (!(~i) || s[i] ==  + ) {         if (i >= 0) {           cout << s[i] <<    ;         }         for (int j = 1; j <= tmp; ++j) {           int mn = (pls - 1) - mins * tmp;           int mx = (pls - 1) * tmp - mins;           if (mn <= tmp - (curr + j) && mx >= tmp - (curr + j)) {             cout << j <<    ;             pls--;             curr += j;             break;           }         }       } else {         cout << s[i] <<    ;         for (int j = 1; j <= tmp; ++j) {           int mn = pls - (mins - 1) * tmp;           int mx = pls * tmp - (mins - 1);           if (mn <= tmp - (curr - j) && mx >= tmp - (curr - j)) {             cout << j <<    ;             mins--;             curr -= j;             break;           }         }       }     }     cout <<   =   << tmp <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 100;   int head[maxn], cnt;   vector<int> pos[maxn];   int len[maxn];   int val[maxn], pre[maxn], vis[maxn];   char str[1100];   char pat[1100];   struct edge {     int from, to, flow, next, cost;   } e[2 * maxn];   void addedge(int from, int to, int flow, int cost) {     e[cnt].from = from;     e[cnt].to = to;     e[cnt].flow = flow;     e[cnt].cost = cost;     e[cnt].next = head[from];     head[from] = cnt++;   }   void line(int from, int to, int flow, int cost) {     addedge(from, to, flow, cost);     addedge(to, from, 0, -cost);   }   int dis[maxn];   queue<int> q;   int spfa(int s, int t, int st) {     while (!q.empty()) q.pop();     memset(vis, 0, sizeof(vis));     memset(pre, 0, sizeof(pre));     for (int i = 0; i <= st; i++) dis[i] = 1;     q.push(s);     vis[s] = 1, dis[s] = 0;     while (!q.empty()) {       int now = q.front();       vis[now] = 0;       q.pop();       for (int i = head[now]; i != -1; i = e[i].next) {         if (!e[i].flow) continue;         if (dis[now] + e[i].cost < dis[e[i].to]) {           dis[e[i].to] = dis[now] + e[i].cost;           pre[e[i].to] = i;           if (!vis[e[i].to]) {             vis[e[i].to] = 1;             q.push(e[i].to);           }         }       }     }     if (dis[t] >= 0) return 1;     int u = t;     while (u != s) {       int xy = pre[u];       e[xy].flow -= 1;       e[xy ^ 1].flow += 1;       u = e[xy].from;     }     return dis[t];   }   int MFMC(int s, int t, int ct) {     int sum = 0;     int a;     while ((a = spfa(s, t, ct)) < 0) {       sum += a;     }     return sum;   }   struct Ac {     int next[maxn][26], fail[maxn];     int size;     queue<int> q;     void insert(char *S, int xi) {       int len = strlen(S);       int now = 0;       for (int i = 0; i < len; i++) {         char c = S[i];         if (next[now][c -  a ] == 0) {           next[now][c -  a ] = ++size;           now = size;         } else {           now = next[now][c -  a ];         }       }       pos[now].push_back(xi);     }     void build() {       for (int i = 0; i < 26; i++) {         if (next[0][i]) q.push(next[0][i]);       }       while (!q.empty()) {         int now = q.front();         q.pop();         for (int i = 0; i < 26; i++) {           if (next[now][i]) {             fail[next[now][i]] = next[fail[now]][i];             q.push(next[now][i]);           } else             next[now][i] = next[fail[now]][i];         }       }     }     void match(char *S) {       int le = strlen(S);       int now = 0;       for (int i = 0; i < le; i++) {         int x = S[i] -  a ;         now = next[now][x];         int temp = now;         while (temp) {           for (int j = 0; j < pos[temp].size(); j++) {             int k = pos[temp][j];             line(i - len[k] + 1, i + 1, 1, -val[k]);           }           temp = fail[temp];         }       }     }   } ac;   int main() {     memset(head, -1, sizeof(head));     cnt = 0;     int n;     scanf( %d , &n);     scanf( %s , pat);     int m;     scanf( %d , &m);     for (int i = 0; i < m; i++) {       scanf( %s %d , str, &val[i]);       len[i] = strlen(str);       ac.insert(str, i);     }     int x;     scanf( %d , &x);     int s = n + 1, t = n + 2;     line(s, 0, x, 0);     line(n, t, x, 0);     for (int i = 0; i < n; i++) {       line(i, i + 1, x, 0);     }     ac.build();     ac.match(pat);     int ans = -MFMC(s, t, n + 2);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline const int read() {     int r = 0, k = 1;     char c = getchar();     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) k = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) r = r * 10 + c -  0 ;     return k * r;   }   long long n;   int k, a[110];   bool vis[1000010];   long long dp[110][100000];   long long dfs(int pos, long long n) {     if (pos == k + 1) return n;     if (n <= 0) return 0;     if (n < 100000 && dp[pos][n] != -1) return dp[pos][n];     long long ans = dfs(pos + 1, n) - dfs(pos + 1, n / a[pos]);     if (n < 100000) dp[pos][n] = ans;     return ans;   }   void input() {     memset(dp, -1, sizeof(dp));     cin >> n >> k;     for (int i = (1), _ = (k); i <= _; i++) a[i] = read();     sort(a + 1, a + k + 1, greater<int>());   }   void solve() { cout << dfs(1, n) << endl; }   int main() {     input(), solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int k;   string s, t;   int dp[100005][2], cnt[2];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> s >> t;     cin >> k;     int n = s.length();     for (int i = 1; i < n; i++) {       int l = n - i;       string tmp = s.substr(i, l) + s.substr(0, i);       if (tmp == t)         cnt[0]++;       else         cnt[1]++;     }     if (s == t)       dp[0][0]++, cnt[0]++;     else       dp[0][1]++, cnt[1]++;     for (int i = 1; i <= k; i++) {       dp[i][0] =           (dp[i - 1][0] * 1ll * (cnt[0] - 1) + dp[i - 1][1] * 1ll * cnt[0]) % mod;       dp[i][1] =           (dp[i - 1][0] * 1ll * cnt[1] + dp[i - 1][1] * 1ll * (cnt[1] - 1)) % mod;     }     printf( %d n , dp[k][0]);   }


#include <bits/stdc++.h>   using namespace std;   long long ar[1000000 + 9];   long long POW1[1000000 + 9];   long long POW2[1000000 + 9];   pair<long long, long long> KEEP[1000000 + 9];   map<pair<long long, long long>, long long> mymap;   struct data {     long long a, b, val;   };   vector<data> vec;   long long query(int beg, int end) {     if (beg == end) return 0;     int mid = (beg + end) >> 1;     long long ans, i, val, a, b, len;     ans = query(beg, mid) + query(mid + 1, end);     vec.clear();     mymap.clear();     for (i = mid; i >= beg; i--) {       if (vec.size() && vec[vec.size() - 1].val == ar[i]) {         vec.pop_back();         a = 0;         b = 0;         if (vec.size()) a = vec[vec.size() - 1].a;         if (vec.size()) b = vec[vec.size() - 1].b;       } else {         a = 0;         b = 0;         if (vec.size()) a = vec[vec.size() - 1].a;         if (vec.size()) b = vec[vec.size() - 1].b;         len = vec.size() + 1;         a += ar[i] * POW1[len];         b += ar[i] * POW2[len];         a %= 1000000007;         b %= 1000000007;         data curr;         curr.a = a;         curr.b = b;         curr.val = ar[i];         vec.push_back(curr);       }       val = mymap[make_pair(a, b)];       mymap[make_pair(a, b)] = val + 1;     }     vec.clear();     for (i = mid + 1; i <= end; i++) {       if (vec.size() && vec[vec.size() - 1].val == ar[i]) {         vec.pop_back();         a = 0;         b = 0;         if (vec.size()) a = vec[vec.size() - 1].a;         if (vec.size()) b = vec[vec.size() - 1].b;       } else {         a = 0;         b = 0;         if (vec.size()) a = vec[vec.size() - 1].a;         if (vec.size()) b = vec[vec.size() - 1].b;         len = vec.size() + 1;         a += ar[i] * POW1[len];         b += ar[i] * POW2[len];         a %= 1000000007;         b %= 1000000007;         data curr;         curr.a = a;         curr.b = b;         curr.val = ar[i];         vec.push_back(curr);       }       val = mymap[make_pair(a, b)];       ans += val;     }     return ans;   }   int main() {     long long i, j, k, l, n, m = 0, tot, temp, curr, val, prev, a, b, c, t, ans,                              expon, flag, x, y, siz, w, h, d, ii, jj, xx, yy, ind,                              len, max_n, q, s, f, g;     POW1[0] = POW2[0] = 1;     for (i = 1; i <= 1000000; i++) POW1[i] = (POW1[i - 1] * 31) % 1000000007;     for (i = 1; i <= 1000000; i++) POW2[i] = (POW2[i - 1] * 37) % 1000000007;     cin >> q;     while (q--) {       scanf( %lld , &n);       for (i = 1; i <= n; i++) scanf( %lld , &ar[i]);       ans = query(1, n);       printf( %lld n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   const long long INF = (long long)1e17 + 10;   int n, m, s, t;   int a[N], b[N], l[N];   struct edge {     int to, cost;     edge(int to, int cost) : to(to), cost(cost) {}   };   vector<edge> e;   vector<int> g[N];   vector<int> g2[N];   long long diss[N], dist[N];   long long len;   bool vis[N], ans[N];   map<int, long long> mp;   set<pair<pair<long long, long long>, int> > st;   void dijkstra(int sc, vector<int> g[N], long long *dis) {     fill(dis + 1, dis + n + 1, INF);     priority_queue<pair<long long, int> > pq;     pq.push(make_pair(0, sc));     memset(vis, 0, sizeof(vis));     while (!pq.empty()) {       pair<long long, int> tmp = pq.top();       pq.pop();       if (vis[tmp.second]) continue;       vis[tmp.second] = 1;       dis[tmp.second] = -tmp.first;       for (auto j : g[tmp.second]) {         int u = e[j].to;         int c = e[j].cost;         if (vis[u]) continue;         pair<long long, int> nxt = make_pair(-dis[tmp.second] - c, u);         pq.push(nxt);       }     }   }   int main() {     scanf( %d%d%d%d , &n, &m, &s, &t);     for (int i = 0; i < m; ++i) {       scanf( %d%d%d , a + i, b + i, l + i);       g[a[i]].push_back(e.size());       e.push_back(edge(b[i], l[i]));       g2[b[i]].push_back(e.size());       e.push_back(edge(a[i], l[i]));     }     dijkstra(s, g, diss);     dijkstra(t, g2, dist);     len = diss[t];     for (int i = 0; i < m; ++i) {       if (diss[a[i]] + dist[b[i]] + l[i] == len) {         st.insert(make_pair(make_pair(diss[a[i]], diss[b[i]]), i));         ans[i] = 1;       }     }     long long mx = 0;     for (auto k : st) {       mp[k.second] = mx;       mx = max(k.first.second, mx);     }     for (int i = 0; i < m; ++i) {       if (diss[a[i]] + dist[b[i]] + l[i] == len) {         st.erase(make_pair(make_pair(diss[a[i]], diss[b[i]]), i));         auto it = st.lower_bound(make_pair(make_pair(diss[a[i]], -1), -1));         if (!(it == st.end() || it->first.first == diss[b[i]])) {           ans[i] = 0;         }         if (mp[i] > diss[a[i]]) {           ans[i] = 0;         }         st.insert(make_pair(make_pair(diss[a[i]], diss[b[i]]), i));       }     }     for (int i = 0; i < m; ++i) {       if (ans[i]) {         puts( YES );       } else {         long long mn = diss[a[i]] + dist[b[i]];         if (len - 1 > mn) {           printf( CAN %d n , l[i] - (len - 1 - mn));         } else {           puts( NO );         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX;   const long long INFL = LLONG_MAX;   int N, M, X[1000], a, b, c;   int main() {     ios_base::sync_with_stdio(0);     cout.precision(15);     cin >> N >> M;     for (int(i) = 1; (i) <= (N); (i)++) cin >> X[i];     long double answer = 0;     for (int(i) = 1; (i) <= (M); (i)++) {       cin >> a >> b >> c;       answer = max(answer, (long double)(X[a] + X[b]) / c);     }     cout << answer << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, l = 1, a;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a;       if (l == 1) {         if (a % 2 == 1) {           cout << 2 << endl;           l = 1;         } else {           l = 2;           cout << 1 << endl;         }         continue;       }       if (l == 2) {         if (a % 2 == 1) {           l = 2;           cout << 1 << endl;         } else {           l = 1;           cout << 2 << endl;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXQ = 2e5;   vector<int> solve(int K, vector<tuple<uint32_t, uint32_t, int> > V) {     uint32_t mask = (((uint32_t)1) << K) - 1;     vector<int> HT(1 << K), LT(1 << K);     for (auto [l, r, v] : V)       if (v) {         uint32_t lhi = l >> K, llo = l & mask;         uint32_t rhi = r >> K, rlo = r & mask;         if (lhi == rhi) {           LT[llo]++;           if (rlo != ((1 << K) - 1)) LT[rlo + 1]--;         } else {           LT[llo]++;           LT[0]++;           if (rlo != ((1 << K) - 1)) LT[rlo + 1]--;         }         HT[lhi]++;         if (rhi != ((1 << K) - 1)) HT[rhi + 1]--;       }     for (int i = 0; i < (1 << K) - 1; ++i) HT[i + 1] += HT[i];     for (int i = 0; i < (1 << K); ++i)       if (HT[i]) HT[i] = 1;     for (int i = 0; i < (1 << K) - 1; ++i) LT[i + 1] += LT[i];     for (int i = 0; i < (1 << K); ++i)       if (LT[i]) LT[i] = 1;     auto ans = LT;     copy(HT.begin(), HT.end(), back_inserter(ans));     for (int i = 0; i < (1 << K) - 1; ++i) HT[i + 1] += HT[i];     for (int i = 0; i < (1 << K) - 1; ++i) LT[i + 1] += LT[i];     auto SH = [&](int L, int R) {       int ans = HT[R];       if (L) ans -= HT[L - 1];       return ans;     };     auto SL = [&](int L, int R) {       int ans = LT[R];       if (L) ans -= LT[L - 1];       return ans;     };     for (auto [l, r, v] : V)       if (!v) {         uint32_t lhi = l >> K, llo = l & mask;         uint32_t rhi = r >> K, rlo = r & mask;         if (lhi == rhi) {           if (SH(lhi, lhi) != 0 && SL(llo, rlo) != 0) return {};         } else {           if (SH(lhi, lhi) != 0 && SL(llo, (1 << K) - 1) != 0) return {};           if (SH(lhi + 1, rhi - 1) != 0 && SL(0, (1 << K) - 1) != 0) return {};           if (SH(rhi, rhi) != 0 && SL(0, rlo) != 0) return {};         }       }     return ans;   }   int K, Q;   uint32_t L[MAXQ], R[MAXQ], V[MAXQ];   int main() {     scanf( %d%d , &K, &Q);     for (int i = 0; i < Q; ++i) {       scanf( %  SCNu32  %  SCNu32  %  SCNu32, L + i, R + i, V + i);     }     vector<vector<int> > ans(16);     for (int i = 0; i < 16; ++i) {       vector<tuple<uint32_t, uint32_t, int> > P;       for (int j = 0; j < Q; ++j) P.emplace_back(L[j], R[j], (V[j] >> i) & 1);       ans[i] = solve(K, P);       if (ans[i].size() == 0) {         puts( impossible );         return 0;       }     }     puts( possible );     for (int i = 0; i < (2 << K); ++i) {       int r = 0;       for (int j = 0; j < 16; ++j)         if (ans[j][i]) r |= 1 << j;       printf( %d n , r);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int rmax = 15;   const int nmax = 100500;   struct DP {     int x;     int y;     int z;     int i;     int j;     int k;   };   bool operator<(const DP& l, const DP& r) {     return l.x < r.x || (l.x == r.x && l.y < r.y) ||            (l.x == r.x && l.y == r.y && l.z < r.z);   }   class SparseTable {    public:     SparseTable(vector<pair<int, int> >& vals) {       N = vals.size();       sparse.assign(N, vector<pair<int, int> >(rmax));       init();       build(vals);     }     void build(vector<pair<int, int> >& vals) {       for (int i = 0; i < vals.size(); ++i) {         sparse[i][0] = vals[i];       }       for (int r = 1; r < rmax; ++r) {         for (int i = 0; i < N; ++i) {           int t = min(N - 1, i + (1 << (r - 1)));           sparse[i][r] = max(sparse[i][r - 1], sparse[t][r - 1]);         }       }     }     pair<int, int> getMax(int l, int r) {       int len = r - l + 1;       int k = deg[len];       return max(sparse[l][k], sparse[l + len - (1 << k)][k]);     }     void init() {       deg.assign(nmax, 0);       deg[0] = -1;       for (int i = 1; i < nmax; ++i) {         deg[i] = deg[i - 1];         if (!(i & (i - 1))) {           ++deg[i];         }       }     }       private:     vector<vector<pair<int, int> > > sparse;     int N = 0;     vector<int> deg;   };   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     vector<int> vec(n);     vector<pair<int, int> > a;     for (int i = 0; i < n; ++i) {       cin >> vec[i];       a.push_back({vec[i], i});     }     sort((a).begin(), (a).end());     vector<pair<int, int> > vals;     vals.push_back({a[0].first, 0});     for (int i = 1; i < n; ++i) {       vals.push_back({a[i].first - a[i - 1].first, i});     }     SparseTable st(vals);     DP ret;     ret.x = -1;     ret.y = -1;     ret.z = -1;     ret.i = 0;     ret.j = 0;     ret.k = 0;     for (int i = n - 1; i >= 0; --i) {       for (int j = i - 1; j >= 0; --j) {         int len_a = n - 1 - i + 1;         int len_b = i - 1 - j + 1;         if (len_a > 2 * len_b || len_b > 2 * len_a) {           continue;         }         int max_len_c = min({j, 2 * len_a, 2 * len_b});         int min_len_c = max({1, (len_a + 1) / 2, (len_b + 1) / 2});         if (max_len_c < min_len_c) {           continue;         }         pair<int, int> p = st.getMax(j - max_len_c, j - min_len_c);         DP temp;         temp.x = a[i].first - a[i - 1].first;         temp.y = a[j].first - a[j - 1].first;         temp.z = p.first;         temp.i = i;         temp.j = j;         temp.k = p.second;         if (ret < temp) {           ret = temp;         }       }     }     vector<int> ans(n);     for (int i = 0; i < ret.k; ++i) {       ans[a[i].second] = -1;     }     for (int i = ret.k; i < ret.j; ++i) {       ans[a[i].second] = 3;     }     for (int i = ret.j; i < ret.i; ++i) {       ans[a[i].second] = 2;     }     for (int i = ret.i; i < n; ++i) {       ans[a[i].second] = 1;     }     for (int i = 0; i < n; ++i) {       cout << ans[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( sse4,avx )   const int inf = 100000;   int rec(size_t gl, std::vector<int>& odd, std::vector<bool>& flags,           std::vector<std::vector<int>>& graph) {     if (gl == odd.size()) {       return 0;     }     if (flags[gl]) {       return rec(gl + 1, odd, flags, graph);     }     int res = 1000000000;     for (size_t i = gl + 1; i < odd.size(); i++) {       if (!flags[i]) {         flags[i] = true;         res = std::min(res,                        graph[odd[gl]][odd[i]] + rec(gl + 1, odd, flags, graph));         flags[i] = false;       }     }     return res;   }   void run(std::istream& in, std::ostream& out) {     int n, m;     in >> n >> m;     std::vector<std::vector<int>> graph(n, std::vector<int>(n, inf));     for (int i = 0; i < n; i++) graph[i][i] = 0;     std::vector<int> degs(n);     int64_t sum = 0;     for (int i = 0; i < m; i++) {       int x, y, w;       in >> x >> y >> w;       x--;       y--;       degs[x]++;       degs[y]++;       sum += w;       graph[x][y] = std::min(graph[x][y], w);       graph[y][x] = std::min(graph[y][x], w);     }     for (size_t i = 0; i < n; i++) {       for (size_t j = 0; j < n; j++) {         for (size_t k = 0; k < n; k++) {           if (graph[j][k] > graph[j][i] + graph[i][k]) {             graph[j][k] = graph[j][i] + graph[i][k];           }         }       }     }     for (size_t i = 0; i < n; i++) {       if (graph[0][i] == inf && degs[i] != 0) {         out <<  -1  << std::endl;         return;       }     }     std::vector<int> odd;     for (size_t i = 0; i < n; i++) {       if ((degs[i] % 2) != 0) {         odd.push_back(i);       }     }     std::vector<bool> flags(odd.size());     sum += rec(0, odd, flags, graph);     out << sum << std::endl;   }   int main() {     std::cin.sync_with_stdio(false);     std::cin.tie(nullptr);     run(std::cin, std::cout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Oli() {     int a;     cin >> a;     vector<pair<int, int>> pr(a);     for (int i = 0; i < a; i++) {       cin >> pr[i].first >> pr[i].second;     }     int s = 0;     int k = 1;     for (int i = 0; i < pr.size(); i++) {       if (pr[i].second >= 1) {         k--;         k += pr[i].second;         s += pr[i].first;         pr.erase(pr.begin() + i);         i--;       }     }     sort(pr.rbegin(), pr.rend());     int i = 0;     while (k > 0 && i < pr.size()) {       s += pr[i].first;       i++;       k--;     }     cout << s << endl;   }   int main() {     int t = 1;     while (t--) {       Oli();     }     return 0;   }


#include <bits/stdc++.h>   int loya[8];   int tloyal[8];   int level[8];   double pb[1 << 8];   int N, K, A;   void init_search(int state, int B, int deepth, int cnt) {     if (deepth == N) {       pb[state] = cnt > (N >> 1) ? 1.0 : A / (double)(A + B);     } else {       init_search(state | (1 << deepth), B, deepth + 1, cnt + 1);       init_search(state, B + level[deepth], deepth + 1, cnt);     }   }   double calcu(double prb, int state, int deepth) {     return (deepth == N)                ? prb * pb[state]                : calcu(prb * (tloyal[deepth] / 10.0), state | (1 << deepth),                        deepth + 1) +                      calcu(prb * (1 - tloyal[deepth] / 10.0), state, deepth + 1);   }   double search(int candy, int deepth) {     double ans = 0.0;     if (deepth == N) {       ans = calcu(1.0, 0, 0);     } else {       int i;       for (i = 0; i <= candy && loya[deepth] + i <= 10; i++) {         tloyal[deepth] = loya[deepth] + i;         double tmp = search(candy - i, deepth + 1);         ans = tmp > ans ? tmp : ans;       }     }     return ans;   }   int main() {     while (scanf( %d %d %d , &N, &K, &A) == 3) {       int i;       for (i = 0; i < N; i++) {         scanf( %d %d , level + i, loya + i);         loya[i] /= 10;       }       init_search(0, 0, 0, 0);       printf( %.10f n , search(K, 0));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long h, n;   long long ret = 0LL;   int a[60];   long long two(int x) {     if (x == 0) return 1LL;     long long half = two(x / 2);     half *= half;     return x % 2 ? half * 2 : half;   }   void solve() {     int c = 0;     --n;     while (n) {       a[c++] = n % 2;       n >>= 1;     }     for (int i = c; i < h; ++i) a[i] = 0;     int e = 0;     for (int i = h - 1; i >= 0; --i) {       if (a[i] != e) {         ret += two(i + 1);       }       if (a[i] == e) {         ret += 1;         e = !e;       }     }     cout << ret << endl;   }   int main() {     cin >> h >> n;     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, a[101], m, ans;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> k;       if (k % 2) a[++m] = k;       ans += k;     }     if (m == 0) {       cout << 0 << endl;       return 0;     }     if (m % 2 == 0) {       sort(a + 1, a + m + 1);       ans -= a[1];     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int a[100010];   struct node {     int x, id;   } p[100010];   int main() {     while (scanf( %d%d , &n, &k) != EOF) {       for (int i = 1; i <= n; i++) {         scanf( %d , &a[i]);       }       int ans = 99999999;       int pos = 1;       for (int i = 1; i <= n; i++) {         bool flag = false;         int cnt = 0;         for (int j = i; j >= 1; j--) {           if (a[i] - (i - j) * k == a[j]) continue;           cnt++;           if (a[i] - (i - j) * k <= 0) {             flag = true;             break;           }         }         if (flag) continue;         int cnt1 = 0;         for (int j = i; j <= n; j++) {           if (a[i] + (j - i) * k == a[j]) continue;           cnt1++;         }         if (cnt1 + cnt < ans) {           ans = cnt1 + cnt;           pos = i;         }       }       printf( %d n , ans);       for (int j = 1; j <= pos; j++) {         if (a[j] + (pos - j) * k == a[pos]) continue;         if (a[j] < a[pos] - (pos - j) * k) {           printf( + %d %d n , j, a[pos] - (pos - j) * k - a[j]);         } else {           printf( - %d %d n , j, a[j] - (a[pos] - (pos - j) * k));         }       }       for (int j = pos; j <= n; j++) {         if (a[pos] + (j - pos) * k == a[j]) continue;         if (a[j] < a[pos] + (j - pos) * k) {           printf( + %d %d n , j, a[pos] + (j - pos) * k - a[j]);         } else {           printf( - %d %d n , j, a[j] - (a[pos] + (j - pos) * k));         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void upd_min(T& dest, const T& src) {     if (src < dest) dest = src;   }   template <typename T>   inline void upd_max(T& dest, const T& src) {     if (dest < src) dest = src;   }   template <typename T, int n>   struct Queue {     T q[n];     int qf, qr;     Queue() : qf(0), qr(0) {}     inline void clear() { qf = qr = 0; }     inline bool empty() { return qf == qr; }     inline void push(const T& data) {       q[qr] = data;       if (++qr == n) qr = 0;     }     inline void pop() {       if (++qf == n) qf = 0;     }     inline T& front() { return q[qf]; }   };   template <int maxN>   struct Disjoint {     int N;     int p[maxN];     inline void init(int n) {       N = n;       for (int i = 0; i < N; ++i) p[i] = i;     }     inline int root(int i) {       for (; i != p[i]; i = p[i]) p[i] = p[p[i]];       return i;     }     inline void unite(int a, int b) { p[root(b)] = root(a); }     inline bool query(int a, int b) { return root(a) == root(b); }   };   template <typename T, int N>   struct Stack {     T s[N];     int index;     Stack() : index(0) {}     inline void clear() { index = 0; }     inline T& top() { return s[index]; }     inline void pop() { --index; }     inline bool empty() { return index == 0; }     inline void push(T data) { s[++index] = data; }   };   int nextInt() {     int ret;     char c;     while (c = getchar(), c <  0  || c >  9 )       ;     ret = c -  0 ;     while (c = getchar(), c >=  0  && c <=  9 ) ret = ret * 10 + c -  0 ;     return ret;   }   const int inf = 0x7f7f7f7f;   int N;   char c[255];   int main() {     N = nextInt();     for (int t = 1; t <= N; t++) {       scanf( %s , c);       int ll = strlen(c);       int sf(0);       for (int i = 0; i < ll; i++)         if (c[i] ==  : ) sf++;       if (sf == 2 && ll == 2) {         printf( 0000:0000:0000:0000:0000:0000:0000:0000 n );       } else {         int ind(1), k(1);         for (int i = 1; i < ll; i++) {           if (c[i] !=  : )             ind++;           else {             if (c[i - 1] ==  : ) {               if (i == 1) sf--;               for (int j = 1; j <= 8 - sf; j++) {                 if (k != 1) printf( : );                 printf( 0000 );                 k++;               }             } else {               if (k != 1) printf( : );               k++;               for (int j = 1; j <= 4 - ind; j++) printf( 0 );               for (int j = 1; j <= ind; j++) printf( %c , c[i - ind - 1 + j]);             }             ind = 0;           }         }         if (k == 8) {           printf( : );           for (int j = 1; j <= 4 - ind; j++) printf( 0 );           for (int j = 1; j <= ind; j++) printf( %c , c[ll - ind - 1 + j]);         }         printf(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Max = 2e5 + 10;   int n, k;   int v, u;   vector<int> stl[Max];   struct node {     long long cou;     long long huo;     node() { cou = huo = 0; }   } point[Max];   int vis[Max];   long long tot = 0;   void dfs(int idex, int cou) {     vis[idex] = 1;     point[idex].cou = cou;     int flag = 0;     for (int i = 0; i < stl[idex].size(); i++) {       if (vis[stl[idex][i]] == 0) {         dfs(stl[idex][i], cou + 1);         flag = 1;       }     }     if (!flag) {       point[idex].huo = 1;       return;     }     for (int i = 0; i < stl[idex].size(); i++)       point[idex].huo += point[stl[idex][i]].huo;     point[idex].huo++;   }   long long ans[Max];   int main() {     cin >> n >> k;     int flag = 1;     for (int i = 1; i <= n - 1; i++) {       cin >> v >> u;       stl[v].push_back(u);       stl[u].push_back(v);     }     dfs(1, 1);     for (int i = 1; i <= n; i++) {       ans[i] = point[i].cou - point[i].huo;     }     sort(ans + 1, ans + n + 1);     for (int i = n; i > n - k; i--) {       tot += ans[i];     }     cout << tot << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   string s;   int a[4][100];   vector<int> seq;   vector<pair<int, int> > poseq;   bool check() {     for (int i = 0; i < n; i++) {       if (a[1][i] != 0 || a[2][i] != 0) {         return true;       }     }     return false;   }   pair<int, int> next(pair<int, int> pos) {     if (pos.first == 1) {       if (pos.second != 0) {         pos.second -= 1;       } else {         pos.first = 2;       }     } else {       if (pos.second < n - 1) {         pos.second += 1;       } else {         pos.first = 1;       }     }     return pos;   }   void rotate() {     int r, c;     for (int i = 0; i < n; i++) {       if (a[1][i] == 0) {         r = 1;         c = i;       }       if (a[2][i] == 0) {         r = 2;         c = i;       }     }     pair<int, int> init = make_pair(r, c), prev = init, curr = next(init);     while (init != curr) {       if (a[curr.first][curr.second] != 0) {         a[prev.first][prev.second] = a[curr.first][curr.second];         seq.push_back(a[curr.first][curr.second]);         a[curr.first][curr.second] = 0;         poseq.push_back(prev);       }       prev = curr;       curr = next(prev);     }   }   void park() {     for (int i = 0; i < n; i++) {       if (a[1][i] > 0 && a[1][i] == a[0][i]) {         seq.push_back(a[1][i]);         poseq.push_back(make_pair(0, i));         a[1][i] = 0;       }       if (a[2][i] > 0 && a[2][i] == a[3][i]) {         seq.push_back(a[2][i]);         poseq.push_back(make_pair(3, i));         a[2][i] = 0;       }     }   }   void run() {     cin >> n >> k;     for (int i = 0; i < 4; i++) {       for (int j = 0; j < n; j++) {         cin >> a[i][j];       }     }     if (k == 2 * n) {       bool allfull = true;       for (int i = 0; i < n; i++) {         if (a[1][i] == a[0][i] || a[2][i] == a[3][i]) {           allfull = false;           break;         }       }       if (allfull) {         cout << setprecision(30) << -1 << endl;         return;         ;       }     }     park();     while (check()) {       rotate();       park();     }     cout << setprecision(30) << seq.size() << endl;     ;     for (int i = 0; i < (int)seq.size(); i++) {       cout << setprecision(30) << seq[i] <<    ;       ;       cout << setprecision(30) << poseq[i].first + 1 <<    ;       ;       cout << setprecision(30) << poseq[i].second + 1 << endl;       ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int tests = 1;     for (int i = 1; i <= tests; i++) run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, l, r, m;     cin >> n >> k;     deque<pair<int, int>> bfs;     vector<int> lines;     vector<int> ans(n);     --k;     bfs.push_back({0, n});     while (!bfs.empty()) {       l = bfs[0].first;       r = bfs[0].second;       m = (l + r) / 2;       bfs.pop_front();       if (k > 0 && r - l > 1) {         k -= 2;         lines.push_back(m);         bfs.push_back({l, m});         bfs.push_back({m, r});       }     }     if (k != 0) {       cout << -1;       return 0;     } else {       int num = 1;       lines.push_back(0);       lines.push_back(n);       sort(lines.begin(), lines.end());       for (int i = lines.size() - 2; i >= 0; --i) {         for (int j = lines[i]; j != lines[i + 1]; ++j) {           ans[j] = num;           ++num;         }       }     }     for (int i = 0; i != n; ++i) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000010, mod = 1e9 + 7, INF = 0x3f3f3f3f;   const double eps = 1e-6;   int n, m;   int id[N];   vector<int> v[N];   bool st[N];   bool check() {     int cnt = 0;     for (int i = 1; i <= n; i++)       if (!id[i]) {         cnt++;         id[i] = cnt;         int s = 0;         if (cnt > 3) return false;         for (auto x : v[i]) st[x] = 1, s++;         st[i] = 1;         for (int j = 1; j <= n; j++)           if (!st[j]) {             if (id[j]) return false;             id[j] = cnt;             int sum = 0;             for (auto x : v[j]) {               if (!st[x]) return false;               sum++;             }             if (sum != s) return false;           }         for (auto x : v[i]) st[x] = 0;         st[i] = 0;       }     if (cnt < 3) return false;     for (int i = 1; i <= n; i++) printf( %d  , id[i]);     puts(  );     return true;   }   int main() {     scanf( %d%d , &n, &m);     while (m--) {       int a, b;       scanf( %d%d , &a, &b);       v[a].push_back(b);       v[b].push_back(a);     }     if (!check()) puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 1010;   const int inf = 1 << 23;   int ch[Maxn << 1][3], siz[Maxn << 1], maxs[Maxn << 1], alls, core;   bool vis[Maxn << 1];   int n, tot, T;   void dfs(int x, int fa) {     siz[x] = 1;     maxs[x] = 0;     for (int i = 0; i < 3; i++) {       int y = ch[x][i];       if (y == fa || !y || vis[y]) continue;       dfs(y, x);       if (maxs[x] < siz[y]) maxs[x] = siz[y];       siz[x] += siz[y];     }     if (maxs[x] < alls - siz[x]) maxs[x] = alls - siz[x];     if (maxs[x] < maxs[core] || (maxs[x] == maxs[core] && x > core)) core = x;   }   void dfs2(int x, int fa) {     siz[x] = 1;     for (int i = 0; i < 3; i++) {       int y = ch[x][i];       if (y == fa || !y || vis[y]) continue;       dfs(y, x);       siz[x] += siz[y];     }   }   int getl(int x) { return x <= n ? x : getl(ch[x][1]); }   void solve(int x) {     vis[x] = true;     if (x <= n) {       tot++;       int fa = ch[x][0];       if (ch[fa][1] == x)         ch[fa][1] = tot;       else         ch[fa][2] = tot;       ch[tot][0] = fa;       ch[x][0] = tot;       ch[tot][1] = x;       ch[tot][2] = T;       ch[T][0] = tot;       return;     }     int l1 = getl(ch[x][1]), l2 = getl(ch[x][2]);     cout << l1 <<     << l2 <<     << T << endl;     char c;     cin >> c;     if (c ==  X ) {       if (vis[ch[x][0]] || !ch[x][0]) {         tot++;         int fa = ch[x][0];         if (fa) {           if (ch[fa][1] == x)             ch[fa][1] = tot;           else             ch[fa][2] = tot;         }         ch[tot][0] = fa;         ch[x][0] = tot;         ch[tot][1] = x;         ch[tot][2] = T;         ch[T][0] = tot;         return;       }       dfs2(ch[x][0], x);       alls = siz[ch[x][0]];       core = 0;       dfs(ch[x][0], x);       solve(core);     } else if (c ==  Y ) {       if (vis[ch[x][2]]) {         tot++;         ch[tot][0] = x;         ch[tot][1] = ch[x][2];         ch[tot][2] = T;         ch[ch[x][2]][0] = tot;         ch[x][2] = tot;         ch[T][0] = tot;         return;       }       dfs2(ch[x][2], x);       alls = siz[ch[x][2]];       core = 0;       dfs(ch[x][2], x);       solve(core);     } else {       if (vis[ch[x][1]]) {         tot++;         ch[tot][0] = x;         ch[tot][1] = ch[x][1];         ch[tot][2] = T;         ch[ch[x][1]][0] = tot;         ch[x][1] = tot;         ch[T][0] = tot;         return;       }       dfs2(ch[x][1], x);       alls = siz[ch[x][1]];       core = 0;       dfs(ch[x][1], x);       solve(core);     }   }   int main() {     int i, j, k;     cin >> n;     tot = n;     ch[1][0] = ch[2][0] = ++tot;     ch[tot][1] = 1;     ch[tot][2] = 2;     maxs[0] = inf;     for (T = 3; T <= n; T++) {       memset(vis, false, sizeof(vis));       alls = 2 * T - 3;       core = 0;       dfs(1, 0);       solve(core);     }     cout <<  -1  << endl;     for (i = 1; i <= tot; i++) {       if (!ch[i][0])         cout <<  -1  ;       else         cout << ch[i][0] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int to[2000];   char used[2000];   int a[2000];   int s;   char res[3000];   int calc(int x, char &f) {     f = 0;     int cnt = 1;     if (x == s) f = 1;     while (to[x] != -1) {       ++cnt;       x = to[x];       if (x == s) {         f = 1;         cnt = 1;       }     }     return cnt;   }   int main() {     int n, x;     cin >> n >> x;     --x;     s = x;     for (int i = 0; i < n; ++i) to[i] = -1;     for (int i = 0; i < n; ++i) {       cin >> to[i];       --to[i];       if (to[i] >= 0) used[to[i]] = 1;     }     int sl = -1;     int q = 0;     for (int i = 0; i < n; ++i)       if (!used[i]) {         char f;         int len = calc(i, f);         if (f)           sl = len;         else           a[q++] = len;       }     assert(sl != -1);     res[sl] = 1;     for (int i = 0; i < q; ++i) {       for (int j = n; j >= 0; --j)         if (res[j]) res[j + a[i]] = 1;     }     for (int i = 0; i <= n; ++i)       if (res[i]) cout << i <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int SIZE = 1000005;   char sa[SIZE], sb[SIZE];   char rab[SIZE * 2], ba[SIZE * 2];   int f1[SIZE * 2];   int f2[SIZE * 2];   int main() {     while (gets(sa) && gets(sb)) {       int l1 = strlen(sa);       int l2 = strlen(sb);       if (l1 != l2) {         printf( -1 -1 n );         continue;       }       strcpy(rab, sa);       reverse(rab, rab + l1);       strcat(rab,  # );       strcat(rab, sb);       rab[l1] =   0 ;       strcpy(ba, sb);       strcat(ba,  # );       strcat(ba, sa);       ba[l1] =   0 ;       int n = l1;       f1[0] = 0;       for (int i = 1; i <= 2 * n; i++) {         f1[i] = f1[i - 1];         while (f1[i] > 0 && rab[f1[i]] != rab[i]) f1[i] = f1[f1[i] - 1];         if (rab[f1[i]] == rab[i]) f1[i]++;       }       f2[0] = 0;       for (int i = 1, l = 0, r = 0; i <= 2 * n; i++) {         f2[i] = 0;         if (i <= r) f2[i] = min(f2[i - l], r - i + 1);         while (i + f2[i] <= 2 * n && ba[f2[i]] == ba[i + f2[i]]) f2[i]++;         if (i + f2[i] - 1 > r) {           l = i;           r = i + f2[i] - 1;         }       }       int r1 = -1, r2 = -1;       for (int i = 0; i < n - 1; i++) {         if (sa[i] != sb[n - i - 1]) break;         int len = f1[2 * n - i - 1];         if (f2[n + 1 + i + 1] >= n - i - len - 1) {           r1 = i;           r2 = n - len;         }       }       printf( %d %d n , r1, r2);     }   }


#include <bits/stdc++.h>   using namespace std;   int CeilIndex(int A[], int l, int r, int key) {     int m;     while (r - l > 1) {       m = l + (r - l) / 2;       (A[m] <= key ? l : r) = m;     }     return r;   }   int LongestIncreasingSubsequenceLength(int A[], int size) {     int *tailTable = new int[size];     int len;     memset(tailTable, 0, sizeof(tailTable[0]) * size);     tailTable[0] = A[0];     len = 1;     for (int i = 1; i < size; i++) {       if (A[i] < tailTable[0])         tailTable[0] = A[i];       else if (A[i] >= tailTable[len - 1])         tailTable[len++] = A[i];       else         tailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i];     }     delete[] tailTable;     return len;   }   int main() {     int n, a[100009], c[100009];     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       c[i] = 0;     }     int ans = 0;     ans = LongestIncreasingSubsequenceLength(a, n);     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int weight(char c) {     if (c ==  Q  || c ==  q ) return 9;     if (c ==  R  || c ==  r ) return 5;     if (c ==  B  || c ==  b ) return 3;     if (c ==  N  || c ==  n ) return 3;     if (c ==  P  || c ==  p ) return 1;     return 0;   }   int main() {     int white = 0, black = 0;     string board[8];     for (int i = 0; i < 8; i++) {       cin >> board[i];       for (int j = 0; j < 8; j++) {         if (board[i][j] >=  A  && board[i][j] <=  Z )           white += weight(board[i][j]);         else if (board[i][j] >=  a  && board[i][j] <=  z )           black += weight(board[i][j]);       }     }     if (white > black)       cout <<  White ;     else if (white < black)       cout <<  Black ;     else       cout <<  Draw ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200 * 1000 + 10;   struct edge {     int u, v, w;     edge() {}     edge(int u, int v, int w) : u(u), v(v), w(w) {}   } e[N];   vector<int> vec[N];   int n, m, root[N], mx[35][N], par[35][N], h[N], ans[N];   bool mst[N], mark[N];   multiset<int> add[N], rem[N];   bool cmp(int i, int j) { return e[i].w < e[j].w; }   int dfs(int v) {     mark[v] = true;     for (int ind : vec[v]) {       int u = e[ind].u + e[ind].v - v;       if (mst[ind]) {         if (!mark[u]) {           h[u] = h[v] + 1;           par[0][u] = v;           mx[0][u] = e[ind].w;           ans[ind] = dfs(u);           if ((int)add[u].size() > (int)add[v].size()) swap(add[u], add[v]);           for (int x : add[u]) add[v].insert(x);         }       }     }     for (int x : rem[v]) add[v].erase(add[v].find(x));     if (add[v].empty()) return -1;     return *add[v].begin() - 1;   }   void fill_par() {     for (int i = 0; i < n; i++) mark[i] = false;     for (int i = 0; i < 31; i++)       for (int j = 0; j < n; j++) par[i][j] = -1;     dfs(0);     for (int i = 1; i < 31; i++)       for (int j = 0; j < n; j++)         if (par[i - 1][j] != -1) {           mx[i][j] = max(mx[i - 1][j], mx[i - 1][par[i - 1][j]]);           par[i][j] = par[i - 1][par[i - 1][j]];         }   }   int get_root(int v) {     if (v == root[v]) return v;     return root[v] = get_root(root[v]);   }   pair<int, int> get_lca(int u, int v) {     if (h[u] < h[v]) swap(u, v);     int mxe = 0;     for (int i = 30; i >= 0; i--)       if ((h[u] - h[v]) & (1 << i)) {         mxe = max(mxe, mx[i][u]);         u = par[i][u];       }     for (int i = 30; i >= 0; i--)       if (par[i][u] != par[i][v]) {         mxe = max(mxe, mx[i][v]), mxe = max(mxe, mx[i][u]);         u = par[i][u], v = par[i][v];       }     if (u != v) {       mxe = max(mxe, mx[0][v]), mxe = max(mxe, mx[0][u]);       u = par[0][u];     }     return {u, mxe};   }   void merge(int ind, int ty) {     int u = e[ind].u, v = e[ind].v;     int pu = get_root(u), pv = get_root(v);     if (pu != pv) {       mst[ind] = true;       root[pu] = pv;     }     if (pu != pv || !ty) return;     ans[ind] = (get_lca(u, v)).second - 1;   }   void merge() {     for (int i = 0; i < n; i++) root[i] = i;     vector<int> temp(m);     iota(temp.begin(), temp.end(), 0);     sort(temp.begin(), temp.end(), cmp);     for (int i = 0; i < m; i++) merge(temp[i], 0);     fill_par();     for (int i = 0; i < m; i++)       if (!mst[i]) {         int u = e[i].u, v = e[i].v;         int lca = get_lca(u, v).first;         add[u].insert(e[i].w);         add[v].insert(e[i].w);         rem[lca].insert(e[i].w);         rem[lca].insert(e[i].w);       }     fill_par();     for (int i = 0; i < n; i++) root[i] = i;     for (int i = 0; i < m; i++) merge(temp[i], 1);   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v, w;       cin >> u >> v >> w;       u--, v--;       e[i] = edge(u, v, w);       vec[u].push_back(i);       vec[v].push_back(i);     }     merge();     for (int i = 0; i < m; i++) cout << ans[i] <<    n [i == m - 1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double a, b, m, vx, vy, vz;     cin >> a >> b >> m >> vx >> vy >> vz;     double X = a / 2 - m / vy * vx;     double Z = -m / vy * vz;     while (X < 0 || X > a)       if (X > a)         X = 2 * a - X;       else         X = -X;     while (Z < 0 || Z > b)       if (Z > b)         Z = 2 * b - Z;       else         Z = -Z;     printf( %.9lf %.9lf , X, Z);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char table[500 + 10][500 + 10];   int vis[500 + 10][500 + 10];   int n, m;   int dirr[4] = {1, -1, 0, 0};   int dirc[4] = {0, 0, 1, -1};   vector<tuple<int, int, int> > ans;   int dfs(int i, int j, int depth) {     if (i < 0 || i >= n || j < 0 || j >= m) return 0;     if (vis[i][j] || table[i][j] ==  # ) return 0;     vis[i][j] = 1;     ans.push_back(make_tuple(0, i + 1, j + 1));     for (int d = 0; d < 4; d++) {       dfs(i + dirr[d], j + dirc[d], depth + 1);     }     if (depth > 0) {       ans.push_back(make_tuple(1, i + 1, j + 1));       ans.push_back(make_tuple(2, i + 1, j + 1));     }     return 0;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> table[i][j];       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (table[i][j] ==  # ) continue;         if (vis[i][j] == 0) {           dfs(i, j, 0);         }       }     }     printf( %d n , ans.size());     int a, b, c;     for (tuple<int, int, int> t : ans) {       tie(a, b, c) = t;       if (a == 0) {         printf( B %d %d n , b, c);       } else if (a == 1) {         printf( D %d %d n , b, c);       } else {         printf( R %d %d n , b, c);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int t;     cin >> t;     while (t--) {       int b[8];       for (int i = 1; i <= 7; ++i) cin >> b[i];       int first = b[7] - b[6];       int last = b[7] - b[5];       cout << first <<     << b[7] - (first + last) <<     << last << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     x = 0;     int f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     x *= f;   }   inline void judge() {     freopen( in.txt ,  r , stdin);     freopen( out.txt ,  w , stdout);   }   const int maxn = 100005;   int fac[maxn], facinv[maxn];   const int mod = 1e9 + 7;   inline int powmod(int a, int b) {     int res = 1;     for (; b; b >>= 1) {       if (b & 1) res = 1ll * res * a % mod;       a = 1ll * a * a % mod;     }     return res;   }   inline void prprpr() {     fac[0] = 1;     for (int i = (1); i <= (100000); i++) fac[i] = 1ll * fac[i - 1] * i % mod;     for (int i = (0); i <= (100000); i++) facinv[i] = powmod(fac[i], mod - 2);   }   inline int C(int n, int m) {     return 1ll * fac[n] * facinv[m] % mod * facinv[n - m] % mod;   }   inline int Gans(int x, int n, int *a) {     if (n < x) return 0;     return a[n - x + 1] * 1ll * powmod(26, n) % mod;   }   inline void calc(int x, int *&a) {     a = (int *)malloc(140005 * sizeof(int));     int inv = powmod(26, mod - 2);     int v1 = powmod(inv, x), v2 = 1;     for (int i = (x); i <= (100000); i++) {       a[i - x + 1] = 1ll * C(i - 1, x - 1) * v2 % mod * v1 % mod;       v1 = 1ll * v1 * inv % mod;       v2 = 1ll * v2 * (26 - 1) % mod;       a[i - x + 1] = (a[i - x + 1] + a[i - x]) % mod;     }   }   char s[maxn];   int nowlen;   map<int, int *> zball;   int main() {     prprpr();     int m;     read(m);     scanf( %s , s + 1);     nowlen = strlen(s + 1);     calc(nowlen, zball[nowlen]);     for (int i = (1); i <= (m); i++) {       int x;       read(x);       if (x == 2) {         int v;         read(v);         printf( %d n , Gans(nowlen, v, zball[nowlen]));       } else {         scanf( %s , s + 1);         nowlen = strlen(s + 1);         if (!zball.count(nowlen)) calc(nowlen, zball[nowlen]);       }     }     return 0;   }