#include <bits/stdc++.h>   using namespace std;      /*<DEBUG>*/   #define tem template <typename    #define can_shift(_X_, ...) enable_if_t<sizeof test<_X_>(0) __VA_ARGS__ 8, debug&> operator<<(T i)   #define _op debug& operator<<   tem C > auto test(C *x) -> decltype(cerr << *x, 0LL);   tem C > char test(...);   tem C > struct itr{C begin, end; };   tem C > itr<C> get_range(C b, C e) { return itr<C>{b, e}; }   struct debug{   #ifdef _LOCAL    ~debug(){ cerr << endl; }    tem T > can_shift(T, ==){ cerr << boolalpha << i; return *this; }    tem T> can_shift(T, !=){ return *this << get_range(begin(i), end(i)); }    tem T, typename U > _op (pair<T, U> i){      return *this <<  <   << i.first <<   ,   << i.second <<   > ; }    tem T> _op (itr<T> i){     *this <<   {  ;     for(auto it = i.begin; it != i.end; it++){      *this <<   ,   + (it==i.begin?2:0) << *it;     }     return *this <<   } ;    }   #else   tem T> _op (const T&) { return *this; }   #endif    };      string _ARR_(int* arr, int sz){    string ret =  {   + to_string(arr[0]);     for(int i = 1; i < sz; i++) ret +=   ,   +  to_string(arr[i]);    ret +=   } ; return ret;   }      #define exp(...)   [   << #__VA_ARGS__ <<   :   << (__VA_ARGS__) <<   ]    /*</DEBUG>*/      typedef long long ll;   typedef unsigned long long ull;   typedef unsigned int uint;   typedef pair<int, int> pii;   //mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());      #define pb push_back   #define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)   #define TC int __TC__; cin >> __TC__; while(__TC__--)   #define ar array      const int INF = 1e9 + 7;      int main(void)   {    FAST;    vector<ll> mx;    for(ll i = 1; i*i + (i+1)*(i+1) <= INF; ++i){     mx.pb(i*i + (i+1) * (i+1));    }       TC{     int n; cin >> n;     int pos = (lower_bound(mx.begin(), mx.end(), n) - mx.begin());     if(mx[pos] == n) ++pos;     cout << pos <<   n ;    }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long n, k;     cin >> n >> k;     vector<long long> occ(255);     string s;     cin >> s;     long long streak = 0;     char curr = s[0];     for (long long i = 0; i < n; i++) {       if (s[i] == curr) {         streak++;         if (streak == k) {           occ[curr]++;           streak = 0;         }       } else {         streak = 1;         curr = s[i];       }     }     long long mx = 0;     for (long long i = 0; i < 255; i++) {       mx = max(occ[i], mx);     }     cout << mx << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   const int MOD = 1e9 + 7;   template <typename Tp>   void read(Tp &x) {     x = 0;     int op = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) op = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     x *= op;   }   template <typename Tp>   void CMax(Tp &x, Tp y) {     if (y > x) x = y;   }   template <typename Tp>   void CMin(Tp &x, Tp y) {     if (y < x) x = y;   }   int n, m, a[N], mx;   int f[N], res1, res2, ans;   void norm(int &x) {     while (x >= MOD) x -= MOD;     while (x < 0) x += MOD;   }   int Inv(int x, int p = MOD - 2) {     int ret = 1;     while (p) {       if (p & 1) ret = 1ll * ret * x % MOD;       x = 1ll * x * x % MOD;       p >>= 1;     }     return ret;   }   int main() {     read(n);     for (int i = (1); i <= (n); ++i) read(a[i]), m += a[i], CMax(mx, a[i]);     ans = 1ll * m * (m - 1) % MOD;     for (int i = (1); i <= (mx); ++i) {       res1 += res2;       norm(res1);       int v = Inv(i - 1 - m + MOD);       res2 += v;       norm(res2);       res1 += v;       norm(res1);       f[i] = 1ll * res1 * (m - 1) % MOD;       norm(f[i]);     }     for (int i = (1); i <= (n); ++i) ans += f[a[i]], norm(ans);     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int SIZE = 1 << 17;   char buffer[SIZE];   int pointer = SIZE;   char Advance() {     if (pointer == SIZE) {       fread(buffer, 1, SIZE, stdin);       pointer = 0;     }     return buffer[pointer++];   }   int Read() {     int answer = 0;     char ch = Advance();     while (!isdigit(ch)) ch = Advance();     while (isdigit(ch)) {       answer = answer * 10 + ch -  0 ;       ch = Advance();     }     return answer;   }   const int MAXN = 100000;   const int MAXQ = 200000;   const int MAXNODES = 262144;   struct Point {     int x;     int y;     bool operator<(const Point &other) const { return x < other.x; }   };   Point v[1 + MAXQ];   struct Query {     Point a;     Point b;     int index;     bool operator<(const Query &other) const { return b < other.b; };   };   Query query[1 + MAXQ];   bool ok[1 + MAXQ];   int tree[1 + MAXNODES], where, from, to, change;   void Update(int node, int left, int right) {     if (left == right) {       tree[node] = change;       return;     }     int middle = (left + right) / 2;     if (where <= middle)       Update(2 * node, left, middle);     else       Update(2 * node + 1, middle + 1, right);     tree[node] = min(tree[2 * node], tree[2 * node + 1]);   }   int Query(int node, int left, int right) {     if (from <= left && right <= to) return tree[node];     int answer = MAXN, middle = (left + right) / 2;     if (from <= middle) answer = min(answer, Query(2 * node, left, middle));     if (middle + 1 <= to)       answer = min(answer, Query(2 * node + 1, middle + 1, right));     return answer;   }   void Solve(int k, int q, int n, int m) {     sort(v + 1, v + k + 1);     sort(query + 1, query + q + 1);     for (int i = 1, j = 1; i <= q; i++) {       while (j <= k && v[j].x <= query[i].b.x) {         where = v[j].y;         change = v[j].x;         Update(1, 1, m);         j++;       }       from = query[i].a.y;       to = query[i].b.y;       if (Query(1, 1, m) >= query[i].a.x) ok[query[i].index] = true;     }   }   int main() {     int n = Read(), m = Read(), k = Read(), q = Read();     for (int i = 1; i <= k; i++) {       v[i].x = Read();       v[i].y = Read();     }     for (int i = 1; i <= q; i++) {       query[i].a.x = Read();       query[i].a.y = Read();       query[i].b.x = Read();       query[i].b.y = Read();       query[i].index = i;     }     Solve(k, q, n, m);     for (int i = 1; i <= k; i++) swap(v[i].x, v[i].y);     memset(tree, 0, sizeof(tree));     for (int i = 1; i <= q; i++) {       swap(query[i].a.x, query[i].a.y);       swap(query[i].b.x, query[i].b.y);     }     Solve(k, q, m, n);     for (int i = 1; i <= q; i++)       if (ok[i])         printf( YES n );       else         printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d%d , &n, &m);     ;     int cnt = 0;     for (int i = 0; i < (n + 1); i++)       for (int j = 0; j < (n + 1); j++) {         if (i * i + j == n && i + j * j == m) cnt++;       }     printf( %d n , cnt);   }


#include <bits/stdc++.h>   using namespace std;   int N, ans = 0, overtake = 0, pspeed, plimit = 1000;   stack<int> signs;   int main() {     cin >> N;     for (int i = 0, a, b; i < N; i++) {       cin >> a;       if (a == 1) {         cin >> b;         pspeed = b;         while (!signs.empty()) {           if (signs.top() < b) {             ans++;             signs.pop();           } else {             break;           }         }       } else if (a == 2) {         if (overtake > 0) {           ans += overtake;           overtake = 0;         }       } else if (a == 3) {         cin >> b;         signs.push(b);         while (!signs.empty()) {           if (signs.top() < pspeed) {             ans++;             signs.pop();           } else {             break;           }         }       } else if (a == 4) {         overtake = 0;       } else if (a == 5) {         while (!signs.empty()) signs.pop();       } else {         overtake++;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long N = 1e6 + 5;   const long long inf = 1e18;   long long powermod(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;   loop:     while (t--) {       long long n;       cin >> n;       long long x = n / 4;       if (n % 4 != 0) x++;       n -= x;       while (n--) {         cout << 9;       }       while (x--) cout << 8;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     int sum = 0;     int c;     int ans = 0;     int k = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> c;       sum += c;       k += c;       if (k < 0) k = 0;       ans = max(ans, k);     }     cout << -sum + ans * 2;   }


