#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   const int MOD = 1e9 + 7;   int dir[8][2] = {-1, 0, 1, 0, 0, -1, 0, 1, -1, -1, -1, 1, 1, -1, 1, 1};   template <typename S, typename T>   ostream &operator<<(ostream &os, const pair<S, T> x) {     os <<  (  << x.first <<  ,   << x.second <<  ) ;     return os;   }   template <typename S, typename T>   inline bool Min(S &a, const T &b) {     return a > b ? a = b, true : false;   }   template <typename S, typename T>   inline bool Max(S &a, const T &b) {     return a < b ? a = b, true : false;   }   template <typename S, typename T>   inline void Adm(S &a, const T &b) {     a = (a + b) % MOD;     if (a < 0) a += MOD;   }   template <typename T>   inline bool IsPri(T x) {     if (x < 2) return false;     for (T i = 2; i * i <= x; ++i)       if (x % i == 0) return false;     return true;   }   template <typename T>   inline T _Gcd(T a, T b) {     while (b) {       T t = b;       b = a % b;       a = t;     }     return a;   }   template <typename T>   inline int _BitCnt(T x) {     int cnt = 0;     while (x) ++cnt, x &= x - 1;     return cnt;   }   inline long long Pow(long long a, long long n) {     long long t = 1;     a %= MOD;     while (n > 0) {       if (n & 1) t = t * a % MOD;       a = a * a % MOD, n >>= 1;     }     return t % MOD;   }   inline int read() {     static char buf[1000000], *p1 = buf, *p2 = buf;     register int x = false;     register char ch =         p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)             ? EOF             : *p1++;     ;     register bool sgn = false;     while (ch !=  -  && (ch <  0  || ch >  9 ))       ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)                ? EOF                : *p1++;     ;     if (ch ==  - )       sgn = true,       ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)                ? EOF                : *p1++;     ;     while (ch >=  0  && ch <=  9 )       x = (x << 1) + (x << 3) + (ch ^ 48),       ch = p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)                ? EOF                : *p1++;     ;     return sgn ? -x : x;   }   const int N = 1e5 + 100;   char s[N];   int main() {     scanf( %s , s);     int n = strlen(s);     string str, ss;     vector<int> pos;     stack<pair<int, string>> stk;     for (int i = n - 1; i >= 0; --i) {       char c = s[i];       if (str.empty() || str.back() != c || pos.back() - i > 1) {         str.push_back(c), pos.push_back(i);         if (ss.empty() || ss.back() != c) ss.push_back(c);       } else {         if (((int)(ss).size()) == 1 || ss[((int)(ss).size()) - 2] < c) {           str.pop_back(), pos.pop_back();           if (str.empty() || str.back() != ss.back()) ss.pop_back();         } else {           str.push_back(c), pos.push_back(i);           if (ss.empty() || ss.back() != c) ss.push_back(c);         }       }       pair<int, string> now = {((int)(str).size()),   };       if (((int)(str).size()) <= 10)         now.second = str;       else         now.second =             str.substr(0, 2) +  ...  + str.substr(((int)(str).size()) - 5, 5);       reverse((now.second).begin(), (now.second).end());       stk.push(now);     }     while (!stk.empty())       printf( %d %s n , stk.top().first, stk.top().second.c_str()), stk.pop();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3333;   int cnt[maxn][maxn][2], fuck[maxn], dep[maxn][maxn], dis[maxn][maxn];   struct Edge {     int t, next, v;   } edge[maxn << 1];   int head[maxn], tot, n;   void new_edge(int a, int b, int t) {     edge[tot].t = b;     edge[tot].next = head[a];     edge[tot].v = t;     head[a] = tot++;   }   void dfs(int u, int fa, int rt) {     int i;     for (i = head[u]; i != -1; i = edge[i].next) {       int e = edge[i].t;       if (e == fa) continue;       dep[rt][e] = dep[rt][u] + 1;       int add = edge[i].v;       cnt[rt][e][1] = min(cnt[rt][u][0], cnt[rt][u][1]) + !add;       cnt[rt][e][0] = cnt[rt][u][0] + add;       dis[rt][e] = dis[rt][u] + add;       fuck[rt] += add;       dfs(e, u, rt);     }   }   int main() {     tot = 0;     int i, j, k;     memset(head, -1, sizeof(head));     scanf( %d , &n);     for (i = 1; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       new_edge(a, b, 0);       new_edge(b, a, 1);     }     for (i = 1; i <= n; i++) dfs(i, 0, i);     int ans = 111111111;     for (i = 1; i <= n; i++)       for (j = 1; j <= n; j++) {         ans = min(ans, fuck[i] - dis[i][j] + min(cnt[i][j][0], cnt[i][j][1]));         ans = min(ans, fuck[i]);       }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool besarDulu(const int &a, const int &b) { return a > b; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int h, m;       cin >> h >> m;       int minutes = (24 - h - 1) * 60 + (60 - m);       cout << minutes <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool cur1;   int n, m, K;   int L[100005 * 120], R[100005 * 120], res[100005 * 120], tt, rt[100005 * 3];   int update(int p, int l, int r, int x, int v) {     int c = ++tt;     L[c] = L[p], R[c] = R[p];     if (l == r) {       res[c] = min((p ? res[p] : 0x3f3f3f3f), v);       return c;     }     int mid = (l + r) >> 1;     if (x <= mid)       L[c] = update(L[p], l, mid, x, v);     else       R[c] = update(R[p], mid + 1, r, x, v);     res[c] = max(res[L[c]], res[R[c]]);     return c;   }   int query(int p, int u, int v, int l, int r) {     if (u <= l && r <= v) {       return res[p];     }     int mid = (l + r) >> 1;     int ans = 0;     if (u <= mid) ans = max(ans, query(L[p], u, v, l, mid));     if (v > mid) ans = max(ans, query(R[p], u, v, mid + 1, r));     return ans;   }   struct seg {     int a, b, c;     bool operator<(const seg &_) const {       if (a != _.a) return a < _.a;       if (c != _.c) return c < _.c;       if (b != _.b) return b > _.b;     }   } Sg[100005 * 3];   int B[100005 * 3];   void solve() {     tt = 0;     int tot = 0;     scanf( %d %d %d , &n, &m, &K);     for (int a, b, c, i = 1; i <= K; i++) {       scanf( %d %d %d , &a, &b, &c);       B[i] = a;       Sg[i] = (seg){a, b, c};     }     sort(B + 1, B + K + 1);     sort(Sg + 1, Sg + K + 1);     tot = unique(B + 1, B + 1 + K) - B - 1;     for (int i = 1; i <= n; i++)       rt[tot + 1] = update(rt[tot + 1], 1, n, i, 0x3f3f3f3f);     Sg[K + 1].a = 0x3f3f3f3f;     for (int i = K; i >= 1; i--) {       int t = lower_bound(B + 1, B + 1 + tot, Sg[i].a) - B;       if (Sg[i].a != Sg[i + 1].a) {         rt[t] = update(rt[t + 1], 1, n, Sg[i].c, Sg[i].b);       } else         rt[t] = update(rt[t], 1, n, Sg[i].c, Sg[i].b);     }     while (m--) {       int a, b, c, d;       scanf( %d %d %d %d , &a, &b, &c, &d);       if (c > B[tot]) {         puts( no );         fflush(stdout);         continue;       } else {         int t = lower_bound(B + 1, B + 1 + tot, c) - B;         if (query(rt[t], a, b, 1, n) <= d)           puts( yes );         else           puts( no );       }       fflush(stdout);     }   }   bool cur2;   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t;     cin >> t;     while (t != 0) {       t--;       int n, k, l = -1, r = -1;       cin >> n >> k;       int c = k + 1, z, res = 0;       string x;       cin >> x;       for (int i = 0; i < n; i++) {         if (x[i] ==  1 ) {           r = i;           if (l == -1)             z = r - l - 1 - k;           else             z = r - l - 1 - (2 * k);           if (z > 0) {             c = k + 1;             for (int j = 0; j < z; j++) {               if (c > k) {                 res++;                 c = 0;               }               c++;             }           }           l = i;           z = 0;         }       }       r = n;       if (l == -1)         z = r - l - 1;       else         z = r - l - 1 - k;       if (z > 0) {         c = k + 1;         for (int j = 0; j < z; j++) {           if (c > k) {             res++;             c = 0;           }           c++;         }       }       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long b[n];     pair<long long, long long> arr[n];     for (long long i = 0; i < n; i++) {       cin >> b[i];       arr[i].first = b[i] - i + 200000;       arr[i].second = b[i];     }     sort(arr, arr + n);     long long maxi = 0;     long long i = -1;     while (i < (n - 1)) {       i++;       long long c = 0;       c += arr[i].second;       while (arr[i].first == arr[i + 1].first) {         c += arr[i + 1].second;         i++;       }       maxi = max(c, maxi);     }     if (n == 1) {       cout << b[0];     } else {       cout << maxi;     }   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());   mt19937_64 rnd64(       chrono::high_resolution_clock::now().time_since_epoch().count());   long long power(long long a, long long m, long long mod) {     long long ans = 1;     while (m) {       if (m % 2) {         ans *= a;         ans %= (mod);       }       a = (a * a) % (mod);       m >>= 1;     }     return ans;   }   void init(long long* a, long long n, long long val) {     for (long long i = 0; i < n; i++) a[i] = val;   }   void solve() {     long long i, j, _, n;     cin >> n;     long long a[n], pre[n];     for (i = 0; i < n; i++) cin >> a[i];     vector<long long> ans;     sort(a, a + n);     j = 0;     for (i = 0; i < n; i++) cin >> j, j += a[i], j %= 998244353, pre[i] = j;     for (i = 1; i < n; i++) {       long long k = 0;       for (j = n - i - 1; j > -1; j -= i) k += pre[j], k %= 998244353;       ans.push_back(k);     }     ans.push_back(0);     n = power(n, 998244353 - 2, 998244353);     for (auto& i : ans) i *= n, i %= 998244353, cout << i <<    ;     cout << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long T = 1;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   long long power(long long x, long long y) {     if (y == 0) return 1;     long long a = power(x, y / 2);     if (y % 2) {       return (a * ((a * x) % mod)) % mod;     } else {       return (a * a) % mod;     }   }   int main() {     long long i, j, k, m, n;     cin >> n >> k;     long long ans = 0;     long long arr[n];     vector<vector<long long> > ind(11);     for (i = 0; i < n; i++) cin >> arr[i];     for (i = 0; i < n; i++) {       j = arr[i] % 10;       ind[j].push_back(i);     }     for (j = 9; j >= 1 && k > 0; j--) {       for (i = 0; i < ind[j].size(); i++) {         m = ind[j][i];         if (k >= (10 - j)) {           k -= 10 - j;           arr[m] += 10 - j;         }       }     }     sort(arr, arr + n);     for (i = 0; i < n; i++) {       if (k >= 100 - arr[i]) {         k -= 100 - arr[i];         arr[i] = 100;       } else {         long long flag = 1;         while (flag) {           if (k >= 10 && 1) {             k -= 10;             arr[i] += 10;           } else             flag = 0;         }       }     }     for (i = 0; i < n; i++) {       ans += arr[i] / 10;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string b[51];   bool check(pair<int, int> f, pair<int, int> s) {     bool r1 = true, r2 = true, c1 = true, c2 = true;     for (int i = f.first; i <= s.first; i++) {       if (b[i][f.second] ==  W ) c1 = false;       if (b[i][s.second] ==  W ) c2 = false;     }     for (int i = s.first; i <= f.first; i++) {       if (b[i][f.second] ==  W ) c1 = false;       if (b[i][s.second] ==  W ) c2 = false;     }     for (int i = f.second; i <= s.second; i++) {       if (b[f.first][i] ==  W ) r1 = false;       if (b[s.first][i] ==  W ) r2 = false;     }     for (int i = s.second; i <= f.second; i++) {       if (b[f.first][i] ==  W ) r1 = false;       if (b[s.first][i] ==  W ) r2 = false;     }     return (c1 && r2) || (c2 && r1);   }   vector<pair<int, int> > v;   int main() {     int r, c;     cin.tie(0);     cin >> r >> c;     for (int i = 0; i < r; i++) {       cin >> b[i];       for (int j = 0; j < c; j++)         if (b[i][j] ==  B ) v.push_back({i, j});     }     int sz = v.size();     for (int i = 0; i < sz; i++)       for (int j = i + 1; j < sz; j++) {         if (!check(v[i], v[j])) {           cout <<  NO ;           return 0;         };       }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   enum var_type {     TYPE_DOUBLE,     TYPE_STRING,     TYPE_INT,     TYPE_T,   };   using namespace std;   struct proc {     string name;     vector<var_type> types;   };   vector<proc> procedures;   map<string, var_type> vars;   vector<int> results;   var_type get_type(string type_name) {     if (type_name ==  double ) return TYPE_DOUBLE;     if (type_name ==  int ) return TYPE_INT;     if (type_name ==  string ) return TYPE_STRING;     if (type_name ==  T ) return TYPE_T;   }   void proc_procedures() {     int n;     cin >> n;     cin.ignore(1,   n );     for (int i = 0; i < n; ++i) {       char buf[200];       gets(buf);       string str(buf);       int j = 0;       while (str[j] ==    ) ++j;       j += 4;       while (str[j] ==    ) ++j;       string name;       while (str[j] !=     && str[j] !=  ( ) {         name += str[j];         ++j;       }       while (str[j] !=  ( ) ++j;       ++j;       vector<var_type> var_types;       while (str[j] !=  ) ) {         if (str[j] ==    ) {           ++j;           continue;         }         string cur_type;         while (str[j] !=     && str[j] !=  )  && str[j] !=  , ) {           cur_type += str[j];           ++j;         }         var_types.push_back(get_type(cur_type));         while (str[j] !=  )  && str[j] !=  , ) ++j;         if (str[j] ==  , ) ++j;       }       proc temp;       temp.name = name;       temp.types = var_types;       procedures.push_back(temp);     }   }   void proc_variables() {     int n;     cin >> n;     cin.ignore(1,   n );     for (int i = 0; i < n; ++i) {       char buf[200];       gets(buf);       string str(buf);       int j = 0;       while (str[j] ==    ) ++j;       string cur_type;       while (str[j] !=    ) {         cur_type += str[j];         ++j;       }       while (str[j] ==    ) ++j;       string name;       while (j < str.size() && str[j] !=    ) {         name += str[j];         ++j;       }       vars.insert(pair<string, var_type>(name, get_type(cur_type)));     }   }   void proc_calls() {     int n;     cin >> n;     cin.ignore(1,   n );     for (int i = 0; i < n; ++i) {       char buf[200];       gets(buf);       string str(buf);       int j = 0;       while (str[j] ==    ) ++j;       string name;       while (str[j] !=     && str[j] !=  ( ) {         name += str[j];         ++j;       }       while (str[j] !=  ( ) ++j;       ++j;       vector<var_type> var_types;       while (str[j] !=  ) ) {         if (str[j] ==    ) {           ++j;           continue;         }         string cur_type;         while (str[j] !=     && str[j] !=  )  && str[j] !=  , ) {           cur_type += str[j];           ++j;         }         var_types.push_back(vars[cur_type]);         while (str[j] !=  )  && str[j] !=  , ) ++j;         if (str[j] ==  , ) ++j;       }       int res = 0;       for (int j = 0; j < procedures.size(); ++j) {         if (procedures[j].name != name) continue;         if (var_types.size() != procedures[j].types.size()) continue;         bool is_ok = true;         for (int k = 0; k < var_types.size(); ++k) {           if (procedures[j].types[k] == TYPE_T) continue;           if (procedures[j].types[k] != var_types[k]) is_ok = false;         }         if (is_ok) ++res;       }       results.push_back(res);     }   }   int main() {     proc_procedures();     proc_variables();     proc_calls();     for (int i = 0; i < results.size(); ++i) cout << results[i] << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   const int inf = 0x3f3f3f3f;   const long long LL_INF = 0x3f3f3f3f3f3f3f3f;   template <typename T>   T gcd(T a, T b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long power(long long a, long long b, long long m = 1000000007) {     long long answer = 1;     while (b) {       if (b & 1) answer = (answer * a) % m;       b /= 2;       a = (a * a) % m;     }     return answer;   }   using namespace std;   bool chk[1048576];   int main() {     set<int> st;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       set<int>::iterator it;       set<int> st2;       for (it = st.begin(); it != st.end(); it++) {         int y = *it;         st2.insert(y | x);       }       st2.insert(x);       st = st2;       st2.clear();       for (it = st.begin(); it != st.end(); it++) {         chk[*it] = 1;       }     }     int cnt = 0;     for (int i = 0; i < 1048576; i++) {       if (chk[i]) cnt++;     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1 << 20;   long long fac[20];   vector<long long> lst;   vector<long long> lucky;   void prepare(int cnt, int all, long long now) {     if (cnt == all) {       lucky.push_back(now);       return;     }     prepare(cnt + 1, all, now * 10 + 4);     prepare(cnt + 1, all, now * 10 + 7);   }   inline bool chk(long long x) {     while (x) {       if (x % 10 != 4 && x % 10 != 7) return false;       x /= 10;     }     return true;   }   int main() {     ios::sync_with_stdio(false);     for (int i = 0; i <= 10; i++) prepare(0, i, 0);     fac[0] = 1;     for (int i = 1; i < 20; i++) fac[i] = fac[i - 1] * i;     long long n, k;     cin >> n >> k;     long long p = 1;     while (fac[p] < k) p++;     if (p > n) return cout << -1 <<   n , 0;     k--;     for (long long i = n - p + 1; i <= n; i++) lst.push_back(i);     while (k) {       int i;       for (i = p; ~i; i--)         if (fac[i] <= k) break;       int w = k / fac[i];       k -= fac[i] * w;       for (int s = 0; s < w; s++) swap(lst[p - 1 - i], lst[p - i + s]);     }     long long res =         upper_bound(lucky.begin(), lucky.end(), n - p) - lucky.begin() - 1;     for (int i = 0; i < lst.size(); i++)       if (chk(n - p + i + 1) && chk(lst[i])) res++;     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int block(long int x) {     vector<long int> v;     while (x > 0) {       v.push_back(x % 2);       x = x / 2;     }     int ret = 0;     for (int i = 0; i < v.size(); i++) {       if (v[i] == 1) {         ret++;       }     }     return ret;   }   void pprint(long int x) {     vector<long int> v;     while (x > 0) {       v.push_back(x % 2);       x = x / 2;     }     cout <<  YES n ;     int ret = 0;     for (int i = 0; i < v.size(); i++) {       if (v[i] == 1) {         ret++;         int A = 1 << i;         cout << A <<    ;       }     }     cout << endl;   }   void solve(long int x, long long k, long long mini) {     vector<long int> v;     long long rem = k - mini;     while (x > 0) {       v.push_back(x % 2);       x = x / 2;     }     int ret = 0;     cout <<  YES n ;     int i = v.size() - 1;     while (rem > 0) {       v[i]--;       v[i - 1] += 2;       if (v[i] == 0) {         i--;       }       rem--;     }     for (int i = 0; i < v.size(); i++) {       while (v[i] > 0) {         ret++;         int A = 1 << i;         cout << A <<    ;         v[i]--;       }     }     cout << endl;   }   int main() {     long long x;     long long n, k;     cin >> n >> k;     if (k > n) {       cout <<  NO n ;       return 0;     }     if (k == n) {       cout <<  YES n ;       for (int i = 0; i < n; i++) {         cout << 1 <<    ;       }       return 0;     }     int mini = block(n);     if (k < mini) {       cout <<  NO n ;       return 0;     }     if (k == mini) {       pprint(n);     } else {       solve(n, k, mini);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5001;   long long a[N], mem[N][2], b[N];   int n, m;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(b, b + n);     m = unique(b, b + n) - b;     for (int i = n - 1; i >= 0; i--)       mem[i][1 - m & 1] =           abs(a[i] - b[m - 1]) + ((i + 1 < n) ? mem[i + 1][1 - m & 1] : 0ll);     for (int j = m - 2; j >= 0; j--)       for (int i = n - 1; i >= 0; i--)         mem[i][j & 1] =             min(mem[i][1 - j & 1],                 abs(a[i] - b[j]) + ((i + 1 < n) ? mem[i + 1][j & 1] : 0ll));     long long ans = 1ll << 50;     ans = min(mem[0][0], mem[0][1]);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T, class V>   T power(T t, V v) {     T second = 1;     while (v--) second *= t;     return second;   }   void _print(long long t) { cerr << t; }   void _print(int t) { cerr << t; }   void _print(string t) { cerr << t; }   void _print(char t) { cerr << t; }   void _print(long double t) { cerr << t; }   void _print(double t) { cerr << t; }   void _print(unsigned long long t) { cerr << t; }   template <class T, class V>   void _print(pair<T, V> p);   template <class T>   void _print(vector<T> v);   template <class T>   void _print(set<T> v);   template <class T, class V>   void _print(map<T, V> v);   template <class T>   void _print(multiset<T> v);   template <class T, class V>   void _print(pair<T, V> p) {     cerr <<  { ;     _print(p.first);     cerr <<    ;     _print(p.second);     cerr <<  } ;   }   template <class T>   void _print(vector<T> v) {     int n = v.size();     cerr <<  [  ;     for (T i : v) {       _print(i);       n--;       cerr << (n ?  ,   :    );     }     cerr <<  ] ;   }   template <class T>   void _print(set<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(multiset<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void _print(map<T, V> v) {     int n = v.size();     cerr <<  {  ;     for (auto p : v) {       cerr <<  [ ;       _print(p.first);       cerr <<  ]= ;       _print(p.second);       n--;       cerr << (n ?  ,   :    );     }     cerr <<  } ;   }   void go() {     int n;     cin >> n;     string a;     string b;     cin >> a >> b;     int sz = 0, so = 0, nsz = 0, nso = 0;     for (int i = 0; i < n; i++) {       if (a[i] == b[i]) {         if (a[i] ==  0 )           sz++;         else           so++;       } else if (a[i] ==  0 )         nsz++;       else         nso++;     }     int N = 100000000;     int ans = N;     if (so - sz == 1) ans = min(ans, so + sz);     if (nsz == nso) ans = min(ans, nsz + nso);     if (ans == N)       cout <<  -1 n ;     else       cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     cin >> t;     while (t--) {       go();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   int inf = 0x3f3f3f3f;   long long infl = 0x3f3f3f3f3f3f3f3fLL;   long double infd = 1.0 / 0.0;   const long long MOD = 1e9 + 7;   const double pi = 2 * acos(0.0);   long long modi(long long a, long long n) {     long long x = 1;     while (n) {       if (n & 1) x = (x * a) % MOD;       n >>= 1;       a = (a * a) % MOD;     }     return x;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int tt = 1;     while (tt--) {       long long a, b, n, x;       cin >> a >> b >> n >> x;       long long as = (((a * x) % MOD) + b) % MOD;       long long le = (x * modi(a, n)) % MOD;       long long ri = a == 1ll ? ((b * (n % MOD)) % MOD)                               : ((b * (((((modi(a, n) - 1 + MOD) % MOD)) *                                         (modi(a - 1, MOD - 2))) %                                        MOD)) %                                  MOD);       cout << ((((le + ri) % (MOD)) + (MOD)) % (MOD)) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int s1, s2, s3, a, b, c;     cin >> s1 >> s2 >> s3;     a = (s1 * s2) / s3;     a = pow(a, 0.5);     b = (s2 * s3) / s1;     b = pow(b, 0.5);     c = (s1 * s3) / s2;     c = pow(c, 0.5);     cout << 4 * (a + b + c) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, ans = 0;     cin >> n;     for (;; ans++) {       if (n == 1) break;       if (n % 6 == 0)         n /= 6;       else if (n % 3 == 0) {         if ((n * 2) % 3 != 0) {           cout <<  -1 n ;           return;         }         n *= 2;       } else {         cout <<  -1 n ;         return;       }     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   void debug() { cerr <<  ] n ; }   template <class H, class... T>   void debug(H h, T... t) {     cerr << h;     if (sizeof...(t)) {       cerr <<  ,  ;     }     debug(t...);   }   void solve() {     int n;     cin >> n;     string s;     cin >> s;     int o, e;     o = e = 0;     int f1, f2;     f1 = f2 = 0;     for (int i = 0; i < n; i++) {       if (i & 1) {         if ((int)(s[i] -  0 ) & 1) {         } else           f2 = 1;       } else {         if ((int)(s[i] -  0 ) & 1) {           f1 = 1;         }       }     }     if (n == 1) {       cout << (((s[0] -  0 ) & 1) ?  1  :  2 ) <<   n ;       return;     }     if (n & 1) {       cout << (f1 ?  1  :  2 ) <<   n ;     } else {       cout << (f2 ?  2  :  1 ) <<   n ;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int _;     cin >> _;     for (int i = 1; i <= _; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double g[110][110], x[110];   int n, m, ues[110];   pair<pair<int, int>, int> p[5010];   bool vis[110];   void read(int &x) {     char ch = getchar();     int mark = 1;     for (; ch !=  -  && (ch <  0  || ch >  9 ); ch = getchar())       ;     if (ch ==  - ) mark = -1, ch = getchar();     for (x = 0; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch - 48;     x *= mark;   }   double Abs(double x) {     if (x < 0) return -x;     return x;   }   int main() {     read(n);     read(m);     g[1][1] = 1;     g[n][n] = 1;     g[n][n + 1] = 1;     for (int i = 1; i <= m; i++) {       read(p[i].first.first);       read(p[i].first.second);       read(p[i].second);       g[p[i].first.first][p[i].first.first]++;       g[p[i].first.first][p[i].first.second]--;       g[p[i].first.second][p[i].first.second]++;       g[p[i].first.second][p[i].first.first]--;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++)         if (Abs(g[i][j]) && !vis[j]) {           vis[j] = 1;           ues[i] = j;           break;         }       for (int j = 1; j <= n; j++)         if (ues[i] != j && Abs(g[j][i])) {           double tmp = -g[j][i] / g[ues[i]][i];           for (int k = 1; k <= n + 1; k++) g[j][k] += g[ues[i]][k] * tmp;         }     }     for (int i = 1; i <= n; i++) x[i] = g[ues[i]][n + 1] / g[ues[i]][i];     double Min = 1e20;     for (int i = 1; i <= m; i++) {       if (Abs(x[p[i].first.first] - x[p[i].first.second]) > 1e-6)         Min = min(Min,                   p[i].second / Abs(x[p[i].first.first] - x[p[i].first.second]));     }     double ans = 0;     for (int i = 1; i <= m; i++)       if (p[i].first.first == 1)         ans += Min * (x[p[i].first.second] - x[p[i].first.first]);       else if (p[i].first.second == 1)         ans -= Min * (x[p[i].first.second] - x[p[i].first.first]);     printf( %.5lf n , ans);     if (Abs(ans) < 1e-6) memset(x, 0, sizeof(x));     for (int i = 1; i <= m; i++)       printf( %.5lf n , Min * (x[p[i].first.second] - x[p[i].first.first]));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int k, a;     bool operator<(const node &X) const { return a > X.a; }   };   int n, fa[5010], limi[5010], ans[5010];   int order[5010], co;   vector<int> edge[5010];   vector<int> val[5010];   priority_queue<node> train[5010];   void dfs(int u, int father, int weight) {     order[++co] = u;     fa[u] = father;     limi[u] = weight;     for (int i = 0; i < edge[u].size(); i++) {       int v = edge[u][i];       int w = val[u][i];       if (v == father) continue;       dfs(v, u, w);     }   }   int main() {     cin >> n;     node tt;     for (int i = 1; i <= n; i++) {       cin >> tt.a;       tt.k = i;       train[i].push(tt);     }     int x, y, z;     for (int i = 1; i <= n - 1; i++) {       cin >> x >> y >> z;       edge[x].push_back(y);       val[x].push_back(z);       edge[y].push_back(x);       val[y].push_back(z);     }     co = 0;     dfs(1, 0, 0);     int cnt = 0;     for (int i = 0; i <= n - 1; i++) {       while (!train[1].empty()) {         tt = train[1].top();         train[1].pop();         ans[tt.k] = i;         cnt += 1;       }       if (cnt == n) break;       for (int i = 2; i <= n; i++) {         int u = order[i];         int v = fa[u];         int w = limi[u];         for (int i = 1; i <= w; i++) {           if (train[u].empty()) break;           tt = train[u].top();           train[u].pop();           train[v].push(tt);         }       }     }     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int f = 1;     int res = 0;     char ch;     do {       ch = getchar();       if (ch ==  - ) f = -f;     } while (ch <  0  || ch >  9 );     do {       res = res * 10 + ch -  0 ;       ch = getchar();     } while (ch >=  0  && ch <=  9 );     return f == 1 ? res : -res;   }   const int MAXN = 100010;   const int MAXP = MAXN * 51;   const long long INF = 2000000000000LL;   int n, m, D;   int mod = 1000000007;   int X[MAXN], Y[MAXN];   char open[MAXN][52];   int stck[MAXP], in[MAXP], dfsn[MAXP], low[MAXP], idx, top;   int li[MAXN], bak;   bool hv[MAXN];   int head[MAXP], nxt[MAXP], to[MAXP], tot;   int nid[MAXP], dag[MAXP], sz[MAXP];   std::queue<int> q;   int dp[MAXP];   void addEdge(int x, int y) {     tot++;     nxt[tot] = head[x];     head[x] = tot;     to[tot] = y;   }   int getIndex(int x, int d) { return x + (d % D) * n; }   void append(int x) {     --x;     int c = x % n + 1;     int d = x / n;     if (c <= 0 || d >= D) cout <<  x:   << x << endl;     if (!hv[c] && (c > 0 && d < D && open[c][d] ==  1 )) {       li[++bak] = c;       hv[c] = true;     }   }   void clr() {     for (int i = 1; i <= bak; i++) hv[li[i]] = false;     bak = 0;   }   void tarjan(int u) {     dfsn[u] = low[u] = ++idx;     in[stck[++top] = u] = true;     for (int i = head[u]; i; i = nxt[i])       if (!dfsn[to[i]]) {         tarjan(to[i]);         low[u] = std::min(low[u], low[to[i]]);       } else if (in[to[i]])         low[u] = std::min(low[u], dfsn[to[i]]);     if (low[u] == dfsn[u]) {       int v;       do in[v = stck[top--]] = false, append(v), nid[v] = u;       while (u != v);       sz[u] = bak;       clr();     }   }   int main() {     scanf( %d%d%d , &n, &m, &D);     for (int i = 0; i < m; i++) {       int u = read();       int v = read();       X[i] = u;       Y[i] = v;       for (int j = 0; j < D; j++)         addEdge(getIndex(X[i], j), getIndex(Y[i], j + 1));     }     for (int i = 1; i <= n; i++) {       scanf( %s , open[i]);     }     tarjan(getIndex(1, 0));     memset(head, 0, sizeof(head));     tot = 0;     for (int i = 0; i < m; i++) {       for (int j = 0; j < D; j++) {         int u = getIndex(X[i], j);         int v = getIndex(Y[i], j + 1);         if (!nid[u] || !nid[v]) continue;         if (nid[u] == nid[v]) continue;         addEdge(nid[u], nid[v]);         dag[nid[v]]++;       }     }     q.push(getIndex(1, 0));     int ans = 0;     while (!q.empty()) {       int t = q.front();       q.pop();       ans = std::max(ans, dp[t] += sz[t]);       for (int i = head[t]; i; i = nxt[i]) {         dp[to[i]] = std::max(dp[to[i]], dp[t]);         if (!--dag[to[i]]) q.push(to[i]);       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ans[1000005];   int main() {     int n;     cin >> n;     int a[n], b[n];     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     int l = 0;     for (int i = 0; i < n; i++) {       for (int j = i; j < n; j++) {         if (b[j] == a[i]) {           for (int k = j; k > i; k--) {             ans[l++] = k;             swap(b[k - 1], b[k]);           }           break;         }       }     }     cout << l << endl;     for (int i = 0; i < l; i++) {       cout << ans[i] <<     << ans[i] + 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.size();     string s1 =  hello ;     int n1 = s1.size();     int i = 0, j = 0;     int count = 0;     while (j < n1 && i < n) {       if (s1[j] == s[i]) {         j++;         count++;       }       i++;     }     if (count == n1) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long i, j = 0, k, sum = 0, ctr = 0, c = 0, ok = 0;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long a, b, c;     cin >> a >> b >> c;     for (i = a; i >= 0; i--) {       if (c >= i * 4 && b >= i * 2) {         ok = i;         break;       }     }     cout << ok * 7;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int cen, feet = 0, inch;     cin >> cen;     inch = cen / 3;     if (cen % 3 == 2) inch++;     if (inch >= 12) {       feet = inch / 12;       inch = inch % 12;     }     cout << feet <<     << inch << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int nmin, nmax = 1;     int n, m, a, b;     scanf( %d%d , &n, &m);     nmin = n;     for (int i = 0; i < m; i++) {       scanf( %d%d , &a, &b);       if (b < a) swap(a, b);       nmin = min(nmin, b);       nmax = max(nmax, a);     }     if (nmax < nmin)       printf( %d n , nmin - nmax);     else       printf( 0 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int infinity = 10000000;   int railway[401][401];   int calculatedistance(int start, int end, bool bus) {     bool visitedtown[401];     int distance[401];     queue<int> myQueue;     for (int i = 1; i <= 400; i++) visitedtown[i] = false;     for (int i = 1; i <= 400; i++) distance[i] = infinity;     distance[start] = 0;     visitedtown[start] = true;     myQueue.push(start);     while (!myQueue.empty()) {       int town = myQueue.front();       myQueue.pop();       for (int i = 1; i <= end; i++)         if (i != town) {           if (bus) {             if (!railway[town][i])               if (!visitedtown[i])                 if (distance[town] + 1 < distance[i]) {                   distance[i] = distance[town] + 1;                   visitedtown[i] = true;                   myQueue.push(i);                 }           } else {             if (railway[town][i])               if (!visitedtown[i])                 if (distance[town] + 1 < distance[i]) {                   distance[i] = distance[town] + 1;                   visitedtown[i] = true;                   myQueue.push(i);                 }           }         }     }     return distance[end];   }   int main() {     int n, m, u, v;     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) railway[i][j] = 0;     for (int i = 0; i < m; i++) {       cin >> u >> v;       railway[u][v] = 1;       railway[v][u] = 1;     }     int bdis = calculatedistance(1, n, true);     int tdis = calculatedistance(1, n, false);     if (bdis == infinity || tdis == infinity) {       cout <<  -1 ;       return 0;     }     if (bdis != tdis) {       cout << max(bdis, tdis);       return 0;     }     int disb = infinity;     for (int i = 2; i < n; i++)       disb = min(disb,                  calculatedistance(1, i, false) + calculatedistance(i, n, false));     int dist;     for (int i = 2; i < n; i++)       dist = min(dist,                  calculatedistance(1, i, true) + calculatedistance(i, n, true));     cout << min(disb, dist);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int limit[100005] = {0};   int main() {     ios::sync_with_stdio(false);     memset(limit, 0, sizeof(limit));     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int x, k;       cin >> x >> k;       if (x == limit[k])         limit[k]++;       else if (x > limit[k]) {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, w, h;     string temp;     vector<string> img;     cin >> w >> h;     for (i = 0; i < h; i++) {       cin >> temp;       img.push_back(temp);     }     for (j = 0; j < w; j++) {       for (i = 0; i < h; i++) cout << img[i][j] << img[i][j];       cout << endl;       for (i = 0; i < h; i++) cout << img[i][j] << img[i][j];       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int a[1005][1005];   int main() {     int h, w;     cin >> h >> w;     vector<int> r(h), c(w);     for (int i = 0; i < h; i++) {       cin >> r[i];     }     for (int i = 0; i < w; i++) {       cin >> c[i];     }     memset(a, -1, sizeof(a));     for (int i = 0; i < h; i++) {       for (int j = 0; j < r[i]; j++) {         a[i][j] = 1;       }       a[i][r[i]] = 0;     }     for (int i = 0; i < w; i++) {       for (int j = 0; j < c[i]; j++) {         if (a[j][i] == 0) {           cout << 0 << endl;           return 0;         }         a[j][i] = 1;       }       if (a[c[i]][i] == 1) {         cout << 0 << endl;         return 0;       }       a[c[i]][i] = 0;     }     int ans = 1;     for (int i = 0; i < h; i++) {       for (int j = 0; j < w; j++) {         if (a[i][j] == -1) {           ans = (1ll * 2 * ans) % mod;         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void pv(T a, T b) {     for (T i = a; i != b; ++i) cout << *i <<    ;     cout << endl;   }   template <typename T>   void chmin(T &t, const T &f) {     if (t > f) t = f;   }   template <typename T>   void chmax(T &t, const T &f) {     if (t < f) t = f;   }   int in() {     int x;     scanf( %d , &x);     return x;   }   const long long MO = 1000000007;   namespace SA {   int n;   char t[300010];   int ki[300010], ik[300010], is[300010], hh;   bool cmp(const int &a, const int &b) {     return (a == b)           ? 0            : (ik[a] != ik[b]) ? (ik[a] < ik[b])                               : (ik[a + hh] < ik[b + hh]);   }   void makeSA() {     n = strlen(t);     int i;     for (i = 0; i <= n; ++i) ik[ki[i] = i] = t[i];     is[0] = is[n] = hh = 0;     sort(ki, ki + n + 1, cmp);     for (hh = 1; is[n] != n; hh <<= 1) {       sort(ki, ki + n + 1, cmp);       for (i = 0; i < n; ++i) is[i + 1] = is[i] + (cmp(ki[i], ki[i + 1]) ? 1 : 0);       for (i = 0; i <= n; ++i) ik[ki[i]] = is[i];     }   }   int lcp[300010];   void makeHA() {     int h = 0, i, j;     for (i = 0; i < n; ++i) {       for (j = ki[ik[i] - 1]; t[j + h] == t[i + h]; ++h)         ;       lcp[ik[i] - 1] = h;       if (h) --h;     }   }   }  // namespace SA   int LA, LB, LC;   long long ans[300010];   int eventsLen;   pair<int, int> events[300010];   int uf[300010];   long long cnt[300010][3];   long long prodSum;   int root(int u) { return (uf[u] < 0) ? u : (uf[u] = root(uf[u])); }   void conn(int u, int v) {     u = root(u);     v = root(v);     if (u == v) return;     if (uf[u] > uf[v]) swap(u, v);     uf[u] += uf[v];     uf[v] = u;     prodSum -= cnt[u][0] * cnt[u][1] * cnt[u][2];     prodSum -= cnt[v][0] * cnt[v][1] * cnt[v][2];     cnt[u][0] += cnt[v][0];     cnt[u][1] += cnt[v][1];     cnt[u][2] += cnt[v][2];     prodSum += cnt[u][0] * cnt[u][1] * cnt[u][2];   }   int main() {     using namespace SA;     for (; ~scanf( %s , t);) {       LA = strlen(t);       t[LA] =  0 ;       scanf( %s , t + LA + 1);       LB = strlen(t + LA + 1);       t[LA + 1 + LB] =  1 ;       scanf( %s , t + LA + 1 + LB + 1);       LC = strlen(t + LA + 1 + LB + 1);       t[LA + 1 + LB + 1 + LC] =  2 ;       t[LA + 1 + LB + 1 + LC + 1] = 0;       makeSA();       makeHA();       eventsLen = 0;       for (int i = 0; i < n; ++i) {         events[eventsLen++] = make_pair(lcp[i], i);       }       sort(events, events + eventsLen);       reverse(events, events + eventsLen);       fill(uf, uf + n + 1, -1);       for (int i = 0; i <= n; ++i) {         cnt[i][0] = 0;         cnt[i][1] = 0;         cnt[i][2] = 0;         if (0 <= ki[i] && ki[i] < LA) {           cnt[i][0] = 1;         } else if (LA + 1 <= ki[i] && ki[i] < LA + 1 + LB) {           cnt[i][1] = 1;         } else if (LA + 1 + LB + 1 <= ki[i] && ki[i] < LA + 1 + LB + 1 + LC) {           cnt[i][2] = 1;         }       }       prodSum = 0;       for (int h = 0, k = n; k >= 0; --k) {         for (; h < eventsLen && events[h].first == k; ++h) {           const int i = events[h].second;           conn(i, i + 1);         }         ans[k] = prodSum;       }       const int ansLen = min({LA, LB, LC});       for (int k = 1; k <= ansLen; ++k) {         if (k > 1) printf(   );         printf( %d , (int)(ans[k] % MO));       }       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000005;   int l[N], r[N], n, i, ans, a[N], w, j;   char c[N];   bool bb[N];   set<int> s;   set<int>::iterator it;   inline void maintain(int i) {     if ((l[i] && c[i] != c[l[i]]) || (r[i] <= n && c[r[i]] != c[i]))       s.insert(i);     else if (s.count(i))       s.erase(i);   }   int main() {     scanf( %s , c + 1);     n = strlen(c + 1);     for (i = 1; i <= n; ++i) {       l[i] = i - 1, r[i] = i + 1;       r[0] = 1, l[n + 1] = n;       if ((i > 1 && c[i] != c[i - 1]) || (i < n && c[i] != c[i + 1])) a[++w] = i;     }     ans = bool(w);     for (;;) {       for (i = 1; i <= w; ++i) bb[a[i]] = 1;       s.clear();       for (i = 1; i <= w; ++i) {         j = a[i];         l[r[j]] = l[j];         r[l[j]] = r[j];         if (!bb[l[j]] && l[j]) maintain(l[j]);         if (!bb[r[j]] && r[j] <= n) maintain(r[j]);       }       for (i = 1; i <= w; ++i) bb[a[i]] = 0;       if (s.empty()) break;       ++ans;       for (it = s.begin(), w = 0; it != s.end(); ++it) a[++w] = *it;       s.clear();     }     return printf( %d n , ans), 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     vector<int> A(91, 0);     for (int i = 0; s[i]; i++) {       A[(int)s[i]]++;     }     for (int i = 65; i < 65 + k; i++)       if (A[i] == 0) {         cout <<  0 ;         return 0;       }     cout << k * (*min_element(A.begin() + 65, A.begin() + 65 + k));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   struct Matrix {     long long coef[105][105];     Matrix() {       for (int i = (0); i <= (101); ++i)         for (int j = (0); j <= (101); ++j) coef[i][j] = 0;     }     Matrix operator*(Matrix a) {       Matrix res;       for (int i = (0); i <= (101); ++i) {         for (int j = (0); j <= (101); ++j) {           for (int k = (0); k <= (101); ++k) {             res.coef[i][j] =                 (res.coef[i][j] + coef[i][k] * a.coef[k][j] % mod) % mod;           }         }       }       return res;     }   };   Matrix expo(Matrix A, long long n) {     if (n == 1) return A;     Matrix Q = expo(A, n / 2);     if (n % 2 == 0) return Q * Q;     return Q * Q * A;   }   int a[50001];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, b, k, x;     cin >> n >> b >> k >> x;     Matrix A;     for (int i = 1; i <= int(n); i++) cin >> a[i];     for (int i = 1; i <= int(n); i++) {       for (int m = 0; m < int(x); m++) {         int newm = (m * 10 + a[i]) % x;         A.coef[m][newm]++;       }     }     Matrix B = expo(A, b);     cout << B.coef[0][k] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const long long int INF = 1e18 + 2;   bool compareBysecond(pair<long long int, long long int> a,                        pair<long long int, long long int> b) {     return a.second > b.second;   }   int log(long long int x) {     int cnt = 0;     while (x > 0) {       cnt++;       x = x >> 1;     }     return cnt;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, x, y;       cin >> n >> x >> y;       int k = n;       while (((y - x) % (k - 1)) != 0) k--;       int d = (y - x) / (k - 1);       vector<int> ans;       for (int i = 0; x + i * d <= y; ++i) {         ans.push_back(x + i * d);       }       if (ans.size() != n) {         int temp = x - d;         while (temp > 0 && ans.size() != n) {           ans.push_back(temp);           temp -= d;         }       }       if (ans.size() != n) {         int temp = y + d;         while (ans.size() != n) {           ans.push_back(temp);           temp += d;         }       }       for (auto it : ans) cout << it <<    ;       cout <<   n ;       ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000 + 10;   const int MAXM = 10000 + 10;   const int INF = 1000 * 1000 * 1000;   int n, m, a[MAXM], b[MAXM], c[MAXM], q[MAXN], d[MAXN][MAXN], s, minimum[MAXN];   int main() {     int check = 0;     int sum = 0;     int pt = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       minimum[i] = INF;     }     cin >> m;     for (int i = 0; i < m; i++) {       cin >> a[i] >> b[i] >> c[i];       d[a[i]][b[i]] = c[i];       minimum[b[i]] = min(c[i], minimum[b[i]]);     }     for (int i = 1; i <= n; i++) {       if (minimum[i] != INF) {         sum += minimum[i];         check++;       }     }     if (check == n - 1)       cout << sum;     else       cout << -1;     cin >> s;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char arr[2][100010];   int vis[2][100010];   int k, n, curj1, curj2;   bool valid(int i, int j) {     if (i >= 0 && i < 2 && j >= 0 && j >= n) return true;     if (i >= 0 && i < 2 && j >= 0 && j < n && arr[i][j] !=  X  && vis[i][j] == 0)       return true;     return false;   }   void bfs(int i, int j) {     queue<pair<int, int> > q;     q.push(make_pair(i, j));     vis[i][j] = 1;     while (!q.empty()) {       int toi = q.front().first;       int toj = q.front().second;       q.pop();       if (toj >= n) {         cout <<  YES  << endl;         return;       }       if (valid(toi + 1, toj + k)) {         q.push(make_pair(toi + 1, toj + k));         vis[toi + 1][toj + k] = vis[toi][toj] + 1;       }       if (valid(toi - 1, toj + k)) {         q.push(make_pair(toi - 1, toj + k));         vis[toi - 1][toj + k] = vis[toi][toj] + 1;       }       if (valid(toi, toj + 1)) {         q.push(make_pair(toi, toj + 1));         vis[toi][toj + 1] = vis[toi][toj] + 1;       }       if (valid(toi, toj - 1) && toj - 1 > vis[toi][toj] - 1) {         q.push(make_pair(toi, toj - 1));         vis[toi][toj - 1] = vis[toi][toj] + 1;       }     }     cout <<  NO  << endl;   }   int main() {     int i, j;     cin >> n >> k;     for (i = 0; i < 2; i++) {       for (j = 0; j < n; j++) cin >> arr[i][j];     }     bfs(0, 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Res[2][7010], N[2][7010], Loss[2][7010];   int n, m, k, OpN[2];   queue<pair<int, int> > Q;   int main() {     srand((unsigned)time(0));     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     cin.get();     for (int i = 0; i < 2; i++) {       cin >> m;       OpN[i] = m;       for (int j = 0; j < m; j++) {         cin >> k;         N[i][j] = k;         Res[i][n + 1 - k] = 1;         Q.push({i, n + 1 - k});       }     }     pair<int, int>* P;     while (!Q.empty()) {       P = &Q.front();       int k = !P->first, i = P->second;       Q.pop();       for (int j = 0; j < OpN[k]; j++) {         int h = N[k][j], l = ((i - h < 1) ? (i - h + n) : (i - h));         if (Res[k][l] == 0) {           Loss[k][l]++;         }       }       for (int i = 2; i < n + 1; i++) {         if (Res[k][i] == 0) {           if (Loss[k][i] == OpN[k]) {             Res[k][i] = 2;             for (int t = 0; t < OpN[!k]; t++) {               int h = N[!k][t], l = ((i - h < 1) ? (i - h + n) : (i - h));               if (Res[!k][l] == 0) {                 Res[!k][l] = 1;                 Q.push({!k, l});               }             }           }         }       }     }     string Out[3] = { Loop ,  Win ,  Lose };     for (int k = 0; k < 2; k++) {       for (int i = 2; i < n + 1; i++) {         cout << Out[Res[k][i]].c_str() <<    ;       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long a, b, c, d;       cin >> a >> b >> c >> d;       bool prob[5];       for (bool& i : prob) {         i = true;       }       if ((a == 0 && b == 0) || (a + b) % 2 == 0) {         prob[1] = prob[2] = false;         if (a == 0 && d == 0) {           prob[4] = false;         } else if (b == 0 && c == 0) {           prob[3] = false;         }       } else {         prob[3] = prob[4] = false;         if (a == 0 && d == 0) {           prob[1] = false;         } else if (b == 0 && c == 0) {           prob[2] = false;         }       }       for (int i = 1; i <= 4; i++) {         cout << (prob[i] ?  Ya   :  Tidak  );       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> p[3030];   long long dist[3030][3030];   pair<long long, long long> out[3030][5];   pair<long long, long long> in[3030][5];   void bfs(int x) {     dist[x][x] = 0;     queue<pair<long long, long long> > q;     q.push(make_pair(0, x));     pair<long long, long long> t;     while (!q.empty()) {       t = q.front();       q.pop();       for (int i = 0; i < p[t.second].size(); i++) {         if (dist[x][p[t.second][i]] > 1 + t.first) {           dist[x][p[t.second][i]] = 1 + t.first;           out[x][0] = make_pair(dist[x][p[t.second][i]], p[t.second][i]);           sort(out[x], out[x] + 5);           in[p[t.second][i]][0] = make_pair(dist[x][p[t.second][i]], x);           sort(in[p[t.second][i]], in[p[t.second][i]] + 5);           q.push(make_pair(dist[x][p[t.second][i]], p[t.second][i]));         }       }     }   }   int main() {     int n, m, x, y;     cin >> n >> m;     for (int i = 0; i < m; i++) {       scanf( %d%d , &x, &y);       p[x].push_back(y);     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         dist[i][j] = 1e18;       }       for (int j = 0; j <= 4; j++) {         out[i][j] = make_pair(-1, -1);         in[i][j] = make_pair(-1, -1);       }     }     for (int i = 1; i <= n; i++) bfs(i);     long long l1, l2;     int res[5];     long long maxx = -1;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i == j) continue;         l2 = dist[i][j];         if (l2 == 1e18) continue;         for (int k = 4; k >= 0; k--) {           for (int k1 = 4; k1 >= 0; k1--) {             l1 = l2;             x = in[i][k].second;             y = out[j][k1].second;             if (x == y) continue;             if (x == i || x == j) continue;             if (y == i || y == j) continue;             if (x == -1 || y == -1) continue;             l1 += in[i][k].first;             l1 += out[j][k1].first;             if (maxx < l1) {               maxx = l1;               res[0] = x;               res[1] = i;               res[2] = j;               res[3] = y;             }           }         }       }     }     for (int i = 0; i < 4; i++) printf( %d  , res[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10, mod = 1e9 + 7;   void solve() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     int ans = 0;     for (int i = 1; i < n; ++i) {       if (a[i] == 3 && a[i - 1] == 1) {         ans += 4;       } else if (a[i] == 1 && a[i - 1] == 3) {         ans += 4;       } else if (a[i] == 2 && a[i - 1] == 1) {         if (i > 1 && a[i - 2] == 3) {           ans += 2;         } else {           ans += 3;         }       } else if (a[i] == 1 && a[i - 1] == 2) {         ans += 3;       } else if (a[i] == 3 && a[i - 1] == 2) {         cout <<  Infinite  << endl;         return;       } else if (a[i] == 2 && a[i - 1] == 3) {         cout <<  Infinite  << endl;         return;       }     }     cout <<  Finite  << endl;     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   const int M = 100;   int cal(int t) { return (t >= 0 ? t : -t); }   int n, d, a[M + 5], x[M + 5], y[M + 5], dist[M + 5][M + 5];   int main() {     scanf( %d %d , &n, &d);     for (int i = 2; i < n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) scanf( %d %d , &x[i], &y[i]);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         dist[i][j] =             (i == j ? 0 : cal(x[i] - x[j]) * d + cal(y[i] - y[j]) * d - a[j]);     for (int k = 1; k <= n; k++)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++)           dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);     printf( %d , dist[1][n]);   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, k;     cin >> n >> k;     vector<string> s(n);     for (long long i = 0; i < n; i++) cin >> s[i];     vector<long long> g[n * n];     for (long long i = 0; i < n; i++)       for (long long j = 0; j < n; j++) {         if (i + 1 < n) g[i * n + j].push_back((i + 1) * n + j);         if (j + 1 < n) g[i * n + j].push_back(i * n + (j + 1));       }     vector<long long> kval(n * n);     vector<char> cval(n * n);     vector<char> cval2(n * n);     for (long long i = 0; i < n; i++)       for (long long j = 0; j < n; j++) {         cval[i * n + j] = s[i][j];         cval2[i * n + j] = s[i][j];       }     kval[0] = k;     if (cval[0] !=  a  && kval[0]) {       cval[0] =  a ;       kval[0] -= 1;     }     string ans;     queue<long long> q;     ans += cval[0];     q.push(0);     while (q.size()) {       set<long long> tq;       long long maxkval = 0;       char mincval =  z ;       while (q.size()) {         long long x = q.front();         q.pop();         for (auto y : g[x]) {           tq.insert(y);           if (kval[x]) {             kval[y] = max(kval[y], kval[x] - (cval[y] !=  a ));             cval2[y] =  a ;           }           maxkval = max(maxkval, kval[y]);           mincval = min(mincval, cval2[y]);         }       }       ans += mincval;       for (auto v : tq)         if (cval2[v] == mincval) q.push(v);     }     cout << ans.substr(0, 2 * n - 1) <<   n ;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using std::abs;   using std::cerr;   using std::cin;   using std::cout;   using std::map;   using std::max;   using std::min;   using std::pair;   using std::set;   using std::string;   using std::swap;   using std::vector;   using ll = long long;   using uint = unsigned int;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   template <typename T>   void err(vector<string>::iterator it, T a) {     cerr << it->substr((*it)[0] ==    ) <<   =   << a <<   n ;   }   template <typename T, typename... Ts>   void err(vector<string>::iterator it, T a, Ts... as) {     cerr << it->substr((*it)[0] ==    ) <<   =   << a <<  ,  ;     err(++it, as...);   }   struct init {     init() {       cin.tie(0);       std::iostream::sync_with_stdio(0);       cout << std::fixed << std::setprecision(10);       cerr << std::fixed << std::setprecision(10);       srand(228);     }     ~init() {       cerr <<  Time elapsed:   << 1.0 * (double)clock() / CLOCKS_PER_SEC            <<  s. n ;     }   } init;   const int MAXN = 1e5 + 15;   const ll INF = 1e16;   ll a[MAXN][3];   ll dp[MAXN][3][2];   int main() {     int n;     cin >> n;     for (int i = 0; i <= n; ++i)       for (int j = 0; j < 3; ++j)         for (int k = 0; k < 2; ++k) dp[i][j][k] = -INF;     for (int i = 0; i < 3; ++i)       for (int j = 1; j <= n; ++j) cin >> a[j][i];     a[0][1] = a[0][2] = -INF;     dp[0][0][0] = 0;     for (int i = 1; i <= n; ++i) {       dp[i][0][0] =           max({dp[i - 1][0][0] + a[i][0], dp[i - 1][1][0] + a[i - 1][0] + a[i][0],                dp[i - 1][2][0] + a[i - 1][1] + a[i - 1][0] + a[i][0],                i > 1 ? dp[i - 1][2][1] + a[i - 1][1] + a[i - 2][1] + a[i - 2][0] +                            a[i - 1][0] + a[i][0]                      : -INF});       dp[i][0][1] = dp[i - 1][0][0] + a[i][0];       dp[i][1][0] =           max({dp[i - 1][0][0] + a[i - 1][1] + a[i][1], dp[i - 1][1][0] + a[i][1],                dp[i - 1][2][0] + a[i - 1][1] + a[i][1]});       dp[i][1][1] = -INF;       dp[i][2][0] =           max({dp[i - 1][0][0] + a[i - 1][1] + a[i - 1][2] + a[i][2],                dp[i - 1][1][0] + a[i - 1][2] + a[i][2], dp[i - 1][2][0] + a[i][2],                i > 1 ? dp[i - 1][0][1] + a[i - 1][1] + a[i - 2][1] + a[i - 2][2] +                            a[i - 1][2] + a[i][2]                      : -INF});       dp[i][2][1] = dp[i - 1][2][0] + a[i][2];       for (int j = 0; j < 3; ++j)         ;     }     ll ans =         max({dp[n][0][0] + a[n][1] + a[n][2], dp[n][1][0] + a[n][2], dp[n][2][0],              dp[n][0][1] + a[n][1] + a[n - 1][1] + a[n - 1][2] + a[n][2]});     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1e-9;   const long double PI = atan(1) * 4;   const long long M = 1000000007;   struct PT {     double x, y;     PT() {}     PT(double x, double y) : x(x), y(y) {}     PT(const PT &p) : x(p.x), y(p.y) {}     PT operator+(const PT &p) const { return PT(x + p.x, y + p.y); }     PT operator-(const PT &p) const { return PT(x - p.x, y - p.y); }     PT operator*(double c) const { return PT(x * c, y * c); }     PT operator/(double c) const { return PT(x / c, y / c); }   };   double dot(PT p, PT q) { return p.x * q.x + p.y * q.y; }   double dist2(PT p, PT q) { return dot(p - q, p - q); }   double cross(PT p, PT q) { return p.x * q.y - p.y * q.x; }   double cos_u2v(const PT &u, const PT &v) {     return dot(u, v) / sqrt(dot(u, u) * dot(v, v));   }   double sin_u2v(const PT &u, const PT &v) {     return cross(u, v) / sqrt(dot(u, u) * dot(v, v));   }   ostream &operator<<(ostream &os, const PT &p) {     os <<  (  << p.x <<  ,  << p.y <<  ) ;   }   double vector2angle(const PT &v) { return atan2(v.y, v.x); }   struct UnionFind {     vector<long long> C;     UnionFind(long long n) : C(n) {       for (int i = 0; i < n; i++) C[i] = i;     }     long long find(long long x) { return (C[x] == x) ? x : C[x] = find(C[x]); }     void merge(long long x, long long y) { C[find(x)] = find(y); }   };   long long mod(long long x, long long m) { return ((x % m) + m) % m; }   long long gcd(long long a, long long b) {     for (; b > 0; swap(a, b)) a %= b;     return a;   }   long long extended_euclid(long long a, long long b, long long &x,                             long long &y) {     long long xx = y = 0;     long long yy = x = 1;     while (b) {       long long q = a / b;       long long t = b;       b = a % b;       a = t;       t = xx;       xx = x - q * xx;       x = t;       t = yy;       yy = y - q * yy;       y = t;     }     return a;   }   long long mod_inverse(long long a, long long n) {     long long x, y;     long long d = extended_euclid(a, n, x, y);     if (d > 1) return -1;     return mod(x, n);   }   long long discretize(vector<long long> &x) {     set<long long> avset(x.begin(), x.end());     map<long long, long long> vmap;     long long dn = 0;     for (auto it = avset.begin(); it != avset.end(); it++) vmap[*it] = dn++;     for (long long i = 0, n = x.size(); i < n; i++) x[i] = vmap[x[i]];     return dn;   }   struct LPSolver {     int m, n;     vector<long long> B, N;     vector<vector<long double>> D;     LPSolver(const vector<vector<long double>> &A, const vector<long double> &b,              const vector<long double> &c)         : m(b.size()),           n(c.size()),           N(n + 1),           B(m),           D(m + 2, vector<long double>(n + 2)) {       for (int i = 0; i < m; i++)         for (int j = 0; j < n; j++) D[i][j] = A[i][j];       for (int i = 0; i < m; i++) {         B[i] = n + i;         D[i][n] = -1;         D[i][n + 1] = b[i];       }       for (int j = 0; j < n; j++) {         N[j] = j;         D[m][j] = -c[j];       }       N[n] = -1;       D[m + 1][n] = 1;     }     void Pivot(int r, int s) {       for (int i = 0; i < m + 2; i++)         if (i != r)           for (int j = 0; j < n + 2; j++)             if (j != s) D[i][j] -= D[r][j] * D[i][s] / D[r][s];       for (int j = 0; j < n + 2; j++)         if (j != s) D[r][j] /= D[r][s];       for (int i = 0; i < m + 2; i++)         if (i != r) D[i][s] /= -D[r][s];       D[r][s] = 1.0 / D[r][s];       swap(B[r], N[s]);     }     bool Simplex(int phase) {       int x = phase == 1 ? m + 1 : m;       while (true) {         int s = -1;         for (int j = 0; j <= n; j++) {           if (phase == 2 && N[j] == -1) continue;           if (s == -1 || D[x][j] < D[x][s] || D[x][j] == D[x][s] && N[j] < N[s])             s = j;         }         if (D[x][s] > -EPS) return true;         int r = -1;         for (int i = 0; i < m; i++) {           if (D[i][s] < EPS) continue;           if (r == -1 || D[i][n + 1] / D[i][s] < D[r][n + 1] / D[r][s] ||               (D[i][n + 1] / D[i][s]) == (D[r][n + 1] / D[r][s]) && B[i] < B[r])             r = i;         }         if (r == -1) return false;         Pivot(r, s);       }     }     long double solve(vector<long double> &x) {       int r = 0;       for (int i = 1; i < m; i++)         if (D[i][n + 1] < D[r][n + 1]) r = i;       if (D[r][n + 1] < -EPS) {         Pivot(r, n);         if (!Simplex(1) || D[m + 1][n + 1] < -EPS)           return -numeric_limits<long double>::infinity();         for (int i = 0; i < m; i++)           if (B[i] == -1) {             int s = -1;             for (int j = 0; j <= n; j++)               if (s == -1 || D[i][j] < D[i][s] ||                   D[i][j] == D[i][s] && N[j] < N[s])                 s = j;             Pivot(i, s);           }       }       if (!Simplex(2)) return numeric_limits<long double>::infinity();       x = vector<long double>(n);       for (int i = 0; i < m; i++)         if (B[i] < n) x[B[i]] = D[i][n + 1];       return D[m][n + 1];     }   };   void buildadjlist(long long n, const vector<long long> &froms,                     const vector<long long> &tos, vector<long long> &v2e0,                     vector<long long> &e2n) {     v2e0.resize(n);     v2e0.assign(n, -1);     long long en = froms.size();     e2n.resize(en);     for (int i = 0; i < en; i++) {       long long f = froms[i];       long long t = tos[i];       e2n[i] = v2e0[f];       v2e0[f] = i;     }   }   void dijkstra(const vector<long long> &v2e0, const vector<long long> &e2t,                 const vector<long long> &e2c, const vector<long long> &e2n,                 long long src, vector<long long> &dist, vector<long long> &prec) {     long long n = v2e0.size();     dist.resize(n);     dist.assign(n, INT_MAX);     prec.resize(n);     prec.assign(n, -1);     vector<bool> arr(n);     long long sel = src;     dist[sel] = 0;     while (sel >= 0) {       arr[sel] = true;       for (long long i = v2e0[sel]; i >= 0; i = e2n[i]) {         long long to = e2t[i];         long long cost = e2c[i];         if (!arr[to] && dist[to] > dist[sel] + cost) {           dist[to] = dist[sel] + cost;           prec[to] = sel;         }       }       sel = -1;       for (long long i = 0; i < n; i++)         if (!arr[i] && (sel == -1 || dist[i] < dist[sel])) sel = i;     }   }   void tarjan_dfs(long long v, long long &timer, long long &cn,                   vector<long long> &vtime, vector<long long> &rtime,                   const vector<long long> &v2e0, const vector<long long> &e2t,                   const vector<long long> &e2n, vector<long long> &v2c,                   stack<long long> &stk) {     stk.push(v);     rtime[v] = vtime[v] = timer++;     for (long long i = v2e0[v]; i >= 0; i = e2n[i]) {       long long w = e2t[i];       if (vtime[w] == -1) {         tarjan_dfs(w, timer, cn, vtime, rtime, v2e0, e2t, e2n, v2c, stk);         rtime[v] = min(rtime[v], rtime[w]);       } else if (v2c[w] == -1)         rtime[v] = min(rtime[v], vtime[w]);     }     if (vtime[v] == rtime[v]) {       while (true) {         long long pv = stk.top();         v2c[pv] = cn;         stk.pop();         if (pv == v) break;       }       cn++;     }   }   void tarjan_strong(long long n, const vector<long long> &v2e0,                      const vector<long long> &e2t, const vector<long long> &e2n,                      vector<long long> &v2c) {     v2c.assign(n, -1);     vector<long long> vtime(n, -1);     vector<long long> rtime(n, -1);     stack<long long> stk;     long long timer = 0, cn = 0;     for (long long i = 0; i < n; i++) {       if (vtime[i] >= 0) continue;       tarjan_dfs(i, timer, cn, vtime, rtime, v2e0, e2t, e2n, v2c, stk);     }   }   struct FordFulk {     const vector<long long> &v2e0;     const vector<long long> &e2f;     const vector<long long> &e2t;     const vector<long long> &e2c;     const vector<long long> &e2n;     long long s, t;     FordFulk(const vector<long long> &_v2e0, const vector<long long> &_e2f,              const vector<long long> &_e2t, const vector<long long> &_e2c,              const vector<long long> &_e2n, long long _s, long long _t)         : s(_s), t(_t), v2e0(_v2e0), e2f(_e2f), e2t(_e2t), e2c(_e2c), e2n(_e2n) {}     long long _find_aug_path(const vector<long long> &v2e0,                              const vector<long long> &e2f,                              const vector<long long> &e2t,                              const vector<long long> &e2c,                              const vector<long long> &e2n, long long s,                              long long t, vector<long long> &epath) {       vector<long long> q2v;       vector<long long> q2p;       vector<long long> q2e;       vector<long long> q2f;       vector<bool> inq(v2e0.size(), false);       q2v.push_back(s);       q2p.push_back(-1);       q2e.push_back(-1);       q2f.push_back(INT_MAX);       inq[s] = true;       for (long long i = 0; i < q2v.size(); i++) {         long long crt = q2v[i];         long long f = q2f[i];         for (long long j = v2e0[crt]; j != -1; j = e2n[j]) {           long long to = e2t[j];           long long rem = e2c[j];           if (inq[to]) continue;           if (rem <= 0) continue;           q2v.push_back(to);           q2p.push_back(i);           q2e.push_back(j);           q2f.push_back(min(f, rem));           inq[to] = true;         }       }       for (long long i = 0; i < q2v.size(); i++) {         if (q2v[i] != t) continue;         stack<long long> stk;         for (long long j = i; j > 0; j = q2p[j]) {           stk.push(q2e[j]);         }         while (!stk.empty()) {           epath.push_back(stk.top());           stk.pop();         }         return q2f[i];       }       return 0;     }     long long eval() {       long long en = e2f.size();       map<pair<long long, long long>, long long> rsd;       for (long long i = 0; i < en; i++) {         long long f = e2f[i];         long long t = e2t[i];         rsd[make_pair(f, t)] += e2c[i];         rsd[make_pair(t, f)] += 0;       }       map<pair<long long, long long>, long long> nei;       long long ren = 0;       for (auto er : rsd) {         nei[er.first] = ren++;       }       long long rvn = v2e0.size();       vector<long long> rv2e0(rvn, -1);       vector<long long> re2f(ren);       vector<long long> re2t(ren);       vector<long long> re2c(ren);       vector<long long> re2n(ren);       vector<long long> re2p(ren);       long long rei = 0;       for (auto er : rsd) {         long long f = er.first.first;         long long t = er.first.second;         long long c = er.second;         re2f[rei] = f;         re2t[rei] = t;         re2c[rei] = c;         re2p[rei] = nei[make_pair(t, f)];         re2n[rei] = rv2e0[f];         rv2e0[f] = rei;         ++rei;       }       long long sol = 0;       vector<long long> epath;       while (true) {         epath.clear();         long long res =             _find_aug_path(rv2e0, re2f, re2t, re2c, re2n, s, t, epath);         if (res == 0) break;         for (auto ei : epath) {           re2c[ei] -= res;           re2c[re2p[ei]] += res;         }         sol += res;       }       return sol;     }   };   template <typename T>   struct BIT1D {     long long n;     vector<T> v;     T (*fnx)(long long, T);     T (*fab)(T, T);     long long rg(long long k) { return ((k ^ (k + 1)) + 1) / 2; }     BIT1D(long long _n, T v0, T (*_fnx)(long long, T), T (*_fab)(T, T))         : n(_n), v(_n), fnx(_fnx), fab(_fab) {       for (long long i = 0; i < n; i++) v[i] = fnx(rg(i), v0);     }     void update(long long i, T v1) {       for (; i < n; i += rg(i)) v[i] = fab(v[i], v1);     }     T query(long long i) {       long long j = i - rg(i);       return (j < 0) ? v[i] : (query(j) + v[i]);     }   };   template <typename T>   struct LazySegTree1D {     vector<T> v;     vector<long long> opr;     vector<T> opd;     vector<long long> nxt;     long long LEFT;     long long RGHT;     T (*fnx)(long long, T);     T (*fab)(T, T);     LazySegTree1D(long long _l, long long _r, T _v, T (*_fnx)(long long, T),                   T (*_fab)(T, T))         : v(1), opr(1), opd(1), nxt(1), LEFT(_l), RGHT(_r), fnx(_fnx), fab(_fab) {       v[0] = fnx(RGHT - LEFT + 1, _v);       opr[0] = 0;       opd[0] = _v;       nxt[0] = -1;     }     void _split(long long i, long long l0, long long r0) {       assert(nxt[i] == -1);       assert(opr[i] == 0);       assert(l0 < r0);       long long n = v.size();       nxt[i] = n;       long long m0 = (l0 + r0) / 2;       v.push_back(fnx(m0 - l0 + 1, opd[i]));       v.push_back(fnx(r0 - m0, opd[i]));       opr.push_back(0);       opr.push_back(0);       opd.push_back(opd[i]);       opd.push_back(opd[i]);       nxt.push_back(-1);       nxt.push_back(-1);     }     void _pushdown(long long i, long long l0, long long r0) {       if (opr[i] == -1) return;       long long m0 = (l0 + r0) / 2;       if (nxt[i] == -1)         _split(i, l0, r0);       else if (opr[i] >= 0) {         _set(nxt[i], l0, m0, l0, m0, opr[i], opd[i]);         _set(nxt[i] + 1, m0 + 1, r0, m0 + 1, r0, opr[i], opd[i]);       }       opr[i] = -1;     }     void _set(long long i, long long l0, long long r0, long long l1, long long r1,               long long o1, T v1) {       assert(l1 >= l0 && r1 <= r0);       if (l0 == l1 && r0 == r1) {         if (o1 == 0) {           v[i] = fnx(r0 - l0 + 1, v1);           opr[i] = 0;           opd[i] = v1;         } else if (o1 == 1) {           v[i] = fab(v[i], fnx(r0 - l0 + 1, v1));           if (opr[i] == -1) {             opr[i] = 1;             opd[i] = v1;           } else if (opr[i] == 0) {             opr[i] = 0;             opd[i] = fab(opd[i], v1);           } else if (opr[i] == 1) {             opr[i] = 1;             opd[i] = fab(opd[i], v1);           }         }         return;       }       long long m0 = (l0 + r0) / 2;       _pushdown(i, l0, r0);       if (l1 <= m0) _set(nxt[i], l0, m0, l1, min(r1, m0), o1, v1);       if (r1 > m0) _set(nxt[i] + 1, m0 + 1, r0, max(l1, m0 + 1), r1, o1, v1);       v[i] = fab(v[nxt[i]], v[nxt[i] + 1]);     }     T _get(long long i, long long l0, long long r0, long long l1, long long r1) {       assert(l0 <= l1 && r1 <= r0);       if (l0 == l1 && r1 == r0) return v[i];       _pushdown(i, l0, r0);       long long m0 = (l0 + r0) / 2;       if (r1 <= m0) return _get(nxt[i], l0, m0, l1, r1);       if (m0 + 1 <= l1) return _get(nxt[i] + 1, m0 + 1, r0, l1, r1);       T lv = _get(nxt[i], l0, m0, l1, m0);       T rv = _get(nxt[i] + 1, m0 + 1, r0, m0 + 1, r1);       return fab(lv, rv);     }     void updres(long long l1, long long r1, T v1) {       _set(0, LEFT, RGHT, l1, r1, 1, v1);     }     void setval(long long l1, long long r1, T v1) {       _set(0, LEFT, RGHT, l1, r1, 0, v1);     }     T get(long long l1, long long r1) { return _get(0, LEFT, RGHT, l1, r1); }   };   void suffix_array(const string &s, vector<long long> &sa,                     vector<long long> &rank) {     long long n = s.size();     long long ri = 0;     vector<vector<long long>> tmprank(2, vector<long long>(n));     vector<pair<pair<long long, long long>, long long>> kni(n);     for (long long g = 1; g / 2 <= n - 1; g *= 2, ri = 1 - ri) {       for (long long i = 0; i < n; i++) {         long long key1 = (g == 1) ? s[i] : tmprank[ri][i];         long long key2 = (g == 1)          ? 0                          : (i + g / 2 < n) ? (tmprank[ri][i + g / 2])                                            : -1;         kni[i] = make_pair(make_pair(key1, key2), i);       }       sort(kni.begin(), kni.end());       for (long long i = 0, last_rank = -1; i < n; i++) {         long long this_rank =             (i > 0 && kni[i].first == kni[i - 1].first) ? last_rank : i;         last_rank = tmprank[1 - ri][kni[i].second] = this_rank;       }     }     rank.resize(n);     rank.assign(tmprank[ri].begin(), tmprank[ri].end());     sa.resize(n);     for (long long i = 0; i < n; i++) sa[rank[i]] = i;   }   struct SuffixTree {     string str;     vector<unordered_map<long long, long long>> sta;     vector<unordered_map<long long, long long>> end;     vector<unordered_map<long long, long long>> nxt;     vector<long long> suflink;     long long capacity;     long long node_count;     long long act_node;     long long act_br;     long long act_len;     long long todo_count;     bool _nodehasbr(long long node, long long br) {       auto m = nxt[node];       return m.find(br) != m.end();     }     long long _newnode() {       if (node_count < capacity) {         long long newi = node_count++;         suflink[newi] = -1;         sta[newi].clear();         end[newi].clear();         nxt[newi].clear();         return newi;       }       sta.emplace_back();       end.emplace_back();       nxt.emplace_back();       suflink.push_back(-1);       ++node_count;       ++capacity;       return node_count - 1;     }     long long _edgerealend(long long node, long long br) {       long long tmp = end[node][br];       return (tmp == -1) ? (str.size() - 1) : tmp;     }     long long _edgelen(long long node, long long br) {       return (br == -1) ? 0              : (!_nodehasbr(node, br))                  ? 0                  : (_edgerealend(node, br) - sta[node][br] + 1);     }     void clear() {       node_count = 0;       act_node = 0;       act_br = -1;       act_len = 0;       todo_count = 0;       _newnode();     }     SuffixTree(long long est_strlen) {       capacity = 0;       if (est_strlen > 0) {         long long est_nodecnt = est_strlen * 2;         capacity = est_nodecnt;         sta = vector<unordered_map<long long, long long>>(est_nodecnt);         end = vector<unordered_map<long long, long long>>(est_nodecnt);         nxt = vector<unordered_map<long long, long long>>(est_nodecnt);         suflink = vector<long long>(est_nodecnt, -1);       }       clear();     }     bool _tryextend(long long chr) {       if (act_len == 0) {         if (!_nodehasbr(act_node, chr)) return false;         act_br = chr;         ++act_len;         return true;       }       if (act_len == _edgelen(act_node, act_br)) {         long long nxtnode = nxt[act_node][act_br];         if (!_nodehasbr(nxtnode, chr)) return false;         act_node = nxtnode;         act_br = chr;         act_len = 1;         return true;       }       long long start = sta[act_node][act_br];       if (chr != str[start + act_len]) return false;       ++act_len;       return true;     }     void _branch(long long node, long long chr) {       long long newnode = _newnode();       sta[node][chr] = str.size() - 1;       end[node][chr] = -1;       nxt[node][chr] = newnode;     }     long long _actsplit(long long chr) {       long long new0 = _newnode();       long long new1 = _newnode();       long long start = sta[act_node][act_br];       sta[new0][str[start + act_len]] = start + act_len;       end[new0][str[start + act_len]] = end[act_node][act_br];       nxt[new0][str[start + act_len]] = nxt[act_node][act_br];       sta[new0][chr] = str.size() - 1;       end[new0][chr] = -1;       nxt[new0][chr] = new1;       sta[act_node][act_br] = start;       end[act_node][act_br] = start + act_len - 1;       nxt[act_node][act_br] = new0;       return new0;     }     long long _splitorbranch(long long chr) {       if (act_br >= 0 && act_len < _edgelen(act_node, act_br))         return _actsplit(chr);       long long target_node = (act_len == 0) ? 0 : nxt[act_node][act_br];       _branch(target_node, chr);       return target_node;     }     string _edgestr(long long node, long long br) {       long long start = sta[node][br];       long long end = _edgerealend(node, br);       return str.substr(start, end - start + 1);     }     void _actsupdate(long long node, long long br, long long len) {       act_node = node, act_br = br, act_len = len;     }     void _actfastfwd(long long start, long long slen) {       if (act_br == -1) return;       while (true) {         long long elen = _edgelen(act_node, act_br);         if (slen <= elen) return;         long long new_act_node = nxt[act_node][act_br];         long long new_act_br = str[start + elen];         long long new_act_len = act_len - elen;         _actsupdate(new_act_node, new_act_br, new_act_len);         start += elen;         slen -= elen;       }     }     bool _actsgotonextsuf() {       if (act_len == 0) return false;       long long estart = sta[act_node][act_br];       if (act_node == 0) {         act_br = (act_len == 1) ? (-1) : str[estart + 1];         --act_len;         _actfastfwd(estart + 1, act_len);       } else {         act_node = (suflink[act_node] >= 0) ? suflink[act_node] : 0;         _actfastfwd(estart, act_len);       }     }     void insert(long long chr) {       str.push_back(chr);       ++todo_count;       long long prev_created = -1;       for (long long waitlink = -1; todo_count > 0; --todo_count) {         bool suffix_exists = _tryextend(chr);         if (suffix_exists) {           waitlink = act_node;         } else {           waitlink = _splitorbranch(chr);         }         if (prev_created >= 0) suflink[prev_created] = waitlink;         prev_created = waitlink;         if (suffix_exists) break;         _actsgotonextsuf();       }     }   };   const int N = 100;   int l0[N] = {};   int l1[N] = {};   int r0[N] = {};   int r1[N] = {};   int main() {     srand(time(NULL));     int n, m;     cin >> n >> m;     int p = 1;     for (int i = 0; i < n; ++i) {       if (p > m) break;       l0[i] = p++;       if (p > m) break;       r0[i] = p++;       if (p > m) break;     }     for (int i = 0; i < n; ++i) {       if (p > m) break;       l1[i] = p++;       if (p > m) break;       r1[i] = p++;       if (p > m) break;     }     for (int i = 0; i < n; ++i) {       if (l1[i] > 0) printf( %d  , l1[i]);       if (l0[i] > 0) printf( %d  , l0[i]);       if (r1[i] > 0) printf( %d  , r1[i]);       if (r0[i] > 0) printf( %d  , r0[i]);     }     printf(  n );     return 0;   }


