#include <bits/stdc++.h>   using namespace std;   char s[10001000];   int n;   vector<int> sep;   void lindon() {     for (int i = 0; i < n;) {       sep.push_back(i);       int p1 = i, p2 = i + 1;       while (p2 < n && s[p1] <= s[p2]) {         if (s[p1] == s[p2])           ++p1, ++p2;         else           p1 = i, ++p2;       }       int len = p2 - p1;       while (i <= p1) i += len;     }   }   int z[10001000];   void exkmp() {     int id, mx = -1;     for (int i = 1; i <= 2 * n; ++i) {       int p = 0;       if (mx > i) p = max(p, min(mx - i, z[i - id]));       while (p <= 2 * n && s[p] == s[i + p]) ++p;       z[i] = p;       if (i + p > mx) id = i, mx = i + p;     }     z[0] = 2 * n + 1;   }   string ans;   bool same(string s) {     string t = s;     reverse(t.begin(), t.end());     return s == t;   }   int T, m;   void rua3() {     sep.push_back(n);     m = sep.size() - 2;     while (T >= 3 && m >= 0) {       ans += string(s + sep[m], sep[m + 1] - sep[m]);       --m;       if (!(m >= 0 && same(string(s + sep[m], sep[m + 1] - sep[m])) &&             same(string(s + sep[m + 1], sep[m + 2] - sep[m + 1]))))         --T;     }   }   int rev(int x) { return 2 * n - x; }   string fix(string s) {     string t = s;     reverse(t.begin(), t.end());     return min(s, t);   }   long long bas1, bas2, mod1, mod2, hasinit;   bool ispri(int x) {     for (int i = 2; i * i <= x; ++i)       if (x % i == 0) return 0;     return 1;   }   int ranpri(int l, int r) {     for (;;) {       long long tmp =           rand() % 10000 * (1e8) + rand() % 10000 * (1e4) + rand() % 10000;       tmp = tmp % (r - l + 1) + l;       if (ispri(tmp)) return tmp;     }   }   struct HASH {     static const int mxlen = 1e7 + 10;     int nn, h1[mxlen + 233], h2[mxlen + 233], p1[mxlen + 233], p2[mxlen + 233];     void init(char *s, int n) {       if (!hasinit) {         srand(time(0));         hasinit = 1;         bas1 = ranpri(1e3, 1e4);         bas2 = ranpri(1e3, 1e4);         mod1 = ranpri(5e8, 1e9);         mod2 = ranpri(5e8, 1e9);       }       nn = n;       h1[0] = h2[0] = 0;       p1[0] = p2[0] = 1;       for (int i = 1; i <= n; ++i) {         h1[i] = (h1[i - 1] * bas1 + s[i - 1]) % mod1;         h2[i] = (h2[i - 1] * bas2 + s[i - 1]) % mod2;         p1[i] = p1[i - 1] * bas1 % mod1;         p2[i] = p2[i - 1] * bas2 % mod2;       }     }     pair<int, int> gay(int l, int r) {       if (r > nn) return (pair<int, int>){rand(), rand()};       int res1 = (h1[r] - (long long)h1[l] * p1[r - l] % mod1 + mod1) % mod1;       int res2 = (h2[r] - (long long)h2[l] * p2[r - l] % mod2 + mod2) % mod2;       return (pair<int, int>){res1, res2};     }   } hs;   int fuck(int pa, int pb, int lim) {     int lcp = 0;     for (int i = 25; i >= 0; --i)       if (hs.gay(pa, pa + (1 << i)) == hs.gay(pb, pb + (1 << i))) {         pa += 1 << i;         pb += 1 << i;         lcp += 1 << i;       }     if (lcp >= lim) return 0;     return s[pa] < s[pb] ? 1 : -1;   }   vector<pair<int, int> > hashmin(vector<pair<int, int> > a,                                   vector<pair<int, int> > b) {     if (!a.size() || !b.size()) return max(a, b);     if (a[0].second > b[0].second) swap(a, b);     {       int t = fuck(a[0].first, b[0].first, a[0].second);       if (t) return t == 1 ? a : b;     }     {       int t =           fuck(a[1].first, b[0].first + a[0].second, b[0].second - a[0].second);       if (t) return t == 1 ? a : b;     }     {       int t =           fuck(a[1].first + b[0].second - a[0].second, b[1].first, b[1].second);       if (t) return t == 1 ? a : b;     }     return a;   }   string gaolas() {     int l = sep[m + 1];     string res = fix(string(s, l));     if (T <= 1 || m <= 0) return res;     {       int mn = 0;       char c1, c2;       for (int i = 1; i < l - 1; ++i) {         int lcp1 = z[rev(i)];         if (lcp1 < i - mn) {           c1 = s[i - lcp1];           c2 = s[lcp1];         } else {           int lcp2 = z[i - mn];           c1 = s[lcp2];           c2 = s[i - mn + lcp2];         }         if (c1 > c2) mn = i;       }       string t1(s, mn + 1), t2(s + mn + 1, l - mn - 1);       reverse(t2.begin(), t2.end());       string t = t2 + t1;       res = min(res, t);     }     {       vector<pair<int, int> > best;       for (int i = m; i >= 0 && i >= m - 25; --i) {         {           vector<pair<int, int> > v;           v.push_back({sep[i], l - sep[i]});           v.push_back({0, sep[i]});           best = hashmin(best, v);         }         {           vector<pair<int, int> > v;           v.push_back({sep[i], l - sep[i]});           v.push_back({rev(sep[i] - 1), sep[i]});           best = hashmin(best, v);         }       }       string tmp = string(s + best[0].first, best[0].second) +                    string(s + best[1].first, best[1].second);       res = min(res, tmp);     }     return res;   }   int main() {     scanf( %s%d , s, &T);     n = strlen(s);     for (int i = 0; i < n; ++i) s[i + n + 1] = s[i];     reverse(s, s + n);     s[n] =  # ;     s[n * 2 + 1] =  $ ;     lindon();     exkmp();     hs.init(s, 2 * n + 1);     rua3();     ans += gaolas();     printf( %s n , ans.c_str());   }


#include <bits/stdc++.h>   using namespace std;   int a[1010][1010];   int mapa[1010][1010];   int n, m;   int TIME = 0;   bool ok(int val) {     for (int i = 0; i < n; i++) {       vector<int> row;       for (int j = 0; j < m; j++) {         if (a[i][j] >= val) row.push_back(j);       }       for (int first = 0; first < row.size(); first++)         for (int second = first + 1; second < row.size(); second++) {           if (mapa[row[first]][row[second]] == TIME) return true;           mapa[row[first]][row[second]] = TIME;         }     }     return false;   }   int solve(int lo, int hi) {     if (lo == hi) return lo;     int mid = (lo + hi + 1) / 2;     TIME++;     if (ok(mid)) return solve(mid, hi);     return solve(lo, mid - 1);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) scanf( %d , &a[i][j]);     printf( %d , solve(0, 1000100100));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using uint = unsigned;   using ll = long long;   using ull = unsigned long long;   using vi = vector<int>;   using vvi = vector<vi>;   using vl = vector<ll>;   using vvl = vector<vl>;   using vd = vector<double>;   using vvd = vector<vd>;   using vs = vector<string>;   void print_vars(ostream&) {}   template <typename Car, typename... Cdr>   void print_vars(ostream& os, const Car& car, const Cdr&... cdr) {     print_vars(os << car << (sizeof...(cdr) ?  ,  :   ), cdr...);   }   template <typename T1, typename T2>   ostream& operator<<(ostream& os, const pair<T1, T2>& p) {     return os <<  (  << p.first <<  ,  << p.second <<  ) ;   }   template <int I, typename Tuple>   void print_tuple(ostream&, const Tuple&) {}   template <int I, typename Car, typename... Cdr, typename Tuple>   void print_tuple(ostream& os, const Tuple& t) {     os << get<I>(t) << (sizeof...(Cdr) ?  ,  :   );     print_tuple<I + 1, Cdr...>(os, t);   }   template <typename... Args>   ostream& operator<<(ostream& os, const tuple<Args...>& t) {     print_tuple<0, Args...>(os <<  ( , t);     return os <<  ) ;   }   template <typename Ch, typename Tr, typename C>   basic_ostream<Ch, Tr>& operator<<(basic_ostream<Ch, Tr>& os, const C& c) {     os <<  [ ;     for (auto i = begin(c); i != end(c); ++i)       os << (i == begin(c) ?    :    ) << *i;     return os <<  ] ;   }   constexpr int INF = 1e9;   constexpr int MOD = 1e9 + 7;   constexpr double EPS = 1e-9;   vector<tuple<ll, ll>> compress(const vector<tuple<ll, ll>>& b, ll n, ll k) {     vector<tuple<ll, ll>> res;     ll cur = -1, cnt = 0;     for (int i = int(0); i < int(b.size()); i++) {       ll x, c;       tie(x, c) = b[i];       if (x != cur) {         if (cur != -1) res.emplace_back(cur, cnt);         cur = x, cnt = c;       } else {         (cnt += c) %= k;         if (cnt == 0) {           if (res.empty())             cur = -1;           else {             tie(cur, cnt) = res.back();             res.pop_back();           }         }       }     }     if (cnt > 0) res.emplace_back(cur, cnt);     if (res.size() > 2 * n) {       int l = n, r = res.size() - n;       ll cnt = 0;       for (int i = int(l); i < int(r); i++) cnt += get<1>(res[i]);       res.erase(begin(res) + l, begin(res) + r);       res.emplace(begin(res) + l, INF, cnt);     }     return res;   }   ll solve(ll n, ll k, ll m, vl a) {     vector<vector<tuple<ll, ll>>> b(30);     {       vector<tuple<ll, ll>> t;       for (int i = int(0); i < int(n); i++) t.emplace_back(a[i], 1);       b[0] = compress(t, n, k);     }     for (int i = int(1); i < int(b.size()); i++) {       vector<tuple<ll, ll>> t = b[i - 1];       t.insert(end(t), begin(b[i - 1]), end(b[i - 1]));       b[i] = compress(t, n, k);     }     vector<tuple<ll, ll>> c;     for (int i = int(0); i < int(30); i++)       if (m >> i & 1) {         c.insert(end(c), begin(b[i]), end(b[i]));         c = compress(c, n, k);       }     ll res = 0;     for (auto t : c) res += get<1>(t);     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     constexpr char endl =   n ;     for (ll n, k, m; cin >> n >> k >> m && n | k | m;) {       vl a(n);       for (int i = int(0); i < int(n); i++) cin >> a[i];       cout << solve(n, k, m, a) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long mypow(long long x, int y) {     long long an = 1;     while (y) {       if (y & 1) {         an *= x;         an %= 1000000007;       }       x *= x;       x %= 1000000007;       y >>= 1;     }     return an;   }   int d[1000001];   int f(int k, int w) {     memset(d, 0, sizeof(d));     d[k] = w;     long long an = mypow(k, w);     long long tmp = an;     int now = k;     for (int i = k - 1; i; i--) {       d[i] += 2;       tmp *= mypow(i, 2);       tmp %= 1000000007;       while (d[now] == 1) now--;       d[now]--;       tmp *= mypow(now, 1000000007 - 2);       tmp %= 1000000007;       an += tmp;       if (an >= 1000000007) an -= 1000000007;     }     return an;   }   int main() {     int i, j, k, w;     scanf( %d%d , &k, &w);     int an = f(k, w + 1) - f(k, w);     if (an < 0) an += 1000000007;     an += mypow(k, w);     if (an >= 1000000007) an -= 1000000007;     printf( %d n , an);     return 0;   }


