#include <bits/stdc++.h>   using namespace std;   inline int in() {     int32_t x;     scanf( %d , &x);     return x;   }   inline string get() {     char ch[1000010];     scanf( %s , ch);     return ch;   }   const int MAX_LG = 21;   const long long maxn = 5e5 + 10;   const long long base = 29;   const long long mod = 1e9 + 7;   const long long INF = 1e9;   inline long long getlen(long long x) {     long long ret = 0;     while (x) ret++, x /= 10;     return ret;   }   long long has[20];   long long cnt2[20];   long long cnt[20];   string res;   string ans;   string check;   string mini;   int32_t main() {     string v =  21111222211112222222222112 ;     long long sz = (long long)v.size();     string s = get();     bool c = false;     if ((long long)s.size() > sz && s.substr(0, sz) == v) {       c = true;     }     string t = get();     if (s ==  0  || s ==  00 ) {       cout << 0 <<   n ;       return 0;     }     long long theln = 0;     for (long long i = 1; i <= 1000000; i++) {       long long ln = getlen(i);       if (i + ln == s.size()) {         theln = i;         break;       }     }     for (long long i = 0; i < s.size(); i++) {       cnt[s[i] -  0 ]++;     }     while (theln) {       cnt[theln % 10]--;       theln /= 10;     }     for (long long i = 0; i < t.size(); i++) cnt[t[i] -  0 ]--;     for (long long i = 0; i <= 10; i++) cnt2[i] = cnt[i];     for (long long i = 0; i <= 9; i++) {       while (cnt2[i]) {         cnt2[i]--, mini += char(i +  0 );       }     }     long long lim = -1;     if (!cnt[0]) {       for (long long i = 1; i <= 9; i++) {         while (cnt[i]) {           res += char( 1  + i - 1);           cnt[i]--;         }       }     } else {       long long mrk = -1;       for (long long i = 1; i <= 9; i++) {         if (cnt[i]) {           mrk = i;           cnt[i]--;           break;         }       }       if (mrk != -1) res += char( 1  + mrk - 1);       for (long long i = 0; i <= 9; i++) {         while (cnt[i]) {           res += char( 1  + i - 1);           cnt[i]--;         }       }     }     if (res.size() >= 2 && res[1] ==  0 ) {       for (long long j = 1; j < res.size() && res[j] ==  0 ; j++) lim = j;     }     if (!res.size()) {       cout << t <<   n ;       return 0;     }     for (long long i = 0; i < res.size(); i++) has[res[i] -  0 ]++;     if (res[0] ==  0 ) {       cout << t << res <<   n ;       return 0;     }     if (t[0] !=  0 ) {       ans = t + mini;     } else {       for (long long i = 0; i <= 1e6; i++) ans +=  9 ;     }     long long yk = -1;     if (t.size() > 1)       for (long long i = 1; i < t.size(); i++) {         if (yk == -1 && t[i] != t[0]) {           yk = t[i] -  0 ;         }       }     if (!has[t[0] -  0 ]) {       bool fl = false;       if (c) return cout << 2 <<   n , 0;       for (long long i = lim + 1; i < s.size(); i++) {         if (s[i] > t[0]) {           lim = max(lim, i - 1);           break;         }       }       for (long long i = 0; i < res.size(); i++) {         if (i > lim && (t[i] !=  0  || i) && !fl) {           check += t;           fl = true;         }         check += res[i];       }       if (!fl) check += t;     } else if (yk == -1 || yk > (t[0] -  0 )) {       bool fl = false;       for (long long i = 0; i < res.size(); i++) {         if (res[i] > t[0]) break;         if (res[i] == t[0]) lim = i;       }       for (long long i = 0; i < res.size(); i++) {         if (i > lim && !fl) {           check += t;           fl = true;         }         check += res[i];       }       if (!fl) check += t;     } else {       if (c) return cout << 4 <<   n , 0;       bool fl = false;       for (long long i = lim + 1; i < res.size(); i++) {         if (res[i] == t[0]) {           lim = max(lim, i - 1);           break;         }       }       for (long long i = 0; i < res.size(); i++) {         if (i > lim && !fl) {           check += t;           fl = true;         }         check += res[i];       }       if (!fl) check += t;     }     ans = min(ans, check);     cout << ans <<   n ;   }


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


#include <bits/stdc++.h>   using namespace std;   map<long long, string> mp;   long long n;   int main() {     scanf( %I64d , &n);     for (long long i = 2; i * i <= n; i++) {       for (long long j = i * i, k = 2; j <= n; j *= i, k++) {         string tmp = to_string(i) +  ^  + to_string(k);         if (!mp.count(j)) mp[j] = to_string(j);         if (tmp.size() < mp[j].size()) mp[j] = tmp;       }     }     string ans = to_string(n);     for (auto x : mp) {       string tmp =   ;       long long k = n / x.first, b = n % x.first;       if (k > 1) tmp = (mp.count(k) ? mp[k] : to_string(k)) +  * ;       tmp += x.second;       if (b) tmp +=  +  + (mp.count(b) ? mp[b] : to_string(b));       if (tmp.size() < ans.size()) ans = tmp;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char ch[100010];   int flag[26];   int main() {     while (~scanf( %s , ch)) {       memset(flag, 0, sizeof(flag));       flag[0] = 1;       flag[ H  -  A ] = 1;       flag[ I  -  A ] = 1;       flag[ M  -  A ] = 1;       flag[ O  -  A ] = 1;       flag[ T  -  A ] = 1;       flag[ U  -  A ] = 1;       flag[ V  -  A ] = 1;       flag[ W  -  A ] = 1;       flag[ X  -  A ] = 1;       flag[ Y  -  A ] = 1;       int len = strlen(ch);       int flag1 = 0;       for (int i = 0; i < len; i++) {         if (!flag[ch[i] -  A ]) {           flag1 = 1;           break;         }       }       if (flag1) {         printf( NO n );       } else {         string str;         str = ch;         reverse(str.begin(), str.end());         for (int i = 0; i < len; i++) {           if (str[i] != ch[i]) {             flag1 = 1;             break;           }         }         if (flag1) {           printf( NO n );         } else {           printf( YES n );         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   const mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count());   const int MOD = 998244353;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       vector<int> a(n);       for (int &i : a) cin >> i;       map<int, int> pos;       for (int i = 0; i < n; i++) pos[a[i]] = i;       vector<int> b(k);       for (int &i : b) cin >> i;       long long ans = 1;       set<int> sb(b.begin(), b.end());       for (int i : b) {         int p = pos[i];         long long nxt = 0;         if (p != 0) {           int vl = a[p - 1];           if (sb.count(vl) == 0) nxt += ans;         }         if (p != n - 1) {           int vr = a[p + 1];           if (sb.count(vr) == 0) nxt += ans;         }         sb.erase(i);         if (nxt >= MOD) nxt -= MOD;         ans = nxt;       }       cout << ans <<   n ;     }     exit(0);   }