#include <bits/stdc++.h>   template <typename T>   inline void read(T &x) {     x = 0;     char c = getchar();     bool flag = false;     while (!isdigit(c)) {       if (c ==  - ) flag = true;       c = getchar();     }     while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();     if (flag) x = -x;   }   using namespace std;   const int inf = 987654321;   int n, m, s, t;   struct edge {     int nxt, to, val;     edge() {}     edge(int jzp, int zzz, int lsr) { nxt = jzp, to = zzz, val = lsr; }   } e[5001000];   int head[101000], ecnt = 1, hcur[101000];   inline void addedge(int from, int to, int val) {     e[++ecnt] = edge(head[from], to, val);     head[from] = ecnt;   }   inline void Addedge(int u, int v, int w) { addedge(u, v, w), addedge(v, u, 0); }   int ls[101000], rs[101000], root_in, root_out, ttot;   void build_out(int L, int R, int &cur) {     cur = ++ttot;     if (L == R) return Addedge(s, cur, 1), void();     int mid = (L + R) >> 1;     build_out(L, mid, ls[cur]), build_out(mid + 1, R, rs[cur]);     Addedge(ls[cur], cur, inf);     Addedge(rs[cur], cur, inf);   }   void build_in(int L, int R, int &cur) {     cur = ++ttot;     if (L == R) return Addedge(cur, t, 1), void();     int mid = (L + R) >> 1;     build_in(L, mid, ls[cur]), build_in(mid + 1, R, rs[cur]);     Addedge(cur, ls[cur], inf), Addedge(cur, rs[cur], inf);   }   void Addedge_out(int L, int R, int l, int r, int p, int cur) {     if (l <= L && R <= r) return Addedge(cur, p, inf), void();     int mid = (L + R) >> 1;     if (l <= mid) Addedge_out(L, mid, l, r, p, ls[cur]);     if (r > mid) Addedge_out(mid + 1, R, l, r, p, rs[cur]);   }   void Addedge_in(int L, int R, int l, int r, int p, int cur) {     if (l <= L && R <= r) return Addedge(p, cur, inf), void();     int mid = (L + R) >> 1;     if (l <= mid) Addedge_in(L, mid, l, r, p, ls[cur]);     if (r > mid) Addedge_in(mid + 1, R, l, r, p, rs[cur]);   }   inline void Seg_Addedge(int l, int r, int d, int u) {     if (l > r || d > u) return;     ++ttot;     Addedge_out(1, n, l, r, ttot, root_out);     Addedge_in(1, n, d, u, ttot, root_in);   }   struct node {     int x, l, r, t;     node() {}     node(int jzp, int zzz, int lsr, int chr) {       x = jzp, l = zzz, r = lsr, t = chr;     }   } nd[101000];   int ntot;   inline bool cmp(const node &a, const node &b) {     return a.x < b.x || (a.x == b.x && a.t > b.t);   }   struct ODT {     int l, r, v;     ODT() {}     ODT(int jzp, int zzz, int lsr) { l = jzp, r = zzz, v = lsr; }     inline bool operator<(const ODT &a) const { return l < a.l; }   };   set<ODT> st;   inline set<ODT>::iterator Split(int p) {     if (p > n) return st.end();     set<ODT>::iterator it = --st.upper_bound(ODT(p, 0, 0));     if (it->l == p) return it;     if (it->r < p) return ++it;     int l = it->l, r = it->r, v = it->v;     st.erase(it);     st.insert(ODT(l, p - 1, v));     return st.insert(ODT(p, r, v)).first;   }   inline void Assign(int l, int r, int x) {     set<ODT>::iterator itr = Split(r + 1), itl = Split(l);     for (set<ODT>::iterator it = itl; it != itr; ++it) {       Seg_Addedge(it->v, x - 1, it->l, it->r);     }     st.erase(itl, itr);   }   inline void Insert(int l, int r, int v) { st.insert(ODT(l, r, v)); }   int dep[101000], que[101000], front, rear;   inline bool bfs() {     memset(dep, 0x3f, sizeof(dep));     front = rear = 0;     for (int i = 1; i <= ttot; ++i) hcur[i] = head[i];     dep[s] = 0;     que[++rear] = s;     while (front < rear) {       int cur = que[++front];       for (int i = head[cur]; i; i = e[i].nxt) {         int to = e[i].to;         if (!e[i].val || dep[to] < 5001000) continue;         que[++rear] = to;         dep[to] = dep[cur] + 1;       }     }     return dep[t] <= 5001000;   }   int dfs(int cur, int limi) {     if (cur == t || !limi) return limi;     int flow = 0;     for (int i = hcur[cur]; i; i = e[i].nxt) {       int to = e[i].to;       hcur[cur] = i;       if (dep[to] != dep[cur] + 1) continue;       int tmp = dfs(to, min(e[i].val, limi));       if (!tmp) continue;       e[i].val -= tmp;       e[i ^ 1].val += tmp;       flow += tmp;       limi -= tmp;       if (!limi) break;     }     return flow;   }   int main() {     read(n);     read(m);     for (int i = 1; i <= m; ++i) {       int x_1, y_1, x_2, y_2;       read(x_1), read(y_1), read(x_2), read(y_2);       nd[++ntot] = node(x_1, y_1, y_2, 0);       nd[++ntot] = node(x_2 + 1, y_1, y_2, 1);     }     sort(nd + 1, nd + 1 + ntot, cmp);     s = 1, t = 2;     ttot = 2;     build_out(1, n, root_out);     build_in(1, n, root_in);     Insert(1, n, 1);     for (int i = 1; i <= ntot; ++i) {       int x = nd[i].x, l = nd[i].l, r = nd[i].r, t = nd[i].t;       if (t == 0) {         Assign(l, r, x);       } else {         Insert(l, r, x);       }     }     for (set<ODT>::iterator it = st.begin(); it != st.end(); ++it) {       Seg_Addedge(it->v, n, it->l, it->r);     }     int mxflow = 0;     while (bfs()) mxflow += dfs(s, inf);     printf( %d n , mxflow);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 666;   const double eps = 1e-10;   int n, m, K, cnt, sz;   int id[N], nod[N], cur[N];   double deg[N], g[N][N];   bool trap[N];   double v[N][N];   struct node {     double vec[N];   } vv[N];   struct mat {     double v[166][166];     mat() { memset(v, 0, sizeof(v)); }   } ans;   node operator*(node a, double w) {     for (int i = 0; i <= n; i++) a.vec[i] *= w;     return a;   }   node operator/(node a, double w) {     for (int i = 0; i <= n; i++) a.vec[i] /= w;     return a;   }   node operator+(node a, node b) {     for (int i = 0; i <= n; i++) a.vec[i] += b.vec[i];     return a;   }   node operator-(node a, node b) {     for (int i = 0; i <= n; i++) a.vec[i] -= b.vec[i];     return a;   }   mat operator*(mat a, mat b) {     mat t;     memset(t.v, 0, sizeof(t.v));     for (int i = 0; i <= sz; i++) {       for (int j = 0; j <= sz; j++) {         for (int k = 0; k <= sz; k++) {           t.v[i][j] += a.v[i][k] * b.v[k][j];         }       }     }     return t;   }   int main() {     cin >> n >> m >> K;     for (int i = 1; i <= n; i++) scanf( %d , &trap[i]);     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       ++deg[x], ++deg[y], ++g[x][y], ++g[y][x];     }     for (int i = 1; i <= n; i++) {       if (trap[i]) {         nod[++cnt] = i, id[i] = cnt;       }     }     sz = cnt;     for (int i = 1; i <= n; i++) {       v[i][i] = -1;       for (int j = 1; j <= n; j++) {         if (trap[j]) {           v[i][id[j] + n] += 1.0 * g[i][j] / deg[i];         } else {           v[i][j] += 1.0 * g[i][j] / deg[i];         }       }     }     for (int i = 1; i <= sz; i++) {       vv[i + n].vec[i] = 1;       v[i + n][i + n] = 1;     }     for (int i = 1; i <= n + sz; i++) {       int me = -1;       double mx = 0;       for (int j = 1; j <= n + sz; j++) {         if (abs(v[i][j]) > mx) {           mx = abs(v[i][j]);           me = j;         }       }       if (me == -1 || abs(mx) < eps) continue;       cur[i] = me;       double val = v[i][me];       for (int j = 1; j <= n + sz; j++) v[i][j] /= val;       vv[i] = vv[i] / val;       for (int j = 1; j <= n + sz; j++) {         if (j != i && abs(v[j][me]) > eps) {           double val = v[j][me];           for (int k = 1; k <= n + sz; k++) v[j][k] -= v[i][k] * val;           vv[j] = vv[j] - vv[i] * val;         }       }     }     for (int i = 1; i <= n + sz; i++) {       if ((cur[i] <= n && trap[cur[i]]) || cur[i] == 1) {         if (cur[i] == 1) {           for (int j = 1; j <= sz; j++) ans.v[0][j] = vv[i].vec[j];         } else {           for (int j = 1; j <= sz; j++) ans.v[id[cur[i]]][j] = vv[i].vec[j];         }       }     }     mat res;     memset(res.v, 0, sizeof(res.v));     for (int i = 0; i <= sz; i++) res.v[i][i] = 1;     int nn = K - 1;     for (; nn; nn >>= 1) {       if (nn & 1) res = res * ans;       ans = ans * ans;     }     printf( %.10lf n , res.v[0][id[n]]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace Input {   const int BUF = 65536;   char buf[BUF + 1];   char *head = buf, *tail = buf;   inline char inputchar() {     if (head == tail) *(tail = (head = buf) + fread(buf, 1, BUF, stdin)) = 0;     return *head++;   }   inline void inputnum(int &ret) {     char ch = inputchar();     while (ch <  0  || ch >  9 ) ch = inputchar();     for (ret = 0; ch >=  0  && ch <=  9 ; ch = inputchar())       ret = ret * 10 + ch -  0 ;   }   };  // namespace Input   using Input::inputnum;   const int MAXN = 100005;   struct Node {     long long sum;     Node *c[2];     Node() {}     Node(Node *a, Node *b) : sum(0) { c[0] = a, c[1] = b; }     inline void modify(int v) { sum = v; }     inline void update() {       sum = (c[0] ? c[0]->sum : 0) + (c[1] ? c[1]->sum : 0);     }   } node[MAXN * 90], *root[MAXN];   int cnt = 0;   inline Node *newnode() {     node[cnt] = Node(0, 0);     return &node[cnt++];   }   void modify(Node *&p, int x, int L, int R, int v) {     if (!p) p = newnode();     if (L == R) {       p->modify(v);       return;     }     int M = (L + R) >> 1;     if (x <= M)       modify(p->c[0], x, L, M, v);     else       modify(p->c[1], x, M + 1, R, v);     p->update();   }   long long query(Node *p, int qL, int qR, int L, int R) {     if (!p) return 0;     if (L >= qL && R <= qR) return p->sum;     int M = (L + R) >> 1;     long long ret = 0;     if (qL <= M) ret += query(p->c[0], qL, qR, L, M);     if (qR > M) ret += query(p->c[1], qL, qR, M + 1, R);     return ret;   }   set<int> pos[MAXN];   int a[MAXN];   int n, m, id, p, y, l, r;   inline void modify(int x, int y, int v) {     for (int i = x; i <= n; i += (i & -i)) modify(root[i], y, 1, n, v);   }   inline long long query(int x, int R) {     long long ret = 0;     for (int i = x; i > 0; i ^= (i & -i)) ret += query(root[i], 1, R, 1, n);     return ret;   }   void init() {     memset(root, 0, sizeof(root));     for (int i = 1; i <= n; i++) {       set<int> &cur = pos[a[i]];       cur.insert(i);       set<int>::iterator pre = cur.find(i);       if (pre != cur.begin()) {         --pre;         modify(*pre, i, i - *pre);       }     }   }   int main() {     inputnum(n), inputnum(m);     for (int i = 1; i <= n; i++) inputnum(a[i]);     init();     for (int i = 1; i <= m; i++) {       inputnum(id);       if (id == 1) {         inputnum(p), inputnum(y);         int x = a[p];         a[p] = y;         set<int> &sx = pos[x], &sy = pos[y];         set<int>::iterator pre, next;         pre = next = sx.find(p);         ++next;         if (pre != sx.begin() && next != sx.end()) {           --pre;           modify(*pre, p, 0);           modify(p, *next, 0);           modify(*pre, *next, *next - *pre);         } else if (pre != sx.begin()) {           --pre;           modify(*pre, p, 0);         } else if (next != sx.end()) {           modify(p, *next, 0);         }         sx.erase(p);         sy.insert(p);         pre = next = sy.find(p);         ++next;         if (pre != sy.begin() && next != sy.end()) {           --pre;           modify(*pre, *next, 0);           modify(*pre, p, p - *pre);           modify(p, *next, *next - p);         } else if (pre != sy.begin()) {           --pre;           modify(*pre, p, p - *pre);         } else if (next != sy.end()) {           modify(p, *next, *next - p);         }       } else {         inputnum(l), inputnum(r);         printf( %I64d n , query(r, r) - query(l - 1, r));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   long long n, m, dau, cuoi, giua, pos1, pos2, t;   bool kt;   struct point {     long long x, y;   } p[N], ab, ac, z;   long long ccw(point a, point b, point c) {     ab = {b.x - a.x, b.y - a.y};     ac = {c.x - a.x, c.y - a.y};     return ab.x * ac.y - ab.y * ac.x;   }   long long dis(point a, point b) {     return (b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y);   }   bool cmp1(point a, point b) { return (a.y < b.y || (a.y == b.y && a.x < b.x)); }   bool cmp2(point b, point c) {     t = ccw(p[1], b, c);     return t > 0 || (t == 0 && dis(p[1], b) > dis(p[1], c));   }   bool check(point z) {     if (ccw(p[1], p[2], z) <= 0) return 0;     if (ccw(p[n], p[1], z) <= 0) return 0;     pos1 = pos2 = 0;     dau = 2;     cuoi = n;     while (dau <= cuoi) {       giua = (dau + cuoi) / 2;       if (ccw(p[1], p[giua], z) >= 0)         pos1 = giua, dau = giua + 1;       else         cuoi = giua - 1;     }     if (pos1 == 0) return 0;     dau = 2;     cuoi = n;     while (dau <= cuoi) {       giua = (dau + cuoi) / 2;       if (ccw(p[1], p[giua], z) <= 0)         pos2 = giua, cuoi = giua - 1;       else         dau = giua + 1;     }     if (pos2 == 0) return 0;     if (pos1 == pos2) {       if (dis(p[1], p[pos1]) <= dis(p[1], z))         return 0;       else         return 1;     }     if (ccw(p[pos1], p[pos2], z) <= 0) return 0;     return 1;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> p[i].x >> p[i].y;     }     sort(p + 1, p + 1 + n, cmp1);     sort(p + 2, p + 1 + n, cmp2);     cin >> m;     kt = 1;     for (int i = 1; i <= m; i++) {       cin >> z.x >> z.y;       if (kt == 1)         if (check(z) == 0) {           kt = 0;         }     }     if (kt == 1)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   long long power(long long base, long long exp);   void solve() {     long long n, m, k;     cin >> n >> m >> k;     vector<vector<long long>> arr(n, vector<long long>(m, 0));     long long count[3][5001];     memset(count, 0, sizeof(count));     list<pair<long long, long long>> key;     for (long long i = 0; i < k; i++) {       long long a, b, c;       cin >> a >> b >> c;       key.push_front({a, b});       count[a][b] = c;     }     set<pair<long long, long long>> s;     for (auto k : key) {       long long x = k.first;       if (s.count(k))         continue;       else         s.insert(k);       if (x == 2) {         for (long long i = 0; i < n; i++) {           if (arr[i][k.second - 1] == 0) {             arr[i][k.second - 1] = count[k.first][k.second];           }         }       } else {         for (long long i = 0; i < m; i++) {           if (arr[k.second - 1][i] == 0) {             arr[k.second - 1][i] = count[k.first][k.second];           }         }       }     }     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         cout << arr[i][j] <<    ;       }       cout <<   n ;     }   }   int32_t main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     srand(chrono::high_resolution_clock::now().time_since_epoch().count());     long long t = 1;     while (t--) {       solve();     }     return 0;   }   long long power(long long base, long long exp) {     base %= 1000000007;     long long result = 1;     while (exp > 0) {       if (exp & 1) result = ((long long)result * base) % 1000000007;       base = ((long long)base * base) % 1000000007;       exp >>= 1;     }     return result;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     string s;     getline(cin, s);     for (auto i = s.end() - 1; i >= s.begin(); i--) {       if ((int(*i) >= 65 && (int(*i) <= 90)) ||           (int(*i) >= 97 && (int(*i) <= 122))) {         if (*i ==  A  || *i ==  E  || *i ==  I  || *i ==  O  || *i ==  U  ||             *i ==  a  || *i ==  e  || *i ==  i  || *i ==  o  || *i ==  u  ||             *i ==  y  || *i ==  Y )           cout <<  YES ;         else           cout <<  NO ;         return 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 110;   int N;   struct notlaptop {     int speed, ram, hdd, cost;     notlaptop(int a, int b, int c, int d) {       speed = a;       ram = b;       hdd = c;       cost = d;     }     notlaptop()<% %>   };   notlaptop ar[MAXN];   int main() {     scanf( %d , &N);     for (int i = 0; i < N; i++) {       int a, b, c, d;       cin >> a >> b >> c >> d;       ar[i] = notlaptop(a, b, c, d);     }     int bcost = 1e9, res = -1;     for (int i = 0; i < N; i++) {       bool outdated = false;       for (int j = 0; j < N; j++) {         if (ar[i].speed < ar[j].speed and ar[i].ram < ar[j].ram and             ar[i].hdd < ar[j].hdd) {           outdated = true;           break;         }       }       if (!outdated) {         if (ar[i].cost < bcost) {           bcost = ar[i].cost, res = i + 1;         }       }     }     cout << res <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char now[1 << 16], *S, *T;     if (T == S) {       T = (S = now) + fread(now, 1, 1 << 16, stdin);       if (T == S) return EOF;     }     return *S++;   }   inline long long read() {     register long long x = 0, f = 1;     char ch = gc();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = gc();     }     while (isdigit(ch)) {       x = (x << 3) + (x << 1) + ch -  0 ;       ch = gc();     }     return (f == 1) ? x : -x;   }   struct edge {     int to, nxt, dis;   } g[1200001];   int head[1200001], tot, n, m;   inline void made(int from, int to, int dis) {     g[++tot].to = to;     g[tot].nxt = head[from];     head[from] = tot;     g[tot].dis = dis;   }   int sz[1200001], dep[1200001], wson[1200001];   int s[1200001], a[1200001], F[10000001], ans[1200001];   void dfs0(int u, int fa) {     sz[u] = 1;     dep[u] = dep[fa] + 1;     for (int i = head[u]; i; i = g[i].nxt) {       int v = g[i].to;       if (v == fa) continue;       s[v] = a[v] ^ s[u] ^ g[i].dis;       dfs0(v, u);       sz[u] += sz[v];       if (sz[wson[u]] < sz[v]) wson[u] = v;     }   }   void get(int u, int fa, int wht) {     if (wht)       F[s[u]] = max(F[s[u]], dep[u]);     else       F[s[u]] = 0;     for (int i = head[u]; i; i = g[i].nxt) {       int v = g[i].to;       if (v == fa) continue;       get(v, u, wht);     }   }   void calc(int zx, int u, int fa) {     if (F[s[u]]) ans[zx] = max(F[s[u]] + dep[u] - 2 * dep[zx], ans[zx]);     for (int i = 0, two = 1; i < 22; i++, two <<= 1) {       if (F[s[u] ^ two])         ans[zx] = max(F[s[u] ^ two] + dep[u] - 2 * dep[zx], ans[zx]);     }     for (int i = head[u]; i; i = g[i].nxt) {       int v = g[i].to;       if (v == fa) continue;       calc(zx, v, u);     }   }   void doit(int u, int fa, int wht) {     for (int i = head[u]; i; i = g[i].nxt) {       int v = g[i].to;       if (v == fa || v == wson[u]) continue;       doit(v, u, 0);     }     if (wson[u]) doit(wson[u], u, 1);     if (F[s[u]]) ans[u] = max(F[s[u]] - dep[u], ans[u]);     for (int i = 0, two = 1; i < 22; i++, two <<= 1) {       if (F[s[u] ^ two]) ans[u] = max(F[s[u] ^ two] - dep[u], ans[u]);     }     F[s[u]] = max(F[s[u]], dep[u]);     for (int i = head[u]; i; i = g[i].nxt) {       int v = g[i].to;       if (v == fa || v == wson[u]) continue;       calc(u, v, u);       get(v, u, 1);     }     if (!wht) get(u, fa, 0);   }   void dfs1(int u, int fa) {     for (int i = head[u]; i; i = g[i].nxt) {       int v = g[i].to;       if (v == fa) continue;       dfs1(v, u);       ans[u] = max(ans[u], ans[v]);     }   }   int main() {     n = read();     for (int i = 1; i < n; i++) {       int u = read();       char ch = gc();       while (!isalpha(ch)) ch = gc();       made(i + 1, u, (1 << (ch -  a )));       made(u, i + 1, (1 << (ch -  a )));     }     dfs0(1, 0);     doit(1, 0, 0);     dfs1(1, 0);     for (int i = 1; i <= n; i++) {       printf( %d  , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, s = 0;     scanf( %I64d , &n);     while (n > 0) {       if (n % 8 == 1) s++;       n /= 8;     }     printf( %I64d , s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int a = sqrt(n);       long long int b = n / a;       if (n % a != 0) b++;       if (n == 1)         cout <<  0 n ;       else {         cout << a - 1 + b - 1 <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long n, m, t;   long long a[500000];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> t;     for (long long ti = 0; ti < t; ti++) {       map<vector<long long>, long long> tab;       map<vector<long long>, long long>::iterator iter;       cin >> n >> m;       vector<long long> v[n + 1];       for (long long i = 0; i < n; i++) cin >> a[i];       for (long long i = 0; i < m; i++) {         long long a, b;         cin >> a >> b;         v[b].push_back(a);       }       for (long long i = 0; i < n; i++) sort(v[i + 1].begin(), v[i + 1].end());       for (long long i = 0; i < n; i++)         if (!v[i + 1].empty()) tab[v[i + 1]] += a[i];       long long g;       iter = tab.begin();       g = iter->second;       iter++;       for (; iter != tab.end(); iter++) g = gcd(g, iter->second);       cout << g <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[600];   char s[600];   int cnt = 0;   int rec[3];   void dfs(int src, char c) {     s[src] = c;     for (int i = 0; i < v[src].size(); i++)       if (s[v[src][i]] !=  b ) {         cnt++;         s[v[src][i]] = c;       }   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);     }     for (int i = 1; i <= n; i++)       if (v[i].size() == n - 1) {         cnt++;         s[i] =  b ;       }     rec[1] = cnt;     for (int i = 1; i <= n; i++)       if (s[i] !=  b ) {         cnt++;         dfs(i,  a );         break;       }     rec[0] = cnt - rec[1];     for (int i = 1; i <= n; i++)       if (s[i] !=  a  && s[i] !=  b ) {         cnt++;         dfs(i,  c );         break;       }     rec[2] = cnt - rec[0] - rec[1];     int x = rec[0] * (rec[0] + rec[1] - 1) + rec[1] * (n - 1) +             rec[2] * (rec[1] + rec[2] - 1);     if (cnt != n || x / 2 != m)       cout <<  No  << endl;     else {       cout <<  Yes  << endl;       for (int i = 1; i <= n; i++) cout << s[i];       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int i;   int main() {     cin >> s;     i = s.find( 0 );     if (i > -1)       s.erase(i, 1);     else       s.erase(0, 1);     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   inline void chmin(A &a, B b) {     if (a > b) a = b;   }   template <typename A, typename B>   inline void chmax(A &a, B b) {     if (a < b) a = b;   }   long long N, M;   string S;   signed main() {     cin >> N >> M >> S;     long long ans = 0;     vector<long long> cnt(M);     for (long long i = N - 1; i >= 0; i--) {       long long c = S[i] -  a ;       if (i + 1 < N && S[i] != S[i + 1]) {         ans += N - i - 1 - cnt[c];         ans += cnt[c] * (M - 1);         ans += (N - i - 1 - cnt[c]) * (M - 2);       }       cnt[c]++;     }     fill((cnt).begin(), (cnt).end(), 0ll);     vector<long long> st(N);     for (long long i = 0; i < N; i++) {       long long c = S[i] -  a ;       if (i && S[i - 1] != S[i]) {         st[i] = 1;         if (i >= 3 && S[i - 3] == S[i - 1] && S[i - 2] == S[i])           st[i] += st[i - 2];         ans += i - cnt[c] - st[i];         ans += cnt[c] * (M - 1);         ans += (i - cnt[c]) * (M - 2);         long long tmp = st[i] - 1;         if (i - st[i] * 2 >= 0 && S[i - st[i] * 2] == S[i]) tmp++;         ans -= tmp;       }       cnt[c]++;     }     ans += (M - 1) * N;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, k, a[105], b[105], c[105], ai[105];   map<long long int, long long int> pos;   void apply_f(long long int c[105]) {     for (int i = 1; i <= n; i++) c[i] = a[c[i]];   }   void apply_if(long long int c[105]) {     for (int i = 1; i <= n; i++) c[i] = ai[c[i]];   }   bool compare(long long int a1[105], long long int a2[105]) {     for (int i = 1; i <= n; i++)       if (a1[i] != a2[i]) return 0;     return 1;   }   bool Check(int l, int r) {     if (l == 0 || l > k) return 0;     if ((k - l) % 2 == 1) return 0;     if (l == 1 && k != 1 && r == 1) return 0;     return 1;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       ai[a[i]] = i;       c[i] = i;     }     for (int i = 1; i <= n; i++) {       cin >> b[i];     }     long long int loc = 0;     for (int i = 0; i <= 100; i++) {       if (compare(c, b)) {         pos[i] = 1;       }       apply_f(c);     }     for (int i = 1; i <= n; i++) c[i] = i;     for (int i = 0; i <= 100; i++) {       if (compare(c, b)) {         pos[-i] = 1;       }       apply_if(c);     }     long long int R = 0, L = 0;     for (int i = 0; i <= 100; i++) {       if (pos[i]) {         R = i;         break;       }     }     for (int i = 0; i >= -100; i--) {       if (pos[i]) {         L = -i;         break;       }     }     if (Check(L, R) || Check(R, L))       cout <<  YES  <<   n ;     else       cout <<  NO  <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e3 + 10, MAXM = 2e5 + 10;   pair<int, int> v[MAXM];   int l[MAXM], r[MAXM], s[MAXM], t[MAXM];   vector<int> qv[MAXM];   bool ans[MAXM];   int last[MAXN][MAXN];   int main() {     int n, m, q;     scanf( %d %d %d , &n, &m, &q);     for (int i = 1; i <= m; i++) scanf( %d %d , &v[i].first, &v[i].second);     for (int i = 0; i < q; i++)       scanf( %d %d %d %d , l + i, r + i, s + i, t + i), qv[l[i]].push_back(i);     for (int i = 0; i <= n; i++)       for (int k = 0; k <= n; k++) last[i][k] = m + 1;     for (int time = m; time > 0; time--) {       int x, y;       x = v[time].first, y = v[time].second;       last[x][y] = last[y][x] = time;       for (int vx = 1; vx <= n; vx++) {         if (last[x][vx] < last[y][vx])           last[y][vx] = last[x][vx];         else           last[x][vx] = last[y][vx];       }       for (int ix : qv[time]) ans[ix] = (last[s[ix]][t[ix]] <= r[ix]);     }     for (int i = 0; i < q; i++)       if (ans[i])         printf( Yes n );       else         printf( No n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, x1, y1, x2, y2;     long double s = 0;     scanf( %d %d , &n, &k);     scanf( %d %d , &x1, &y1);     for (int i = 1; i < n; i++) {       scanf( %d %d , &x2, &y2);       s += (long double)sqrt((long double)(x2 - x1) * (x2 - x1) +                              (long double)(y2 - y1) * (y2 - y1));       x1 = x2;       y1 = y2;     }     printf( %.6Lf , s * (long double)k / (long double)50);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, ans, t;   int a[100005];   int main() {     scanf( %d%d , &n, &k);     ans = 1;     t = 1;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       if (a[i] == a[i - 1]) {         ans = max(ans, i - t);         t = i;       }     }     ans = max(ans, n - t + 1);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int fx[] = {-1, 1, 0, 0};   int fy[] = {0, 0, 1, -1};   int dx[] = {-1, 1, 0, 0, 1, 1, -1, -1};   int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};   int cx[] = {1, 1, 2, 2, -1, -1, -2, -2};   int cy[] = {2, -2, 1, -1, 2, -2, 1, -1};   const int N = 1 << 11;   int n;   int ans[N + 1];   int ask(int p, int q) {     printf( ? %d %d n , p, q);     fflush(stdout);     int x;     scanf( %d , &x);     return x;   }   int value(int x) {     int ans = N - 1;     for (int i = 1; i <= 15; i++) {       int a = rand() % n + 1;       if (a == x) continue;       ans &= ask(x, a);     }     return ans;   }   void solve() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     srand(2137);     scanf( %d , &n);     vector<int> v;     for (int i = 1; i <= n; i++) v.push_back(i);     random_shuffle(v.begin(), v.end());     pair<int, int> zero = {v[0], value(v[0])};     for (int i = 1; i <= n - 1; i++) {       int a = ask(zero.first, v[i]);       if ((a & zero.second) == a) zero = {v[i], value(v[i])};     }     for (int i = 1; i <= n; i++)       if (i != zero.first) ans[i] = ask(i, zero.first);     printf( !  );     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);   }   signed main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Compteur {     int nbs[4];     Compteur() {       for (int iCoeff = 0; iCoeff < 4; iCoeff++) {         nbs[iCoeff] = 0;       }     }   };   Compteur operator+(const Compteur &a, const Compteur &b) {     Compteur nouv;     for (int iCoeff = 0; iCoeff < 4; iCoeff++) {       nouv.nbs[iCoeff] = a.nbs[iCoeff] + b.nbs[iCoeff];     }     return nouv;   }   int getP2(int a) {     int s = 1;     while (s < a) {       s *= 2;     }     return s;   }   vector<Compteur> arbres[10][10];   void modif(vector<Compteur> &a, int pos, Compteur val) {     pos += (int)a.size() / 2;     while (pos != 0) {       a[pos] = a[pos] + val;       pos /= 2;     }   }   Compteur getSomme(vector<Compteur> &a, int deb, int fin) {     deb += (int)a.size() / 2;     fin += (int)a.size() / 2;     Compteur somme;     while (deb < fin) {       if (deb % 2 == 1) {         somme = somme + a[deb];         deb++;       }       if (fin % 2 == 1) {         fin--;         somme = somme + a[fin];       }       deb /= 2;       fin /= 2;     }     return somme;   }   int conv[256];   int main() {     string chaine;     cin >> chaine;     conv[ A ] = 0;     conv[ T ] = 1;     conv[ G ] = 2;     conv[ C ] = 3;     for (int iTaille = 1; iTaille <= 10; iTaille++) {       for (int iMod = 0; iMod < iTaille; iMod++) {         arbres[iTaille - 1][iMod] = vector<Compteur>(             2 * getP2((chaine.size() + iTaille) / iTaille), Compteur());       }     }     for (int iCar = 0; iCar < chaine.size(); iCar++) {       Compteur nouv;       nouv.nbs[conv[chaine[iCar]]]++;       for (int iTaille = 1; iTaille <= 10; iTaille++) {         int mod = iCar % iTaille;         int pos = iCar / iTaille;         modif(arbres[iTaille - 1][mod], pos, nouv);       }     }     int nbReqs;     cin >> nbReqs;     for (int iReq = 0; iReq < nbReqs; iReq++) {       int type;       cin >> type;       if (type == 1) {         int iCar;         char val;         cin >> iCar >> val;         iCar--;         Compteur nouv;         nouv.nbs[conv[val]]++;         nouv.nbs[conv[chaine[iCar]]]--;         for (int iTaille = 1; iTaille <= 10; iTaille++) {           int mod = iCar % iTaille;           int pos = iCar / iTaille;           modif(arbres[iTaille - 1][mod], pos, nouv);         }         chaine[iCar] = val;       } else {         int deb, fin;         string comp;         cin >> deb >> fin >> comp;         deb--;         int iTaille = comp.size();         int somme = 0;         for (int iMod = 0; iMod < iTaille; iMod++) {           int mod = (deb + iMod) % iTaille;           int debPos = (deb + iMod) / iTaille;           int finPos = (fin - iTaille) / iTaille;           while (finPos * iTaille + mod < fin) {             finPos++;           }           Compteur vals = getSomme(arbres[iTaille - 1][mod], debPos, finPos);           somme += vals.nbs[conv[comp[iMod]]];         }         cout << somme << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, d, b;     char a, ch[3];     cin >> s;     long long i, j, ans, n, flag = 0;     a = s[0];     for (i = 1; i < s.size(); i++) {       if (s[i] ==  . ) continue;       if (s[i] ==  e ) {         flag = 1;       }       if (s[i] !=  e ) {         if (flag)           b.push_back(s[i]);         else           d.push_back(s[i]);       }     }     if (d.size() == 1 && d[0] ==  0 ) d.clear();     if (a ==  0 ) {       cout << a;       if (d.size()) cout <<  .  << d;       return 0;     }     for (i = 0; i < b.size(); i++) ch[i] = b[i];     long long pr = atoi(ch);     if (d.size() == pr) cout << a << d;     if (d.size() > pr) {       cout << a;       for (i = 0; i < d.size(); i++) {         if (i == pr) cout <<  . ;         cout << d[i];       }     }     if (pr > d.size()) {       if (a !=  0 ) cout << a;       for (i = 0; i < pr; i++) {         if (i < d.size())           cout << d[i];         else {           cout <<  0 ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int sz = 15000001;   int n;   int sieve[sz];   int v[300001];   int cnt[sz];   inline void solve() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &v[i]);     }     for (int i = 2; i < sz; i++)       if (sieve[i] == 0) {         for (int j = i; j < sz; j += i) sieve[j] = i;       }     for (int i = 0; i < n; i++) {       int x = v[i];       if (x == 1) continue;       vector<int> f;       while (x != 1) {         f.push_back(sieve[x]);         x /= sieve[x];       }       int cur = f[f.size() - 1];       cnt[cur]++;       for (int j = f.size() - 2; j >= 0; j--) {         if (f[j] == f[j + 1])           cur *= f[j];         else           cur = f[j];         cnt[cur]++;       }     }     int otv = n;     for (int i = 0; i < sz; i++) {       if (n != cnt[i]) otv = min(n - cnt[i], otv);     }     if (otv == n)       printf( %d , -1);     else       printf( %d , otv);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int q = 1;     for (; q > 0; q--) {       solve();       cout <<   n ;     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   template <typename T>   inline void rit(T &x) {     char c;     for (x = 0, c = getchar(); c <  - ; c = getchar())       ;     for (; c >=  0 ; x = x * 10 + c -  0 , c = getchar())       ;   }   int Q, op, x, c, p = 1;   long long int s[500001];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     rit(Q);     while (Q--) {       rit(op);       if (op == 1) {         s[c + 1] = s[c] + x, ++c, rit(x);       } else {         while (p < c && s[p] + x >= (s[p + 1] - s[p]) * p) ++p;         double ans = (double)x - (double)(s[p] + x) / p;         int a = ans;         cout << a <<  .  << setw(7) << setfill( 0 ) << (int)((ans - a) * 1e7)              <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   long long n;   int Q;   void ReadInput() {     cin >> n >> Q;     n *= 2LL;   }   long long Get(long long first) {     if (first % 2 == 1) return (first + 1) / 2;     return Get(first + (n - first) / 2);   }   void Solve() {     while (Q-- > 0) {       long long first;       cin >> first;       cout << Get(first) <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     ReadInput();     Solve();   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   string a[2005];   int common[2005][2005];   int main() {     std::ios::sync_with_stdio(false);     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++)         for (int k = 0; k < a[i].size() && k < a[j].size(); k++)           if (a[i][k] == a[j][k])             common[i][j] = k + 1;           else             break;     int ans = 0;     for (int i = 0; i < (1 << n); i++)       if (__builtin_popcount(i) == k) {         int cur = 0;         for (int j = 0; j < n; j++)           if (i & (1 << j))             for (int k = j + 1; k < n; k++)               if (i & (1 << k)) cur += common[j][k];         if (cur > ans) ans = cur;       }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void bfs(int v, vector<vector<int> > &graf, vector<vector<int> > &dist) {     queue<int> q;     q.push(v);     while (!q.empty()) {       int p = q.front();       q.pop();       for (int i = 0; i < graf[p].size(); i++) {         int to = graf[p][i];         if (dist[v][to] != 1e9) continue;         dist[v][to] = dist[v][p] + 1;         q.push(to);       }     }   }   struct ship {     int pos, attack, fuel;   };   struct base {     int pos, def;   };   vector<bool> used;   vector<int> lnk;   bool dfs(int v, vector<vector<int> > &vv) {     used[v] = 1;     for (int i = 0; i < vv[v].size(); i++) {       int u = vv[v][i];       if (lnk[u] == -1 || !used[lnk[u]] && dfs(lnk[u], vv)) {         lnk[u] = v;         return true;       }     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n, m;     cin >> n >> m;     vector<vector<int> > dist(n + 1, vector<int>(n + 1, 1e9));     vector<vector<int> > graf(n + 1);     for (int i = 0; i < m; i++) {       int first, t;       cin >> first >> t;       graf[first].push_back(t);       graf[t].push_back(first);     }     for (int i = 1; i <= n; i++) dist[i][i] = 0;     for (int i = 1; i <= n; i++) bfs(i, graf, dist);     int second, b, k, h;     cin >> second >> b >> k >> h;     vector<ship> ships(second);     for (int i = 0; i < second; i++) {       cin >> ships[i].pos >> ships[i].attack >> ships[i].fuel;     }     vector<base> bases(b);     for (int i = 0; i < b; i++) {       cin >> bases[i].pos >> bases[i].def;     }     vector<vector<int> > vv(second);     for (int i = 0; i < second; i++) {       for (int j = 0; j < b; j++) {         int d = dist[ships[i].pos][bases[j].pos];         if (d <= ships[i].fuel && bases[j].def <= ships[i].attack)           vv[i].push_back(j);       }     }     int ans = 0;     used.resize(second);     lnk.resize(b, -1);     for (int i = 0; i < second; i++) {       used.assign(n, 0);       if (dfs(i, vv)) ans++;     }     cout << min(1LL * ans * k, 1LL * second * h);   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   template <class T>   void chkmin(T &a, T b) {     if (a > b) a = b;   }   int n, s, m;   int a[2005];   int z[2005], id[2005];   int dp[2][2005], f[2][2005];   int nxt[2005], prv[2005];   int ans;   vector<int> v[2005];   int cnt;   int pos[2005];   bool cmp(int x, int y) { return a[x] > a[y]; }   int dist(int x, int y) {     if (x > y) swap(x, y);     return min(y - x, n - y + x);   }   int cdist(int x, int y) {     if (y <= x) return x - y;     return n - y + x;   }   void calc_dp() {     for (int x = m - 1; x >= 0; x--) {       for (int ii = 0; ii < v[x].size(); ii++) {         int i = v[x][ii];         if (a[i] == m - 1)           dp[1][i] = 0;         else {           dp[1][i] = INF;           for (int j = 0; j < n; j++) {             if (a[j] == a[i] + 1) {               if (dp[1][i] > dp[0][j] + dist(i, j)) {                 dp[1][i] = dp[0][j] + dist(i, j);                 f[1][i] = j;               }             }           }         }       }       for (int ii = 0; ii < v[x].size(); ii++) {         int i = v[x][ii];         if (v[x].size() == 1)           dp[0][i] = dp[1][i], f[0][i] = i;         else {           dp[0][i] = dp[1][prv[i]] + cdist(prv[i], i), f[0][i] = 0;           if (dp[0][i] > dp[1][nxt[i]] + cdist(i, nxt[i])) {             dp[0][i] = dp[1][nxt[i]] + cdist(i, nxt[i]);             f[0][i] = 1;           }         }       }     }     ans = INF;     int t = 0;     for (int i = 0; i < n; i++) {       if (a[i] == 0) {         if (ans > dp[0][i] + dist(i, s)) {           ans = dp[0][i] + dist(i, s);           t = i;         }       }     }     printf( %d n , ans);     if (cdist(s, t) == dist(s, t)) {       printf( -%d n , dist(s, t));     } else       printf( +%d n , dist(s, t));     int e = 0;     while (1) {       if (e == 0) {         if (prv[t] == t)           ;         else {           if (f[e][t] == 0) {             int tl = t, tr = nxt[t];             while (tr != t) {               printf( +%d n , cdist(tr, tl));               tr = nxt[tr], tl = nxt[tl];             }             t = prv[t];           } else {             int tl = prv[t], tr = t;             while (tl != t) {               printf( -%d n , cdist(tr, tl));               tr = prv[tr], tl = prv[tl];             }             t = nxt[t];           }         }       } else {         if (a[t] == m - 1)           break;         else {           if (cdist(t, f[e][t]) == dist(t, f[e][t])) {             printf( -%d n , dist(t, f[e][t]));           } else             printf( +%d n , dist(t, f[e][t]));           t = f[e][t];         }       }       e ^= 1;     }   }   int main() {     scanf( %d %d , &n, &s);     s--;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       z[m++] = a[i];       id[i] = i;     }     sort(z, z + m);     m = unique(z, z + m) - z;     for (int i = 0; i < n; i++) {       a[i] = lower_bound(z, z + m, a[i]) - z;       v[a[i]].push_back(i);     }     for (int i = 0; i < n; i++) {       if (v[a[i]].size() == 1)         nxt[i] = prv[i] = i;       else {         for (int j = 1; j < n; j++) {           if (a[(i + j) % n] == a[i]) prv[i] = (i + j) % n;           if (a[(i + n - j) % n] == a[i]) nxt[i] = (i + n - j) % n;         }       }     }     sort(id, id + n, cmp);     calc_dp();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool chk(int a, int b, int c, int sum) { return a + b + c == sum; }   int main() {     int sum = 0;     vector<int> u(6);     for (int i = 0; i < 6; i++) {       cin >> u[i];       sum += u[i];     }     if (sum % 2) {       cout <<  NO ;       return 0;     }     sum /= 2;     for (int a = 0; a < 6; a++)       for (int b = 0; b < 6; b++)         for (int c = 0; c < 6; c++)           if (a != b && b != c && a != c && u[a] + u[b] + u[c] == sum) {             cout <<  YES ;             return 0;           }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[100000], lim, n, flag;   void DFS(long long x, long long y) {     if (x > n) {       if (y == a[lim]) flag = 1;       return;     }     if (flag) return;     DFS(x + 1, y);     if (x != lim) {       DFS(x + 1, y + a[x]);       DFS(x + 1, y - a[x]);     }   }   inline void work() {     lim = flag = n = 0;     memset(a, 0, sizeof(a));     scanf( %lld , &n);     for (register long long i = 1; i <= n; ++i) scanf( %lld , &a[i]);     for (lim = 1; lim <= n; ++lim) {       DFS(1, 0);       if (flag) {         puts( YES );         return;       }     }     puts( NO );   }   signed main() {     long long T;     scanf( %lld , &T);     while (T--) work();   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const double eps = 1e-9;   vector<long long> prnum;   void sieve() {     bool prime[1000001];     memset(prime, true, sizeof(prime));     for (int i = 2; i * i <= 1000000; i++) {       if (prime[i] == true) {         for (int j = 2 * i; j <= 1000000; j += i) {           prime[j] = false;         }       }     }     for (int i = 2; i <= 1000000; i++) {       if (prime[i]) prnum.push_back(i);     }   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       if (k >= n) {         cout << 1 <<   n ;       } else {         long long ans = 1000000000;         for (long long i = 1; i * i <= n; i++) {           if (i > k) break;           if (n % i == 0) {             if ((n / i) <= k) {               ans = min(ans, i);             } else {               ans = min(ans, n / i);             }           }         }         cout << ans <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   signed main() {     long long n, sum = 0, temp;     multiset<long long> a;     cin >> n;     for (long long i = 0; i < n; ++i) {       cin >> temp;       a.insert(temp);     }     while (a.size() > 1) {       long long temp_sum = 0, sz = a.size();       for (long long j = 0; j < ((sz % 2 == 0) ? 2 : min(3ll, sz)); ++j) {         temp_sum += *a.begin();         a.erase(a.begin());       }       sum += temp_sum;       a.insert(temp_sum);     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 0;     char ch = getchar();     while (!isdigit(ch)) f |= ch ==  - , ch = getchar();     while (isdigit(ch)) x = 10 * x + ch -  0 , ch = getchar();     return f ? -x : x;   }   template <typename T>   void print(T x) {     if (x < 0) putchar( - ), x = -x;     if (x >= 10) print(x / 10);     putchar(x % 10 +  0 );   }   template <typename T>   void print(T x, char let) {     print(x), putchar(let);   }   const int maxn = 2e5 + 5;   const int mn = (1 << 18) - 1;   int n, a[maxn], b[mn], f[mn], sz[mn];   int find(int k) {     if (f[k] == k) return k;     return f[k] = find(f[k]);   }   void merge(int a, int b) {     int fa = find(a);     int fb = find(b);     if (sz[fa] <= sz[fb]) {       f[fa] = fb;       sz[fb] += sz[fa];     } else {       f[fb] = fa;       sz[fa] += sz[fb];     }   }   int main() {     n = read();     long long sum1 = 0;     for (int i = 1; i <= n; i++) {       a[i] = read();       sum1 += a[i];       b[a[i]]++;     }     b[0]++;     for (int i = 0; i <= mn; i++) f[i] = i;     long long sum = 0;     for (int i = mn; i >= 1; i--) {       if (b[0] > 0 && b[i] > 0 && find(0) != find(i)) {         merge(0, i);         sum += (long long)(b[0] + b[i] - 1) * i;         b[0] = b[i] = 1;       }       for (int j = i; j; j = (j - 1) & i) {         int k = i ^ j;         if (b[j] > 0 && b[k] > 0 && find(j) != find(k)) {           merge(j, k);           sum += (long long)(b[j] + b[k] - 1) * i;           b[j] = b[k] = 1;         }       }     }     cout << sum - sum1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int x, y;     cin >> x >> y;     int u = 0, v = 0, turns = 0, flag = 1, c = 1;     while (1) {       if (u == x and v == y) break;       if (flag == 1) {         int d = 0;         while (d != c) {           u++;           if (u == x and v == y) break;           d++;         }         flag = 2;         if (u != x or v != y) turns++;       } else if (flag == 2) {         int d = 0;         while (d != c) {           v++;           if (u == x and v == y) break;           d++;         }         if (u != x or v != y) turns++;         flag = 3;         c++;       } else if (flag == 3) {         int d = 0;         while (d != c) {           u--;           if (u == x and v == y) break;           d++;         }         flag = 4;         if (u != x or v != y) turns++;       } else if (flag == 4) {         int d = 0;         while (d != c) {           v--;           if (u == x and v == y) break;           d++;         }         c++;         flag = 1;         if (u != x or v != y) turns++;       }     }     cout << turns;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string line;     int persons = 0;     int data = 0;     while (getline(cin, line)) {       if (line[0] ==  + )         ++persons;       else if (line[0] ==  - )         --persons;       else         data += (line.size() - line.find( : ) - 1) * persons;     }     cout << data << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string s;   int l = 0, u = 0, d = 0;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       int l = -1, u = -1, d = -1;       cin >> s;       for (int j = 0; j < s.length(); j++) {         if (isdigit(s[j])) d = j;         if (islower(s[j])) l = j;         if (isupper(s[j])) u = j;       }       if (d == -1)         for (int j = 0; j < s.length(); j++)           if (j != l && j != u) {             s[j] =  4 ;             d = j;             break;           }       if (l == -1)         for (int j = 0; j < s.length(); j++)           if (j != d && j != u) {             s[j] =  a ;             l = j;             break;           }       if (u == -1)         for (int j = 0; j < s.length(); j++)           if (j != l && j != d) {             s[j] =  A ;             u = j;             break;           }       cout << s << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int count = 0;     cin >> n;     for (int i = 0; i < n; i++) {       string a;       cin >> a;       if (a ==  ABSINTH  || a ==  BEER  || a ==  BRANDY  || a ==  CHAMPAGNE  ||           a ==  GIN  || a ==  RUM  || a ==  SAKE  || a ==  TEQUILA  ||           a ==  VODKA  || a ==  WHISKEY  || a ==  WINE  || a ==  0  || a ==  1  ||           a ==  2  || a ==  3  || a ==  4  || a ==  5  || a ==  6  || a ==  7  ||           a ==  8  || a ==  9  || a ==  10  || a ==  11  || a ==  12  ||           a ==  13  || a ==  14  || a ==  15  || a ==  16  || a ==  17 )         count++;     }     cout << count;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int a, b;     cin >> a >> b;     int c = min(a, b);     a = max(a, b) - c;     cout << c <<     << a / 2;     ;   }   int main() {     int count = 1;     while (count--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long modpower(long long n, long long k) {     long long res = 1;     while (k) {       if (k & 1) res = (res * n) % 1000000009;       k >>= 1;       n = (n * n) % 1000000009;     }     return res;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     long long a[n];     bool f = 0;     for (long long i = 0; i < n; ++i) {       cin >> a[i];       if (a[i] != 1) f = 1;     }     sort(a, a + n);     if (!f) {       for (long long i = 0; i < n - 1; ++i) {         cout << a[i] <<    ;       }       cout << 2;       return 0;     }     cout << 1 <<    ;     for (long long i = 0; i < n - 1; ++i) {       cout << a[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   vector<vector<int> > g;   vector<int> depth;   void dfs(int v, int d = 0) {     depth[v] = d;     for (int to : g[v]) {       if (depth[to] == -1) {         dfs(to, d + 1);       }     }   }   int main() {     int n, m;     cin >> n >> m;     g.resize(n);     for (int i = 0; i < m; ++i) {       int u, v;       cin >> u >> v;       --u, --v;       g[u].push_back(v);       g[v].push_back(u);     }     depth.assign(n, -1);     dfs(0);     int v = 0;     for (int i = 1; i < n; ++i) {       if (depth[i] > depth[v]) {         v = i;       }     }     depth.assign(n, -1);     dfs(v);     int ans = 0;     for (int i = 0; i < n; ++i) {       ans = max(ans, depth[i]);     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   class strocks {    public:     string strocksguy() {}   };   int main() {     strocks strocks;     iostream::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     string s, d;     unordered_map<string, string> master;     for (long long i = 0; i < m; i++) {       cin >> s >> d;       if (s.size() > d.size()) {         master.insert(make_pair(s, d));       } else         master.insert(make_pair(d, s));     }     for (long long i = 0; i < n; i++) {       cin >> s;       if (master.find(s) != master.end())         cout << master.at(s) <<    ;       else         cout << s <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   const int N = 100005;   int n, m, k;   vector<int> adj[N];   int cnt[N];   int mark[N];   int pass;   int aux[N];   bool ta[N];   bool clique(int x) {     pass++;     mark[x] = pass;     int id = 0;     for (int i : adj[x])       if (!ta[i]) {         mark[i] = pass;         aux[id++] = i;       }     for (int i = 0; i < id; i++) {       for (int j = i + 1; j < id; j++) {         if (!binary_search(adj[aux[i]].begin(), adj[aux[i]].end(), aux[j]))           return 0;       }     }     return 1;   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       scanf( %d %d %d , &n, &m, &k);       for (int i = 1; i <= n; i++) {         adj[i].clear();         cnt[i] = 0;         ta[i] = 0;       }       for (int i = 0; i < m; i++) {         int a, b;         scanf( %d %d , &a, &b);         adj[a].push_back(b);         adj[b].push_back(a);         cnt[b]++;         cnt[a]++;       }       for (int i = 1; i <= n; i++) {         sort(adj[i].begin(), adj[i].end());       }       priority_queue<ii> pq;       for (int i = 1; i <= n; i++) {         pq.push({-cnt[i], i});       }       bool ok = 0;       while (1) {         if (pq.empty()) break;         int c, x;         tie(c, x) = pq.top();         c = -c;         if (c != cnt[x]) {           pq.pop();           continue;         }         if (c >= k) {           vector<int> ans;           while (!pq.empty()) {             int c, x;             tie(c, x) = pq.top();             c = -c;             pq.pop();             if (c != cnt[x]) {               continue;             }             ans.push_back(x);           }           printf( 1 %d n , (int)ans.size());           for (int i : ans) {             printf( %d  , i);           }           printf(  n );           ok = 1;           break;         }         pq.pop();         if (c == k - 1) {           if (clique(x)) {             printf( 2 n );             printf( %d , x);             for (int i : adj[x])               if (!ta[i]) {                 printf(  %d , i);               }             printf(  n );             ok = 1;             break;           }         }         cnt[x] = 0;         ta[x] = 1;         for (int i : adj[x])           if (cnt[i]) {             cnt[i]--;             pq.push({-cnt[i], i});           }       }       if (!ok) {         printf( -1 n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ara[1000];   int rf[1000];   int main() {     int n, i, f, w, cnt = 0, m, r;     char str[1000001];     scanf( %d %d , &n, &m);     scanf( %s , str);     for (i = 0; i < n; i++) {       r = str[i];       ara[r] = ara[r] + 1;     }     for (i = 0; i < n; i++) {       r = str[i];       if (rf[r] == 0) {         cnt++;         rf[r] = 1;         if (cnt > m) {           printf( YES );           return 0;         }       }       ara[r] = ara[r] - 1;       if (ara[r] == 0) {         cnt--;       }     }     printf( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const long long mint = 0x7fffffff;   const long long linf = 1000000000000000000LL;   const long long mod = 1000000007LL;   const double eps = 1e-3;   const int N = 1000020;   inline long long read() {     long long x = 0, 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();     }     return x * f;   }   long long qpow(long long a, long long b, long long m) {     long long ans = 1;     while (b > 0) {       if (b & 1) {         ans = ans * a % m;       }       a = a * a % m;       b >>= 1;     }     return ans;   }   int main(void) {     for (int _ = read(); _ > 0; _--) {       int n = read();       long long p = read();       vector<long long> k(n);       long long b = 0;       for (int i = 0; i < n; i++) k[i] = read();       sort(k.begin(), k.end(), greater<long long>());       long long q = 1;       bool f = false;       if (p == 1) {         printf( %d n , n % 2 == 1 ? 1 : 0);         continue;       }       long long now = k[0];       b = 1;       int i = 1;       for (; i < n; i++) {         if (b == 0)           now = k[i];         else           while (now > k[i] && !f) {             if (b >= n) {               f = true;               break;             }             b = b * p;             now--;           }         if (f) {           break;         } else {           if (b > 0)             b--;           else             b++;         }       }       long long ans = b % mod * qpow(p, now, mod) % mod;       for (; i < n; i++) ans = (ans + (mod - 1) * qpow(p, k[i], mod) % mod) % mod;       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   long long n;   long long a[N], b[N], c[N];   bool check() {     bool check = 0;     for (long long i = 1; i <= n; i++)       if (a[i] != b[i]) check = 1;     bool check2 = 0;     for (long long i = 1; i <= n; i++)       if (a[i] != c[i]) check2 = 1;     return check & check2;   }   void work() {     for (long long i = 1; i <= n - 1; i++) {       if (a[i] != a[i + 1]) {         swap(a[i], a[i + 1]);         if (check()) {           cout << i <<     << i + 1;           exit(0);         }         swap(a[i], a[i + 1]);       }     }   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       b[i] = a[i];       c[i] = b[i];     }     sort(b + 1, b + n + 1);     sort(c + 1, c + n + 1, greater<long long>());     work();     cout <<  -1 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, dem;   string s;   void setup() {}   void solve() {     cin >> n;     cin >> s;     if (n == 1)       cout << s;     else {       for (int i = 0; i <= n - 1; ++i) dem += s[i] ==  0 ;       cout << 1;       for (int i = 1; i <= dem; ++i) cout << 0;     }   }   int main() {     setup();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long f[100], f0[100];   int main() {     int n, k, m;     scanf( %d %d %d , &n, &k, &m);     for (int i = 1; i < k; i++) f0[i] = 0, f[i] = 0;     int tmp = 1;     long long ans = 0;     for (int i = 0; i < n; i++) {       f0[0] = 1;       for (int j = 0; j < k; j++)         if (f0[j] > 0) {           for (int p = 0; p < 10; p++) {             f[(p * tmp + j) % k] = (f[(p * tmp + j) % k] + f0[j]) % m;           }         }       tmp = tmp * 10 % k;       long long asd = 1;       for (int j = i + 1; j < n - 1; j++) asd = asd * 10 % m;       if (i + 1 < n) asd = (asd * 9) % m;       ans = (ans + asd * (f[0] - 1) + m) % m;       f[0] = 0;       memcpy(f0, f, sizeof f0);       memset(f, 0, sizeof f);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n;     cin >> n;     long long int a[n];     for (long long int i = 0; i < n; i++) cin >> a[i];     long long int m;     cin >> m;     long long int num1[m], num2[m];     for (long long int i = 0; i < m; i++) {       cin >> num1[i] >> num2[i];     }     for (long long int i = 0; i < m; i++) {       long long int x = num1[i] - 1;       long long int y = num2[i];       if (x - 1 >= 0) {         a[x - 1] += y - 1;       }       if (x + 1 < n) {         a[x + 1] += a[x] - y;       }       a[x] = 0;     }     for (long long int i = 0; i < n; i++) cout << a[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e16;   const long long maxn = 128;   const long long maxlog = 60;   long long a, b;   string s, t;   long long dp[maxlog][maxn];   long long ans;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> a >> b;     cin >> s >> t;     string S =   ;     for (long long i = 100; i--; S += s)       ;     for (long long i = 0; i < s.size(); i++) {       long long p1 = 0, p2 = i;       for (; p1 < t.size(); p1++, p2++) {         for (; p2 < S.size() and S[p2] != t[p1]; p2++)           ;         if (p2 == S.size()) break;       }       if (p1 == t.size())         dp[0][i] = p2 - i;       else         dp[0][i] = inf;     }     for (long long j = 1; j < maxlog; j++)       for (long long i = 0; i < s.size(); i++)         dp[j][i] =             min(dp[j - 1][i] + dp[j - 1][(i + dp[j - 1][i]) % s.size()], inf);     long long len = 0;     for (long long j = maxlog; j--;)       if (dp[j][len % s.size()] + len <= a * s.size())         ans |= 1ll << j, len = len + dp[j][len % s.size()];     cout << ans / b << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   template <typename T>   using vec = vector<T>;   template <typename T>   using Prior = priority_queue<T>;   template <typename T>   using prior = priority_queue<T, vector<T>, greater<T>>;   const int INF = 1e9;   const int nINF = -1e9;   const ll llINF = 4 * 1e18;   const int MOD = 1e9 + 7;   ll& pmod(ll& a, ll b) {     a = (a + b) % MOD;     return a;   }   ll& pmod(ll& a, ll b, ll c) {     a = (a + b) % c;     return a;   }   ll& mmod(ll& a, ll b) {     a = (a - b + MOD) % MOD;     return a;   }   ll& mmod(ll& a, ll b, ll c) {     a = (a - b + c) % c;     return a;   }   ll& tmod(ll& a, ll b) {     a = (a * b) % MOD;     return a;   }   ll mul(ll a, ll b) { return (a * b) % MOD; }   ll mul(ll a, ll b, ll c) { return (a * b) % c; }   ll POW(ll a, ll b) {     ll res = 1;     do {       if (b % 2) tmod(res, a);       tmod(a, a);     } while (b >>= 1);     return res;   }   ll FAC(ll a) {     ll res = 1;     for (int i = 1; i <= a; i++) tmod(res, i);     return res;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2> a) {     cout << a.first <<     << a.second;     return out;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0);     int n;     cin >> n;     vec<int> _list(n);     for (auto& i : _list) cin >> i;     if (n % 2) {       cout <<  YES n ;       cout << n - 2 <<   n ;       for (int i = 0; i < n - 2; i += 2)         cout << i + 1 <<     << i + 2 <<     << i + 3 <<   n ;       for (int i = 0; i < n - 3; i += 2)         cout << i + 1 <<     << i + 2 <<     << n <<   n ;     } else {       int tmp = 0, idx = -1;       for (int i = 0; i < n; i++) {         tmp ^= _list[i];         if (_list[i]) idx = i;       }       if (tmp != 0)         cout <<  NO n ;       else {         cout <<  YES n ;         cout << n - 2 <<   n ;         for (int i = 0; i < n - 2; i += 2)           cout << i + 1 <<     << i + 2 <<     << i + 3 <<   n ;         for (int i = 0; i < n - 3; i += 2)           cout << i + 1 <<     << i + 2 <<     << n <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long int M = 100 + 5, SM = 600;   const long long int inf = 1e18;   const long long int lg = 18;   const long long int z = 26;   long long int dp[M][M][M];   string dps[M][M][M];   long long int x;   long long int nxt[M][z];   long long int tt = 1;   long long int f[M];   long long int insert(string s) {     long long int p = 0;     for (char c : s) {       if (nxt[p][c -  A ] == 0) {         nxt[p][c -  A ] = tt++;       }       p = nxt[p][c -  A ];     }     return p;   }   int main() {     string s, t, virus;     cin >> s >> t;     long long int n = ((long long int)s.size());     long long int m = ((long long int)t.size());     cin >> virus;     long long int vi = insert(virus);     {       queue<long long int> q;       for (long long int i = 0; i < 26; i++) {         if (nxt[0][i] != 0) q.push(nxt[0][i]);       }       while (((long long int)q.size()) > 0) {         long long int x = q.front();         q.pop();         for (long long int i = 0; i < 26; i++) {           if (nxt[x][i] == 0)             nxt[x][i] = nxt[f[x]][i];           else {             f[nxt[x][i]] = nxt[f[x]][i];             q.push(nxt[x][i]);           }         }       }     }     for (long long int i = 1; i < n + 1; i++) {       for (long long int j = 1; j < m + 1; j++) {         if (s[i - 1] == t[j - 1]) {           for (long long int k = 0; k < tt; k++) {             long long int d = nxt[k][s[i - 1] -  A ];             if (k == vi || d == vi) continue;             if (dp[i][j][d] < dp[i - 1][j - 1][k] + 1) {               dp[i][j][d] = dp[i - 1][j - 1][k] + 1;               dps[i][j][d] = dps[i - 1][j - 1][k] + s[i - 1];             }           }         }         for (long long int k = 0; k < tt; k++) {           if (dp[i][j][k] < dp[i][j - 1][k]) {             dp[i][j][k] = dp[i][j - 1][k];             dps[i][j][k] = dps[i][j - 1][k];           }           if (dp[i][j][k] < dp[i - 1][j][k]) {             dp[i][j][k] = dp[i - 1][j][k];             dps[i][j][k] = dps[i - 1][j][k];           }         }       }     }     long long int res = 0;     string pes =   ;     for (long long int k = 0; k < tt; k++) {       if (k != vi) {         if (res < dp[n][m][k]) {           res = dp[n][m][k];           pes = dps[n][m][k];         }       }     }     cout << (pes ==    ?  0  : pes);   }