#include <bits/stdc++.h>   long long dx[4] = {0, -1, 0, 1};   long long dy[4] = {1, 0, -1, 0};   using namespace std;   class pa3 {    public:     long long x, y, z;     pa3(long long x = 0, long long y = 0, long long z = 0) : x(x), y(y), z(z) {}     bool operator<(const pa3 &p) const {       if (x != p.x) return x < p.x;       if (y != p.y) return y < p.y;       return z < p.z;     }     bool operator>(const pa3 &p) const {       if (x != p.x) return x > p.x;       if (y != p.y) return y > p.y;       return z > p.z;     }     bool operator==(const pa3 &p) const {       return x == p.x && y == p.y && z == p.z;     }     bool operator!=(const pa3 &p) const {       return !(x == p.x && y == p.y && z == p.z);     }   };   class pa4 {    public:     double x;     long long y, z, w;     pa4(double x = 0, long long y = 0, long long z = 0, long long w = 0)         : x(x), y(y), z(z), w(w) {}     bool operator<(const pa4 &p) const {       if (x != p.x) return x < p.x;       if (y != p.y) return y < p.y;       if (z != p.z) return z < p.z;       return w < p.w;     }     bool operator>(const pa4 &p) const {       if (x != p.x) return x > p.x;       if (y != p.y) return y > p.y;       if (z != p.z) return z > p.z;       return w > p.w;     }     bool operator==(const pa4 &p) const {       return x == p.x && y == p.y && z == p.z && w == p.w;     }   };   class pa2 {    public:     long long x, y;     pa2(long long x = 0, long long y = 0) : x(x), y(y) {}     pa2 operator+(pa2 p) { return pa2(x + p.x, y + p.y); }     pa2 operator-(pa2 p) { return pa2(x - p.x, y - p.y); }     bool operator<(const pa2 &p) const { return x != p.x ? x < p.x : y < p.y; }     bool operator>(const pa2 &p) const { return x != p.x ? x > p.x : y > p.y; }     bool operator==(const pa2 &p) const {       return abs(x - p.x) == 0 && abs(y - p.y) == 0;     }     bool operator!=(const pa2 &p) const {       return !(abs(x - p.x) == 0 && abs(y - p.y) == 0);     }   };   class Point {    public:     double x, y;     Point(double x = 0, double y = 0) : x(x), y(y) {}     Point operator+(Point p) { return Point(x + p.x, y + p.y); }     Point operator-(Point p) { return Point(x - p.x, y - p.y); }     Point operator*(double a) { return Point(x * a, y * a); }     Point operator/(double a) { return Point(x / a, y / a); }     double absv() { return sqrt(norm()); }     double norm() { return x * x + y * y; }     bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }     bool operator==(const Point &p) const {       return fabs(x - p.x) < (1e-10) && fabs(y - p.y) < (1e-10);     }   };   struct Segment {     Point p1, p2;   };   double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }   double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }   bool parareru(Point a, Point b, Point c, Point d) {     return abs(cross(a - b, d - c)) < (1e-10);   }   double distance_ls_p(Point a, Point b, Point c) {     if (dot(b - a, c - a) < (1e-10)) return (c - a).absv();     if (dot(a - b, c - b) < (1e-10)) return (c - b).absv();     return abs(cross(b - a, c - a)) / (b - a).absv();   }   bool is_intersected_ls(Segment a, Segment b) {     if (a.p1 == b.p1 || a.p2 == b.p1 || a.p1 == b.p2 || a.p2 == b.p2)       return false;     if (parareru((a.p2), (a.p1), (a.p1), (b.p2)) &&         parareru((a.p2), (a.p1), (a.p1), (b.p1))) {       if (dot(a.p1 - b.p1, a.p1 - b.p2) < (1e-10)) return true;       if (dot(a.p2 - b.p1, a.p2 - b.p2) < (1e-10)) return true;       if (dot(a.p1 - b.p1, a.p2 - b.p1) < (1e-10)) return true;       if (dot(a.p1 - b.p2, a.p2 - b.p2) < (1e-10)) return true;       return false;     } else       return (cross(a.p2 - a.p1, b.p1 - a.p1) * cross(a.p2 - a.p1, b.p2 - a.p1) <               (1e-10)) &&              (cross(b.p2 - b.p1, a.p1 - b.p1) * cross(b.p2 - b.p1, a.p2 - b.p1) <               (1e-10));   }   double segment_dis(Segment a, Segment b) {     if (is_intersected_ls(a, b)) return 0;     double r = distance_ls_p(a.p1, a.p2, b.p1);     r = min(r, distance_ls_p(a.p1, a.p2, b.p2));     r = min(r, distance_ls_p(b.p1, b.p2, a.p2));     r = min(r, distance_ls_p(b.p1, b.p2, a.p1));     return r;   }   Point intersection_ls(Segment a, Segment b) {     Point ba = b.p2 - b.p1;     double d1 = abs(cross(ba, a.p1 - b.p1));     double d2 = abs(cross(ba, a.p2 - b.p1));     double t = d1 / (d1 + d2);     return a.p1 + (a.p2 - a.p1) * t;   }   string itos(long long i) {     ostringstream s;     s << i;     return s.str();   }   long long gcd(long long v, long long b) {     if (v > b) return gcd(b, v);     if (v == b) return b;     if (b % v == 0) return v;     return gcd(v, b % v);   }   double distans(double x1, double y1, double x2, double y2) {     double rr = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);     return sqrt(rr);   }   long long beki(long long wa, long long rr, long long warukazu) {     if (rr == 0) return 1 % warukazu;     if (rr == 1) return wa % warukazu;     if (rr % 2 == 1) return (beki(wa, rr - 1, warukazu) * wa) % warukazu;     long long zx = beki(wa, rr / 2, warukazu);     return (zx * zx) % warukazu;   }   double bekid(double w, long long r) {     if (r == 0) return 1.0;     if (r == 1) return w;     if (r % 2) return bekid(w, r - 1) * w;     double f = bekid(w, r / 2);     return f * f;   }   long long a[1000020];   void dfs(long long r) {     if (r == 0) return;     if (r == 2) {       a[1] = 2, a[2] = 1;       return;     }     long long t = -1;     for (long long j = 0; j < 30; j++)       if (r & (1 << j)) t = j;     long long g = (1 << (t + 1)) - 1;     for (long long i = (1 << t); i <= r; i++) {       a[i] = g - i;       a[g - i] = i;     }     dfs(g - r - 1);   }   bool ch(long long r) {     if (r % 2) return false;     dfs(r);     return true;   }   vector<long long> ve[30];   void ch2(long long r) {     cout <<  YES  << endl;     if (r == 6) {       cout <<  3 6 1 5 4 2  << endl;       return;     }     ve[0].push_back(6);     ve[0].push_back(1);     ve[0].push_back(5);     ve[0].push_back(4);     ve[0].push_back(7);     ve[0].push_back(2);     ve[0].push_back(3);     for (long long i = 8; i <= r; i++) {       long long t = 0;       for (long long j = 0; j < 30; j++)         if (i & (1 << j)) t = j;       ve[t].push_back(i);     }     for (long long i = 0; i < 30; i++)       if (ve[i].size()) {         cout << ve[i].back() <<    ;         for (long long j = 0; j < ve[i].size() - 1; j++) cout << ve[i][j] <<    ;       }     cout << endl;     exit(0);   }   signed main() {     long long n;     cin >> n;     if (ch(n)) {       cout <<  YES  << endl;       for (long long i = 1; i <= n; i++) cout << a[i] <<    ;       cout << endl;     } else       cout <<  NO  << endl;     if (n <= 5 || (n & (-n)) == n)       cout <<  NO  << endl;     else       ch2(n);     return 0;     for (long long i = 1; i <= n; i++) ch2(i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int x, id;   };   node a[1005];   bool cmp(node a, node b) { return a.x < b.x; }   int main() {     int n, k;     int i;     scanf( %d%d , &n, &k);     for (i = 1; i <= n; i++) {       scanf( %d , &a[i].x);       a[i].id = i;     }     sort(a + 1, a + 1 + n, cmp);     int sum = 0;     for (i = 1; i <= n; i++) {       sum += a[i].x;       if (sum > k) break;     }     printf( %d n , i - 1);     for (i = i - 1; i > 0; i--) {       printf( %d  , a[i].id);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   using namespace std;   long long int n, k, ans = 0;   long long int arr[500005];   void solve() {     cin >> n >> k;     map<long long int, long long int> mpp, tot, till;     for (long long int i = 1; i <= n; i++) {       cin >> arr[i];       tot[arr[i]]++;     }     for (long long int i = 1; i <= n; i++) {       till[arr[i]]++;       if ((arr[i] % (k)) == 0) {         long long int a = arr[i] / k, b = arr[i] * k;         ans = ans + (mpp[a]) * (tot[b] - till[b]);       }       mpp[arr[i]]++;     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     {       solve();       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a;     cin >> a;     if (a[0] >=  a  && a[0] <=  z ) a[0] -= 32;     cout << a;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int c = 0;     int u =  a ;     for (int i = 0; i < s.length(); i++) {       if (c >= 26) break;       if (s[i] <= u) {         s[i] = u;         c++;         u++;         if (u >  z ) break;       }     }     if (c >= 26)       cout << s;     else       cout <<  -1 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e+5;   char str[2 * maxn + 5];   int main() {     int cishu;     cin >> cishu;     while (cishu--) {       int n;       cin >> n;       for (int a = 0; a < n - 1; a++) cin >> str[a];       str[n - 1] =  0 ;       int tmp = n;       for (int i = 0; i < n; i++) {         if (str[i] ==  < ) {           int amt = 2;           for (int a = i + 1; a < n; a++) {             if (str[a] ==  < )               amt++;             else               break;           }           int print = tmp - amt + 1;           tmp = print - 1;           for (int b = 0; b < amt; b++)             printf( %d%c , print++, i + b == n - 1 ?   n  :    );           i = i + amt - 1;         } else           printf( %d%c , tmp--, i == n - 1 ?   n  :    );       }       tmp = 1;       for (int i = 0; i < n; i++) {         if (str[i] ==  > ) {           int amt = 2;           for (int a = i + 1; a < n; a++) {             if (str[a] ==  > )               amt++;             else               break;           }           int print = tmp + amt - 1;           tmp = print + 1;           for (int b = 0; b < amt; b++)             printf( %d%c , print--, i + b == n - 1 ?   n  :    );           i = i + amt - 1;         } else           printf( %d%c , tmp++, i == n - 1 ?   n  :    );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());   template <typename T>   T ceil(T a, T b) {     return (a + b - 1) / b;   }   template <typename T>   T binpow(T a, T b) {     T res = 1;     while (b > 0) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   void solve() {     long long n, c = 0;     string s, t;     cin >> n;     cin >> s >> t;     if (n == 1) {       if (s == t) {         cout << 0;       } else {         cout << 1;       }       return;     }     vector<long long> a, b;     for (long long i = 1; i < n; i++) {       if (s[i] != t[i] && s[i - 1] != t[i - 1]) {         pair<char, char> a, b;         a = {s[i], t[i]};         b = {s[i - 1], t[i - 1]};         if (a != b) {           swap(s[i - 1], s[i]);           c++;         }       }     }     for (long long i = 0; i < n; i++) {       c += (s[i] != t[i]);     }     cout << c <<   n ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long t = 1;     for (long long i = 1; i < t + 1; i++) {       solve();     }     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class Data {    public:     int l, r, num;     Data() {}     Data(int a, int b, int c) {       l = a;       r = b;       num = c;     }     bool operator<(const Data& a) const { return l < a.r; }   };   vector<Data> a;   int main() {     int L, b, f, n, q, k;     cin >> L >> b >> f >> n;     for (int(qwe) = 0; (qwe) < (n); ++(qwe)) {       cin >> q >> k;       if (q == 2) {         for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)           if (i->num == k) {             a.erase(i);             break;           }       } else {         bool ok = 0;         int l = 0;         int r = L - k;         if (!a.empty()) r = a[0].l - k - f;         if (l <= r) {           a.insert(a.begin(), Data(l, l + k, qwe + 1));           cout << l << endl;           continue;         }         for (int i = 0; i < ((int)(a).size()) - 1; ++i)           if (a[i].r + b <= a[i + 1].l - f - k) {             cout << a[i].r + b << endl;             a.insert(a.begin() + i + 1,                      Data(a[i].r + b, a[i].r + b + k, qwe + 1));             ok = 1;             break;           }         if (ok) continue;         r = L - k;         l = 0;         if (!a.empty()) l = a.back().r + b;         if (l <= r) {           a.push_back(Data(l, l + k, qwe + 1));           cout << l << endl;         } else           cout <<  -1 n ;       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     std::string str;     std::getline(std::cin, str);     int number = 0;     for (int j = 0, i = 0; j < str.size(); ++j) {       int n = 0;       while (j < str.size() && isdigit(str.at(j))) n = n * 10 + str.at(j++) - 48;       number = number + n * i++;       if (j >= str.size()) break;     }     std::cout << number << std::endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       double a, b, c, d, k;       cin >> a >> b >> c >> d >> k;       double pen = a / c;       double pencil = b / d;       pen = ceil(pen);       pencil = ceil(pencil);       if ((pen + pencil) <= k) {         double diff = k - pen - pencil;         cout << pen + diff <<     << pencil <<   n ;       } else         cout << -1 <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000023;   long long int power(long long int a, long long int b) {     long long int ans = 1;     while (b) {       if (b & 1) ans = (ans * a);       b /= 2;       a = (a * a);     }     return ans;   }   bool sortbysec(const pair<long long int, long long int> &a,                  const pair<long long int, long long int> &b) {     if (a.first > b.first)       return 1;     else if (a.first == b.first)       return (a.second < b.second);     else       return 0;   }   long long int hash1[N];   long long int p_pow[N];   string str;   long long int n;   void cal_pow() {     long long int p = 31;     for (long long int i = 0; i < N; i++) {       if (i != 0)         p_pow[i] = (p_pow[i - 1] * p) % 1000000007;       else         p_pow[i] = 1;     }   }   void calc() {     hash1[0] = str[0] -  a  + 1;     for (long long int i = 1; i <= str.size() - 1; i++) {       hash1[i] = (hash1[i - 1] + (p_pow[i] * (str[i] -  a  + 1)) % 1000000007) %                  1000000007;     }   }   long long int check(long long int val, long long int len) {     for (long long int i = 1; i < n - len; i++) {       long long int temp =           (p_pow[n - 1 - i] * (hash1[i + len - 1] - hash1[i - 1] + 1000000007) %            1000000007) %           1000000007;       if (temp == val) return 1;     }     return 0;   }   void solve() {     cin >> str;     cal_pow();     calc();     vector<pair<long long int, long long int>> v;     n = str.size();     for (long long int i = 0; i < n - 1; i++) {       long long int f = (p_pow[n - 1] * hash1[i]) % 1000000007;       long long int s =           (p_pow[i] * (hash1[n - 1] - hash1[n - i - 2] + 1000000007) %            1000000007) %           1000000007;       if (f == s) v.push_back({i + 1, f});     }     if (!v.size()) {       cout <<  Just a legend  << endl;       return;     }     sort((v).begin(), (v).end());     v.push_back({n + 3, 1});     long long int l = 0, r = v.size() - 1;     if (!check(v[0].second, v[0].first)) {       cout <<  Just a legend  << endl;       return;     }     while ((l + 1) < r) {       long long int mid = (l + r) / 2;       if (check(v[mid].second, v[mid].first))         l = mid;       else         r = mid;     }     long long int idx = 0, len = v[l].first;     while (len--) {       cout << str[idx];       idx++;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int Test;     Test = 1;     long long int t = 0;     while (t++ < Test) {       solve();     }     cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pll = pair<ll, ll>;   bool cmpx(const pll& a, const pll& b) { return a.first < b.first; }   bool cmpy(const pll& a, const pll& b) { return a.second < b.second; }   ll sq(const ll& first) { return first * first; }   ll dis(const pll& a, const pll& b) {     return sq(a.first - b.first) + sq(a.second - b.second);   }   vector<pll> px, py;   ll closest_pair(int l, int r) {     if (r - l <= 1) return 1e18;     int m = (l + r) / 2;     ll d = min(closest_pair(l, m), closest_pair(m, r));     inplace_merge(py.begin() + l, py.begin() + m, py.begin() + r, cmpy);     vector<pll> strip;     for (int i = l; i < r; i++)       if (sq(py[i].first - px[m].first) < d) strip.push_back(py[i]);     for (int i = 0; i < strip.size(); i++)       for (int j = i + 1;            j < strip.size() && sq(strip[j].second - strip[i].second) < d; j++)         d = min(d, dis(strip[i], strip[j]));     return d;   }   void solve() {     int n;     cin >> n;     ll cur = 0, first;     for (int i = 0; i < n; i++) {       cin >> first;       cur += first;       px.emplace_back(i, cur);     }     sort(px.begin(), px.end(), cmpx);     py = px;     cout << closest_pair(0, n) <<   n ;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int owo = 1;     while (owo--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const long long int INF = 1000000007;   const int N = 1000000 + 7;   long long int trans[N];   long long int ca[N];   long long int maxb[N];   int main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     int n;     long long int d;     cin >> n >> d;     for (int i = 0; i < n; i++) cin >> trans[i];     ca[0] = trans[0];     for (int i = 1; i < n; i++) ca[i] = ca[i - 1] + trans[i];     maxb[n] = LLONG_MIN / 2;     for (int i = n - 1; i >= 0; i--) maxb[i] = max(ca[i], maxb[i + 1]);     long long int currentAdd = 0;     int ans = 0;     for (int i = 0; i < n; i++) {       ca[i] += currentAdd;       if (ca[i] > d) {         cout << -1 << endl;         return 0;       }       if (trans[i] == 0) {         if (ca[i] < 0) {           long long int all = d - (maxb[i + 1] + currentAdd);           if (ca[i] + all > d) {             all = d - ca[i];           }           ca[i] += all;           currentAdd += all;           if (ca[i] < 0) {             cout << -1 << endl;             return 0;           }           ans++;         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   const int mod = 1000000007;   int dp[4][200005];   int main() {     long long a, b;     scanf( %I64d %I64d , &a, &b);     long long t = sqrt(2 * (a + b));     while ((t * t + t > 2 * (a + b)) || ((t * t + 3 * t + 2) <= 2 * (a + b))) {       --t;     }     long long sum = t * (t + 1) / 2;     dp[0][0] = 1;     dp[1][0] = 1;     dp[1][1] = 1;     int cur = 0;     for (int i = 1; i <= t; ++i) {       long long temp = i * (i + 1) / 2;       for (int j = 0; j <= temp && j <= a; ++j) {         cur = i % 3;         if (j == 0) {           dp[cur][j] = 1;           continue;         }         int k = cur - 1;         if (k < 0) k = k + 3;         dp[cur][j] = dp[k][j];         if (j >= i) dp[cur][j] += dp[k][j - i];         if (dp[cur][j] >= mod) dp[cur][j] %= mod;       }     }     long long result = 0;     long long temp = sum - b;     if (temp < 0) temp = 0;     t = t % 3;     for (int i = (int)temp; i <= a; ++i) {       result += dp[t][i];       result %= mod;     }     printf( %I64d n , result);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   template <class T1, class T2>   struct cmpf {     bool rev;     inline bool operator()(const pair<T1, T2>& a, const pair<T1, T2>& b) const {       return (a.first < b.first) ^ rev;     }     cmpf(bool b = false) { rev = b; }   };   template <class T1, class T2>   struct cmps {     bool rev;     inline bool operator()(const pair<T1, T2>& a, const pair<T1, T2>& b) const {       return (a.second < b.second) ^ rev;     }     cmps(bool b = false) { rev = b; }   };   long long binpow(long long x, long long p, const long long& mod) {     assert(mod > 0);     long long ret = 1;     for (; p > 0; p >>= 1, x = x * x % mod)       if (p & 1) ret = ret * x % mod;     return ret;   }   template <class T>   bool chmn(T& a, const T& b) {     return (greater<T>()(a, b) ? (a = b, true) : false);   }   template <class T>   bool chmx(T& a, const T& b) {     return (less<T>()(a, b) ? (a = b, true) : false);   }   void setIO(const string& filename =   ) {     if (filename.size() > 0) {       freopen((filename +  .in ).c_str(),  r , stdin);       freopen((filename +  .out ).c_str(),  w , stdout);     }     cin.tie(0)->sync_with_stdio(0);   }   int chr[8] = {-1, 0, 1, 0, -1, -1, 1, 1};   int chc[8] = {0, 1, 0, -1, -1, 1, -1, 1};   const long long MOD = 1e9 + 7;   const int INIT = 1001001001;   const int MN = 201001;   const long long INF = 2e18 + 1;   long long N, M, K, Q;   pair<long long, long long> A[MN];   long long safe[MN];   long long treasure[MN][2];   long long dp[MN][2];   void solve(int testcase) {     cin >> N >> M >> K >> Q;     for (int i = 0; i < N; ++i) {       treasure[i][0] = INIT;       treasure[i][1] = 0;       dp[i][0] = dp[i][1] = INF;     }     vector<long long> rows;     rows.push_back(0);     for (int i = 0; i < K; ++i) {       cin >> A[i].first >> A[i].second;       --A[i].first;       --A[i].second;       rows.push_back(A[i].first);     }     for (int i = 0; i < Q; ++i) {       cin >> safe[i];       --safe[i];     }     sort(safe, safe + Q);     sort(begin(rows), end(rows));     rows.resize(unique(begin(rows), end(rows)) - rows.begin());     const int R = ((int)(rows.size()));     long long up_cost = 0;     for (int i = 0; i < K; ++i) {       chmx(up_cost, A[i].first);       A[i].first = lower_bound(begin(rows), end(rows), A[i].first) - rows.begin();       chmn(treasure[A[i].first][0], A[i].second);       chmx(treasure[A[i].first][1], A[i].second);     }     if (treasure[0][0] == INIT) treasure[0][0] = 0;     dp[0][0] = treasure[0][1] + (treasure[0][1] - treasure[0][0]);     dp[0][1] = treasure[0][1];     for (int r = 1; r < R; ++r) {       long long reach_left = INF, reach_right = INF;       for (int i = 0; i < 4; ++i) {         int idx;         if (i >= 2) {           idx = (upper_bound(safe, safe + Q, treasure[r - 1][i & 1]) - safe) - 1;         } else {           idx = lower_bound(safe, safe + Q, treasure[r - 1][i & 1]) - safe;         }         if (0 <= idx && idx < Q) {           const long long dist =               dp[r - 1][i & 1] + abs(safe[idx] - treasure[r - 1][i & 1]);           chmn(reach_left, dist + abs(treasure[r][0] - safe[idx]));           chmn(reach_right, dist + abs(treasure[r][1] - safe[idx]));         }       }       const long long between = treasure[r][1] - treasure[r][0];       dp[r][0] = reach_right + between;       dp[r][1] = reach_left + between;     }     (treasure, R, 2);     (dp, R, 2);     cout << up_cost + min(dp[R - 1][0], dp[R - 1][1]) << endl;   }   int main() {     setIO();     long long T = 1;     for (int t = 1; t <= T; ++t) {       solve(t);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char buf[100005];   int cnt[10];   int cnt2[10];   int main() {     scanf( %s , buf);     int N = strlen(buf);     for (int i = 0; i < (N); ++i) cnt[buf[i] -  0 ]++;     for (int i = 0; i < (10); ++i) cnt2[i] = cnt[i];     int best = 0, bestres = cnt[0];     for (int d = 1; d <= 9; ++d) {       if (!cnt[d] || !cnt2[10 - d]) continue;       cnt[d]--;       cnt2[10 - d]--;       int temp = 1;       for (int i = 0; i < (10); ++i) temp += min(cnt[i], cnt2[9 - i]);       temp += max(0, min(cnt[0] - cnt2[9], cnt2[0] - cnt[9]));       cnt[d]++;       cnt2[10 - d]++;       if (temp > bestres) {         bestres = temp;         best = d;       }     }     if (best == 0) {       for (int i = 0; i < (2); ++i) {         for (int j = 9; j >= 0; j--)           for (int k = 0; k < (cnt[j]); ++k) printf( %d , j);         printf(  n );       }     } else {       cnt[best]--;       cnt2[10 - best]--;       int ilezer = max(0, min(cnt[0] - cnt2[9], cnt2[0] - cnt[9]));       for (int j = 0; j < (10); ++j) {         int ile = cnt[j] - min(cnt[j], cnt2[9 - j]);         if (j == 0) ile -= ilezer;         for (int k = 0; k < (ile); ++k) printf( %d , j);       }       for (int j = 0; j < (10); ++j) {         for (int k = 0; k < (min(cnt[j], cnt2[9 - j])); ++k) printf( %d , j);       }       printf( %d , best);       for (int k = 0; k < (ilezer); ++k) printf( 0 );       printf(  n );       for (int j = 0; j < (10); ++j) {         int ile = cnt2[j] - min(cnt2[j], cnt[9 - j]);         if (j == 0) ile -= ilezer;         for (int k = 0; k < (ile); ++k) printf( %d , j);       }       for (int j = 9; j >= 0; j--) {         for (int k = 0; k < (min(cnt2[j], cnt[9 - j])); ++k) printf( %d , j);       }       printf( %d , 10 - best);       for (int k = 0; k < (ilezer); ++k) printf( 0 );       printf(  n );     }   }


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


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int a[100];   int ans;   int main() {     cin >> n >> m >> k;     for (int i = 0; i < k; i++) {       cin >> a[i];       a[i]--;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int x;         cin >> x;         x--;         int pos = 0;         while (a[pos] != x) {           pos++;         }         ans += pos + 1;         for (int i = pos; i > 0; i--) {           a[i] = a[i - 1];         }         a[0] = x;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     long long n, k;     cin >> n >> k;     long long ans = 0;     for (int i = (int)0; i < (int)n; ++i) {       long long l, r;       cin >> l >> r;       ans += r - l + 1;     }     int ted = 0;     while (ans % k) {       ted++;       ans++;     }     cout << ted << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<string> val;   bool check1[110];   bool check2[110];   char a[5] = { R ,  G ,  B ,  Y ,  W };   bool used1[5];   bool used2[5];   char val1[5];   int val2[5];   int ans = 1000 * 1000;   void go2(int pos, int cnt, int cnt2) {     if (pos == cnt) {       for (int i = 0; i < val.size(); i++) {         check1[i] = false;         check2[i] = false;       }       for (int i = 0; i < cnt2; i++) {         for (int j = 0; j < val.size(); j++) {           if (val[j][0] == val1[i]) {             check1[j] = true;           }         }       }       for (int i = 0; i < cnt; i++) {         for (int j = 0; j < val.size(); j++) {           if ((val[j][1] -  0 ) == val2[i]) check2[j] = true;         }       }       for (int i = 0; i < val.size(); i++) {         if (check1[i] == true && check2[i]) continue;         if (check1[i] && !check2[i]) {           for (int j = i + 1; j < val.size(); j++) {             if (check1[j] && !check2[j])               if (val[i][1] != val[j][1] && val[i][0] == val[j][0]) return;           }         }         if (!check1[i] && check2[i]) {           for (int j = i + 1; j < val.size(); j++) {             if (!check1[j] && check2[j]) {               if (val[i][0] != val[j][0] && val[i][1] == val[j][1]) return;             }           }         }         if (!check1[i] && !check2[i]) {           for (int j = i + 1; j < val.size(); j++) {             if (!check1[j] && !check2[j])               if (val[i] != val[j]) return;           }         }       }       if (ans > cnt + cnt2) ans = cnt + cnt2;     } else {       for (int i = 0; i < 5; i++) {         if (!used2[i]) {           used2[i] = true;           val2[pos] = i + 1;           go2(pos + 1, cnt, cnt2);           used2[i] = false;         }       }     }   }   void go1(int pos, int cnt) {     if (pos == cnt) {       go2(0, 0, cnt);       go2(0, 1, cnt);       go2(0, 2, cnt);       go2(0, 3, cnt);       go2(0, 4, cnt);       go2(0, 5, cnt);     } else {       for (int i = 0; i < 5; i++) {         if (!used1[i]) {           used1[i] = true;           val1[pos] = a[i];           go1(pos + 1, cnt);           used1[i] = false;         }       }     }   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       val.push_back(s);     }     go1(0, 0);     go1(0, 1);     go1(0, 2);     go1(0, 3);     go1(0, 4);     go1(0, 5);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long m;   long long f(long long a) {     long long res = 0;     for (long long k = 2;; k++) {       long long k3 = k * k * k;       if (k3 > a) break;       if (res > m - a / k3) return -1;       res += a / k3;     }     return res;   }   int main() {     cin >> m;     long long l = 1, r = 9000000000000000000LL;     while (l < r) {       long long mid = (l + r) >> 1;       long long rr = f(mid);       if (rr >= m || rr == -1)         r = mid;       else         l = mid + 1;     }     while (f(l - 1) == m) l--;     cout << (f(l) == m ? l : -1) << endl;     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 505;   const long long MOD = 998244353;   int n, sizb, sizc;   long long a[MAXN], b[MAXN], c[MAXN];   bool fac[MAXN];   std::map<long long, int> mp;   inline long long gcd(long long x, long long y) {     if (!x || !y) return x + y;     while (y) {       std::swap(x, y);       y %= x;     }     return x;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %I64d , &a[i]);       if (a[i] == 1) n--, i--;     }     for (int i = 1; i <= n; i++) {       long long sq = sqrt(a[i]) + 0.5;       if (sq * sq == a[i]) {         fac[i] = 1;         long long sqsq = sqrt(sq) + 0.5;         if (sqsq * sqsq == sq) {           if (mp.find(sqsq) != mp.end())             mp[sqsq] = mp[sqsq] + 4;           else             mp[sqsq] = 4;           continue;         }         if (mp.find(sq) != mp.end())           mp[sq] = mp[sq] + 2;         else           mp[sq] = 2;         continue;       }       long long cb = cbrt(a[i]) + 0.5;       if (cb * cb * cb == a[i]) {         fac[i] = 1;         if (mp.find(cb) != mp.end())           mp[cb] = mp[cb] + 3;         else           mp[cb] = 3;         continue;       }     }     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         if (a[i] == a[j]) continue;         long long d = gcd(a[i], a[j]);         if (d == 1) continue;         if (!fac[i]) {           if (mp.find(d) != mp.end())             mp[d] = mp[d] + 1;           else             mp[d] = 1;           long long e = a[i] / d;           if (mp.find(e) != mp.end())             mp[e] = mp[e] + 1;           else             mp[e] = 1;           fac[i] = 1;         }         if (!fac[j]) {           if (mp.find(d) != mp.end())             mp[d] = mp[d] + 1;           else             mp[d] = 1;           long long e = a[j] / d;           if (mp.find(e) != mp.end())             mp[e] = mp[e] + 1;           else             mp[e] = 1;           fac[j] = 1;         }       }       if (!fac[i]) c[++sizc] = a[i];     }     std::sort(c + 1, c + sizc + 1);     long long ans = 1;     for (auto it : mp) ans = ans * (it.second + 1) % MOD;     int temp = 0;     for (int i = 1; i <= sizc; i++) {       if (i == 1 || c[i] == c[i - 1])         temp++;       else {         ans = ans * (temp + 1) % MOD * (temp + 1) % MOD;         temp = 1;       }     }     ans = ans * (temp + 1) % MOD * (temp + 1) % MOD;     printf( %I64d n , ans);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int MX = 1e5 + 10;   unordered_set<int> adj[MX];   vector<int> ans;   bool vis[MX];   set<pair<int, int>> ord;   void dfs(int u) {     vis[u] = true;     ans.push_back(u);     for (int v : adj[u]) {       if (!vis[v]) dfs(v);     }   }   bool can(int k, int t, int n) {     k -= t;     for (int i = 1; i <= n; i++) vis[i] = false;     while (!ord.empty()) {       auto it = ord.begin();       if ((*it).first >= k) break;       int u = (*it).second;       ord.erase(it);       for (int v : adj[u]) {         ord.erase({adj[v].size(), v});         adj[v].erase(u);         if (adj[v].size() != 0) ord.insert({adj[v].size(), v});       }       adj[u].clear();     }     if (t == 0) {       for (int i = 1; i <= n; i++) {         if (!vis[i]) {           ans.clear();           dfs(i);           if (ans.size() > k) {             cout << 1 <<     << ans.size() <<   n ;             for (int xx : ans) cout << xx <<    ;             cout <<   n ;             return true;           }         }       }       return false;     }     while (!ord.empty()) {       auto it = ord.begin();       if ((*it).first > k) break;       int u = (*it).second;       if ((*it).first == k) {         vector<int> vv;         vv.push_back(u);         for (int v : adj[u]) vv.push_back(v);         bool ok = true;         for (int i = 0; i <= k; i++) {           for (int j = i + 1; j <= k; j++) {             if (adj[vv[i]].find(vv[j]) == adj[vv[i]].end()) {               ok = false;               break;             }           }           if (!ok) break;         }         if (ok) {           cout << 2 <<   n ;           for (int xx : vv) cout << xx <<    ;           cout <<   n ;           return true;         }       }       ord.erase(it);       for (int v : adj[u]) {         ord.erase({adj[v].size(), v});         adj[v].erase(u);         if (adj[v].size() != 0) ord.insert({adj[v].size(), v});       }       adj[u].clear();     }     return false;   }   void solve() {     int n, m, k;     cin >> n >> m >> k;     ord.clear();     ans.clear();     for (int i = 1; i <= n; i++) {       adj[i].clear();       vis[i] = false;     }     int x, y;     for (int i = 0; i < m; i++) {       cin >> x >> y;       adj[x].insert(y);       adj[y].insert(x);     }     for (int i = 1; i <= n; i++) ord.insert({adj[i].size(), i});     if (can(k, 1, n)) return;     if (can(k, 0, n)) return;     cout << -1 <<   n ;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout.precision(10);     cout << fixed;     int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string str;   string sbyt( 127 ), ssho( 32767 ), sint( 2147483647 ),       slon( 9223372036854775807 );   int main() {     while (cin >> str) {       if (str.size() > 19) {         cout <<  BigInteger n ;         continue;       }       if (str.size() < sbyt.size())         cout <<  byte n ;       else if (str.size() == sbyt.size() && str <= sbyt)         cout <<  byte n ;       else if (str.size() < ssho.size())         cout <<  short n ;       else if (str.size() == ssho.size() && str <= ssho)         cout <<  short n ;       else if (str.size() < sint.size())         cout <<  int n ;       else if (str.size() == sint.size() && str <= sint)         cout <<  int n ;       else if (str.size() < slon.size())         cout <<  long n ;       else if (str.size() == slon.size() && str <= slon)         cout <<  long n ;       else         cout <<  BigInteger n ;     }   }


#include <bits/stdc++.h>   namespace tree {   const int N = 501000, MOD = 998244353;   inline void inc(int a, int &b) { b = (a + b) % MOD; }   int begin[N], next[N * 2], to[N * 2];   int f[N][2], siz[N][2];   int n, e;   void add(int x, int y, bool k = 1) {     to[++e] = y;     next[e] = begin[x];     begin[x] = e;     if (k) add(y, x, 0);   }   void dfs(int p = 1, int h = 0) {     f[p][0] = 0, f[p][1] = 0;     siz[p][0] = 1, siz[p][1] = 0;     for (int i = begin[p], q; i; i = next[i])       if ((q = to[i]) != h) {         dfs(q, p);         int F[2] = {0}, S[2] = {0};         for (int cut = 0; cut <= 1; cut++)           for (int x = 0; x <= 1; x++)             for (int y = 0; y <= 1; y++) {               if (!cut && !x && !y) {                 inc((long long)f[p][x] * siz[q][y] % MOD, F[1]);                 inc((long long)f[q][y] * siz[p][x] % MOD, F[1]);                 inc((long long)siz[p][x] * siz[q][y] % MOD, F[1]);                 inc((long long)siz[p][x] * siz[q][y] % MOD, S[1]);               } else {                 inc((long long)f[p][x] * siz[q][y] % MOD, F[x]);                 inc((long long)f[q][y] * siz[p][x] % MOD, F[x]);                 inc((long long)siz[p][x] * siz[q][y] % MOD, S[x]);               }             }         f[p][0] = F[0], siz[p][0] = S[0];         f[p][1] = F[1], siz[p][1] = S[1];       }   }   void solve() {     scanf( %d , &n);     for (int i = 1, u, v; i < n; i++) scanf( %d%d , &u, &v), add(u, v);     dfs();     int ans = (f[1][0] + f[1][1]) * 2ll % MOD;     ans = (ans + MOD) % MOD;     printf( %d n , ans);   }   }  // namespace tree   int main() {     tree::solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5;   int n, fa[maxn + 2], cont[maxn + 2];   int mx1[maxn + 2], mx2[maxn + 2], diameter[maxn + 2];   bool vist[maxn + 2];   vector<int> G[maxn + 2];   vector<long long> dist[maxn + 2];   map<pair<int, int>, double> Map;   void dfs1(int x, int pre, int col) {     vist[x] = 1, fa[x] = col;     int aa[3];     for (auto nx : G[x]) {       if (nx == pre) continue;       dfs1(nx, x, col);       aa[0] = mx1[nx] + 1, aa[1] = mx1[x], aa[2] = mx2[x];       sort(aa, aa + 3);       mx1[x] = aa[2], mx2[x] = aa[1];     }   }   void dfs2(int x, int pre, vector<long long> &ds, int di) {     ds.push_back(max(di, mx1[x]));     for (auto nx : G[x]) {       if (nx == pre) continue;       if (mx1[nx] + 1 == mx1[x])         dfs2(nx, x, ds, max(di, mx2[x]) + 1);       else         dfs2(nx, x, ds, max(di, mx1[x]) + 1);     }   }   int BinSearch(vector<long long> &arr, long long key) {     int l = 1, r = arr.size() - 1, res = 0;     while (l <= r) {       int mid = (l + r) >> 1;       if (arr[mid] - arr[mid - 1] < key)         res = mid, l = mid + 1;       else         r = mid - 1;     }     return res;   }   int main() {     int m, T, u, v;     scanf( %d%d%d , &n, &m, &T);     for (int i = 1; i <= n; ++i) fa[i] = i;     for (int i = 1; i <= m; ++i) {       scanf( %d%d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     for (int i = 1; i <= n; ++i)       if (!vist[i]) {         dfs1(i, 0, i);         dfs2(i, 0, dist[i], 0);         dist[i].push_back(0);         sort(dist[i].begin(), dist[i].end());         diameter[i] = dist[i][dist[i].size() - 1];         for (int k = 1; k < dist[i].size(); ++k) dist[i][k] += dist[i][k - 1];       }     while (T--) {       scanf( %d%d , &u, &v);       u = fa[u], v = fa[v];       if (u == v) {         printf( %d n , -1);         continue;       }       if (Map.count(make_pair(u, v))) {         printf( %f n , Map[make_pair(u, v)]);         continue;       }       if (dist[u].size() > dist[v].size()) swap(u, v);       long long mxd = max(diameter[u], diameter[v]), sum = 0;       for (int i = 1; i < dist[u].size(); ++i) {         int index = BinSearch(dist[v], mxd - (dist[u][i] - dist[u][i - 1]) - 1);         sum += (dist[v][dist[v].size() - 1] - dist[v][index]);         sum += (dist[u][i] - dist[u][i - 1] + 1) * (dist[v].size() - 1 - index);         sum += mxd * index;       }       double ans = double(sum) / (dist[u].size() - 1) / (dist[v].size() - 1);       Map[make_pair(u, v)] = Map[make_pair(v, u)] = ans;       printf( %.10f n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, i, j, k, x, cnt = 0, y;     vector<int> a;     vector<int> b;     vector<int> c;     vector<int> d;     vector<int> e;     vector<int> f;     vector<int> v;     map<int, int> p;     cin >> n;     for (i = 0; i < n; i++) {       cin >> x;       if (x == 4)         a.push_back(i);       else if (x == 8)         b.push_back(i);       else if (x == 15)         c.push_back(i);       else if (x == 16)         d.push_back(i);       else if (x == 23)         e.push_back(i);       else         f.push_back(i);     }     v.push_back(a.size());     v.push_back(b.size());     v.push_back(c.size());     v.push_back(d.size());     v.push_back(e.size());     v.push_back(f.size());     sort(v.begin(), v.end());     k = v[0];     i = 0;     while (k--) {       j = upper_bound(b.begin(), b.end(), a[i]) - b.begin();       if (j >= b.size() || b.size() == 0) break;       y = j;       j = upper_bound(c.begin(), c.end(), b[j]) - c.begin();       b.erase(b.begin(), b.begin() + y + 1);       if (j >= c.size() || c.size() == 0) break;       y = j;       j = upper_bound(d.begin(), d.end(), c[j]) - d.begin();       c.erase(c.begin(), c.begin() + y + 1);       if (j >= d.size() || d.size() == 0) break;       y = j;       j = upper_bound(e.begin(), e.end(), d[j]) - e.begin();       d.erase(d.begin(), d.begin() + y + 1);       if (j >= e.size() || e.size() == 0) break;       y = j;       j = upper_bound(f.begin(), f.end(), e[j]) - f.begin();       e.erase(e.begin(), e.begin() + y + 1);       if (j >= f.size() || f.size() == 0) break;       f.erase(f.begin(), f.begin() + j + 1);       i++;       cnt++;     }     cout << n - cnt * 6;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int l, r;     cin >> l >> r;     long long int mid = (r - l + 1) / 2;     cout <<  YES  << endl;     while (mid--) {       if (r >= l) {         cout << l <<     << l + 1 << endl;         l = l + 2;       }     }   }


#include <bits/stdc++.h>   using namespace std;   void read_file(bool outToFile = true) {}   int main() {     read_file();     string a, b;     char str[1000000 + 1];     while (scanf( %s , str) != EOF) {       a = str;       scanf( %s , str);       b = str;       int n = a.length(), m = b.length();       if (n != m) {         printf( NO n );         continue;       }       if (n == 1) {         string ans = a == b ?  YES  :  NO ;         printf( %s n , ans.c_str());         continue;       }       bool aHasOne, bHasOne;       aHasOne = bHasOne = 0;       for (int i = 0; i < n; i++) {         if (a[i] ==  1 ) aHasOne = 1;         if (b[i] ==  1 ) bHasOne = 1;       }       string ans = aHasOne == bHasOne ?  YES  :  NO ;       printf( %s n , ans.c_str());     }   }


#include <bits/stdc++.h>   using namespace std;   int n, comp = 0, a[100005], b[100005], v[100005];   bool vis[100005];   set<int> s[100005];   void dfs(int u) {     if (vis[u]) return;     vis[u] = true;     s[comp].insert(u);     dfs(v[u]);   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i];     }     sort(b, b + n);     for (int i = 0; i < n; i++) {       int l = 0, r = n - 1;       while (l <= r) {         int mid = (l + r) / 2;         if (b[mid] == a[i]) {           v[i] = mid;           break;         } else if (b[mid] < a[i]) {           l = mid + 1;         } else {           r = mid - 1;         }       }     }     for (int i = 0; i < n; i++) {       if (!vis[i]) {         dfs(i);         comp++;       }     }     cout << comp << endl;     for (int i = 0; i < comp; i++) {       cout << s[i].size();       for (set<int>::iterator it = s[i].begin(); it != s[i].end(); it++) {         cout <<     << (*it + 1);       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long used[100001], last, a[100001];   vector<long long> v[1000001], verr[100001];   void build(long long tv, long long tl, long long tr) {     if (tl == tr)       v[tv].push_back(used[tl]);     else {       long long tm = (tl + tr) / 2;       build(tv * 2, tl, tm);       build(tv * 2 + 1, tm + 1, tr);       long long x = 0, y = 0;       while (x < v[tv * 2].size() && y < v[tv * 2 + 1].size()) {         if (v[tv * 2][x] < v[tv * 2 + 1][y]) {           v[tv].push_back(v[tv * 2][x]);           x++;         } else {           v[tv].push_back(v[tv * 2 + 1][y]);           y++;         }       }       while (x < v[tv * 2].size()) {         v[tv].push_back(v[tv * 2][x]);         x++;       }       while (y < v[tv * 2 + 1].size()) {         v[tv].push_back(v[tv * 2 + 1][y]);         y++;       }     }   }   long long ans(long long tv, long long tl, long long tr, long long l,                 long long r, long long z) {     if (r < tl || tr < l) return 0;     if (l <= tl && tr <= r) {       long long x, y;       x = 0;       y = v[tv].size() - 1;       while (x + 1 < y) {         long long mm = (x + y) / 2;         if (v[tv][mm] < z)           x = mm;         else           y = mm;       }       if (v[tv][y] < z) return y + 1;       if (v[tv][x] < z) return x + 1;       return 0;     }     long long tm = (tl + tr) / 2;     return ans(tv * 2, tl, tm, l, r, z) + ans(tv * 2 + 1, tm + 1, tr, l, r, z);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long n, k, i, j, l, r, x, y, q;     cin >> n >> k;     for (i = 1; i <= n; i++) {       cin >> a[i];       verr[a[i]].push_back(i);     }     for (i = 1; i <= 100000; i++) {       for (j = 0; j < verr[i].size(); j++) {         if (j + 1 - k > 0) {           used[verr[i][j]] = verr[i][j - k];         }       }     }     build(1, 1, n);     cin >> q;     for (i = 1; i <= q; i++) {       cin >> x >> y;       l = (x + last) % n + 1;       r = (y + last) % n + 1;       if (l > r) swap(l, r);       last = ans(1, 1, n, l, r, l);       cout << last <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n;     string s;     cin >> n >> s;     int steps0 = 0;     int steps1 = 0;     for (int i = 0; i < n; ++i) {       steps0 += ((s[i] -  0 ) != (i % 2));       steps1 += ((s[i] -  0 ) == (i % 2));     }     cout << min(steps0, steps1) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 105;   long long max(long long a, long long b) {     if (a > b)       return a;     else       return b;   }   long long min(long long a, long long b) {     if (a < b)       return a;     else       return b;   }   void vecdisp(vector<long long> v) {     for (long long i = 0; i < v.size(); i++) cout << v[i] <<    ;   }   void arrdisp(long long a[], long long n) {     for (long long i = 0; i < n; i++) cout << a[i] <<    ;   }   void sarrdisp(string s[], long long n) {     for (long long i = 0; i < n; i++) cout << s[i] <<   n ;   }   void twodarrdisp(long long *a, long long r, long long c) {     for (long long i = 0; i < r; i++) {       for (long long j = 0; j < c; j++) cout << (*((a + i * c) + j)) <<    ;       cout <<   n ;     }   }   void setdisp(set<long long> s) {     for (auto it = s.begin(); it != s.end(); ++it) cout <<     << *it;   }   long long nod(long long a) {     long long c = 0;     set<long long> s;     while (a > 0) {       ++c;       s.insert(a % 10);       a /= 10;     }     if (s.size() == c)       return 1;     else       return 0;   }   long long sod(long long a) {     long long c = 0;     while (a > 0) {       c += a % 10;       a /= 10;     }     return c;   }   bool isComposite(long long n) {     if (n <= 1) return false;     if (n <= 3) return false;     if (n % 2 == 0 || n % 3 == 0) return true;     for (long long i = 5; i * i <= n; i += 6) {       if (n % i == 0 || n % (i + 2) == 0) return true;     }     return false;   }   long long countDivisors(long long n) {     long long cnt = 0;     for (long long i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (n / i == i)           cnt++;         else           cnt += 2;       }     }     return cnt;   }   long long isPalindrome(string s) {     long long l = s.size();     long long flag = 0;     for (long long i = 0; i < l; i++) {       if (s[i] != s[l - i - 1]) {         flag = 1;         break;       }     }     if (flag)       return 0;     else       return 1;   }   void solve() {     long long stops[N] = {0};     long long n, r, x;     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> r;       for (long long i = 0; i < r; i++) {         cin >> x;         ++stops[x];       }     }     for (long long i = 1; i <= 100; i++) {       if (stops[i] == n) cout << i <<    ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long t = 1;     if (!t) cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 1;   vector<pair<long long, long long> > g[N];   set<pair<long long, long long> > q;   long long dist[N];   int main() {     cin.tie(0);     cout.tie(0);     long long n, m, u, v, w;     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> u >> v >> w;       u--;       v--;       w = w * 2;       g[u].push_back({v, w});       g[v].push_back({u, w});     }     for (int i = 0; i < n; i++) {       cin >> dist[i];       q.insert({dist[i], i});     }     while (!q.empty()) {       auto now = *q.begin();       auto u = now.second;       q.erase(q.begin());       for (auto v : g[u]) {         if (dist[v.first] > dist[u] + v.second) {           q.erase({dist[v.first], v.first});           dist[v.first] = dist[u] + v.second;           q.insert({dist[v.first], v.first});         }       }     }     for (int i = 0; i < n; i++) cout << dist[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios::sync_with_stdio(false);     string s, res =   ;     cin >> s;     int len = s.length();     if (len <= 3) {       cout << s[0] << endl;       return 0;     }     int l = 0, r = len - 1;     while (l + 1 < r - 1) {       if (s[l] == s[r] || s[l] == s[r - 1])         res += s[l];       else if (s[l + 1] == s[r] || s[l + 1] == s[r - 1])         res += s[l + 1];       l += 2, r -= 2;     }     string ch =   ;     if (l <= r) ch += s[l];     string re_res = res;     reverse(re_res.begin(), re_res.end());     cout << res << ch << re_res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, col[100010], out[100010], sum[3], cn, id[100010];   vector<int> g[100010];   void dfs(int x) {     for (int i = 0, v; i < g[x].size(); i++) {       v = g[x][i];       if (col[v]) continue;       col[v] = 3 ^ col[x];       dfs(v);     }   }   void get() {     for (int i = 1, st = 3; i <= n; i++)       if (col[i] == 1 && !id[i]) {         if (st == 3) cn++, st = 0;         st++, id[i] = cn;       }     for (int i = 1, st = 3; i <= n; i++)       if (col[i] == 2 && !id[i]) {         if (st == 3) cn++, st = 0;         st++, id[i] = cn;       }     puts( YES );     for (int i = 1; i <= n; i++) printf( %d  , id[i]);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0, u, v; i < m; i++) {       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     for (int i = 1; i <= n; i++)       if (!col[i]) col[i] = 1, dfs(i);     for (int i = 1; i <= n; i++)       for (int j = 0; j < g[i].size(); j++)         if (col[i] ^ col[g[i][j]]) out[i]++;     for (int i = 1; i <= n; i++) sum[col[i]]++;     if (!(sum[1] % 3) && !(sum[2] % 3)) return get(), 0;     if (sum[1] % 3 > sum[2] % 3) {       swap(sum[1], sum[2]);       for (int i = 1; i <= n; i++) col[i] = 3 ^ col[i];     }     for (int i = 1; i <= n; i++)       if (col[i] == 1 && sum[2] - out[i] >= 2) {         id[i] = cn = 1;         for (int p = 0; p < g[i].size(); p++) col[g[i][p]] = 0;         for (int p = 1, st = 2; st && p <= n; p++)           if (col[p] == 2) st--, id[p] = 1;         for (int p = 0; p < g[i].size(); p++) col[g[i][p]] = 2;         return get(), 0;       }     if (sum[1] > 1) {       int xp = 0, yp = 0;       for (int i = 1; i <= n; i++)         if (col[i] == 2 && sum[1] - out[i] >= 2) {           if (!xp)             xp = i;           else             yp = i;         }       if (yp) {         id[xp] = cn = 1;         for (int p = 0; p < g[xp].size(); p++) col[g[xp][p]] = 0;         for (int p = 1, st = 2; st && p <= n; p++)           if (col[p] == 1) st--, id[p] = 1;         for (int p = 0; p < g[xp].size(); p++) col[g[xp][p]] = 1;         id[yp] = cn = 2;         for (int p = 0; p < g[yp].size(); p++) col[g[yp][p]] = 0;         for (int p = 1, st = 2; st && p <= n; p++)           if (col[p] == 1) st--, id[p] = 2;         for (int p = 0; p < g[yp].size(); p++) col[g[yp][p]] = 1;         return get(), 0;       }     }     return printf( NO ), 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     vector<bool> possible(1010);     possible[0] = true;     for (int i = 0; i < 1000; ++i) {       if (!possible[i])         continue;       else {         possible[i + 3] = true;         possible[i + 5] = true;         possible[i + 7] = true;       }     }     int t;     cin >> t;     for (int tt = 0; tt < t; ++tt) {       int n;       cin >> n;       if (!possible[n]) {         cout <<  -1 n ;         continue;       } else {         vector<int64_t> ans(3);         while (n != 0) {           if (possible[n - 3]) {             n -= 3;             ans[0]++;           } else if (possible[n - 5]) {             n -= 5;             ans[1]++;           } else {             n -= 7;             ans[2]++;           }         }         cout << ans[0] <<     << ans[1] <<     << ans[2] <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 55;   int a[maxn][maxn], b[maxn][maxn];   int vis[maxn][maxn];   vector<pair<int, int> > ans;   int main(int argc, char const *argv[]) {     ios::sync_with_stdio(false);     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %d , &a[i][j]);       }     }     for (int i = 1; i < n; i++) {       for (int j = 1; j < m; j++) {         if (a[i + 1][j + 1] == 1 && a[i][j] == 1 && a[i + 1][j] == 1 &&             a[i][j + 1] == 1) {           ans.push_back(make_pair(i, j));         }       }     }     for (int i = 0; i < ans.size(); i++) {       int x = ans[i].first;       int y = ans[i].second;       b[x][y] = 1;       b[x + 1][y + 1] = 1;       b[x + 1][y] = 1;       b[x][y + 1] = 1;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (b[i][j] != a[i][j]) {           printf( -1 n );           return 0;         }       }     }     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++) {       printf( %d %d n , ans[i].first, ans[i].second);     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<pair<int, bool> > list(n);     for (int i = 0; i < n; i++) cin >> list[i].first;     int tmp;     for (int i = 0; i < m; i++) {       cin >> tmp;       list[tmp - 1].second = 1;     }     vector<int> v1(n - m), v2(m);     int c1 = 0, c2 = 0;     for (int i = 0; i < n; i++) {       if (list[i].second == 1)         v2[c1++] = list[i].first;       else         v1[c2++] = list[i].first;     }     sort(v1.begin(), v1.end());     sort(v2.begin(), v2.end());     c1 = c2 = 0;     long long cnt = 0;     for (int i = 0; i < v1.size(); i++) cnt += v1[i];     if (cnt < v2.back()) {       cnt += v2.back();       v2.back() = -1;     }     for (int i = 0; i < v2.size(); i++) {       if (v2[i] != -1) cnt *= 2;     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   const int inf = (1ll << 30) - 1;   const int maxn = (int)1e5 + 10;   using namespace std;   int dp[150][(1 << 16) + 100];   int c[111];   int r[111];   int b[111];   char temp[111];   int cntR[(1 << 16) + 10];   int cntB[(1 << 16) + 10];   int n;   void solve() {     memset(dp, -1, sizeof dp);     queue<pair<pair<int, int>, int> > pq;     scanf( %d , &n);     int xx = 0;     for (int i = 0; i < n; i++) {       scanf( %s%d%d , temp, &r[i], &b[i]);       c[i] = temp[0] ==  R  ? 1 : 0;       xx += c[i];     }     if (xx * 2 > n) {       for (int i = 0; i < n; i++) {         c[i] ^= 1;         swap(r[i], b[i]);       }     }     for (int i = 0; i < (1 << n); i++) {       for (int j = 0; j < n; j++) {         if (i & (1 << j)) {           if (c[j])             cntR[i]++;           else             cntB[i]++;         }       }     }     dp[0][0] = 0;     pq.push(make_pair(make_pair(0, 0), 0));     while (pq.size() > 0) {       int x = pq.front().first.first;       int y = pq.front().first.second;       int mask = pq.front().second;       pq.pop();       if (dp[x][mask] < y) continue;       for (int i = 0; i < n; i++) {         if (mask & (1 << i)) continue;         int nmask = mask | (1 << i);         int X = x, Y = y;         if (r[i] >= cntR[mask]) {           X += cntR[mask];         } else           X += r[i];         if (b[i] >= cntB[mask]) {           Y += cntB[mask];         } else           Y += b[i];         if (dp[X][nmask] == -1 || dp[X][nmask] < Y) {           dp[X][nmask] = Y;           pq.push(make_pair(make_pair(X, Y), nmask));         }       }     }     int sumA = 0, sumB = 0;     for (int i = 0; i < n; i++) {       sumA += r[i];       sumB += b[i];     }     int ans = inf;     for (int i = 0; i < 144; i++) {       if (dp[i][(1 << n) - 1] == -1) continue;       ans = min(ans, max(sumA - i, sumB - dp[i][(1 << n) - 1]));     }     printf( %d n , ans + n);   }   int main() {     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long a, b, c, count = 0;     scanf( %lld %lld , &a, &b);     while (a--) {       scanf( %lld , &c);       if (c <= b)         count++;       else         count += 2;     }     printf( %lld , count);   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 300100, MOD = 1e9 + 7;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int main() {     ios::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     int n;     cin >> n;     vector<int> arr(n);     int odd = 0, even = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] % 2 == 0)         even++;       else         odd++;     }     if (odd > 0 && even > 0) sort(arr.begin(), arr.end());     for (auto& a : arr) {       cout << a <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, k, l, ans = 0, sign = 1, count = 0;     string s;     getline(cin, s);     l = s.size();     vector<int> v;     for (i = 0; i < l; i++) {       if (s[i] ==  ? ) {         v.push_back(sign);         sign == 1 ? count++ : count--;       } else if (s[i] ==  + )         sign = 1;       else if (s[i] ==  - )         sign = -1;       else if (s[i] !=     && s[i] !=  = ) {         ans = 10 * ans + s[i] -  0 ;       }     }     int remain = ans - count;     vector<int> v1(v.size(), 1);     for (i = 0; i < v.size(); i++) {       if (v[i] == 1 && remain > 0) {         int old = v1[i];         v1[i] = min(ans, v1[i] + remain);         remain -= (v1[i] - old);       } else if (v[i] == -1 && remain < 0) {         int old = v1[i];         v1[i] = min(ans, v1[i] - remain);         remain += (v1[i] - old);       }     }     if (remain != 0) {       printf( Impossible n );       return 0;     }     printf( Possible n );     for (i = 0; i < v.size(); i++) {       if (i == 0) {         printf( %d  , v1[i]);       } else {         printf( %c %d  , v[i] == 1 ?  +  :  - , v1[i]);       }     }     printf( = %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, ans(0);   int main() {     cin >> n >> m;     while ((n + m) >= 3 && n > 0 && m > 0) {       if (n >= m) {         ans++;         n -= 2;         m--;       } else {         ans++;         m -= 2;         n--;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   void debug_out() { clog <<   n ; }   template <typename H, typename... T>   void debug_out(H head, T... tail) {     clog <<     << head;     debug_out(tail...);   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &vec) {     for (auto &i : vec) os << i <<    ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<vector<T>> &vec) {     if (!vec.empty()) os << vec[0];     for (size_t i = 1; i < vec.size(); ++i) os <<   n  << vec[i];     return os;   }   template <typename T, typename U>   ostream &operator<<(ostream &os, const pair<T, U> &p) {     os << p.first <<     << p.second;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &s) {     for (auto &i : s) os << i <<    ;     return os;   }   struct SegmentTree {     int n;     vector<int> mi;     vector<int64_t> sum;     vector<int> push_value;     SegmentTree(int _n) : n(_n) {       mi.resize(4 * n);       sum.resize(4 * n);       push_value.resize(4 * n);     }     void push(int v, int tl, int tr) {       if (push_value[v]) {         push_value[v * 2] = push_value[v * 2 + 1] = push_value[v];         int mid = tl + tr >> 1;         mi[v * 2] = mi[v * 2 + 1] = push_value[v];         sum[v * 2] = 1LL * (mid - tl + 1) * push_value[v];         sum[v * 2 + 1] = 1LL * (tr - mid) * push_value[v];         push_value[v] = 0;       }     }     void update(int l, int r, int val) { update(1, 0, n - 1, l, r, val); }     void update(int v, int tl, int tr, int l, int r, int val) {       if (l > r) return;       if (tl == l && tr == r) {         push_value[v] = val;         sum[v] = 1LL * (r - l + 1) * val;         mi[v] = val;       } else {         push(v, tl, tr);         int mid = tl + tr >> 1;         update(v * 2, tl, mid, l, min(mid, r), val);         update(v * 2 + 1, mid + 1, tr, max(mid + 1, l), r, val);         mi[v] = min(mi[v * 2], mi[v * 2 + 1]);         sum[v] = sum[v * 2] + sum[v * 2 + 1];       }     }     int ask(int l, int r, int y) { return ask(1, 0, n - 1, l, r, y); }     int ask(int v, int tl, int tr, int l, int r, int y) {       if (mi[v] >= y || l > r) return -1;       if (tl == tr) return tl;       push(v, tl, tr);       int mid = tl + tr >> 1;       int ans = ask(v * 2, tl, mid, l, min(mid, r), y);       if (ans == -1) ans = ask(v * 2 + 1, mid + 1, tr, max(mid + 1, l), r, y);       return ans;     }     int query(int l, int r, int &y) { return query(1, 0, n - 1, l, r, y); }     int query(int v, int tl, int tr, int l, int r, int &y) {       if (mi[v] > y || l > r) return 0;       if (tl == tr) return y -= sum[v], 1;       if (tl == l && tr == r && y >= sum[v]) return y -= sum[v], (r - l + 1);       push(v, tl, tr);       int mid = tl + tr >> 1;       int ans = query(v * 2, tl, mid, l, min(mid, r), y);       ans += query(v * 2 + 1, mid + 1, tr, max(mid + 1, l), r, y);       return ans;     }     int get_element(int pos) { return get_element(1, 0, n - 1, pos); }     int get_element(int v, int tl, int tr, int pos) {       if (tl == tr) return sum[v];       push(v, tl, tr);       int mid = tl + tr >> 1;       if (pos <= mid) return get_element(v * 2, tl, mid, pos);       return get_element(v * 2 + 1, mid + 1, tr, pos);     }     void print_tree() {       cout <<  { ;       if (n) cout << get_element(1, 0, n - 1, 0);       for (int i = 1; i < n; ++i) cout <<  ,   << get_element(1, 0, n - 1, i);       cout <<  } n ;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, q;     cin >> n >> q;     SegmentTree st(n);     for (int i = 0; i < n; ++i) {       int val;       cin >> val;       st.update(i, i, val);     }     while (q--) {       int type, x, y;       cin >> type >> x >> y;       --x;       if (type == 1) {         int pos = st.ask(0, x, y);         if (pos != -1) st.update(pos, x, y);       } else {         int ans = st.query(x, n - 1, y);         cout << ans <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int tc;     std::cin >> tc;     while (tc--) {       int64_t a, b, c;       std::cin >> a >> b >> c;       std::cout << a + b + c - 1 << std::endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, A, ni, ai;   string si;   vector<int> hero;   vector<string> moves;   vector<int> player;   bool used[22][(int)(1 << 20)];   int dp[22][(int)(1 << 20)];   int BAD = 99999999;   int memo(int a, int b) {     if (used[a][b]) return dp[a][b];     if (a == A) return 0;     int res = -BAD;     for (int i = 0; i < A; ++i) {       if ((b & (1 << i)) > 0) continue;       int add = hero[i];       if (moves[a] ==  p ) {         if (player[a] % 2 == 0) {           add *= -1;           if (res == -BAD)             res = add + memo(a + 1, b + (1 << i));           else             res = min(res, add + memo(a + 1, b + (1 << i)));         } else {           if (res == -BAD)             res = add + memo(a + 1, b + (1 << i));           else             res = max(res, add + memo(a + 1, b + (1 << i)));         }       } else {         if (player[a] % 2 == 0) {           if (res == -BAD)             res = memo(a + 1, b + (1 << i));           else             res = min(res, memo(a + 1, b + (1 << i)));         } else {           if (res == -BAD)             res = memo(a + 1, b + (1 << i));           else             res = max(res, memo(a + 1, b + (1 << i)));         }       }     }     used[a][b] = true;     dp[a][b] = res;     return dp[a][b];   }   void solve() { cout << memo(0, 0) << endl; }   int main() {     cin >> N;     for (int i = 0; i < N; ++i) {       cin >> ni;       hero.push_back(ni);     }     sort(hero.begin(), hero.end());     reverse(hero.begin(), hero.end());     cin >> A;     for (int i = 0; i < A; ++i) {       cin >> si;       cin >> ai;       moves.push_back(si);       player.push_back(ai);     }     solve();   }


#include <bits/stdc++.h>   using namespace std;   string s;   int isPalin(int start, int end) {     if (start == end) return 1;     int i = (start + end - 1) / 2;     while (start <= i) {       if (s[start++] != s[end--]) return 0;     }     return 1;   }   int main() {     cin >> s;     int start = 0, end = s.length() - 1, flag = 1;     if (isPalin(start, end)) {       flag = ((end - start + 1) % 2 == 1) ? 2 : flag;       end = (start + end - 1) / 2;     }     while (start < end) {       if (isPalin(start, end)) {         flag = ((end - start + 1) % 2 == 1) ? 2 : flag;         end = (start + end - 1) / 2;       } else {         cout << flag << endl;         return 0;       }     }     end = ((int)s.length() - 2) / 2;     while (start < end) {       if (isPalin(start, end))         end--;       else {         cout << flag << endl;         return 0;       }     }     cout <<  Impossible n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[4];     cin >> a[0] >> a[1] >> a[2] >> a[3];     int sum, i;     sum = 0;     string s;     cin >> s;     for (i = 0; i < s.length(); i++) {       sum += a[((s[i]) -  0 ) - 1];     }     cout << sum;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const int N = 2e6 + 1;   const long long mod = 998244353;   long long fact[N];   long long power(long long x, long long n) {     long long res = 1;     x %= mod;     while (n) {       if (n & 1) res = (res * x) % mod;       x = (x * x) % mod;       n >>= 1;     }     return res;   }   long long modInv(long long n) { return power(n, mod - 2); }   long long ncr(long long n, long long r) {     if (n < 0 || r < 0 || r > n) return 0;     long long num = fact[n];     long long denom = (fact[n - r] * fact[r]) % mod;     return (num * modInv(denom)) % mod;   }   void pre() {     fact[0] = 1;     for (int i = 1; i < N; i++) {       fact[i] = (fact[i - 1] * i) % mod;     }   }   void solve() {     long long n, k;     cin >> n >> k;     long long y = n - k;     if (y < 0) {       cout << 0 <<   n ;       return;     }     long long ans = ncr(n, y);     long long sum = 0;     for (int i = 0; i <= y; i++) {       long long temp = (ncr(y, y - i) * power(y - i, n)) % mod;       if (i % 2) {         sum = (sum + mod - temp) % mod;       } else {         sum = (sum + temp) % mod;       }     }     ans = (ans * sum) % mod;     if (y != n) {       ans = (ans * 2) % mod;     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     std::cout << std::fixed << std::setprecision(20);     ;     int t = 1;     pre();     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char** argv) {     int n;     cin >> n;     long long int sum = 0;     for (int i = 1; i < n; i++) {       sum += ((n - i) * i);     }     cout << sum + n;     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 5000 + 10;   char s[MAXN];   int f[MAXN][MAXN];   bool isP[MAXN][MAXN];   int main() {     scanf( %s , s + 1);     int len = strlen(s + 1);     for (int i = 1; i <= len + 1; i++) {       f[i][i + 1] = 1;       isP[i][i + 1] = isP[i][i] = true;     }     for (int l = 2; l <= len; l++) {       for (int i = 1; i + l <= len + 1; i++) {         int j = i + l;         isP[i][j] = (isP[i + 1][j - 1] && s[i] == s[j - 1]);       }     }     for (int l = 2; l <= len; l++) {       for (int i = 1; i + l <= len + 1; i++) {         int j = i + l;         f[i][j] = f[i][j - 1] + f[i + 1][j] - f[i + 1][j - 1] + isP[i][j];       }     }     int q;     scanf( %d , &q);     while (q--) {       int l, r;       scanf( %d%d , &l, &r);       printf( %d n , f[l][r + 1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   stack<int> ST, SI;   vector<int> P;   char OR[10000], TEMP[10000];   int L, S, C;   int main() {     while (scanf( %s , TEMP) == 1) strcat(OR, TEMP);     L = strlen(OR);     for (S = 0; S < L;) {       if (OR[S + 2] ==  a )         ST.push(0), SI.push(C), C = 0, S += 7;       else if (OR[S + 2] ==  r )         ST.push(1), S += 4;       else if (OR[S + 2] ==  d )         ST.push(2), C++, S += 4;       else if (OR[S + 3] ==  a )         P.push_back(C), C = SI.top(), SI.pop(), S += 8;       else if (OR[S + 3] ==  r )         ST.pop(), S += 5;       else if (OR[S + 3] ==  d )         ST.pop(), S += 5;     }     sort(P.begin(), P.end());     int i;     for (i = 0; i < P.size(); i++) printf( %d  , P[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b;     cin >> a >> b;     while (1) {       if (a >= (2 * b)) {         a = a % (2 * b);       } else if (b >= (2 * a))         b = b % (2 * a);       else         break;       if ((a == 0 || b == 0)) break;     }     cout << a <<     << b << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1100;   int N, K, L;   string S;   int nc[26];   vector<char> res[MAXN];   int main() {     ios_base::sync_with_stdio(0);     for (int i = 0; i < 26; i++) nc[i] = 0;     cin >> N >> L >> K >> S;     for (int i = 0; i < S.length(); i++) nc[S[i] -  a ]++;     int nlo = 0, tlen = 0;     for (int i = 0; i < 26; i++) {       if (tlen == L) break;       int ncnt = (K - nlo);       int nb = nc[i] / ncnt;       nb = min(nb, L - tlen);       for (int j = nlo; j < K; j++) {         for (int k = 0; k < nb; k++) {           res[j].push_back((char) a  + i);           nc[i]--;         }       }       tlen += nb;       if (tlen == L) break;       int nleft = nc[i] % ncnt;       for (int j = 0; j < nleft; j++) {         res[nlo++].push_back((char) a  + i);         nc[i]--;       }     }     for (int i = 0; i < N; i++) {       for (int j = 0; j < 26; j++) {         while (nc[j] > 0 && res[i].size() < L) {           res[i].push_back((char) a  + j);           nc[j]--;         }       }     }     for (int i = 0; i < N; i++) {       for (char c : res[i]) cout << c;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   mt19937 mrand(43);   const double PI = acos((double)-1);   const double eps = 1e-5;   const long long inf0 = 1023 * 1024 * 1024;   const long long inf = inf0 * inf0;   const long long mod = 1e9 + 7;   void solve();   void scan();   signed main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     cout << fixed;     cout.precision(15);     solve();     return 0;   }   const int N = 1e5;   void solve() {     int m;     cin >> m;     vector<int> a;     vector<pair<pair<long long, long long>, pair<long long, long long>>> kek;     long long n = 0;     while (m--) {       int tp;       cin >> tp;       if (tp == 1) {         int x;         cin >> x;         if (a.size() < N)           a.push_back(x);         else           kek.push_back({{n, n}, {-1, x}});         n++;       } else {         long long l, c;         cin >> l >> c;         while (c && a.size() < N) {           for (int i = 0; i < l; i++) {             a.push_back(a[i]);           }           n += l;           c--;         }         if (c) kek.push_back({{n, n + l * c - 1}, {0, l - 1}});         n += l * c;       }     }     int q;     cin >> q;     while (q--) {       long long x;       cin >> x;       x--;       if (x < a.size())         cout << a[x] <<    ;       else {         int h = upper_bound((kek).begin(), (kek).end(),                             make_pair(make_pair(x, (long long)4e18),                                       make_pair(1ll, 1ll))) -                 kek.begin() - 1;         x -= kek[h].first.first;         cout << a[x % (kek[h].second.second + 1)] <<    ;       }     }     return;   }


#include <bits/stdc++.h>   using namespace std;   int al = 1 << 29;   char ans[1000100];   char a[1000100];   int n, m;   void computer(int x, int y) {     int l = 0;     while (x != y) {       if (x > y) {         a[l++] =  T ;         x -= y;       } else {         a[l++] =  B ;         y -= x;       }     }     if (x > 1) return;     a[l++] =  T ;     if (l != n) return;     reverse(a, a + l);     int cur = 0;     int i;     for (i = 1; i < n; i++) {       if (a[i - 1] == a[i]) cur++;     }     if (cur < al) {       al = cur;       for (i = 0; i < n; i++) ans[i] = a[i];     }   }   int main() {     int i;     scanf( %d%d , &n, &m);     for (i = 1; i <= m; i++) {       computer(i, m);       computer(m, i);     }     if (al >= 1000100)       cout <<  IMPOSSIBLE  << endl;     else {       cout << al << endl;       for (i = 0; i < n; i++) cout << ans[i];       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, s;   int a[110][2];   int main() {     scanf( %d %d , &n, &s);     for (int i = 0; i < n; i++) {       scanf( %d %d , &a[i][0], &a[i][1]);     }     int cnt = 0;     int maxcnt = 0;     int temp = 0;     for (int i = 0; i < n; i++) {       if ((a[i][0] == s && a[i][1] != 0) || a[i][0] > s)         temp++;       else         cnt = 100 - a[i][1];       if (cnt > maxcnt && cnt < 100) {         maxcnt = cnt;       }       cnt = 0;     }     if (temp == n)       printf( -1 n );     else       printf( %d n , maxcnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long inf = 0x3f3f3f3f3f3f3f3f;   const long long mod = 998244353;   const int N = 3e5 + 10;   int n;   int a[N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++)       if (a[i] <= a[i - 1] && a[i] <= a[i + 1]) {         puts( NO );         return 0;       }     puts( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   int n, m;   int a[maxn], par[maxn], t[maxn];   vector<int> g[maxn];   int get_par(int v) { return (par[v] == -1) ? v : par[v] = get_par(par[v]); }   void merge(int u, int v) {     u = get_par(u);     v = get_par(v);     if (v == u) return;     par[u] = v;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     cin >> n >> m;     memset(par, -1, sizeof par);     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       merge(u, v);     }     for (int i = 1; i <= n; i++) g[get_par(i)].push_back(a[i]);     for (int i = 1; i <= n; i++) sort(g[i].begin(), g[i].end());     for (int i = 1; i <= n; i++) {       cout << g[get_par(i)].back() <<    ;       g[get_par(i)].pop_back();     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int x, y, n = 0;       cin >> x >> y;       for (int i = 2; i <= x; i++) {         if (x % i == 0) {           n = i;           break;         }       }       cout << x + n + (y - 1) * 2 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int sum = 0;     cin >> n;     int **p;     p = new int *[n];     for (int i = 0; i < n; i++) {       p[i] = new int[n];       for (int j = 0; j < n; j++) {         cin >> p[i][j];       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i == j || i + j == n - 1 || i == (n - 1) / 2 || j == (n - 1) / 2) {           sum += p[i][j];         }       }     }     cout << sum;     return 0;   }


#include <bits/stdc++.h>   int DEBUG = 1;   using namespace std;   const int N = 100 * 1000 + 5;   const long long INF = 1e17;   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long n, k;   long long a, b;   long long x;   long long MIN = +INF;   long long MAX = -INF;   long long dist(long long v, long long u) {     if (v > u) swap(v, u);     return min(u - v, x - (u - v));   }   void check(long long s2) {     long long d = dist(a, s2);     long long L = d;     long long cur = x / gcd(L, x);     MAX = max(MAX, cur);     MIN = min(MIN, cur);   }   int main() {     cin >> n >> k;     cin >> a >> b;     x = n * k;     for (long long e = 0; e < x; e += k) {       check((e - b + x) % x);       check((e + b) % x);     }     cout << MIN <<     << MAX << endl;     return 0;   }


#include <bits/stdc++.h>   #define MAXN   100001     int spf[MAXN];    using namespace std;      #define mod             1000000007   #define int             long long //32bit as well as 64bit   #define vi              vector<int> // a[n] s[n]  v(n)  pop_back      #define vvi             vector<vector<int>>  // vvi(n)  vec[i]=vi(col);   #define maxx(arr)       *max_element(arr.begin(),arr.end())    #define minn(arr)       *min_element(arr.begin(),arr.end())   #define maxa(arr)       *max_element(arr,arr+arr.size())   #define mina(arr)       *min_element(arr,arr+arr.size())   #define sortt(sv)       sort(sv.begin(),sv.end()) //str & v   rbegin,rend   #define pb              push_back  // s0d and v s.pb(s[i])   #define forr(i,z,n)     for(int i=z;i<n;i++)   // n= name.size()   #define forn(i,n,x)     for(int i=n-1;i>=x;i--)    //for(i+=3) loop last line i+=2;   #define aa(i,st)        for(auto i=st.begin();i!=st.end();i++)  //arr not/*i(vec,set,0Dstring)/mp(i->first)   #define an(i,st)        for(auto i=st.rbegin();i!=st.rend();i++)      #define gcd(a,b)        __gcd(a,b) //0,x=x   #define lcm(a,b)        ((a)*(b)/gcd(a,b)) // 0,x =0     #define con(arr,s);     /*string to array*/int arr[s.size()]={0};for(int i=0;i<s.size();i++){arr[i]=arr[i]*10+(s[i]-48);}      int    binpower                                                                                (int base, unsigned int e, int m) {int result = 1;base %= m;while (e) {if (e & 1)result = result * base % m;base = base * base % m;e >>= 1;}return result;}   bool   check_composite                                                                                (int n, int a, int d, int s) {int x = binpower(a, d, n);if (x == 1 || x == n - 1)return false;for (int r = 1; r < s; r++) {x = x * x % n;if (x == n - 1)return false;}return true;};   bool   prime(int n)    /* 1 is not prime*/                                                                                { if (n < 2)return false;int r = 0;int d = n - 1;while ((d & 1) == 0) {d >>= 1;r++;}for (int a : {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}) {if (n == a)return true;if (check_composite(n, a, d, r))return false;}return true;}   int    fact (int n)    /*fa(3)=3*2  fa(0)=1    npr=fa(n)/ fac(n-r)      ncr=fa(n)/(fa(n-r)*fa(r))          for aba 3p2=aa ab ba ba aa ab(6)  and 3c2(3) =  ab aa ba (because input is in int)  */      { int res=1; for(int i=2;i<=n;i++) res=res*i; return res;}    void   helperfactor()                                                                                {spf[1] = 1;for (int i=2; i<MAXN; i++)spf[i] = i;for (int i=4; i<MAXN; i+=2)spf[i] = 2;for (int i=3; i*i<MAXN; i++){if (spf[i] == i){for (int j=i*i; j<MAXN; j+=i)if (spf[j]==j)spf[j] = i;}}}    void   lcmfactor       (vi &ret,int x)                         /*       12= 2 2 3         */                                          { helperfactor();while (x != 1) { ret.push_back(spf[x]); x = x / spf[x];}}    void   primefactor  (vi &arr,int n)                            /*       12= 2 3           */                                                                 {bool prime[n + 1];memset(prime, true, sizeof(prime));for (int p = 2; p * p <= n; p++){if (prime[p] == true){for (int i = p * p; i <= n; i += p)prime[i] = false;}}for (int p = 2; p <= n; p++)if (prime[p])arr.pb(p);}   void   allfactor    (vi &arr,int n)     /*sort to get lexiographically  12= 1 12 2 6 3 4  */                                                 {for (int i=1; i<=sqrt(n); i++){if (n%i == 0){if (n/i == i)arr.pb(i);else{arr.pb(i); arr.pb(n/i);}}}}      // void   longfactor(vi &arr,int n)                                                                           {while (n%2 == 0){arr.pb(2);n = n/2;}for (int i = 3; i <= sqrt(n); i = i+2){while (n%i == 0){arr.pb(i);n = n/i; }}if (n > 2) arr.pb(n); }    // void   helperlongprime(int limit, vi &prime,vi &arr)                                                        {vector<bool> mark(limit + 1, true);for (int p=2; p*p<limit; p++){if (mark[p] == true){for (int i=p*p; i<limit; i+=p)mark[i] = false;}}for (int p=2; p<limit; p++){if (mark[p] == true){prime.push_back(p);arr.pb(p);}}}   // void   longprimefactor(vi &arr,int n)                                                                       {int limit = floor(sqrt(n))+1;vector<int> prime;prime.reserve(limit);helperlongprime(limit, prime,arr);int low = limit;int high = 2*limit;while (low < n){if (high >= n)high = n;bool mark[limit+1];memset(mark, true, sizeof(mark));for (int i = 0; i < prime.size(); i++){int loLim = floor(low/prime[i]) * prime[i];if (loLim < low)loLim += prime[i];for (int j=loLim; j<high; j+=prime[i])mark[j-low] = false;}for (int i = low; i<high; i++)if (mark[i - low] == true)arr.pb(i);low = low + limit;high = high + limit;}}      //use v.size/s=   instead making bool/checkpoints/else if/else     // v(n) imp for cin not for pb               //JAI SARGURU DEV  JAI SATGURU DEV   DONT WASTE TIME   //Dasrath manjhi 22 years  gate 10years  sonu bahiya appu bhaiya kunal akshay alok bhanu me 1 year january 22   //Become financial independent as fast as u can to enjoy life -> STUDENT LIFE,STUDY ONLY   //Dont waste time in finding reason to relax      //  JUST STUDY,NO RELAX,NO REASON   for 1YEAR       void solve(){       int n;   cin>>n;      vi v(n);   forr(i,0,n){       cin>>v[i];   }   int maxy=v[n-1];   vi ans(n);   forn(i,n,0){      ans[i]=v[i];      if(i+ans[i]<n){        ans[i]+=ans[i+ans[i]];      }      if(ans[i]>maxy){       maxy=ans[i];      }   }      cout<<maxy<<  n ;                                    }                              int32_t main(){              ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);       #ifndef ONLINE_JUDGE           freopen( input.txt , r ,stdin);           freopen( output.txt , w ,stdout);       #endif          int t;cin>>t;while(t--)           solve();                     return 0;   }      /*pow(base,power)       sqrt(n)     ceil(cbrt(n))/ceil(n)      long double n = -7.11;       cbrt(n);         gives till .5 point  /long long double not exist   int h= (s[0]- 0 )*10  + s[1]- 0 ;    s.erase(remove(s.begin(),s.end(),  a  ),s.end());        string search in        multimap =mp.insert((pair <int, int> ( fir, sec )));  can have sorted same key and definitely same value     */


#include <bits/stdc++.h>   int main() {     int i, j, k, l;     long long n, m, sum;     while (scanf( %lld%lld , &n, &m) != EOF) {       sum = 0;       for (int i = 1; i <= n; i++) {         if (m % i == 0 && m / i <= n) {           ++sum;         }       }       printf( %d n , sum);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> hsh;   int check(string str, int l, int r) {     int pos = 0, cur = 0;     for (int i = r; i >= l; i--) {       if (str[i] ==  ( )         cur++;       else if (str[i] ==  ) )         cur--;       else if (cur == 0 && pos == 0 && (str[i] ==  *  || str[i] ==  / ))         pos = i;       else if (cur == 0 && (str[i] ==  +  || str[i] ==  - )) {         int lft = check(str, l, i - 1), rgt = check(str, i + 1, r);         if (lft == 2 || rgt == 2) return 2;         if (str[i] ==  + )           return 3;         else if (str[i] ==  - ) {           if (rgt == 3)             return 2;           else             return 3;         }       }     }     if (pos) {       int lft = check(str, l, pos - 1), rgt = check(str, pos + 1, r);       if (lft == 2 || rgt == 2) return 2;       if (str[pos] ==  * ) {         if (lft == 3 || rgt == 3)           return 2;         else           return 4;       } else if (str[pos] ==  / ) {         if (lft == 3 || rgt == 3 || rgt == 4)           return 2;         else           return 4;       }     } else if (str[l] ==  (  && str[r] ==  ) ) {       if (check(str, l + 1, r - 1) == 2)         return 2;       else         return 1;     } else {       string res =   ;       for (int i = l; i <= r; i++) res += str[i];       if (hsh[res])         return hsh[res];       else         return 1;     }   }   int main() {     int n;     string s, exp, ques;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s;       if (s ==  # ) cin >> s;       cin >> s;       getline(cin, exp);       ques =   ;       for (int j = 0; j < exp.length(); j++)         if (exp[j] !=    ) ques += exp[j];       hsh[s] = check(ques, 0, ques.length() - 1);     }     getline(cin, exp);     ques =   ;     for (int i = 0; i < exp.length(); i++)       if (exp[i] !=    ) ques += exp[i];     if (check(ques, 0, ques.length() - 1) == 2)       cout <<  Suspicious  << endl;     else       cout <<  OK  << endl;     return 0;   }