#include <bits/stdc++.h>   using namespace std;   bool solve(int x) {     if (x == 0) return true;     if (x % 1000 == 144) {       return solve(x / 1000);     } else if (x % 100 == 14) {       return solve(x / 100);     } else if (x % 10 == 1) {       return solve(x / 10);     }     return false;   }   int main() {     int x;     cin >> x;     if (solve(x))       cout <<  YES n ;     else       cout <<  NO n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n;     cin >> n;     map<double, int> mp2;     map<string, double> mp1;     vector<string> S;     while (n--) {       string x;       cin >> x;       S.push_back(x);       int plus = 0, end = 0;       double a, b, c;       for (int i = 1; i < x.size(); i++) {         if (x[i] ==  + ) plus = i;         if (x[i] ==  ) ) end = i;       }       a = stod(x.substr(1, plus - 1));       b = stod(x.substr(plus + 1, end - plus - 1));       c = stod(x.substr(end + 2, x.size() - end + 2));       mp1[x] = (a + b) / c;       mp2[(a + b) / c]++;     }     for (auto i : S) {       cout << mp2[mp1[i]] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     std::ios_base::sync_with_stdio(false);     std::cout.tie(nullptr);     std::cin.tie(nullptr);     std::cerr.tie(nullptr);     int64_t n, k;     std::cin >> n >> k;     if (k == 1) std::cout <<  1 n ;     if (k == 2) {       int64_t res = (n * (n - 1)) / 2 + 1;       std::cout << res <<   n ;     }     if (k == 3) {       int64_t res = (n * (n - 1) * (n - 2)) / 3 + (n * (n - 1)) / 2 + 1;       std::cout << res <<   n ;     }     if (k == 4) {       int64_t res = (n * (n - 1) * (n - 2)) / 3 + (n * (n - 1)) / 2 +                     9 * (n * (n - 1) * (n - 2) * (n - 3)) / 24 + 1;       std::cout << res <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using vi = vector<int>;   using vll = vector<ll>;   constexpr int MOD = 1e9 + 7;   constexpr int INF = INT_MAX;   constexpr ll LLINF = LLONG_MAX;   template <class T>   inline bool setmin(T &a, T b) {     if (a > b) return a = b, 1;     return 0;   }   template <class T>   inline bool setmax(T &a, T b) {     if (a < b) return a = b, 1;     return 0;   }   namespace fastio {   template <class T>   istream &operator>>(istream &os, vector<T> &container) {     for (auto &u : container) os >> u;     return os;   }   template <class T>   ostream &operator<<(ostream &os, const vector<T> &container) {     for (auto &u : container) os << u <<    ;     return os;   }   template <class T1, class T2>   inline istream &operator>>(istream &os, pair<T1, T2> &p) {     return os >> p.first >> p.second;   }   template <class T1, class T2>   ostream &operator<<(ostream &os, const pair<T1, T2> &p) {     return os << p.first <<     << p.second;   }   template <typename... args>   void re(args &...tail) {     ((cin >> tail), ...);   }   template <typename... args>   void pr(args... tail) {     ((cout << tail <<    ), ...);   }   template <typename... args>   void prln(args... tail) {     ((cout << tail <<    ), ...);     cout <<   n ;   }   }  // namespace fastio   using namespace fastio;   namespace debug {   template <typename _T>   inline void _debug(const char *s, _T x) {     cerr << s <<   =   << x <<   n ;   }   template <typename _T, typename... args>   void _debug(const char *s, _T x, args... a) {     while (*s !=  , ) cerr << *s++;     cerr <<   =   << x <<  , ;     _debug(s + 1, a...);   }   }  // namespace debug   using namespace debug;   const int N = 1e5 + 7;   string s;   int n, q;   int nxt[N][26];   int dp[257][257][257];   string rel[3];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     re(n, q, s);     for (int i = (0); i <= (25); i++) nxt[n][i] = nxt[n + 1][i] = n;     for (int i = (n - 1); i >= (0); i--) {       for (int j = (0); j <= (25); j++) {         nxt[i][j] = (s[i] ==  a  + j ? i : nxt[i + 1][j]);       }     }     dp[0][0][0] = -1;     for (int _ = (1); _ <= (q); _++) {       char t;       int x;       re(t, x);       x--;       if (t ==  + ) {         char l;         re(l);         rel[x] += l;         int e0 = (int)(rel[0]).size(), e1 = (int)(rel[1]).size(),             e2 = (int)(rel[2]).size();         int b0 = (x == 0 ? e0 : 0);         int b1 = (x == 1 ? e1 : 0);         int b2 = (x == 2 ? e2 : 0);         for (int a = (b0); a <= (e0); a++) {           for (int b = (b1); b <= (e1); b++) {             for (int c = (b2); c <= (e2); c++) {               auto &v = dp[a][b][c];               v = n;               if (a) setmin(v, nxt[dp[a - 1][b][c] + 1][rel[0][a - 1] -  a ]);               if (b) setmin(v, nxt[dp[a][b - 1][c] + 1][rel[1][b - 1] -  a ]);               if (c) setmin(v, nxt[dp[a][b][c - 1] + 1][rel[2][c - 1] -  a ]);             }           }         }       } else {         rel[x].pop_back();       }       prln(dp[(int)(rel[0]).size()][(int)(rel[1]).size()][(int)(rel[2]).size()] <                    n                ?  YES                 :  NO );     }     exit(0);   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   ,  ;     __f(comma + 1, args...);   }   const int N = 1e3 + 10;   vector<vector<int>> g;   vector<int> par, height;   int n;   int bfs(int root) {     int last = root;     par[root] = -1;     height[root] = 0;     queue<int> q;     q.push(root);     while (!q.empty()) {       int u = q.front();       q.pop();       last = u;       for (auto v : g[u])         if (v != par[u]) {           par[v] = u;           height[v] = height[u] + 1;           q.push(v);         }     }     return last;   }   void dfs(int u, int par, int tar) {     for (int v : g[u])       if (v != par) {         if (v == tar) {           g[u].erase(find(g[u].begin(), g[u].end(), v));           g[v].erase(find(g[v].begin(), g[v].end(), u));         } else           dfs(v, u, tar);       }   }   int main() {     int i, j, k, n, m;     cin >> n;     g.resize(n);     par.resize(n);     height.resize(n);     for (i = 0; i < n - 1; ++i) {       int u, v;       cin >> u >> v;       u--, v--;       g[u].push_back(v);       g[v].push_back(u);     }     int x, y, q;     x = bfs(0);     y = bfs(x);     cout <<  ?   << x + 1 <<     << y + 1 << endl;     cin >> q;     q--;     while (1) {       dfs(x, -1, q);       dfs(y, -1, q);       if (g[q].size() == 0) {         cout <<  !   << q + 1 << endl;         return 0;       };       x = bfs(q);       y = bfs(x);       cout <<  ?   << x + 1 <<     << y + 1 << endl;       cin >> q;       q--;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 96;   const int MAXN = 1e6 + 5;   const int MAXK = 8e6 + 5;   const int MOD = 1e9 + 7;   const int MAX_ASCII_CODE = 26;   const int MAX_NUMBER_OF_NODES = 1e5 + 5;   int n, m;   int arr[MAXN];   int rea[MAXK];   int foo(int v) {     if (v == 0) return -2;     if (rea[v] != -1) return rea[v];     if (rea[v] == -2) return -2;     int ho = -2;     for (int i = (int)0; i < (int)(22); i++) {       if ((v & (1 << i)) > 0) {         ho = max(foo((v ^ (1 << i))), ho);       }     }     rea[v] = ho;     return rea[v];   }   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(NULL);     cout << fixed << setprecision(11);     int t = 1;     while (t--) {       cin >> n;       memset(rea, -1, sizeof(rea));       for (int i = (int)0; i < (int)(n); i++) {         cin >> arr[i];         rea[arr[i]] = arr[i];       }       int t;       int no = (1 << 22) - 1;       for (int i = (int)0; i < (int)(n); i++) {         t = arr[i];         t = (no ^ arr[i]);         cout << max(-1, foo(t)) <<    ;       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const int N = 100000 + 100;   const int inf = 0x7fffffff;   int n, a, b, c;   int f[N];   int main() {     scanf( %d%d%d%d , &n, &a, &b, &c);     f[a] = 1;     f[b] = 1;     f[c] = 1;     for (int i = min(a, min(b, c)); i <= n; i++) {       if (f[i]) {         f[i + a] = max(f[i + a], f[i] + 1);         f[i + b] = max(f[i + b], f[i] + 1);         f[i + c] = max(f[i + c], f[i] + 1);       }     }     printf( %d n , f[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;      /*    find my code templates at https://github.com/galencolin/cp-templates   also maybe subscribe please thanks    */       #define send {ios_base::sync_with_stdio(false);}   #define help {cin.tie(NULL);}   #define f first   #define s second   #define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());}   typedef long long ll;   typedef long double lld;   typedef unsigned long long ull;       template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);   template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout <<  (  << p.f <<  ,   << p.s <<  ) ; }   template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {    cout <<  [ ; for(int i = 0; i < v.size(); i++) {if (i) cout <<  ,  ; cout << v[i];} return cout <<  ] ;   }   template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {    cin >> p.first;    return cin >> p.second;   }       mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());   // mt19937_64 rng(61378913);   /* usage - just do rng() */       void usaco(string filename) {     // #pragma message( be careful, freopen may be wrong )    freopen((filename +  .in ).c_str(),  r , stdin);    freopen((filename +  .out ).c_str(),  w , stdout);   }       // #include <atcoder/all>   // using namespace atcoder;       const lld pi = 3.14159265358979323846;   // const ll mod = 1000000007;   // const ll mod = 998244353;   // ll mod;            ll n, m, k, q, l, r, x, y, z;   const ll template_array_size = 1e6 + 8432;   ll a[template_array_size];   ll b[template_array_size];   ll c[template_array_size];   string s, t;   ll ans = 0;       pair<ll, ll> p[200005];   vector<pair<ll, ll>> cv;   map<ll, ll> cnt;   ll tot[5000005];      void solve(int tc = 0) {    cin >> n;    for (ll i = 0; i < n; i++) {     cin >> a[i];     p[i] = {a[i], i};     ++cnt[a[i]];    }        sort(p, p + n);        ll targ = -1;    for (pair<ll, ll> x: cnt) cv.push_back(x);    for (ll i = 0; i < cv.size(); i++) {     tot[2 * cv[i].f] += cv[i].s / 2;     if (tot[2 * cv[i].f] > 1) {      targ = 2 * cv[i].f;      break;     }     for (ll j = i + 1; j < cv.size(); j++) {      tot[cv[i].f + cv[j].f] += min(cv[i].s, cv[j].s);      if (tot[cv[i].f + cv[j].f] > 1) {       targ = cv[i].f + cv[j].f;       break;      }     }     if (targ != -1) break;    }        if (targ == -1) {     cout <<  NO n ;    } else {     cout <<  YES n ;     ll pt = n - 1;     ll t = 0;     for (ll i = 0; i < n; i++) {      while (pt > i && p[i].f + p[pt].f > targ) --pt;      if (pt > i && p[i].f + p[pt].f == targ) {       cout << p[i].s + 1 <<     << p[pt].s + 1 <<    ;       --pt;       ++t;       if (t == 2) exit(0);      }     }    }   }      // two pointers? maybe   // xor tricks (or general bitwise)   // tutorial on my template      int main() {    #ifdef galen_colin_local     auto begin = std::chrono::high_resolution_clock::now();    #endif        send help        #ifndef galen_colin_local     // usaco( code );    #endif        // usaco( cowland );        // freopen( tc.cpp ,  r , stdin);    // freopen( tc2.cpp ,  w , stdout);          cout << setprecision(15) << fixed;            int tc = 1;    // cin >> tc;    for (int t = 0; t < tc; t++) solve(t);        #ifdef galen_colin_local     auto end = std::chrono::high_resolution_clock::now();     cerr << setprecision(4) << fixed;     // cerr <<  Execution time:   << std::chrono::duration_cast<std::chrono::duration<double>>(end - begin).count() <<   seconds  << endl;    #endif   }


#include <bits/stdc++.h>   using namespace std;   int m, n, a[2000100], b[2000100], d[2000100], ans = 1, pos[2000100];   int between(int x, int y, int z) {     if (z < y) return x < z || x > y;     return x > y && x < z;   }   int main() {     memset(d, -1, sizeof(d));     cin >> m >> n;     for (int i = 0; i < m; i++) scanf( %d , &a[i]);     for (int i = 0; i < n; i++) scanf( %d , &b[i]), d[b[i]] = i;     int M = 0;     for (int i = 0; i < m; i++)       if (d[a[i]] >= 0) a[M] = a[i], pos[M++] = i;     swap(m, M);     if (!m) {       puts( 0 );       return 0;     }     for (int i = 0; i < m; i++) a[m + i] = a[i], pos[m + i] = pos[i] + M;     int x = 1, bor = 0;     for (int i = 1; i <= m * 2 - 1; i++)       if (pos[i] == pos[i - 1] + 1) {         x++;         while (x > 2 && !between(d[a[i]], d[a[i - 1]], d[a[bor]])) bor++, x--;         ans = max(ans, x);       } else         x = 1, bor = i;     cout << min(m, ans) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, m, k, i, j;     cin >> n >> m >> k;     long long int a[n];     vector<pair<long long int, long long int> > v;     for (i = 0; i < n; i++) {       cin >> a[i];       v.push_back(make_pair(a[i], i));     }     long long int y = m * k;     long long int x = n - y;     sort(v.begin(), v.end());     long long int mark[n];     memset(mark, 0, sizeof(mark));     i = n - 1;     while (i >= 0 && y > 0) {       mark[v[i].second] = 1;       i--;       y--;     }     i = 0;     long long int z;     long long int ans = 0;     vector<long long int> p;     while (i < n) {       z = 0;       j = i;       while (z < m && j < n) {         if (mark[j] == 1) {           z++;           ans = ans + a[j];         }         j++;       }       p.push_back(j);       if (p.size() == k) break;       i = j;     }     cout << ans << endl;     for (i = 0; i < p.size() - 1; i++) {       cout << p[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 7;   vector<pair<int, int> > G[MAXN];   int n;   int sz[MAXN];   long long MAX, MIN;   void dfs(int u, int fa) {     sz[u] = 1;     for (pair<int, int> edge : G[u]) {       int v = edge.first;       if (v == fa) continue;       dfs(v, u);       sz[u] += sz[v];     }     for (pair<int, int> edge : G[u]) {       int v = edge.first, w = edge.second;       if (v == fa) continue;       if (sz[v] & 1) MIN += w;       MAX += 1ll * w * min(sz[v], (n - sz[v]));     }   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       int k;       scanf( %d , &k);       n = 2 * k;       for (int i = 1, u, v, w; i < n; i++) {         scanf( %d%d%d , &u, &v, &w);         G[u].push_back({v, w});         G[v].push_back({u, w});       }       MAX = MIN = 0;       dfs(1, 0);       printf( %lld %lld n , MIN, MAX);       for (int i = 1; i <= n; i++) G[i].clear();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   int s[2], t[200007][2];   int x[200007];   int n, m, st[200007];   int absi(int x) { return x > 0 ? x : -x; }   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) scanf( %d , &x[i]);     memset(s, 0, sizeof(s));     memset(t, 0, sizeof(t));     memset(st, 0, sizeof(st));     for (int i = 0; i < n; i++) ++s[x[i] > 0];     for (int i = 0; i < n; i++) t[absi(x[i])][x[i] > 0]++;     int cnt = 0;     for (int i = 1; i <= n; ++i) {       int fake = 0;       fake += t[i][1] + s[0] - t[i][0];       if (fake == m) {         st[i] = 1;         ++cnt;       }     }     for (int i = 0; i < n; i++) {       int ss = 0;       if (x[i] > 0 && st[x[i]]) ss |= 1;       if (x[i] > 0 && !st[x[i]]) ss |= 2;       if (x[i] > 0 && cnt > 1) ss |= 2;       if (x[i] < 0 && !st[-x[i]]) ss |= 1;       if (x[i] < 0 && st[-x[i]]) ss |= 2;       if (x[i] < 0 && cnt > 1) ss |= 1;       if (ss == 1) cout <<  Truth n ;       if (ss == 2) cout <<  Lie n ;       if (ss == 3) cout <<  Not defined n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long getnum() {     char c = getchar();     long long num, sign = 1;     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) sign = -1;     for (num = 0; c >=  0  && c <=  9 ;) {       c -=  0 ;       num = num * 10 + c;       c = getchar();     }     return num * sign;   }   char S[200020];   char T[200020];   vector<pair<int, int> > V;   int main() {     int n = getnum(), k = getnum();     gets(T + 3);     int rot = 3;     for (rot = 3; rot <= n + 2; rot++) {       if (T[rot] == T[rot + 1]) break;     }     for (int i = 3, j = rot; i <= n + 2; i++, j++) {       if (j == n + 3) j = 3;       S[i] = T[j];     }     S[1] = S[n + 1];     S[2] = S[n + 2];     S[n + 3] = S[3];     S[n + 4] = S[4];     for (int i = 0; i <= n + 4;) {       int x = i;       while (S[i] == S[x] && i <= n + 4) i++;       if (i - x > 1) V.push_back(make_pair(x, i - 1));     }     if (V.size() == 0) {       if (k % 2) {         for (int i = 3; i <= n + 2; i++) S[i] =  B  +  W  - S[i];       }       S[n + 3] = 0;       printf( %s , S + 3);       return 0;     }     for (int i = 0; i < V.size() - 1; i++) {       int l = V[i].second;       int r = V[i + 1].first;       int t = min(k, (r - l) / 2);       l++, r--;       for (int tt = 1; tt <= t; l++, tt++) S[l] = S[V[i].second];       for (int tt = 1; tt <= t; r--, tt++) S[r] = S[V[i + 1].first];       for (; l <= r; l++) S[l] =  B  +  W  - S[l - 1];     }     T[n + 3] = 0;     for (int i = rot, j = 3; j <= n + 2; i++, j++) {       if (i == n + 3) i = 3;       T[i] = S[j];     }     printf( %s , T + 3);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int cnt = 0;     while (n > 0) {       if (n >= 100) {         n -= 100;         cnt++;       } else if (n >= 20) {         n -= 20;         cnt++;       } else if (n >= 10) {         n -= 10;         cnt++;       } else if (n >= 5) {         n -= 5;         cnt++;       } else if (n >= 1) {         n -= 1;         cnt++;       }     }     cout << cnt;   }