// Codeforces Round #720 (Div. 2)   // Problem link: https://codeforces.com/problemset/problem/1521/B   // Problem tags:         constructive algorithms    math    *1300              // CODE      #include <iostream>   #include <vector>   #include <limits.h>      using namespace std;      int main()    {      int t;      cin >> t;      while(t--)      {           int n;           cin >> n;                     vector<int> arr(n+1);           int min = INT_MAX, pos = -1;            for(int i = 1; i <= n; i++)           {               cin >> arr[i];               if(arr[i] < min)               {                  min = arr[i];                  pos = i;               }           }                     cout << n-1 <<   n ;                     int next = min+1;           for(int i = pos-1; i > 0; i--)           {               arr[i] = next;               cout << pos <<     << i <<     << min <<     << next <<   n ;                next++;           }           next = min+1;           for(int i = pos+1; i <= n; i++)           {               arr[i] = next;               cout << pos <<     << i <<     << min <<     << next <<   n ;                next++;           }                     // cout <<  array:  ;           // for(int i=1; i<=n; i++)           //     cout << arr[i] <<    ;           // cout <<   n ;      }            return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = (int)1e5 + 5;   int test;   vector<int> con[MX];   int dp[MX], sz[MX], prv[MX];   void dfs(int u) {     sz[u] = 1;     for (int v : con[u]) {       dp[v] = dp[u] + 1;       dfs(v);       sz[u] += sz[v];     }   }   int fst[MX], st[MX], en[MX], pn;   void hld(int u, int hd) {     fst[u] = hd;     st[u] = ++pn;     int w = 0;     for (int v : con[u])       if (sz[w] < sz[v]) w = v;     if (w) hld(w, hd);     for (int v : con[u])       if (v != w) hld(v, v);     en[u] = pn;   }   struct Node {     int a, b, clr, len;     Node(int a = 0, int b = 0, int clr = 0) : a(a), b(b), clr(clr) {}     Node operator+(const Node &d) const {       if (b >= d.a)         return Node(a, b - d.a + d.b);       else         return Node(a + d.a - b, d.b);     }     void clear() { a = len, b = 0, clr = 1; }   } node[1 << 20];   void push_down(int id) {     if (node[id].clr) {       node[id + id].clear();       node[id + id + 1].clear();       node[id].clr = 0;     }   }   void push_up(int id) {     node[id] = node[id + id] + node[id + id + 1];     node[id].len = node[id + id].len + node[id + id + 1].len;   }   void build(int id, int st, int en) {     if (st == en) {       node[id] = Node(1, 0, 0);       node[id].len = 1;       return;     }     int mid = st + en >> 1;     build(id + id, st, mid);     build(id + id + 1, mid + 1, en);     push_up(id);   }   void add(int id, int st, int en, int pos, int val) {     if (pos <= st && en <= pos) {       node[id].b += val;       return;     }     push_down(id);     int mid = st + en >> 1;     if (pos <= mid) add(id + id, st, mid, pos, val);     if (pos > mid) add(id + id + 1, mid + 1, en, pos, val);     push_up(id);   }   Node get(int id, int st, int en, int l, int r) {     if (l <= st && en <= r) {       return node[id];     }     push_down(id);     Node res = Node(0, 0);     int mid = st + en >> 1;     if (l <= mid) res = res + get(id + id, st, mid, l, r);     if (r > mid) res = res + get(id + id + 1, mid + 1, en, l, r);     push_up(id);     return res;   }   vector<pair<int, int> > cur;   int get_val(int u, int v, int n) {     int fu, fv;     Node res = Node(0, 0);     cur.clear();     while (true) {       fu = fst[u], fv = fst[v];       if (fu == fv) break;       if (dp[fu] > dp[fv]) swap(u, v), swap(fu, fv);       cur.push_back(make_pair(st[fv], st[v]));       v = prv[fv];     }     if (st[u] > st[v]) swap(u, v);     cur.push_back(make_pair(st[u], st[v]));     for (int i = cur.size() - 1; i >= 0; i--)       res = res + get(1, 1, n, cur[i].first, cur[i].second);     return res.b;   }   void clear(int id, int st, int en, int l, int r) {     if (l <= st && en <= r) {       node[id].clear();       return;     }     push_down(id);     int mid = st + en >> 1;     if (l <= mid) clear(id + id, st, mid, l, r);     if (r > mid) clear(id + id + 1, mid + 1, en, l, r);     push_up(id);   }   int main() {     ios_base::sync_with_stdio(false);     int n, q;     cin >> n >> q;     for (int i = 2; i <= n; i++) {       int u;       cin >> u;       con[u].push_back(i);       prv[i] = u;     }     dp[1] = 1;     dfs(1);     hld(1, 1);     build(1, 1, n);     while (q--) {       int type, v;       cin >> type >> v;       if (type == 1)         add(1, 1, n, st[v], 1);       else {         int val = get_val(v, 1, n);         if (type == 3)           cout << (val > 0 ?  black  :  white ) << endl;         else           add(1, 1, n, st[v], -val), clear(1, 1, n, st[v] + 1, en[v]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t, n, i, s, a1, b1, m;     cin >> t;     while (t--) {       cin >> n >> m;       if (n < m) {         cout <<  0 n ;         continue;       }       if (n == m)         cout << n % 10 <<   n ;       else {         long long int a[10] = {}, b[11] = {};         for (i = 1; i <= 10; i++) {           a[i - 1] = (m * i) % 10;           b[i] += a[i - 1] + b[i - 1];         }         a1 = n / m;         b1 = a1 % 10;         a1 = a1 / 10;         s = a1 * b[10] + b[b1];         cout << s <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int getInt();   int getNegInt();   int T, N;   int get_nearest(int p, int a, vector<vector<int> >& path,                   unordered_set<int>& me) {     if (me.find(a) != me.end()) return a;     for (auto b : path[a]) {       if (b == p) continue;       int tar = get_nearest(a, b, path, me);       if (tar != -1) return tar;     }     return -1;   }   int main(int argc, char** argv) {     int a, b, k1, k2;     T = getInt();     while (T--) {       unordered_set<int> me, he;       N = getInt();       vector<vector<int> > path(N + 1, vector<int>());       for (int i = 1; i < N; i++) {         scanf( %d%d , &a, &b);         path[a].push_back(b);         path[b].push_back(a);       }       k1 = getInt();       int start;       for (int i = 1; i <= k1; i++) {         a = getInt();         me.insert(a);       }       k2 = getInt();       for (int i = 1; i <= k2; i++) {         b = getInt();         start = b;         he.insert(b);       }       int ans = -1;       for (int i = 1; i <= 1; i++) {         cout <<  B   << start << endl;         fflush(stdout);         int index = getInt();         if (me.find(index) != me.end()) {           ans = index;           break;         }         int nearest = get_nearest(index, index, path, me);         cout <<  A   << nearest << endl;         fflush(stdout);         index = getInt();         if (he.find(index) != he.end()) {           ans = nearest;           break;         }       }       cout <<  C   << ans << endl;       fflush(stdout);     }     return 0;   }   int getInt() {     int ret = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) ret *= 10, ret += c -  0 , c = getchar();     return ret;   }   int getNegInt() {     int ret = 0, sign = 1;     char c = getchar();     while ((c <  0  && c !=  - ) || c >  9 ) c = getchar();     if (c ==  - ) sign = -1, c = getchar();     while (c >=  0  && c <=  9 ) ret *= 10, ret += c -  0 , c = getchar();     return ret * sign;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> a;   bool valido;   vector<vector<long long>> adj;   long long d;   void dfs(long long u, long long p = 0) {     if (!valido) return;     for (long long v : adj[u])       if (v != p) dfs(v, u);     if (a[u] % d == 0) {       a[p]++;     } else {       a[u]++;       if (p == 0 || a[u] % d != 0) valido = 0;     }   }   int32_t main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       a.resize(n + 1);       adj = vector<vector<long long>>(n + 1);       for (long long i = 0; i < n - 1; i++) {         long long a, b;         cin >> a >> b;         adj[a].push_back(b);         adj[b].push_back(a);       }       vector<long long> freq(n + 1);       freq[1] = 2;       for (long long i = 1; i < n - 1; i++) freq[1] = 2 * freq[1] % 998244353;       for (d = 2; d <= n - 1; d++) {         if ((n - 1) % d == 0) {           valido = 1;           fill(a.begin(), a.end(), 0);           dfs(1);           freq[d] = valido;         }       }       vector<long long> res(n + 1);       for (long long d = n; d >= 1; d--) {         res[d] = freq[d];         for (long long mult = 2 * d; mult <= n; mult += d) {           res[d] = res[d] - res[mult] + 998244353;           res[d] %= 998244353;         }       }       for (long long d = 1; d <= n; d++) {         cout << res[d] <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> nums;       for (long long i = 0; i < n; i++) {         int num;         cin >> num;         nums.push_back(num);       }       sort(nums.begin(), nums.end());       long long c = 0;       for (int i = 0; i < n; i++) {         if (nums[i] == 0) {           nums[i] += 1;           c++;         }       }       long long sum = 0;       for (int i = 0; i < n; i++) {         sum += nums[i];       }       if (sum == 0) {         c++;       }       cout << c << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int l, r;     node() { l = r = -1; }   } p[30];   int vis[30], sum[1000005];   int main() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     for (int i = 0; i < s.length(); i++) {       int id = s[i] -  A ;       if (!vis[id]) {         p[id].l = p[id].r = i;         vis[id] = 1;       } else         p[id].r = i;     }     for (int i = 0; i < 26; i++) {       if (vis[i]) {         sum[p[i].l]++;         sum[p[i].r + 1]--;       }     }     int ans = sum[0];     if (ans > k) {       cout <<  YES ;       return 0;     }     for (int i = 1; i < n; i++) {       sum[i] = sum[i - 1] + sum[i];       if (sum[i] > k) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int n, q;   int arr[1000010], lazy[1000010 << 2];   string str;   struct data {     int n4, n7, n47, n74;     data() { n4 = n7 = n47 = n74 = 0; }   } tree[1000010 << 2];   void build(int node, int l, int r) {     if (l == r) {       tree[node].n4 = (arr[l] == 4);       tree[node].n7 = (arr[l] == 7);       tree[node].n47 = 1;       tree[node].n74 = 1;       return;     }     int mid = (l + r) >> 1;     build(node << 1, l, mid);     build(node << 1 | 1, mid + 1, r);     tree[node].n4 = tree[node << 1].n4 + tree[node << 1 | 1].n4;     tree[node].n7 = tree[node << 1].n7 + tree[node << 1 | 1].n7;     tree[node].n47 = max(max(tree[node << 1].n47 + tree[node << 1 | 1].n7,                              tree[node << 1].n4 + tree[node << 1 | 1].n47),                          tree[node << 1].n4 + tree[node << 1 | 1].n7);     tree[node].n74 = max(max(tree[node << 1].n7 + tree[node << 1 | 1].n74,                              tree[node << 1].n74 + tree[node << 1 | 1].n4),                          tree[node << 1].n7 + tree[node << 1 | 1].n4);   }   void propagate(int node) {     if (lazy[node]) {       lazy[node << 1] ^= 1, lazy[node << 1 | 1] ^= 1;       swap(tree[node << 1].n4, tree[node << 1].n7);       swap(tree[node << 1 | 1].n4, tree[node << 1 | 1].n7);       swap(tree[node << 1].n47, tree[node << 1].n74);       swap(tree[node << 1 | 1].n47, tree[node << 1 | 1].n74);     }     lazy[node] = 0;   }   void update(int node, int l, int r, int i, int j) {     if (r < i || l > j) return;     if (i <= l && r <= j) {       lazy[node] ^= 1;       swap(tree[node].n4, tree[node].n7);       swap(tree[node].n47, tree[node].n74);       return;     }     int mid = (l + r) >> 1;     propagate(node);     update(node << 1, l, mid, i, j);     update(node << 1 | 1, mid + 1, r, i, j);     tree[node].n4 = tree[node << 1].n4 + tree[node << 1 | 1].n4;     tree[node].n7 = tree[node << 1].n7 + tree[node << 1 | 1].n7;     tree[node].n47 = max(max(tree[node << 1].n47 + tree[node << 1 | 1].n7,                              tree[node << 1].n4 + tree[node << 1 | 1].n47),                          tree[node << 1].n4 + tree[node << 1 | 1].n7);     tree[node].n74 = max(max(tree[node << 1].n7 + tree[node << 1 | 1].n74,                              tree[node << 1].n74 + tree[node << 1 | 1].n4),                          tree[node << 1].n7 + tree[node << 1 | 1].n4);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> q;     for (int i = 0; i < n; ++i) {       char c;       cin >> c;       arr[i + 1] = c -  0 ;     }     build(1, 1, n);     while (q--) {       cin >> str;       if (str ==  count ) {         cout << tree[1].n47 <<   n ;       } else {         int l, r;         cin >> l >> r;         update(1, 1, n, l, r);       }     }   }