#include <bits/stdc++.h>   using namespace std;   void candy(int x, int y) {     int d = 1;     bool flag = true;     while (x >= 0 && y >= 0) {       if (flag) {         x = x - d;         d++;         flag = false;       } else {         y = y - d;         d++;         flag = true;       }       if (flag == true && x < d) {         cout <<  Vladik  << endl;         break;       } else if (flag == false && y < d) {         cout <<  Valera  << endl;         break;       }     }   }   int main(int argc, char** argv) {     int a, b;     cin >> a >> b;     candy(a, b);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, r1, c1, r2, c2;   char a[120][120];   int main() {     cin >> n >> m;     bool sign = true;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> a[i][j];     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (a[i][j] ==  B ) {           if (sign) {             r1 = i;             c1 = j;             sign = false;           }           r2 = i;           c2 = j;         }     cout << (r1 + r2) / 2 <<     << (c1 + c2) / 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   const long long MOD = 1e9 + 7;   const int INF = 1e9;   template <class T>   inline T gcd(T a, T b) {     if (a < 0) return gcd(-a, b);     if (b < 0) return gcd(a, -b);     return (b == 0) ? a : gcd(b, a % b);   }   template <class T>   inline T lcm(T a, T b) {     if (a < 0) return lcm(-a, b);     if (b < 0) return lcm(a, -b);     return a * (b / gcd(a, b));   }   int a, b;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> a >> b;     int t = gcd(a, b);     a /= t;     b /= t;     if (abs(a - b) <= 1) return puts( Equal );     puts(a < b ?  Dasha  :  Masha );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {-1, 0, 1, 0};   int dy[] = {0, 1, 0, -1};   vector<int> f, col, wlk;   int Find(int a) {     if (f[a] == a) return a;     int fa = Find(f[a]);     f[a] = fa;     return fa;   }   void Union(int a, int b) {     int fa = Find(a);     int fb = Find(b);     if (fa == fb) return;     wlk[fa] += wlk[fb];     f[fb] = f[fa];   }   int main() {     ios_base::sync_with_stdio(0);     int n, m;     cin >> n >> m;     vector<vector<int> > pan(3 * n, vector<int>(3 * m, 0));     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) cin >> pan[n + i][m + j];     vector<vector<int> > sym(3 * n, vector<int>(3 * m, -1));     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) cin >> sym[n + i][m + j];     int x, y;     cin >> x >> y;     x = x - 1 + n;     y = y - 1 + m;     vector<vector<int> > spi(3 * n, vector<int>(3 * m));     spi[x][y] = 0;     int nr = 1, ileMam = 1, d = 1;     int akt_x = x, akt_y = y;     while (ileMam < 9 * n * m) {       for (int kier = 0; kier < 4; ++kier) {         for (int i = 0; i < d; ++i) {           akt_x += dx[kier];           akt_y += dy[kier];           if (akt_x >= 0 && akt_x < 3 * n && akt_y >= 0 && akt_y < 3 * m) {             spi[akt_x][akt_y] = nr;             ++ileMam;           }           ++nr;         }         if (kier == 1 || kier == 3) ++d;       }     }     map<int, vector<pair<int, pair<int, int> > > > M;     map<int, pair<int, int> > gdzieCol;     for (int i = 0; i < 3 * n; ++i) {       for (int j = 0; j < 3 * m; ++j) {         gdzieCol[pan[i][j]] = make_pair(i, j);         M[pan[i][j]].push_back(make_pair(-1, make_pair(i, j)));         int H = i * 3 * m + j;         f.push_back(H);         col.push_back(pan[i][j]);         wlk.push_back(1);         if (M.find(pan[i][j]) != M.end()) {           int Hroot = (M[pan[i][j]][0]).second.first * 3 * m +                       (M[pan[i][j]][0]).second.second;           Union(Hroot, H);         }       }     }     long long odp = 0;     queue<pair<int, int> > Q;     Q.push(make_pair(x, y));     while (!Q.empty()) {       pair<int, int> akt = Q.front();       Q.pop();       int colPan = col[Find(akt.first * 3 * m + akt.second)];       int colSym = sym[akt.first][akt.second];       if (colPan == 0 || colPan == colSym) continue;       if (M[colPan].size() != 0) {         for (int i = 0; i < M[colPan].size(); ++i) {           int wx = akt.first - x;           int wy = akt.second - y;           wx *= -1;           wy *= -1;           M[colPan][i].first = spi[M[colPan][i].second.first + wx]                                   [M[colPan][i].second.second + wy];         }         sort(M[colPan].begin(), M[colPan].end());         for (int i = 0; i < M[colPan].size(); ++i)           if ((M[colPan][i].second.first != x ||                M[colPan][i].second.second != y) &&               sym[M[colPan][i].second.first][M[colPan][i].second.second] != -1)             Q.push(M[colPan][i].second);         M[colPan].clear();       }       odp += wlk[Find(akt.first * 3 * m + akt.second)];       if (gdzieCol.find(colSym) != gdzieCol.end() && gdzieCol[colSym].first != -1)         Union(gdzieCol[colSym].first * 3 * m + gdzieCol[colSym].second,               akt.first * 3 * m + akt.second);       else {         col[Find(akt.first * 3 * m + akt.second)] = colSym;         gdzieCol[colSym] = akt;       }       gdzieCol[colPan] = make_pair(-1, -1);     }     cout << odp;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long A[200010], sz[200010], v[200010][11];   vector<long long> l[11];   class Timer {    private:     using clock_t = std::chrono::high_resolution_clock;     using second_t = std::chrono::duration<double, std::ratio<1> >;     std::chrono::time_point<clock_t> m_beg;       public:     Timer() : m_beg(clock_t::now()) {}     void reset() { m_beg = clock_t::now(); }     double elapsed() const {       return std::chrono::duration_cast<second_t>(clock_t::now() - m_beg).count();     }   } T;   long long cnt(long long x) {     long long r = 0;     while (x) r++, x /= 10;     return r;   }   void precompute(long long n, long long k) {     for (long long i = 0; i < n; i++) {       sz[i] = cnt(A[i]);       long long x = A[i];       v[i][0] = x;       for (long long j = 1; j < 11; j++) x = (x * 10) % k, v[i][j] = x;       A[i] %= k;     }   }   void put(long long i) {     l[sz[i]].push_back(A[i]);     return;   }   long long binary(long long T, long long mod) {     long long L = 0, R = (long long)l[T].size() - 1, ans1 = -1;     while (L <= R) {       long long mid = (L + R) >> 1;       if (l[T][mid] == mod)         ans1 = mid, R = mid - 1;       else if (l[T][mid] > mod)         R = mid - 1;       else         L = mid + 1;     }     if (ans1 == -1) return 0;     L = 0, R = (long long)l[T].size() - 1;     long long ans2 = -1;     while (L <= R) {       long long mid = (L + R) >> 1;       if (l[T][mid] == mod)         ans2 = mid, L = mid + 1;       else if (l[T][mid] > mod)         R = mid - 1;       else         L = mid + 1;     }     return (ans2 - ans1 + 1);   }   long long get(long long idx, long long k) {     long long ans = 0LL;     for (long long i = 1; i < 11; i++) {       long long x = v[idx][i];       ans += binary(i, (k - x) % k);       if (i == sz[idx] && (v[idx][i] + A[idx]) % k == 0) ans--;     }     return ans;   }   signed main() {     long long n, k;     scanf( %I64d %I64d , &n, &k);     for (long long i = 0; i < n; i++) scanf( %I64d , &A[i]);     precompute(n, k);     for (long long i = 0; i < n; i++) put(i);     for (long long i = 1; i < 11; i++) sort(l[i].begin(), l[i].end());     long long ans = 0;     for (long long i = 0; i < n; i++) ans += get(i, k);     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     char c = getchar();     int x = 0, f = 1;     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     return x * f;   }   const int MAXN = 3e2 + 5;   const int MAXQ = 2e6 + 5;   struct Query {     int x, y, nc, oc;   } q[MAXQ];   int fa[MAXQ << 1], ans[MAXQ], a[MAXN][MAXN], id[MAXN][MAXN];   int N, M, Q, Num, cnt;   inline int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }   inline int mrg(int x, int y) {     if (find(x) != find(y)) {       fa[fa[x]] = fa[y];       Num--;     }   }   inline void check(int x, int y) {     if (a[x][y] == a[x - 1][y]) mrg(id[x][y], id[x - 1][y]);     if (a[x][y] == a[x + 1][y]) mrg(id[x][y], id[x + 1][y]);     if (a[x][y] == a[x][y - 1]) mrg(id[x][y], id[x][y - 1]);     if (a[x][y] == a[x][y + 1]) mrg(id[x][y], id[x][y + 1]);   }   inline void solveTo() {     for (int i = 1; i <= Q; i++) {       if (q[i].oc == q[i].nc) continue;       int x = q[i].x, y = q[i].y;       Num = 1;       a[x][y] = q[i].nc;       id[x][y] = ++cnt;       fa[cnt] = cnt;       check(x, y);       ans[i] += Num;     }   }   inline void solveBack() {     for (int i = Q; i; i--) {       if (q[i].oc == q[i].nc) continue;       int x = q[i].x, y = q[i].y;       Num = 1;       a[x][y] = q[i].oc;       id[x][y] = ++cnt;       fa[cnt] = cnt;       check(x, y);       ans[i] -= Num;     }   }   int main() {     N = read();     M = read();     Q = read();     for (int i = 1; i <= Q; i++) {       int x = read(), y = read(), z = read();       q[i] = {x, y, z, a[x][y]};       a[x][y] = z;     }     ans[0] = 1;     cnt = 0;     memset(a, -1, sizeof(a));     for (int i = 1; i <= N; i++)       for (int j = 1; j <= M; j++) a[i][j] = 0;     solveTo();     memset(fa, cnt = 0, sizeof(fa));     for (int i = 1; i <= N; i++)       for (int j = 1; j <= M; j++) {         id[i][j] = ++cnt;         fa[cnt] = cnt;       }     for (int i = 1; i <= N; i++)       for (int j = 1; j <= M; j++) check(i, j);     solveBack();     for (int i = 1; i <= Q; i++) {       ans[i] += ans[i - 1];       printf( %d n , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   long long int myRand(long long int B) { return (unsigned long long)rng() % B; }   struct UnionFind {     vector<int> par, num;     vector<bool> done;     UnionFind(int n) : par(n), num(n, 1), done(n, false) {       iota(par.begin(), par.end(), 0);     }     int find(int v) { return (par[v] == v) ? v : (par[v] = find(par[v])); }     void unite(int u, int v) {       u = find(u), v = find(v);       if (u == v) return;       if (num[u] < num[v]) swap(u, v);       num[u] += num[v];       par[v] = u;       done[u] = done[u] | done[v];     }     bool same(int u, int v) { return find(u) == find(v); }     bool ispar(int v) { return v = find(v); }     int size(int v) { return num[find(v)]; }   };   const int BS = 524288;   int CNT, rc;   char inb[BS];   inline char gchar(void) {     if (CNT % BS == 0) {       CNT = 0;       rc = fread(inb, 1, BS, stdin);     }     return CNT < rc ? inb[CNT++] : 0;   }   inline int _readint(int *ptr) {     int n = 0, c = 0;     *ptr = 0;     while (1) {       char read = gchar();       if (read >=  0  && read <=  9 )         read -=  0 , n *= 10, n += read;       else {         *ptr = n;         return n == 0 ? 0 : !c;       }       c++;     }     *ptr = n;     return 0;   }   inline int readint(void) {     int ptr;     while (_readint(&ptr))       ;     return ptr;   }   int main() {     cin.tie(nullptr);     ios::sync_with_stdio(false);     int n, m, q;     cin >> n >> m >> q;     vector<int> x(m), y(m), w(m);     vector<pair<int, int>> v(m);     for (int i = 0; i < m; i++) {       cin >> x[i] >> y[i] >> w[i];       x[i]--;       y[i]--;       v[i] = make_pair(w[i], i);     }     sort(v.rbegin(), v.rend());     while (q--) {       int l, r;       cin >> l >> r;       l--;       int res = -1;       UnionFind uf(2 * n);       for (int i = 0; i < v.size(); i++) {         if (v[i].second < l || r <= v[i].second) continue;         int id = v[i].second;         if (uf.same(x[id], y[id])) {           res = v[i].first;           break;         } else {           uf.unite(x[id], y[id] + n);           uf.unite(x[id] + n, y[id]);         }       }       printf( %d n , res);     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   string S;   long long dp[222][222];   long long GetAnswer(int pos, int numdigs) {     if (pos == S.size()) {       if (numdigs == 0)         return 0;       else         return -1;     }     if (numdigs == 0) return -1;     if (dp[pos][numdigs] != -2) return dp[pos][numdigs];     long long ret = -1;     long long x = 0;     if ((numdigs - 1.0) * log(n) > log(1400000000000000000ll))       return dp[pos][numdigs] = -1;     long long npow = 1;     for (int j = 0; j < numdigs - 1; j++) npow *= n;     if (npow > 1000000000000000000ll) return dp[pos][numdigs] = -1;     for (int j = pos; j < S.size(); j++) {       if (S[pos] ==  0  && j > pos) break;       x = x * 10 + S[j] -  0 ;       if (x >= n) break;       long long curr = GetAnswer(j + 1, numdigs - 1);       if (curr == -1 || curr > 1000000000000000000ll ||           x > 1000000000000000000ll / npow)         continue;       if (log(x) + (numdigs - 1.0) * log(n) > log(1400000000000000000ll - curr))         continue;       curr += x * npow;       if (curr <= 1000000000000000000ll && (ret == -1 || curr < ret)) ret = curr;     }     return dp[pos][numdigs] = ret;   }   int main() {     cin >> n >> S;     long long answer = -1;     for (int j = 0; j < 222; j++)       for (int k = 0; k < 222; k++) dp[j][k] = -2;     for (int numdigs = 1; numdigs <= 61; numdigs++) {       long long curr = GetAnswer(0, numdigs);       if (curr == -1) continue;       if (answer == -1 || (curr < answer)) answer = curr;     }     cout << answer << endl;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     int n, h;     cin >> n >> h;     vector<int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     int lo = 0;     int hi = n - 1;     int ans, mid;     while (lo <= hi) {       mid = lo + (hi - lo) / 2;       vector<int> a(mid + 1);       for (int i = 0; i < mid + 1; i++) a[i] = v[i];       sort(a.begin(), a.end());       int c = 0;       int j = mid;       int leftheight = h;       while (j >= 0 && leftheight > 0) {         if (a[j] <= leftheight) {           leftheight -= a[j];           if (mid % 2 == 0 && j == 0) {             c++;             break;           } else {             j -= 2;             c += 2;           }         } else           break;       }       if (c >= (mid + 1)) {         lo = mid + 1;         ans = mid;       } else         hi = mid - 1;     }     cout << ans + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, flag, ln, prv = -1;   char in[100010][20], pr[100010][20];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %s , in[i]);       ln = strlen(in[i]);       flag = 0;       if (ln < prv) {         printf( NO n );         return 0;       } else if (i == 0 || ln > prv) {         for (int j = 0; j < ln; j++) {           if (j == 0 && in[i][j] ==  ? )             pr[i][j] =  1 ;           else if (in[i][j] ==  ? )             pr[i][j] =  0 ;           else             pr[i][j] = in[i][j];         }       } else {         for (int j = 0; j < ln; j++) {           if (in[i][j] ==  ? ) {             if (flag == 0)               pr[i][j] = pr[i - 1][j];             else               pr[i][j] =  0 ;           } else if (in[i][j] > pr[i - 1][j]) {             pr[i][j] = in[i][j];             flag = 1;           } else if (in[i][j] < pr[i - 1][j] && flag == 0) {             for (int x = j - 1; x >= 0; x--) {               if (in[i][x] ==  ?  && pr[i][x] <  9 ) {                 pr[i][x]++;                 for (int z = x + 1; z < j; z++)                   if (in[i][z] ==  ? ) pr[i][z] =  0 ;                 flag = 1;                 break;               }             }             if (flag == 0) {               printf( NO n );               return 0;             }             pr[i][j] = in[i][j];           } else             pr[i][j] = in[i][j];         }         if (flag == 0) {           for (int j = ln - 1; j >= 0; j--) {             if (in[i][j] ==  ?  && pr[i][j] <  9 ) {               pr[i][j]++;               for (int z = j + 1; z < ln; z++)                 if (in[i][z] ==  ? ) pr[i][z] =  0 ;               flag = 1;               break;             }           }           if (flag == 0) {             printf( NO n );             return 0;           }         }       }       prv = ln;     }     printf( YES n );     for (int i = 0; i < n; i++) printf( %s n , pr[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pi = pair<int, int>;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout << setprecision(15) << fixed;     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     sort(a.begin(), a.end());     int x = a[0];     for (int i = 1; i < n; i++) {       if (a[i] != x) {         if (a[i] < 30) {           ll y = (1ll << x) - 1;           if (y * y > (1ll << a[i]) - 1) {             cout <<  YES n ;             return 0;           }         } else if (2 * x > a[i]) {           cout <<  YES n ;           return 0;         }         x = a[i];       }     }     cout <<  NO n ;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXL = 5e5 + 1e3;   int n, t;   char dat[MAXL + 1];   int main() {     int n;     while (scanf( %d%d%s , &n, &t, dat) >= 1) {       int hl = n, hr = -1, hcnt = 0;       vector<int> shops;       for (int i = 0; i < n; i++)         if (dat[i] ==  H ) {           hl = min(hl, i);           hr = max(hr, i);           hcnt++;         } else if (dat[i] ==  S ) {           shops.push_back(i);         }       t--;       if (hr > t)         printf( -1 n );       else {         int L = -1, R = hcnt;         while (L + 1 < R) {           int M = (L + R) / 2;           assert(M < hcnt);           bool good = false;           int rem = hcnt - M;           if (rem <= ((int)(shops).size())) {             int maxpos = max(hr, shops[rem - 1]);             int ctim = maxpos;             int btim = 2e9;             int bal = M;             for (int i = 0; i <= maxpos; i++) {               if (dat[i] ==  H )                 bal--;               else if (dat[i] ==  S )                 bal++;               if (bal < 0) {                 btim = min(btim, ctim + maxpos - i);                 ctim += 2;               }             }             btim = min(btim, ctim);             if (btim <= t) good = true;           }           if (good)             R = M;           else             L = M;         }         printf( %d n , R);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 5;   const int INF = 1e9;   int N, p[MAXN], tag[MAXN << 2];   long long ans;   struct node {     int mn, cnt;     node(int mn = 0, int cnt = 0) : mn(mn), cnt(cnt) {}     friend node operator+(const node& l, const node& r) {       if (l.mn < r.mn)         return l;       else if (l.mn > r.mn)         return r;       else         return node(l.mn, l.cnt + r.cnt);     }   } t[MAXN << 2];   void pushup(int o) { t[o] = t[(o << 1)] + t[(o << 1 | 1)]; }   void add(int o, int k) { t[o].mn += k, tag[o] += k; }   void pushdown(int o) {     if (tag[o]) add((o << 1), tag[o]), add((o << 1 | 1), tag[o]), tag[o] = 0;   }   void build(int o, int l, int r) {     if (l == r)       t[o] = node(0, 1);     else       build((o << 1), l, ((l + r) >> 1)),           build((o << 1 | 1), ((l + r) >> 1) + 1, r), pushup(o);   }   void ins(int o, int l, int r, int L, int R, int K) {     if (r < L || l > R) return;     if (L <= l && r <= R) return add(o, K);     pushdown(o);     ins((o << 1), l, ((l + r) >> 1), L, R, K),         ins((o << 1 | 1), ((l + r) >> 1) + 1, r, L, R, K);     pushup(o);   }   node qry(int o, int l, int r, int L, int R) {     if (r < L || l > R) return node(INF, 0);     if (L <= l && r <= R) return t[o];     pushdown(o);     return qry((o << 1), l, ((l + r) >> 1), L, R) +            qry((o << 1 | 1), ((l + r) >> 1) + 1, r, L, R);   }   int s1[MAXN], l1, s2[MAXN], l2;   int main() {     scanf( %d , &N);     int x, y;     for (int i = 1; i <= N; ++i) scanf( %d%d , &x, &y), p[x] = y;     build(1, 1, N);     s1[0] = s2[0] = N + 1;     for (int i = N; i >= 1; --i) {       while (l1 && p[s1[l1]] < p[i]) {         ins(1, 1, N, s1[l1], s1[l1 - 1] - 1, p[i] - p[s1[l1]]), --l1;       }       s1[++l1] = i, ins(1, 1, N, i, i, p[i]);       while (l2 && p[s2[l2]] > p[i]) {         ins(1, 1, N, s2[l2], s2[l2 - 1] - 1, p[s2[l2]] - p[i]), --l2;       }       s2[++l2] = i, ins(1, 1, N, i, i, -p[i]);       if (i < N) ins(1, 1, N, i + 1, N, -1);       ans += qry(1, 1, N, i, N).cnt;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, q, a[300010], f[300010], ans[300010], g[300010];   struct edge {     long long v, next;   } e[300010 << 1];   long long eid, p[300010];   void insert(long long u, long long v) {     e[++eid] = {v, p[u]};     p[u] = eid;   }   long long dep[300010], cnt, c[300010], d[300010], siz[300010];   pair<long long, long long> b[300010];   void dfs(long long u, long long f) {     siz[u] = 1;     c[u] = ++cnt, d[cnt] = u;     dep[u] = dep[f] + 1;     b[u] = make_pair(dep[u], c[u]);     for (int i = p[u]; i; i = e[i].next) {       long long v = e[i].v;       if (v == f) continue;       dfs(v, u);       siz[u] += siz[v];     }   }   void dfs1(long long u, long long f) {     g[u] += g[f];     for (int i = p[u]; i; i = e[i].next) {       long long v = e[i].v;       if (v == f) continue;       dfs1(v, u);     }   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i < n; ++i) {       long long u, v;       cin >> u >> v;       insert(u, v);       insert(v, u);     }     dfs(1, 0);     sort(b + 1, b + n + 1);     cin >> q;     while (q--) {       long long v, d, x;       cin >> v >> d >> x;       a[c[v]] += x, a[c[v] + siz[v]] -= x;       long long l =           lower_bound(b + 1, b + n + 1, make_pair(dep[v] + d + 1, c[v])) - b;       long long r = lower_bound(b + 1, b + n + 1,                                 make_pair(dep[v] + d + 1, c[v] + siz[v])) -                     b;       f[l] -= x, f[r] += x;     }     for (int i = 1; i <= n; ++i) a[i] += a[i - 1], f[i] += f[i - 1];     for (int i = 1; i <= n; ++i) g[d[b[i].second]] = f[i];     dfs1(1, 0);     for (int i = 1; i <= n; ++i) ans[d[i]] += a[i];     for (int i = 1; i <= n; ++i) cout << ans[i] + g[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s1, s2;     cin >> s1;     cin >> s2;     int arr[27] = {};     int a[27] = {};     string s =   ;     for (int i = 0; i < s1.length(); i++) {       arr[int(s1[i]) - 97]++;     }     int count1 = 0;     for (int i = 0; i < s2.length(); i++) {       if (arr[int(s2[i]) - 97] == 0) {         cout << -1;         count1++;         break;       } else {         if (a[int(s2[i]) - 97] == 0) {           s += s2[i];         }         a[int(s2[i]) - 97]++;       }     }     long long int sum = 0;     if (count1 == 0) {       for (int i = 0; i < s.length(); i++) {         if (a[int(s[i]) - 97] <= arr[int(s[i]) - 97]) {           sum += a[int(s[i]) - 97];         } else {           sum += arr[int(s[i]) - 97];         }       }       cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve(int a[], int n) {     int cnt = 0, pos = 0;     while (pos < n) {       cnt++;       int mx = pos;       while (pos < n && pos <= mx) {         mx = max(mx, a[pos]);         pos++;       }     }     cout << cnt << endl;   }   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i]--;     }     solve(a, n);     return 0;   }