#include <bits/stdc++.h>   using namespace std;   int num[105];   int main() {     int n;     cin >> n;     set<int> s;     while (n--) {       int a;       cin >> a;       s.insert(a);       num[a]++;     }     if (s.size() == 2 && num[*s.begin()] == num[*s.rbegin()]) {       cout <<  YES n ;       cout << *s.begin() <<     << *s.rbegin() << endl;     } else {       cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, q, acum = 0, ultimo = 0, type, a, count;     scanf( %d%d , &n, &q);     vector<queue<int>> notificaciones_app(n);     unordered_set<int> todas_notificaciones;     while (q--) {       scanf( %d%d , &type, &a);       a--;       switch (type) {         case 1:           acum++;           todas_notificaciones.insert(acum);           notificaciones_app[a].push(acum);           break;         case 2:           while (!notificaciones_app[a].empty())             todas_notificaciones.erase(notificaciones_app[a].front()),                 notificaciones_app[a].pop();           break;         case 3:           a++;           for (int i = ultimo; i <= a; i++) todas_notificaciones.erase(i);           if (a > ultimo) ultimo = a;           break;       }       printf( %d n , todas_notificaciones.size());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n, p;       scanf( %d , &n);       scanf( %d , &p);       vector<pair<int, int> > ans;       int edges = 2 * n + p;       for (int i = int(1); i <= int(n); i++) {         for (int j = int(i + 1); j <= int(n); j++) {           if (edges) {             ans.push_back(pair<int, int>(i, j));             edges--;           }         }       }       for (vector<pair<int, int> >::iterator it = (ans).begin();            it != (ans).end(); it++)         printf( %d %d n , it->first, it->second);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string a, b;     cin >> a >> b;     if (a.size() < b.size()) a = string(b.size() - a.size(),  0 ) + a;     if (b.size() < a.size()) b = string(a.size() - b.size(),  0 ) + b;     if (a == b) cout <<  = ;     if (a < b) cout <<  < ;     if (b < a) cout <<  > ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y, h;   } a[100010];   bool cmp(point a, point b) {     if (a.y != b.y) return a.y < b.y;     return a.x < b.x;   }   int dp[100010];   int main() {     int n;     while (~scanf( %d , &n)) {       for (int i = 0; i < n; i++) scanf( %d%d%d , &a[i].x, &a[i].y, &a[i].h);       sort(a, a + n, cmp);       stack<point> p;       long long ans = 0;       long long mx = 0;       for (int i = n - 1; i >= 0; i--) {         while (1) {           if (p.empty()) break;           point f = p.top();           if (f.y >= a[i].y && f.x < a[i].y) break;           ans -= f.h;           p.pop();         }         p.push(a[i]);         ans += a[i].h;         mx = max(mx, ans);       }       printf( %I64d n , mx);     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> edges;   vector<int> large;   bool ok = true;   vector<pair<long long, long long>> dfs(int cur) {     vector<pair<long long, long long>> child;     for (int i : edges[cur]) {       auto temp = dfs(i);       child.insert(child.end(), temp.begin(), temp.end());     }     sort(child.begin(), child.end());     vector<pair<long long, long long>> res;     int add = 0;     if (large[cur] > child.size()) {       ok = false;     }     for (auto it : child) {       if (res.size() == large[cur]) {         res.push_back({res.size() + 1, cur});       }       res.push_back({res.size() + 1, it.second});     }     if (res.size() == child.size()) {       res.push_back({res.size() + 1, cur});     }     return res;   }   void solve() {     int n;     cin >> n;     edges.clear();     edges.resize(n + 1);     vector<pair<long long, long long>> in(n);     for (auto& it : in) {       cin >> it.first >> it.second;     }     int par = -1;     large.clear();     large.resize(n + 1);     for (int i = 0; i < n; i++) {       if (in[i].first != 0) {         edges[in[i].first].push_back(i + 1);       } else {         par = i + 1;       }       large[i + 1] = in[i].second;     }     auto res = dfs(par);     if (!ok) {       cout <<  NO  << endl;       return;     }     cout <<  YES  << endl;     for (auto it : res) {       large[it.second] = it.first;     }     for (int i = 1; i <= n; i++) {       cout << large[i] <<    ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void maxtt(T& t1, T t2) {     t1 = max(t1, t2);   }   template <typename T>   void mintt(T& t1, T t2) {     t1 = min(t1, t2);   }   bool debug = 0;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   string direc =  URDL ;   const long long MOD2 = (long long)998244353 * (long long)998244353;   long long ln, lk, lm;   void etp(bool f = 0) {     puts(f ?  YES  :  NO );     exit(0);   }   void addmod(int& x, int y, int mod = 998244353) {     assert(y >= 0);     x += y;     if (x >= mod) x -= mod;     assert(x >= 0 && x < mod);   }   void et(int x = -1) {     printf( %d n , x);     exit(0);   }   long long fastPow(long long x, long long y, int mod = 998244353) {     long long ans = 1;     while (y > 0) {       if (y & 1) ans = (x * ans) % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }   long long rL;   int a[1035], b[1035];   long long ansl[1035], ansr[1035];   long long rd(int id, long long x) {     printf( ? %d %lld n , id, x);     fflush(stdout);     scanf( %lld , &lk);     return lk;   }   void cal(int l, int r, long long L, long long R) {     if (l == r) {       ansl[a[l]] = L;       ansr[a[l]] = R;       return;     }     int m1 = (l + r) / 2;     long long X = rL / n * m1, m2;     mt19937 ttrand((int)time(0));     for (int p = l, q = r;;) {       int i = uniform_int_distribution<int>(p, q)(ttrand);       long long lb = L, rb = R;       while (lb < rb) {         long long mb = (lb + rb) / 2;         if (rd(a[i], mb) < X)           lb = mb + 1;         else           rb = mb;       }       int l2 = p, r2 = q;       vector<int> e;       for (int j = p; j <= q; ++j) {         long long y = rd(a[j], lb);         if (y > X)           b[l2++] = a[j];         else if (y < X)           b[r2--] = a[j];         else           e.push_back(a[j]);       }       for (int(j) = 0; (j) < (int)(e.size()); (j)++) b[l2 + j] = e[j];       for (int z = p; z <= q; z++) a[z] = b[z];       if (l2 <= m1 && m1 <= r2) {         m2 = lb;         break;       }       if (l2 < m1)         p = l2 + 1;       else         q = l2 - 1;     }     cal(l, m1, L, m2);     cal(m1 + 1, r, m2, R);   }   void fmain(int tid) {     scanf( %d%lld , &n, &rL);     for (int(i) = 1; (i) <= (int)(n); (i)++) a[i] = i;     cal(1, n, 0, 1e18);     puts( ! );     for (int(i) = 1; (i) <= (int)(n); (i)++)       printf( %lld %lld n , ansl[i], ansr[i]);   }   int main() {     int t = 1;     for (int(i) = 1; (i) <= (int)(t); (i)++) {       fmain(i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, n;     cin >> n >> a >> b;     cout << min(n - a, b + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T sqr(const T &a) {     return a * a;   }   template <class T>   inline T middle(const T &a, const T &b) {     return (a + b) / 2;   }   template <class T>   inline int len(const T &c) {     return static_cast<int>(c.size());   }   const long double EPS = 1e-9;   const long double PI = 2 * acos(0.0);   const int N = 100;   struct Item {     long long r;     char c;     Item() {}     Item(long long rr, char cc) : r(rr), c(cc) {}     void Read() { scanf( %I64d-%c , &r, &c); }   };   int ReadLine(int n, vector<Item> &s) {     Item tmp;     for (int i = 0; i < n; ++i) {       tmp.Read();       if (!s.empty() && s.back().c == tmp.c) {         s.back().r += tmp.r;       } else {         s.push_back(tmp);       }     }     return len(s);   }   inline bool Check1(const vector<Item> &s, const Item &cur, int n, int j) {     if (s[j].c != cur.c) {       return false;     }     if (j == 0 || j == n - 1) {       return s[j].r <= cur.r;     }     return s[j].r == cur.r;   }   int main() {     int n, m;     scanf( %d%d n , &n, &m);     vector<Item> t, s;     n = ReadLine(n, t);     m = ReadLine(m, s);     s.push_back(Item(0,  # ));     s.insert(s.end(), t.begin(), t.end());     long long ans = 0;     vector<int> pi(len(s), 0);     for (int i = 1; i < len(pi); ++i) {       Item &cur = s[i];       int j = pi[i - 1];       while (j && !Check1(s, cur, m, j)) {         j = pi[j - 1];       }       if (Check1(s, cur, m, j)) {         ++j;       }       if (j == m) {         if (m > 1) {           ++ans;         } else {           assert(cur.c == s[0].c);           long long val = cur.r - s[0].r + 1;           ans += val;         }         --j;         if (j) {           j = pi[j - 1];         }         if (Check1(s, cur, m, j)) {           ++j;         }       }       pi[i] = j;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b, c, D, e;   int cs[200020];   int all[200020], A[4], AA[4];   int i, x, y, z, tmp, tim, m;   int main() {     cin >> n;     cin >> a >> b >> c;     if (a > c) swap(a, c);     if (a > b) swap(a, b);     if (b > c) swap(b, c);     A[1] = a;     A[2] = b;     A[3] = c;     for (i = 1; i <= n; i++) {       scanf( %d , &D);       if (D > a + b + c) {         cout << -1 << endl;         return 0;       }       if (D > b + c) {         tim++;         continue;       }       m++;       all[m] = D;     }     AA[1] = m;     AA[2] = m;     AA[3] = m;     sort(all + 1, all + m + 1);     for (i = m; i >= 1; i--) {       if (all[i] && c < all[i]) {         if (a + b >= all[i])           e = 3;         else if (a + c >= all[i])           e = 2;         else           e = 1;         AA[e] = min(AA[e], i - 1);         while (AA[e] >= 0 && all[AA[e]] == 0 || all[AA[e]] > A[e]) AA[e]--;         tim++;         all[AA[e]] = 0;         all[i] = 0;       }     }     n = 0;     for (i = 1; i <= m; i++)       if (all[i]) {         n++;         cs[n] = all[i];       }     if (n == 0) {       cout << tim << endl;       return 0;     }     int l = 1;     int r = n - 1;     int ress = n;     while (l <= r) {       m = (l + r) / 2;       int k = n - m;       if (a + b < cs[k]) {         l = m + 1;         continue;       }       int ja = 0;       for (ja = 1; ja <= k; ja++)         if (cs[ja] > a) break;       ja--;       int jb = 0;       for (jb = 1; jb <= k; jb++)         if (cs[jb] > b) break;       jb--;       while (jb - ja < ja) ja--;       if (max(ja, jb - ja) + k - jb <= m) {         ress = m;         r = m - 1;       } else         l = m + 1;     }     cout << ress + tim << endl;   }