#include <bits/stdc++.h>   using namespace std;   struct FenwickTree {     int N;     vector<int> A;     FenwickTree(int N) : N(N), A(N) {}     int rsq(int b) {       int sum = 0;       for (; b; b -= (b & (-b))) sum += A[b];       return sum;     }     int rsq(int a, int b) { return rsq(b) - (a == 1000000000 ? 0 : rsq(a - 1)); }     void adjust(int k, int v) {       for (; k < A.size(); k += k & -k) A[k] += v;     }   };   int n, k, a, b, q;   int main() {     cin >> n >> k >> a >> b >> q;     FenwickTree bef(n + 5), aft(n + 5);     vector<int> befa(n + 1), afta(n + 1);     int i, j, k1;     for (int c = 0; c < q; c++) {       scanf( %d , &i);       if (i == 1) {         scanf( %d%d , &j, &k1);         int befk = min(k1 + befa[j], b);         int aftk = min(k1 + afta[j], a);         bef.adjust(j, befk - befa[j]);         befa[j] = befk;         aft.adjust(j, aftk - afta[j]);         afta[j] = aftk;       } else {         scanf( %d , &j);         printf( %d n , bef.rsq(1, j - 1) + aft.rsq(k + j, n));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, s, q;     cin >> t >> s >> q;     int ans = 0;     while (s < t) {       s = s * q;       ans++;     }     cout << ans;     return 0;   }