#include <bits/stdc++.h>   template <class C, class E>   inline bool contains(const C &container, const E &element) {     return container.find(element) != container.end();   }   template <class T>   inline void checkmin(T &a, T b) {     if (b < a) a = b;   }   template <class T>   inline void checkmax(T &a, T b) {     if (b > a) a = b;   }   using namespace std;   map<int, bool> res;   enum Type { XOR, AND, IN, NOT, OR };   struct Gate {     Type _type;     int _index;     bool _bOriVal;     int _c[2];   };   vector<Gate> gates;   bool Eval(int index) {     Gate &g = gates[index];     bool bRes;     switch (g._type) {       case OR: {         bool b1 = Eval(g._c[0]);         bool b2 = Eval(g._c[1]);         bRes = b1 || b2;       } break;       case AND: {         bool b1 = Eval(g._c[0]);         bool b2 = Eval(g._c[1]);         bRes = b1 && b2;       } break;       case NOT:         bRes = !Eval(g._c[0]);         break;       case XOR:         bRes = Eval(g._c[0]) != Eval(g._c[1]);         break;       case IN:         bRes = g._bOriVal;         break;     }     g._bOriVal = bRes;     return bRes;   }   void Solve(int index, bool resObt[2]) {     Gate &g = gates[index];     switch (g._type) {       case OR: {         for (int i = 0; i < 2; ++i) {           int askedSubGate = g._c[i];           int otherSubGate = g._c[1 - i];           bool otherSubVal = gates[otherSubGate]._bOriVal;           bool rr[2];           rr[false] = resObt[otherSubVal || false];           rr[true] = resObt[otherSubVal || true];           Solve(askedSubGate, rr);         }         break;       }       case AND:         for (int i = 0; i < 2; ++i) {           int askedSubGate = g._c[i];           int otherSubGate = g._c[1 - i];           bool otherSubVal = gates[otherSubGate]._bOriVal;           bool rr[2];           rr[false] = resObt[otherSubVal && false];           rr[true] = resObt[otherSubVal && true];           Solve(askedSubGate, rr);         }         break;       case NOT: {         bool rr[2];         rr[0] = resObt[1];         rr[1] = resObt[0];         Solve(g._c[0], rr);         break;       }       case XOR: {         for (int i = 0; i < 2; ++i) {           int askedSubGate = g._c[i];           int otherSubGate = g._c[1 - i];           bool otherSubVal = gates[otherSubGate]._bOriVal;           bool rr[2];           rr[false] = resObt[otherSubVal != false];           rr[true] = resObt[otherSubVal != true];           Solve(askedSubGate, rr);         }         break;       }       case IN: {         res[g._index] = resObt[!g._bOriVal];         break;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout << std::setprecision(15);     cout << std::fixed;     int n;     cin >> n;     gates.resize(n + 1);     for (int i = (1), _b = (n); i <= _b; i++) {       string s;       cin >> s;       if (s ==  IN ) {         gates[i]._type = IN;         bool val;         cin >> val;         gates[i]._bOriVal = val;         gates[i]._index = i;       } else if (s ==  AND ) {         gates[i]._type = AND;         cin >> gates[i]._c[0] >> gates[i]._c[1];       } else if (s ==  OR ) {         gates[i]._type = OR;         cin >> gates[i]._c[0] >> gates[i]._c[1];       } else if (s ==  XOR ) {         gates[i]._type = XOR;         cin >> gates[i]._c[0] >> gates[i]._c[1];       } else if (s ==  NOT ) {         gates[i]._type = NOT;         cin >> gates[i]._c[0];       }     }     bool current = Eval(1);     bool rr[2] = {false, true};     Solve(1, rr);     for (auto &v : res) {       cout << (v.second ?  1  :  0 );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   LL g_l, g_r;   LL gcd(LL a, LL b) {     if (b == 0) return a;     return gcd(b, a % b);   }   bool input() {     cin >> g_l >> g_r;     if (cin.eof()) return false;     return true;   }   void solve() {     for (LL i = g_l; i <= g_r; ++i) {       for (LL j = i + 1; j <= g_r; ++j) {         for (LL k = j + 1; k <= g_r; ++k) {           if (gcd(i, k) != 1 && gcd(i, j) == 1 && gcd(j, k) == 1) {             cout << i <<     << j <<     << k << endl;             return;           }         }       }     }     cout << -1 << endl;   }   int main() {     while (input()) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 3) + (x << 1) + ch -  0 ;       ch = getchar();     }     return x * f;   }   long long n, m, a[N], op, x, y, z;   struct SegmentTree {     long long l, r, sum, maxn;   } tree[N << 2];   void pushup(int k) {     tree[k].sum = tree[k << 1].sum + tree[k << 1 | 1].sum;     tree[k].maxn = max(tree[k << 1].maxn, tree[k << 1 | 1].maxn);   }   void build(int k, int l, int r) {     tree[k].l = l, tree[k].r = r;     if (l == r) {       tree[k].sum = tree[k].maxn = a[l];       return;     }     int mid = (l + r) / 2;     build(k << 1, l, mid), build(k << 1 | 1, mid + 1, r);     pushup(k);   }   void changemod(int k, int ql, int qr, long long mod) {     if (tree[k].maxn < mod) return;     if (ql <= tree[k].l && tree[k].r <= qr && tree[k].l == tree[k].r) {       tree[k].sum %= mod, tree[k].maxn %= mod;       return;     }     int mid = (tree[k].l + tree[k].r) / 2;     if (ql <= mid) changemod(k << 1, ql, qr, mod);     if (mid < qr) changemod(k << 1 | 1, ql, qr, mod);     pushup(k);   }   void modify(int k, int q, long long v) {     if (tree[k].l > q || q > tree[k].r) return;     if (tree[k].l == tree[k].r) {       tree[k].sum = tree[k].maxn = v;       return;     }     int mid = (tree[k].l + tree[k].r) / 2;     if (q <= mid)       modify(k << 1, q, v);     else       modify(k << 1 | 1, q, v);     pushup(k);   }   long long query(int k, int ql, int qr) {     long long res = 0;     if (ql <= tree[k].l && tree[k].r <= qr) return tree[k].sum;     int mid = (tree[k].l + tree[k].r) / 2;     if (ql <= mid) res += query(k << 1, ql, qr);     if (mid < qr) res += query(k << 1 | 1, ql, qr);     return res;   }   int main() {     n = read(), m = read();     for (int i = 1; i <= n; i++) a[i] = read();     build(1, 1, n);     while (m--) {       op = read();       if (op == 1) {         x = read(), y = read();         printf( %lld n , query(1, x, y));       }       if (op == 2) {         x = read(), y = read(), z = read();         changemod(1, x, y, z);       }       if (op == 3) {         x = read(), y = read();         modify(1, x, y);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct BipartiteMatcher {     vector<vector<int>> g;     vector<int> L, R;     vector<bool> vis;     BipartiteMatcher(int n, int m) : g(n), L(n, -1), R(m, -1), vis(n) {}     void addEdge(int a, int b) { g[a].emplace_back(b); }     bool match(int x) {       if (vis[x]) return 0;       vis[x] = 1;       for (int v : g[x])         if (R[v] == -1) return R[L[x] = v] = x, 1;       for (int v : g[x])         if (match(R[v])) return R[L[x] = v] = x, 1;       return 0;     }     int solve() {       int cnt = 1;       while (cnt--) {         fill(vis.begin(), vis.end(), 0);         for (int i = 0; i < L.size(); ++i) {           cnt |= L[i] == -1 and match(i);         }       }       int res = 0;       for (int i = 0; i < L.size(); ++i) res += L[i] != -1;       return res;     }   };   int solve(int n, int m) {     BipartiteMatcher BM(n * m, n * m);     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         if ((i + j) % 2 == 1) continue;         for (int k = max(i - 3, 0); k <= min(i + 3, n - 1); ++k) {           for (int l = max(j - 3, 0); l <= min(j + 3, m - 1); ++l) {             if ((k + l) % 2 == 0) continue;             if (abs(i - k) + abs(j - l) == 3) {               BM.addEdge(i * m + j, k * m + l);             }           }         }       }     return 2 * BM.solve();   }   int main() {     int n, m;     cin >> n >> m;     if (n > m) swap(n, m);     if (n <= 20 and m <= 20)       cout << solve(n, m) << endl;     else if (n == 1)       cout << 2 * (m / 6 * 3 + max(m % 6 - 3, 0)) << endl;     else       cout << (n * 1ll * m) / 2 * 2 << endl;     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long x[60002];   long long v[60002];   double ans = 1e12;   long long n;   double ma(double a, double b) {     if (a > b) return a;     return b;   }   double calc(double xx, double& bd) {     double time = -1;     for (int i = 0; i < n; i++) {       double d = abs(xx - x[i]);       if (d / v[i] > time) {         time = d / v[i];         bd = x[i];       }     }     return time;   }   void bs(double s, double e) {     if (s < e - 0.0000001) {       double mid = s + (e - s) / 2;       double xx;       double x1 = calc(mid, xx);       if (ans > x1) {         ans = x1;       }       if (xx > mid)         bs(mid, e);       else         bs(s, mid);     }   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> x[i];     for (int i = 0; i < n; i++) cin >> v[i];     bs(1, 1000000000);     cout << fixed << setprecision(10) << ans;     return 0;   }


#include <bits/stdc++.h>   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       int a[20005], b[20005];       for (int i = 0; i < n; i++) scanf( %d %d , &a[i], &b[i]);       int num = 1;       for (int i = 0; i < n; i++) {         if (num < a[i]) {           num = a[i];         }         if (num <= b[i]) {           printf( %d  , num);           num++;         } else           printf( 0  );       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long int INFL = 0x3f3f3f3f3f3f3f3fLL;   const int MOD = 1e9 + 7;   const int MAX = 1e5 + 5;   int a[1001];   int __attribute__((optimize( -O3 ))) main() {     cin.sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int ans = 1;     for (int i = 0; i < n; i++) {       int l = i, r = i;       while (l > 0 and a[l] >= a[l - 1]) {         l--;       }       while (r < n - 1 and a[r] >= a[r + 1]) {         r++;       }       ans = max(ans, r - l + 1);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 522133279;   const int MAXN = 100000;   const int TOTN = 100 + 100;   const long long MOD = 1000000007;   bool _su[MAXN];   vector<int> su;   vector<int> suc;   int n, k;   void shai() {     memset((_su), true, sizeof(_su));     for (int i = (2); i < (MAXN); i++) {       if (k <= 1) break;       if (_su[i] && k % i == 0) {         su.push_back(i);         suc.push_back(0);         while (k && k % i == 0) {           k /= i;           suc.back()++;         }         for (int j = 2; j * i < MAXN; j++) _su[j * i] = false;       }     }     if (k != 1) {       su.push_back(k);       suc.push_back(1);     }   }   vector<int> fen(int x) {     vector<int> cnt;     cnt.resize(su.size());     for (int i = (0); i < (su.size()); i++) {       while (x && x % su[i] == 0) {         x /= su[i];         cnt[i]++;       }     }     return cnt;   }   vector<vector<int> > lis;   bool divisible(vector<int> cnt) {     bool ok = true;     for (int i = (0); i < (cnt.size()); i++) {       if (cnt[i] < suc[i]) {         ok = false;         break;       }     }     return ok;   }   vector<int> getCnt(int l, int r) {     if (l == 0) return lis[r];     vector<int> res;     for (int i = (0); i < (lis[l].size()); i++) {       res.push_back(lis[r][i] - lis[l - 1][i]);     }     return res;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> k;     shai();     for (int i = (0); i < (n); i++) {       int a;       cin >> a;       lis.push_back(fen(a));     }     for (int i = (1); i < (n); i++) {       for (int j = (0); j < (lis[i].size()); j++) {         lis[i][j] += lis[i - 1][j];       }     }     int l = 0, r = 0;     long long ans = 0;     while (r < n) {       while (r < n && !divisible(getCnt(l, r))) r++;       if (r >= n) break;       ans += n - r;       l++;       if (l > r) r = l;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int p[100000];   int h[100000];   int queries[100000][3];   vector<pair<int, int> > type3[100000];   vector<int> adj[100000];   int visited[100000];   vector<int> who;   int top[100000];   int ok[100000];   vector<pair<int, int> > need[100000];   int which[100000];   int findSet(int x) {     if (p[x] == x) return x;     return p[x] = findSet(p[x]);   }   void mergeSet(int x, int y) {     int r1 = findSet(x);     int r2 = findSet(y);     if (h[r1] > h[r2])       p[r2] = r1;     else if (h[r2] > h[r1])       p[r1] = r2;     else {       p[r1] = r2;       h[r2] += 1;     }   }   bool sameSet(int x, int y) { return findSet(x) == findSet(y); }   void dfs(int x) {     visited[x] = 1;     for (int i = 0; i < type3[x].size(); i++)       if (visited[type3[x][i].first] == 1) ok[type3[x][i].second] = 1;     for (int i = 0; i < adj[x].size(); i++)       if (!visited[adj[x][i]]) dfs(adj[x][i]);     visited[x] = 2;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       top[i] = 1;       p[i] = i;     }     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d%d , &queries[i][0], &a);       if (queries[i][0] != 2) scanf( %d , &b);       queries[i][1] = a - 1;       queries[i][2] = b - 1;       if (queries[i][0] == 1) {         adj[b - 1].push_back(a - 1);         top[a - 1] = 0;       }       if (queries[i][0] == 2) {         who.push_back(a - 1);         which[who.size() - 1] = i;       }       if (queries[i][0] == 3) {         type3[who[b - 1]].push_back(make_pair(a - 1, i));         need[which[b - 1]].push_back(make_pair(a - 1, i));       }     }     for (int i = 0; i < n; i++)       if (top[i]) dfs(i);     for (int i = 0; i < m; i++) {       if (queries[i][0] == 1) mergeSet(queries[i][1], queries[i][2]);       if (queries[i][0] == 2)         for (int j = 0; j < need[i].size(); j++)           if (!sameSet(queries[i][1], need[i][j].first))             ok[need[i][j].second] = 0;       if (queries[i][0] == 3) {         if (ok[i])           printf( YES n );         else           printf( NO n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int st[1000010];   int mod = 1000000007;   vector<vector<int> > g;   int dp[1000010][2];   int n, m, k;   int a[1000010];   int main() {     st[0] = 1;     for (int i = (1); i < (1000010); ++i) {       st[i] = st[i - 1] + st[i - 1];       if (st[i] >= mod) st[i] -= mod;     }     scanf( %d%d%d , &n, &m, &k);     int max1 = -1;     int min1 = 2000000000;     int tot = 0;     for (int i = (0); i < (m); ++i) {       int v1, v2;       scanf( %d%d , &v1, &v2);       v1--;       v2--;       if (((v2 - v1) != 1) && (v2 - v1 != k + 1)) {         cout << 0 << endl;         return 0;       }       if (v2 - v1 == k + 1) {         a[v1] = 1;         max1 = v1;         min1 = ((min1 < v1) ? (min1) : (v1));         tot++;       }     }     if (max1 - min1 > k) {       cout << 0 << endl;       return 0;     }     for (int i = (1); i < (n); ++i) a[i] += a[i - 1];     int res = 1;     for (int i = (0); i < (n); ++i) {       int v = i + k + 1;       if (v >= n) break;       if (i + k + 1 <= max1) continue;       if (i > min1) break;       int last = min(i + k, n - k - 2);       int sum = a[last] - a[i];       int c = a[i];       if (i) c -= a[i - 1];       if (c) res--;       if (res < 0) res += mod;       res += st[last - i - sum];       if (res >= mod) res -= mod;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s;     string c;     cin >> n >> c;     s = n;     string r =   ;     while (n > 0) {       if (n % 2 == 0) {         string y =   ;         y += c[s - n];         y += r;         r = y;       } else {         r += c[s - n];       }       n--;     }     cout << r;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int M, N, maxH[100009], d[100009];   void dfs(int nod) {     if (nod >= (1 << N)) {       maxH[nod] = 0;       return;     }     int f1 = nod << 1, f2 = f1 | 1;     dfs(f1), dfs(f2);     maxH[nod] = max(maxH[f1] + d[f1], maxH[f2] + d[f2]);   }   int ans = 0;   void solve(int nod) {     if (nod >= (1 << N)) return;     int f1 = nod << 1, f2 = f1 | 1;     if (maxH[f1] + d[f1] < maxH[f2] + d[f2]) swap(f1, f2);     solve(f1);     ans += maxH[nod] - (maxH[f2] + d[f2]);     solve(f2);   }   int main() {     scanf( %d , &N), M = (1 << (N + 1)) - 1;     for (int i = 2; i <= M; i++) scanf( %d , &d[i]);     dfs(1);     solve(1);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int L, f, b;   int n;   int pos[110];   map<int, int> lot;   int findpos(int L) {     map<int, int>::iterator cur, next;     cur = lot.begin(), next = cur;     next++;     for (; next != lot.end(); cur++, next++) {       int back = cur->first + cur->second, front = next->first;       if (back + b + L + f <= front) return back + b;     }     return -1;   }   int main() {     scanf( %d%d%d , &L, &b, &f);     scanf( %d , &n);     lot.clear();     lot.insert(make_pair(-b, 0));     lot.insert(make_pair(L + f, 0));     for (int i = 0; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       if (a == 1) {         int pl = findpos(b);         pos[i + 1] = pl;         if (pl >= 0) lot.insert(make_pair(pl, b));         printf( %d n , pl);       } else {         if (pos[b] < 0) continue;         lot.erase(pos[b]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1 << 28;   const long long LINF = 1ll << 61;   string B, N;   long long b, pw[10], C;   int main() {     ios::sync_with_stdio(false);     cin >> B >> N >> C;     int it = N.size();     for (int i = N.size() - 1; i >= 0; i--) {       N[i]--;       if (N[i] <  0 )         N[i] =  9 ;       else         break;     }     b = 0;     for (int i = 0; i < B.size(); i++) b = (b * 10 + B[i] -  0 ) % C;     pw[0] = 1;     for (int i = 1; i < 10; i++) pw[i] = pw[i - 1] * b % C;     long long ans = 1;     for (int i = 0; i < N.size(); i++) {       ans = ans * ans % C;       long long tmp = ans;       ans = ans * ans % C;       ans = ans * ans % C;       ans = ans * tmp % C;       ans = ans * pw[N[i] -  0 ] % C;     }     ans = ans * (b - 1 + C) % C;     if (ans == 0)       cout << C << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, cnt = 1;     cin >> a >> b;     int d = a;     bool flag = true;     while (d >= cnt) {       if (flag) {         a -= cnt;         flag = false;         d = b;       } else {         b -= cnt;         flag = true;         d = a;       }       ++cnt;     }     if (a < cnt && flag)       cout <<  Vladik             <<   n ;     else       cout <<  Valera             <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long tripleIndx = n / 3;       if (!(n % 3)) tripleIndx--;       stack<long long> st;       while (tripleIndx--) {         st.push(tripleIndx % 4ll);         tripleIndx /= 4;       }       long long curA = 1;       long long curB = 2;       long long curC = 3;       long long a[4] = {0, 1, 2, 3};       long long b[4] = {0, 2, 3, 1};       long long c[4] = {0, 3, 1, 2};       while (!st.empty()) {         long long mod = st.top();         st.pop();         curA *= 4;         curA += a[mod];         curB *= 4;         curB += b[mod];         curC *= 4;         curC += c[mod];       }       if (n % 3 == 1) {         cout << curA <<   n ;       } else if (n % 3 == 2) {         cout << curB <<   n ;       } else {         cout << curC <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 110;   int a[maxn];   int main() {     int n;     while (cin >> n) {       int ans = 0;       for (int i = 1; i <= n; i++) {         cin >> a[i];         if (a[i]) ans++;       }       for (int i = 1; i <= n; i++) {         if (a[i] == 1) {           if (i == 1) continue;           if (a[i - 1] && i >= 1) continue;           if (i >= 2 && a[i - 2]) {             ans++;             continue;           }         }       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[1000005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     int n;     cin >> n;     for (long long(i) = (0); (i) < (n); (i)++) cin >> a[i];     int tmp = n + 1;     int ans = 0;     for (int i = n; i >= 1; --i) {       if (i < tmp) ans++;       tmp = min(tmp, i - a[i - 1]);     }     cout << ans << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   priority_queue<long long, vector<long long>, greater<long long> > q;   int main() {     long long n;     while (cin >> n) {       long long e = 0, o = 0;       for (long long i = 1; i <= n; i++) {         long long x;         cin >> x;         if (x % 2)           o++;         else           e++;       }       long long xx = min(e, o);       cout << xx + (o - xx) / 3 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int NCARDS = 8;   const int NVALS = 5;   const int NSTATE = 495;   vector<vector<int> > states;   map<vector<int>, int> mp;   void genstates(vector<int> &v, int at, int rem) {     if (at >= ((int)(v).size())) {       if (rem == 0) {         int id = ((int)(states).size());         states.push_back(v);         mp[v] = id;       }       return;     }     for (v[at] = 0; v[at] <= rem; ++v[at]) genstates(v, at + 1, rem - v[at]);   }   int nxt[NSTATE][NVALS][NVALS];   vector<int> adj[NSTATE][NSTATE];   vector<int> radj[NSTATE][NSTATE];   int deg[NSTATE][NSTATE];   int dp[NSTATE][NSTATE];   int q[NSTATE * NSTATE], qhead, qtail;   void precalc() {     states.clear();     mp.clear();     vector<int> state(NVALS, 0);     genstates(state, 0, NCARDS);     for (int i = (0); i < (((int)(states).size())); ++i)       for (int a = (0); a < (NVALS); ++a)         for (int b = (0); b < (NVALS); ++b) {           if (states[i][a] == 0) {             nxt[i][a][b] = -1;             continue;           }           vector<int> tmp = states[i];           tmp[a]--;           tmp[b]++;           assert(mp.count(tmp));           nxt[i][a][b] = mp[tmp];         }     for (int i = (0); i < (((int)(states).size())); ++i)       for (int j = (0); j < (((int)(states).size())); ++j) {         for (int a = (0); a < (NVALS); ++a)           for (int b = (0); b < (NVALS); ++b)             if (a * b != 0 && states[i][a] != 0 && states[j][b] != 0) {               int c = (a + b) % NVALS;               int ni = j, nj = nxt[i][a][c];               assert(nj != -1);               adj[i][j].push_back(ni * NSTATE + nj);             }         sort(adj[i][j].begin(), adj[i][j].end());         adj[i][j].erase(unique(adj[i][j].begin(), adj[i][j].end()),                         adj[i][j].end());         for (int k = (0); k < (((int)(adj[i][j]).size())); ++k) {           int ii = adj[i][j][k] / NSTATE, jj = adj[i][j][k] % NSTATE;           radj[ii][jj].push_back(i * NSTATE + j);         }       }     int winid = ((int)(states).size()) - 1;     for (int i = (0); i < (((int)(states).size())); ++i)       for (int j = (0); j < (((int)(states).size())); ++j)         dp[i][j] = 0, deg[i][j] = ((int)(adj[i][j]).size());     qhead = qtail = 0;     for (int i = (0); i < (((int)(states).size())); ++i)       dp[i][winid] = -1, q[qhead++] = i * NSTATE + winid;     while (qtail < qhead) {       int i = q[qtail] / NSTATE, j = q[qtail] % NSTATE;       ++qtail;       for (int k = (0); k < (((int)(radj[i][j]).size())); ++k) {         int ii = radj[i][j][k] / NSTATE, jj = radj[i][j][k] % NSTATE;         if (dp[ii][jj] != 0) continue;         if (dp[i][j] == -1) {           dp[ii][jj] = 1;           q[qhead++] = ii * NSTATE + jj;           continue;         }         if (--deg[ii][jj] == 0) {           dp[ii][jj] = -1;           q[qhead++] = ii * NSTATE + jj;           continue;         }       }     }   }   int fst;   int a[NCARDS], b[NCARDS];   void run() {     int nq;     scanf( %d , &nq);     for (int qi = (0); qi < (nq); ++qi) {       scanf( %d , &fst);       for (int i = (0); i < (NCARDS); ++i) scanf( %d , &a[i]);       for (int i = (0); i < (NCARDS); ++i) scanf( %d , &b[i]);       vector<int> acnt(NVALS, 0), bcnt(NVALS, 0);       for (int i = (0); i < (NCARDS); ++i) acnt[a[i]]++, bcnt[b[i]]++;       assert(mp.count(acnt) && mp.count(bcnt));       int aid = mp[acnt], bid = mp[bcnt];       int ans = fst == 0 ? dp[aid][bid] : -dp[bid][aid];       printf( %s n , ans > 0 ?  Alice  : ans < 0 ?  Bob  :  Deal );     }   }   int main() {     precalc();     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> S;   vector<int> ack;   int pop[1100100];   int kol[1100100];   int k[1234];   char c[1234];   const int INF = 1000000000;   int parse(int a) {     if (a == INF) return -INF;     return a;   }   int main() {     int n, m;     scanf( %d , &n);     for (int i = (0); i <= (int(n) - 1); ++i) {       int s;       scanf( %d , &s);       S.push_back(s);     }     sort(S.begin(), S.end());     scanf( %d , &m);     for (int i = (0); i <= (int(m) - 1); ++i) {       ack.push_back(S.back());       S.pop_back();     }     for (int i = (0); i <= (int(m) - 1); ++i) {       scanf(  %c%d , &c[i], &k[i]);     }     for (int q = m - 1; q >= 0; q--) {       for (int i = (0); i <= (int(1 << m) - 1); ++i) pop[i] = kol[i];       int mn = 1;       if (k[q] == 2) mn *= -1;       for (int i = (0); i <= (int(1 << m) - 1); ++i) {         kol[i] = -INF;         for (int j = (0); j <= (int(m) - 1); ++j)           if ((i & (1 << j)) != 0) {             int x = ack[j];             if (c[q] ==  b ) x = 0;             kol[i] =                 mn * max(mn * (pop[i ^ (1 << j)] + mn * x), parse(kol[i] * mn));           }       }     }     printf( %d n , kol[(1 << m) - 1]);   }


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


#include <bits/stdc++.h>   using namespace std;   const int maxn = 20000;   struct node {     int flow;     int ff[5];     int ru;   } mat[maxn];   int n, m;   int kk[500];   int now;   int getup(int id) {     int ret = -1;     int k = id - m;     while (k >= 1) {       if (mat[k].flow != -1) {         ret = k;         break;       }       k -= m;     }     return ret;   }   int getright(int id) {     int ret = -1;     int k = id;     while (k % m != 0) {       k = k + 1;       if (mat[k].flow != -1) {         ret = k;         break;       }     }     return ret;   }   int getdown(int id) {     int ret = -1;     int k = id + m;     while (k <= n * m) {       if (mat[k].flow != -1) {         ret = k;         break;       }       k += m;     }     return ret;   }   int getleft(int id) {     int ret = -1;     int k = id;     while (k % m != 1) {       k--;       if (mat[k].flow != -1) {         ret = k;         break;       }     }     return ret;   }   int fl[maxn][5];   int ans;   int cnt;   int solve(int id) {     int ret = 0;     int k = id;     int ne;     int u, d, r, l;     while (k != -1) {       ret++;       ne = mat[k].ff[mat[k].flow];       u = mat[k].ff[1];       d = mat[k].ff[3];       r = mat[k].ff[2];       l = mat[k].ff[4];       if (u != -1) {         mat[u].ff[3] = d;       }       if (d != -1) {         mat[d].ff[1] = u;       }       if (r != -1) {         mat[r].ff[4] = l;       }       if (l != -1) {         mat[l].ff[2] = r;       }       k = ne;     }     return ret;   }   int main() {     kk[ U ] = 1;     kk[ R ] = 2;     kk[ D ] = 3;     kk[ L ] = 4;     kk[ . ] = -1;     now = 0;     cin >> n >> m;     string s;     for (int i = 1; i <= n; i++) {       cin >> s;       for (int j = 0; j < m; j++) {         mat[++now].flow = kk[s[j]];       }     }     for (int i = 1; i <= now; i++) {       if (mat[i].flow == -1) continue;       if (n != 1) fl[i][1] = getup(i);       if (m != 1) fl[i][2] = getright(i);       if (n != 1) fl[i][3] = getdown(i);       if (m != 1) fl[i][4] = getleft(i);       if (m == 1) {         fl[i][2] = fl[i][4] = -1;       }       if (n == 1) {         fl[i][1] = fl[i][3] = -1;       }     }     for (int i = 1; i <= now; i++) {       int ne = fl[i][mat[i].flow];       if (ne != -1) {         int nne = fl[ne][mat[ne].flow];         if (nne != i)           ;         mat[ne].ru = 1;       }     }     ans = 0;     for (int i = 1; i <= now; i++) {       if (mat[i].flow == -1) continue;       for (int i1 = 1; i1 <= now; i1++) {         for (int j = 1; j <= 4; j++) {           mat[i1].ff[j] = fl[i1][j];         }       }       int z = solve(i);       if (z > ans) {         ans = z;         cnt = 1;       } else if (z == ans) {         cnt++;       }     }     cout << ans <<     << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 100, MOD = 1e9 + 9, INF = 1e15, SQ = 370, LOG = 30;   int n, m, x, y, x2, y2, z, t, now, l, r;   int ans, dp[4][4 * N];   bool lazy[4 * N];   string s;   void bld(int b, int e, int pos) {     if (b == e - 1) {       if (s[b] ==  7 ) {         dp[3][pos]++;       } else {         dp[2][pos]++;       }       dp[0][pos] = dp[1][pos] = 1;       return;     }     int lch = pos << 1, rch = lch + 1, mid = e + b >> 1;     bld(b, mid, lch);     bld(mid, e, rch);     dp[3][pos] = dp[3][lch] + dp[3][rch];     dp[2][pos] = dp[2][lch] + dp[2][rch];     dp[1][pos] = max(dp[3][lch] + dp[1][rch], dp[1][lch] + dp[2][rch]);     dp[0][pos] = max(dp[2][lch] + dp[0][rch], dp[0][lch] + dp[3][rch]);   }   void shift(int pos, int lch, int rch) {     lazy[lch] = !lazy[lch];     lazy[rch] = !lazy[rch];     lazy[pos] = false;     swap(dp[0][lch], dp[1][lch]);     swap(dp[2][lch], dp[3][lch]);     swap(dp[0][rch], dp[1][rch]);     swap(dp[2][rch], dp[3][rch]);   }   void upd(int b, int e, int pos) {     if (b >= y || e <= x) return;     if (x <= b && e <= y) {       lazy[pos] = !lazy[pos];       swap(dp[0][pos], dp[1][pos]);       swap(dp[2][pos], dp[3][pos]);       return;     }     int lch = pos << 1, rch = lch + 1, mid = e + b >> 1;     if (lazy[pos]) shift(pos, lch, rch);     upd(b, mid, lch);     upd(mid, e, rch);     dp[3][pos] = dp[3][lch] + dp[3][rch];     dp[2][pos] = dp[2][lch] + dp[2][rch];     dp[1][pos] = max(dp[3][lch] + dp[1][rch], dp[1][lch] + dp[2][rch]);     dp[0][pos] = max(dp[2][lch] + dp[0][rch], dp[0][lch] + dp[3][rch]);   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m >> s;     bld(0, n, 1);     while (m--) {       cin >> s;       if (s ==  count ) {         cout << dp[0][1] <<   n ;       } else {         cin >> x >> y;         x--;         upd(0, n, 1);       }     }   }


#include <bits/stdc++.h>   using namespace std;   std::vector<std::string> alph;   class IAlphabet {    public:     virtual int encode(char symbol) = 0;     virtual char decode(int code) = 0;     virtual int size() = 0;   };   class alphabet_eng : public IAlphabet {    public:     virtual int encode(char symbol);     virtual char decode(int code);     virtual int size() { return 26; };   };   int alphabet_eng::encode(char symbol) {     if ((symbol < 97) || (symbol >= 123))       return -1;     else       return (symbol - 97);   }   char alphabet_eng::decode(int code) {     if ((code < 0) || (code >= 26))       return 0;     else       return (code + 97);   }   class VocabularyTrie {    public:     VocabularyTrie(IAlphabet& alphabet);     VocabularyTrie(VocabularyTrie& parent);     void Fill();     int GetSize();     bool m_end_of_word;     IAlphabet& m_alphabet;     int winner;     int loser;     std::vector<std::unique_ptr<VocabularyTrie>> m_children;     VocabularyTrie* m_parent;   };   std::set<std::pair<int, VocabularyTrie*>> proce;   VocabularyTrie::VocabularyTrie(IAlphabet& alphabet)       : m_end_of_word(false),         m_children(alphabet.size()),         m_parent(nullptr),         m_alphabet(alphabet) {     winner = 2;   }   VocabularyTrie::VocabularyTrie(VocabularyTrie& parent)       : m_end_of_word(false),         m_children(parent.GetSize()),         m_parent(&parent),         m_alphabet(parent.m_alphabet) {}   int VocabularyTrie::GetSize() { return m_alphabet.size(); }   void VocabularyTrie::Fill() {     for (int i = 0; i < alph.size(); i++) {       std::string word;       word = alph[i];       VocabularyTrie* trie_ptr = this;       for (int letter = 0; letter < word.length(); letter++) {         int curr_letter_code = m_alphabet.encode(word[letter]);         if (trie_ptr->m_children[curr_letter_code] == nullptr) {           trie_ptr->m_children[curr_letter_code].reset(               new VocabularyTrie(*trie_ptr));         }         trie_ptr = trie_ptr->m_children[curr_letter_code].get();       }       trie_ptr->m_end_of_word = true;       proce.insert(std::make_pair(word.length(), trie_ptr));     }   }   int main() {     int m, n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       std::string x;       cin >> x;       alph.push_back(x);     }     alphabet_eng alphabet;     VocabularyTrie nn(alphabet);     nn.Fill();     while (proce.size() >= 1) {       auto h = proce.end();       h--;       int x = h->first;       VocabularyTrie* y = h->second;       proce.erase(std::make_pair(x, y));       int winner = 2;       int loser = 1;       for (int i = 0; i < 26; i++) {         if (y->m_children[i] != nullptr) loser = 2;       }       if (y == nullptr) continue;       for (int i = 0; i < 26; i++) {         if ((y->m_children[i] != nullptr) && (y->m_children[i]->winner == 2))           winner = 1;         if ((y->m_children[i] != nullptr) && (y->m_children[i]->loser == 2))           loser = 1;       }       y->winner = winner;       y->loser = loser;       if (x > 0) proce.insert(std::make_pair(x - 1, y->m_parent));     }     int whowins = 1;     int u = nn.winner;     int v = nn.loser;     if (u == 2)       whowins = 2;     else {       if (v == 1)         whowins = 1;       else         whowins = 2 - (k % 2);     }     if (whowins == 2)       cout <<  Second ;     else       cout <<  First ;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:36777216 )   using namespace std;   const int inf = 1 << 30;   const long long Inf = 1LL << 62;   const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1, 0};   const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1, 0};   const double eps = 1e-9;   const double pi = 3.1415926535897932384626433832795;   template <class T>   inline bool eq(const T &a, const T &b) {     return fabs(a - b) < eps;   }   template <class T>   inline bool deg2(const T &n) {     return (n & (n - 1)) == 0;   }   template <class T>   inline void chmax(T &a, const T &b) {     a = max(a, b);   }   inline int intRand(int l, int r) {     return ((rand() << 16) | rand()) % (r - l + 1) + l;   }   inline long long llRand(long long l, long long r) {     return (((1ll * rand()) << 48) | ((1ll * rand()) << 32) | (rand() << 16) |             rand()) %                (r - l + 1) +            l;   }   int i, n, len, j;   string s, pr;   int main() {     ios_base::sync_with_stdio(false);     srand(time(NULL));     cin >> n;     cin >> pr;     len = (int)pr.size();     for (i = 1; i < n; i++) {       cin >> s;       for (j = 0; j < len; j++)         if (s[j] != pr[j]) break;       len = j;       pr = s;     }     cout << len;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   using namespace std;   int n;   int main() {     cin >> n;     int k1 = 0;     int x = n;     while (x % 10 != 0) {       x++;       k1++;     }     int k2 = 0;     while (n % 10 != 0) {       n--;       k2++;     }     if (k1 > k2)       cout << n;     else       cout << x;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int p[20000000 / 5], cnt;   bool flag[20000000];   void prepare() {     flag[1] = 1;     for (int i = 2; i <= m; i++) {       if (!flag[i]) {         p[cnt++] = i;       }       for (int j = 0; j < cnt && i * p[j] <= m; j++) {         flag[i * p[j]] = 1;         if (i % p[j] == 0) break;       }     }   }   int main() {     cin >> n;     if (n == 2) {       puts( 1 1 );       return 0;     }     m = n * (n + 1) / 2;     prepare();     for (int i = 1; i <= n; i++)       if (!flag[i] && !flag[m - i]) {         for (int j = 1; j <= n; j++) {           printf( %d  , j == i ? 1 : 2);         }         puts(  );         return 0;       }     for (int i = 4; i <= n; i++)       if (!flag[i] && !flag[m - 3 - i]) {         for (int j = 1; j <= n; j++) printf( %d  , j == 3 ? 2 : j == i ? 3 : 1);         return 0;       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct ww {     long double x, y;   } a[100010];   int i, j, k, n, m, xx, yy;   long double LU[100010], RU[100010], LD[100010], RD[100010];   inline bool judge(long double len) {     int i, j;     j = 0;     for (i = 1; i <= n; i++) {       for (; a[j + 1].x + len < a[i].x; j++)         ;       if (max(LU[j], RU[i + 1]) - min(LD[j], RD[i + 1]) <= len) return 1;     }     return 0;   }   inline bool cc1(const ww &a, const ww &b) { return a.x < b.x; }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d%d , &xx, &yy);       a[i].x = yy - xx, a[i].y = xx + yy;     }     sort(a + 1, a + n + 1, cc1);     LD[0] = RD[n + 1] = 1e10;     LU[0] = RU[n + 1] = -1e10;     for (i = 1; i <= n; i++)       LD[i] = min(LD[i - 1], a[i].y), LU[i] = max(LU[i - 1], a[i].y);     for (i = n; i; i--)       RD[i] = min(RD[i + 1], a[i].y), RU[i] = max(RU[i + 1], a[i].y);     long double l = 0, r = 1e10, mid;     for (; l + 1e-7 < r;) {       mid = (l + r) / 2;       if (judge(mid))         r = mid;       else         l = mid;     }     double an = r;     printf( %.10lf n , an / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   template <typename T>   struct modular {     constexpr modular() : val(0) {}     constexpr modular(const modular<T>& _m) : val(_m.val) {}     template <typename U>     constexpr modular(const U& _r = U()) {       val = -MOD <= _r && _r < MOD ? _r : _r % MOD;       if (val < 0) {         val += MOD;       }     }     const T operator()() { return val; }     template <typename U>     explicit operator U() const {       return static_cast<U>(val);     }     modular<T>& operator+=(const modular<T>& _m) {       if ((val += _m.val) >= MOD) {         val -= MOD;       }       return *this;     }     modular<T>& operator-=(const modular<T>& _m) {       if ((val -= _m.val) < 0) {         val += MOD;       }       return *this;     }     modular<T>& operator*=(const modular<T>& _m) {       val = modular<T>(static_cast<int64_t>(val) * static_cast<int64_t>(_m.val))                 .val;       return *this;     }     modular<T>& operator/=(const modular<T>& _m) {       T a = _m.val, b = MOD, u = 0, v = 1;       while (a != 0) {         T q = b / a;         b -= q * a;         swap(a, b);         u -= q * v;         swap(u, v);       }       return *this *= u;     }     modular<T>& operator=(const modular<T>& _m) {       val = _m.val;       return *this;     }     template <typename U>     modular<T>& operator+=(const U& _r) {       return *this += modular<T>(_r);     }     template <typename U>     modular<T>& operator-=(const U& _r) {       return *this -= modular<T>(_r);     }     template <typename U>     modular<T>& operator*=(const U& _r) {       return *this *= modular<T>(_r);     }     template <typename U>     modular<T>& operator/=(const U& _r) {       return *this /= modular<T>(_r);     }     template <typename U>     modular<T>& operator=(const U& _r) {       val = modular<T>(_r).val;       return *this;     }     modular<T> operator-() { return modular<T>(-val); }     template <typename U>     friend bool operator==(const modular<U>&, const modular<U>&);     friend std::istream& operator>>(std::istream& os, modular<T>& _m) {       os >> _m.val;       _m *= 1;       return os;     }     friend std::ostream& operator<<(std::ostream& os, const modular<T>& _m) {       return os << _m.val;     }     template <typename U>     modular<T> exp(U e) {       modular<T> res = 1;       modular<T> b = val;       if (e < 0) {         b = 1 / b;         e *= -1;       }       for (; e; e >>= 1) {         if (e & 1) {           res *= b;         }         b *= b;       }       return res;     }       private:     T val;   };   template <typename T>   inline modular<T> operator+(const modular<T>& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) += _rhs;   }   template <typename T, typename U>   inline modular<T> operator+(const modular<T>& _lhs, const U& _rhs) {     return modular<T>(_lhs) += _rhs;   }   template <typename T, typename U>   inline modular<T> operator+(const U& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) += _rhs;   }   template <typename T>   inline modular<T> operator-(const modular<T>& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) -= _rhs;   }   template <typename T, typename U>   inline modular<T> operator-(const modular<T>& _lhs, const U& _rhs) {     return modular<T>(_lhs) -= _rhs;   }   template <typename T, typename U>   inline modular<T> operator-(const U& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) -= _rhs;   }   template <typename T>   inline modular<T> operator*(const modular<T>& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) *= _rhs;   }   template <typename T, typename U>   inline modular<T> operator*(const modular<T>& _lhs, const U& _rhs) {     return modular<T>(_lhs) *= _rhs;   }   template <typename T, typename U>   inline modular<T> operator*(const U& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) *= _rhs;   }   template <typename T>   inline modular<T> operator/(const modular<T>& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) /= _rhs;   }   template <typename T, typename U>   inline modular<T> operator/(const modular<T>& _lhs, const U& _rhs) {     return modular<T>(_lhs) /= _rhs;   }   template <typename T, typename U>   inline modular<T> operator/(const U& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) /= _rhs;   }   template <typename T>   inline bool operator==(const modular<T>& _lhs, const modular<T>& _rhs) {     return _lhs.val == _rhs.val;   }   template <typename T, typename U>   inline bool operator==(const modular<T>& _lhs, const U& _rhs) {     return _lhs == modular<T>(_rhs);   }   template <typename T, typename U>   inline bool operator==(const U& _lhs, const modular<T>& _rhs) {     return modular<T>(_lhs) == _rhs;   }   template <typename T>   inline bool operator!=(const modular<T>& _lhs, const modular<T>& _rhs) {     return !(_lhs == _rhs);   }   template <typename T, typename U>   inline bool operator!=(const modular<T>& _lhs, const U& _rhs) {     return !(_lhs == _rhs);   }   template <typename T, typename U>   inline bool operator!=(const U& _lhs, const modular<T>& _rhs) {     return !(_lhs == _rhs);   }   const int N = 3003;   modular<int> dp[N][N];   void solve() {     memset(dp, 0, sizeof dp);     int n, m;     cin >> n >> m;     vector<int> a(n);     vector<int> w(n);     for (auto& x : a) {       cin >> x;     }     int H = 0, T = 0;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       w[i] = x;       if (a[i])         H += x;       else         T += x;     }     int tot = H + T;     dp[0][0] = 1;     for (int i = 0; i < m; i++) {       for (int j = 0; j <= i; j++) {         if (i - j <= T) {           dp[i + 1][j] += dp[i][j] * (T - (i - j)) / (tot + j - (i - j));           dp[i + 1][j + 1] += dp[i][j] * (H + j) / (tot + j - (i - j));         }       }     }     modular<int> ad = 0;     modular<int> mi = 0;     for (int j = 0; j <= m; j++) {       ad += dp[m][j] * j;       mi += dp[m][j] * (m - j);     }     vector<modular<int> > res(n);     for (int i = 0; i < n; i++) {       if (a[i]) {         res[i] = w[i] + ad * w[i] / H;       } else {         res[i] = w[i] - mi * w[i] / T;       }     }     for (auto& x : res) {       cout << x <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long double epsilon = 1e-9;   string minus1(const string& str) {     string str1(str);     for (int i = str.size() - 1; i >= 0; i--) {       if (str1[i] !=  0 ) {         str1[i]--;         break;       } else         str1[i] =  9 ;     }     return str1;   }   long long rem(const string& str, long long c) {     long long temp = 0;     for (int i = 0; i < str.size(); i++) {       temp = (temp * 10LL + (long long)(str[i] -  0 )) % c;     }     return temp;   }   long long phi(long long c) {     long long res = 1;     for (long long i = 2; i * i <= c; i++) {       if (c % i == 0) {         c /= i;         res *= (i - 1);         while (c % i == 0) {           c /= i;           res *= i;         }       }     }     if (c > 1) res *= c - 1;     return res;   }   long long rem2(const string& str, long long c) {     long long temp = 0;     long long t2;     for (int i = 0; i < str.size(); i++) {       t2 = (temp * 10LL + (long long)(str[i] -  0 ));       temp = t2 % c + t2 / c;     }     return temp;   }   long long powe(long long a, long long p, long long c) {     long long res = 1;     long long mul = a;     while (p > 0) {       if (p & 1) {         res = (res * mul) % c;       }       mul = (mul * mul) % c;       p >>= 1;     }     return res;   }   long long bruteForce(string B, string N, long long c) {     stringstream ss;     ss << B <<     << N;     long long b, n;     ss >> b >> n;     long long res = (b - 1) % c;     for (int i = 1; i < n; i++) res = (res * b) % c;     if (res == 0) res = c;     return res;   }   long long nod(long long a, long long b) {     if (a < b) swap(a, b);     long long x;     while (b) {       x = a % b;       a = b;       b = x;     }     return a;   }   bool isPow(long long i, long long j) {     if (j == 1) return false;     while (i % j == 0) i /= j;     return i == 1;   }   void fail() {     long long nd;     for (int i = 2; i < 10000; i++) {       for (int j = 1; j < i; j++) {         nd = nod(i, j);         if (isPow(i, nd)) continue;         if (powe(j, phi(i) + 1, i) != j) {           cerr <<  Failed with:   << i <<     << j << endl;           return;         }       }     }   }   int main() {     string n, b;     long long c;     long long e;     int o = 1;     while (cin >> b >> n >> c) {       long long a = rem(minus1(b), c);       long long b2 = rem(b, c);       n = minus1(n);       long long mat[10];       for (int i = 0; i < 10; i++) mat[i] = 1LL;       long long ge, ye;       int idx;       for (int i = n.size() - 1; i >= 0; i--) {         idx = n[i] -  0 ;         mat[idx] = (mat[idx] * b2) % c;         ge = (b2 * b2) % c;         ye = (ge * ge) % c;         ye = (ye * ye) % c;         b2 = (ye * ge) % c;       }       long long re = 1;       for (int i = 0; i < 10; i++) {         for (int j = 0; j < i; j++) re = (re * mat[i]) % c;       }       long long q = (a * re) % c;       if (q == 0) q = c;       cout << q << endl;       o++;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b, sum;   int main() {     cin >> n;     b = -1;     sum = 0;     for (int i = 0; i < n; i++) {       cin >> a;       if (a == 0 || (a == b && b != 3)) {         sum++;         b = 0;       } else if (a == 3 && b == 1)         b = 2;       else if (a == 3 && b == 2)         b = 1;       else         b = a;     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void umax(T &a, T b) {     if (a < b) a = b;   }   template <class T>   inline void umin(T &a, T b) {     if (a > b) a = b;   }   template <class T>   inline T abs(T a) {     return a > 0 ? a : -a;   }   template <class T>   inline T gcd(T a, T b) {     return __gcd(a, b);   }   template <class T>   inline T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   const int inf = 1e9 + 143;   const long long longinf = 1e18 + 143;   inline int read() {     int x;     scanf(  %d , &x);     return x;   }   const int N = 1e5 + 100;   const int MAX = 1e4 + 100;   int n;   long long x[N];   int c[N];   set<pair<int, int> > reach;   bool taken[N];   int sz = 0;   long long a[N];   priority_queue<pair<long long, int> > q;   long long dist[MAX];   bool used[MAX];   void rebuild() {     sort(a, a + sz);     sz = unique(a, a + sz) - a;     int mod = a[0];     dist[0] = 0;     used[0] = 0;     for (int i = 1; i < mod; i++) {       dist[i] = longinf;       used[i] = 0;     }     q.push(make_pair(0ll, 0));     while (!q.empty()) {       int u = q.top().second;       long long len = -q.top().first;       q.pop();       if (dist[u] < len) continue;       for (int i = 1; i < sz; i++) {         int v = (u + a[i]) % mod;         long long c = a[i];         if (dist[v] > dist[u] + c) {           dist[v] = dist[u] + c;           q.push(make_pair(-dist[v], v));         }       }     }     reach.clear();     for (int i = 0; i < n; i++) {       if (taken[i]) continue;       if (dist[x[i] % mod] <= x[i]) {         reach.insert(make_pair(-c[i], i));       }     }   }   int main() {     long long h;     cin >> h;     n = read();     int m = read();     a[sz++] = read();     for (int i = 0; i < n; i++) {       scanf(  %I64d , x + i);       --x[i];       c[i] = read();     }     rebuild();     while (m--) {       int op = read();       if (op == 1) {         long long x;         scanf(  %I64d , &x);         a[sz++] = x;         rebuild();       } else if (op == 2) {         int id = read() - 1;         int y = read();         if (reach.find(make_pair(-c[id], id)) != reach.end()) {           reach.erase(make_pair(-c[id], id));           c[id] -= y;           reach.insert(make_pair(-c[id], id));         } else {           c[id] -= y;         }       } else if (op == 3) {         if (!reach.size()) {           puts( 0 );         } else {           printf( %d n , -reach.begin()->first);           taken[reach.begin()->second] = true;           reach.erase(reach.begin());         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mx = 1e5 + 5;   int f[mx];   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<pair<int, int>> v;     for (int i = 3; 2 * i <= n; i += 2) {       if (f[i] == 0) {         int c = 0;         for (int j = i; j <= n; j += i) c += !f[j];         for (int j = i, l = -1; j <= n; j += i) {           if ((c & 1) && j == 2 * i) continue;           if (!f[j]) {             if (l == -1)               l = j;             else {               v.push_back({l, j});               l = -1;             }           }           f[j] = 1;         }       }     }     for (int j = 2, l = -1; j <= n; j += 2) {       if (!f[j]) {         if (l == -1)           l = j;         else {           v.push_back({l, j});           l = -1;         }       }     }     cout << v.size() <<   n ;     for (auto x : v) cout << x.first <<     << x.second <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   int n, act;   int t[MAXN];   int last[MAXN], len[MAXN];   int main() {     scanf( %d , &n);     for (int i = 1; i < MAXN; ++i) len[i] = -1;     for (int i = 1; i <= n; ++i) {       scanf( %d , &t[i]);       act = t[i];       if (len[act] == -1) {         len[act] = 0;       } else if (len[act] >= 0) {         if (len[act] == 0)           len[act] = i - last[act];         else if (i - last[act] != len[act])           len[act] = -2;       }       last[act] = i;     }     int counter = 0;     for (int i = 1; i < MAXN; ++i)       if (len[i] >= 0) ++counter;     printf( %d n , counter);     for (int i = 1; i < MAXN; ++i) {       if (len[i] >= 0) {         printf( %d %d n , i, len[i]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int MaxN = 300005;   const long long int mod = 1e9 + 7;   const float pi = 3.1415926535897932384626433832795028;   long long int mcd(long long int a, long long int b) {     if (a == 0) return b;     return mcd(b % a, a);   }   int arr[MaxN];   void solve() {     int N, i, j, p, q;     cin >> N;     for (i = 1; i <= N; i++) {       cin >> arr[i];     }     p = 0, q = N + 1;     for (i = 1; i <= N; i++) {       if (arr[i] >= i - 1) {         p = i;       } else         break;     }     for (i = N; i > 0; i--) {       if (arr[i] >= N - i) {         q = i;       } else         break;     }     if (p >= q)       cout <<  Yes n ;     else       cout <<  No n ;   }   int main() {     long long int t, i;     cin >> t;     for (i = 1; i <= t; i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int out = 0, fh = 1;     char jp = getchar();     while ((jp >  9  || jp <  0 ) && jp !=  - ) jp = getchar();     if (jp ==  - ) fh = -1, jp = getchar();     while (jp >=  0  && jp <=  9 ) out = out * 10 + jp -  0 , jp = getchar();     return out * fh;   }   void print(int x) {     if (x >= 10) print(x / 10);     putchar( 0  + x % 10);   }   void write(int x, char c) {     if (x < 0) putchar( - ), x = -x;     print(x);     putchar(c);   }   int phi(int x) {     int res = x;     for (int i = 2; i * i <= x; ++i)       if (x % i == 0) {         res /= i, res *= i - 1;         while (x % i == 0) x /= i;       }     if (x > 1) res /= x, res *= x - 1;     return res;   }   int mul(int a, int b, int Mod) {     long long pr = 1LL * a * b;     if (pr < Mod) return pr;     return pr % Mod + Mod;   }   int fpow(int a, int b, int Mod) {     int res = 1;     while (b) {       if (b & 1) res = mul(res, a, Mod);       a = mul(a, a, Mod);       b >>= 1;     }     return res;   }   int f(int x, int Mod) {     if (x < Mod) return x;     return x % Mod + Mod;   }   const int N = 1e5 + 10;   int n, m, q, Mod[N], k = 0, a[N];   int query(int l, int r, int p) {     if (l == r || p == k) return f(a[l], Mod[p]);     int base = a[l], expo = query(l + 1, r, p + 1);     return fpow(base, expo, Mod[p]);   }   signed main() {     n = read(), m = read();     while (1) {       Mod[++k] = m;       if (m == 1) break;       m = phi(m);     }     for (int i = 1; i <= n; ++i) a[i] = read();     q = read();     for (int i = 1; i <= q; ++i) {       int l = read(), r = read();       int ans = query(l, r, 1) % Mod[1];       write(ans,   n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t[101000], n, h[101000], p[101000];   pair<int, int> w[101000];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &t[i]);       w[i].first = t[i];       w[i].second = i;     }     sort(w, w + n);     for (int i = n - 1; i >= 0; i--) {       h[i] = ((long long)h[i + 1] * 1337 + t[i]) % 1000000009;     }     p[0] = 1;     for (int i = 1; i <= n; i++) p[i] = (long long)p[i - 1] * 1337 % 1000000009;     vector<pair<int, int> > s;     for (int i = 0; i < n; i++) {       int j = i + 1;       while (j < n && w[j].first == w[i].first) {         int len = w[j].second - w[i].second, start = w[i].second;         long long tmp = h[start] - (long long)h[start + len] * p[len];         tmp -= h[start + len] - (long long)h[start + 2 * len] * p[len];         if (tmp % 1000000009 == 0) s.push_back(pair<int, int>(len, start));         j++;       }     }     sort(s.begin(), s.end());     int first = 0;     for (int i = 0; i < s.size(); i++)       if (s[i].second >= first) {         first = s[i].second + s[i].first;       }     printf( %d n , n - first);     for (int i = first; i < n; i++) printf( %d%c , t[i], i + 1 < n ?     :   n );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   const int inf = 1e9;   const int mod = 1e9 + 7;   const long long INF = 1e18;   long long a00, a01, a10, a11, cnt0, cnt1, cnt01, cnt10, ins = 0, t = -1;   long long p[N];   void get() {     for (int i = 1; i <= ins; ++i) {       cout << 1;     }     if (t == -1) {       for (int i = 0; i < cnt0; ++i) {         cout << 0;       }     } else {       ins++;       for (int i = 0; i < cnt0 - t; ++i) {         cout << 0;       }       cout << 1;       for (int i = cnt0 - t; i < cnt0; ++i) {         cout << 0;       }     }     for (int i = ins + 1; i <= cnt1; ++i) {       cout << 1;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     for (long long a = 1; a * (a - 1) / 2 < 1e11 + 1000; ++a) {       p[a] = a * (a - 1) / 2;     }     cin >> a00 >> a01 >> a10 >> a11;     if (!a00 && !a01 && !a10 && !a11) {       return cout << 0, 0;     }     for (int i = 1; i < N; ++i) {       if (p[i] > a00) {         return cout <<  Impossible , 0;       }       if (a00 == p[i]) {         cnt0 = i;         break;       }     }     for (int i = 1; i < N; ++i) {       if (p[i] > a11) {         return cout <<  Impossible , 0;       }       if (a11 == p[i]) {         cnt1 = i;         break;       }     }     if (!a01 && !a10) {       if (!a00) {         for (int i = 0; i < cnt1; ++i) {           cout << 1;         }         return 0;       }       if (!a11) {         for (int i = 0; i < cnt0; ++i) {           cout << 0;         }         return 0;       }     }     if (cnt0 * cnt1 != a01 + a10) {       return cout <<  Impossible , 0;     }     cnt01 = cnt0 * cnt1;     cnt10 = 0;     for (int i = 1; i <= cnt1; ++i) {       if (cnt01 - cnt0 >= a01) {         cnt01 -= cnt0;         cnt10 += cnt0;         ++ins;       } else {         t = cnt01 - a01;         cnt01 -= t;         cnt10 += t;       }       if (cnt01 == a01 && cnt10 == a10) {         get();         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 10;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lcm(long long a, long long b) { return a * b / gcd(a, b); }   long long a[maxn], suf[maxn];   int main() {     long long n, ans = 0;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = n; i >= 1; i--) suf[i] = gcd(suf[i + 1], a[i]);     for (int i = 1; i <= n; i++) ans = gcd(ans, lcm(a[i], suf[i + 1]));     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const int MAXN = 5 * 1e5 + 1, MODM = 1e9 + 7;   int n;   vector<int> g[MAXN];   int sz[MAXN];   int pr[MAXN];   int ans[MAXN];   int m1, m2;   int now;   int root = -1;   void dfs(int v, int p = -1) {     sz[v] = 1;     pr[v] = p;     for (auto to : g[v]) {       if (to != p) {         dfs(to, v);         sz[v] += sz[to];       }     }   }   void dfs2(int v, int p = -1) {     int k = m1;     if (sz[now] == m1) k = m2;     ans[v] |= (n - sz[v] - k <= (n / 2));     ans[v] |= (n - sz[now] <= (n / 2));     for (auto it : g[v])       if (it != p) dfs2(it, v);   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     dfs(1);     for (int v = 1; v <= n; v++) {       int cnt = 0;       for (auto to : g[v])         if (to != pr[v]) cnt += (sz[to] <= (n / 2));       if (v != 1) cnt += (n - sz[v] <= (n / 2));       ans[v] = (cnt == g[v].size());       if (ans[v]) root = v;     }     if (root == -1) {       for (int i = 0; i < n; i++) cout << 0 <<    ;       return 0;     }     fill(sz, sz + MAXN, 0);     dfs(root);     for (auto it : g[root]) {       if (sz[it] > m1) {         m2 = m1;         m1 = sz[it];       } else         m2 = max(m2, sz[it]);     }     for (auto it : g[root]) {       now = it;       dfs2(it, root);     }     for (int i = 0; i < n; i++) cout << ans[i + 1] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5;   const long double PI = acos(-1.0);   char d[MAX];   int l[MAX];   int w[MAX];   int pos;   int main() {     long long n;     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     long long i;     for (i = 0; i < n; i++) cin >> d[i];     for (i = 0; i < n; i++) cin >> l[i];     while (w[pos] == 0) {       w[pos] = 1;       if (d[pos] ==  > )         pos += l[pos];       else         pos -= l[pos];       if (pos < 0 || pos >= n) {         cout <<  FINITE               <<   n ;         return 0;       }     }     cout <<  INFINITE           <<   n ;     return 0;   }