#include <bits/stdc++.h>   using namespace std;   map<long long int, int> mp;   int main() {     long long int b, q, l, m, t;     scanf( %lld%lld%lld%lld , &b, &q, &l, &m);     for (int i = 0; i < m; i++) {       scanf( %lld , &t);       mp[t] = 1;     }     if (b < -l || b > l) {       printf( 0 n );       return 0;     }     if (b == 0) {       if (mp[0])         printf( 0 n );       else         printf( inf n );       return 0;     } else if (q == 0) {       if (mp[b] && mp[0])         printf( 0 n );       else if (!mp[b] && mp[0])         printf( 1 n );       else         printf( inf n );       return 0;     } else if (q == 1) {       if (mp[b])         printf( 0 n );       else         printf( inf n );       return 0;     } else if (q == -1) {       if (mp[b] && mp[-b])         printf( 0 n );       else         printf( inf n );       return 0;     } else {       long long int cont = 0;       while (b <= l && b >= -l) {         if (!mp[b]) cont++;         b *= q;       }       printf( %lld n , cont);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     string a, c;     int b, d, p;     int pos[110];     p = 0;     cin >> b >> d;     cin >> a;     cin >> c;     int t = 0, la, lc;     la = a.length();     lc = c.length();     int k = 0;     for (int i = 0; i < lc; i++) {       k = 0;       for (int j = 0; j < la; j++)         if (a[j] == c[(i + k) % lc]) k++;       pos[i] = k;     }     int sum = 0;     int j = 0;     for (int i = 0; i < b; i++) {       sum += pos[j];       j = (j + pos[j]) % lc;     }     sum /= lc;     p = sum / d;     cout << p << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a, b;   set<pair<int, int> > s;   set<int> sc;   vector<int> ans;   int main() {     cin >> n >> m;     for (int i = 1; i <= m; ++i) {       cin >> a >> b;       s.insert(make_pair(min(a, b), max(a, b)));     }     for (int i = 1; i <= n; ++i) {       sc.insert(i);     }     for (int i = 1; i <= n; ++i) {       if (sc.find(i) != sc.end()) {         int cur = 0;         queue<int> q;         q.push(i);         sc.erase(i);         while (!q.empty()) {           cur++;           int v = q.front();           q.pop();           set<int>::iterator it;           set<int> c = sc;           for (it = c.begin(); it != c.end(); it++) {             int to = *it;             if (s.find(make_pair(min(v, to), max(v, to))) == s.end()) {               q.push(to);               sc.erase(to);             }           }         }         ans.push_back(cur);       }     }     sort(ans.begin(), ans.end());     cout << (int)ans.size() << endl;     for (int i = 0; i < (int)ans.size(); ++i) {       cout << ans[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:10000000 )   using namespace std;   template <typename T>   inline T abs(T a) {     return ((a < 0) ? -a : a);   }   template <typename T>   inline T sqr(T a) {     return a * a;   }   const int INF = (int)1E9 + 7;   const long double EPS = 1E-9;   const long double PI = 3.1415926535897932384626433832795;   const int NMAX = 200 * 1000;   int a[NMAX], sza;   int t[NMAX * 4], cnt[NMAX * 4];   long long sum[NMAX * 4][5];   char buf[300];   void upd(int pos, int idx, int lf, int rg) {     if (lf == rg) {       t[idx] ^= 1;       memset(sum[idx], 0, sizeof sum[idx]);       sum[idx][0] = t[idx] * 1LL * a[pos];       cnt[idx] = t[idx];       return;     }     int mid = (lf + rg) >> 1;     if (pos <= mid)       upd(pos, 2 * idx + 1, lf, mid);     else       upd(pos, 2 * idx + 2, mid + 1, rg);     cnt[idx] = cnt[2 * idx + 1] + cnt[2 * idx + 2];     for (int i = 0; i < int(5); ++i) {       long long& ans = sum[idx][i];       int f = (cnt[2 * idx + 1]) % 5;       f = (i - f + 5) % 5;       ans = sum[2 * idx + 1][i] + sum[2 * idx + 2][f];     }   }   void change(int val) {     int pos = lower_bound(a, a + sza, val) - a;     upd(pos, 0, 0, sza - 1);   }   inline long long getSum() { return sum[0][2]; }   int main() {     int n;     scanf( %d , &n);     gets(buf);     vector<pair<int, int> > q;     for (int i = 0; i < int(n); ++i) {       gets(buf);       if (buf[0] ==  a ) {         int val;         sscanf(buf,  add %d , &val);         q.push_back(make_pair(1, val));         a[sza++] = val;       }       if (buf[0] ==  d ) {         int val;         sscanf(buf,  del %d , &val);         q.push_back(make_pair(-1, val));         a[sza++] = val;       }       if (buf[0] ==  s ) {         q.push_back(make_pair(-1, -1));       }     }     sort(a, a + sza);     sza = unique(a, a + sza) - a;     for (int i = 0; i < int(n); ++i) {       if (q[i] == pair<int, int>(-1, -1)) {         printf( %I64d n , getSum());         continue;       }       if (q[i].first == 1) {         change(q[i].second);       } else {         change(q[i].second);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100001];   int getBound(int start, int dir, int size, int k) {     int cnt = 0;     bool seen[100001];     fill(seen, seen + 100001, false);     for (int i = start; i <= size && i > 0; i += dir) {       if (!seen[a[i]]) cnt++, seen[a[i]] = true;       if (cnt == k) return i;     }     return -1;   }   int main() {     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     int right = getBound(1, 1, n, k);     if (right == -1)       cout << -1 <<     << -1 << endl;     else {       int left = getBound(right, -1, n, k);       cout << left <<     << right << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAX = 10e5;   vector<long long> graph[MAX];   queue<long long> q;   bool visit[MAX];   long long a[MAX];   long long s[MAX];   long long parent[MAX];   int main() {     memset(visit, false, sizeof(visit));     long long nodes;     cin >> nodes;     for (auto i = 2; i <= nodes; ++i) {       long long tmp;       cin >> tmp;       parent[i] = tmp;       graph[i].push_back(tmp);       graph[tmp].push_back(i);     }     for (auto i = 1; i <= nodes; ++i) {       cin >> s[i];     }     a[1] = s[1];     q.push(1);     visit[1] = true;     while (!q.empty()) {       long long n = q.front();       q.pop();       if (n != 1) {         if (s[n] == -1) {           s[n] = s[parent[n]];           if (graph[n].size() > 1) {             long long mini = 10e9;             for (auto v : graph[n]) {               if (v == parent[n]) continue;               mini = min(mini, s[v]);             }             if (mini < s[n]) {               cout << -1;               return 0;             } else {               a[n] = mini - s[n];               s[n] = mini;             }           } else {             a[n] = 0;             s[n] = s[parent[n]];           }         } else {           a[n] = s[n] - s[parent[n]];         }       }       for (auto p : graph[n]) {         if (visit[p]) continue;         q.push(p);         visit[p] = true;       }     }     long long ans = 0;     for (auto i = 1; i <= nodes; i++) {       ans += a[i];     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     string s;     cin >> s;     string ans =   ;     int cnt(0);     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  0  && cnt == 0) {         cnt++;       } else         ans += s[i];     }     if (cnt == 0) {       for (int i = 0; i < ans.size() - 1; i++) cout << ans[i];     } else       cout << ans;   }   int main() {     long long t;     t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};   const int N = 500005;   vector<int> arr[N], cnt[N], adj[N];   int vis[N], st[N], fin[N], dep[N];   int tim;   char inp[N];   void dfs(int i, int d) {     vis[i] = 1;     dep[i] = d;     st[i] = ++tim;     arr[d].push_back(st[i]);     int no = 0;     for (int first = 0; first < (int)26; first++)       no |= (first == inp[i] -  a ) << first;     cnt[d].push_back(no);     for (int v : adj[i])       if (!vis[v]) dfs(v, d + 1);     fin[i] = ++tim;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < (int)n - 1; i++) {       int first;       cin >> first;       adj[first].push_back(i + 2);       adj[i + 2].push_back(first);     }     for (int i = 0; i < (int)n; i++) cin >> inp[i + 1];     dfs(1, 0);     for (int i = 0; i < (int)N; i++) {       for (int j = 1; j < cnt[i].size(); j++) {         cnt[i][j] ^= cnt[i][j - 1];       }     }     for (int wrd = 0; wrd < (int)m; wrd++) {       int a, b;       cin >> a >> b;       b--;       int no_odds = 0;       vector<int>& v = arr[b];       int l = lower_bound((v).begin(), (v).end(), st[a]) - v.begin();       int r = upper_bound((v).begin(), (v).end(), fin[a]) - v.begin() - 1;       if (l > r) {         cout <<  Yes n ;         continue;       }       for (int first = 0; first < (int)26; first++) {         int add = (cnt[b][r] >> first) & 1;         int sub = (l == 0) ? 0 : ((cnt[b][l - 1] >> first) & 1);         no_odds += (add - sub + 2) % 2;       }       if (no_odds <= 1)         cout <<  Yes n ;       else         cout <<  No n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int a[3], i;       for (i = 0; i < 3; i++) cin >> a[i];       sort(a, a + 3);       if (a[2] <= a[1] + a[0] + 1)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   string to_string(string s) { return     + s +    ; }   string to_string(const char* s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto& x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   template <int MOD_>   struct modnum {     static constexpr int MOD = MOD_;     static_assert(MOD_ > 0,  MOD must be positive );       private:     using ll = long long;     int v;     static int minv(int a, int m) {       a %= m;       assert(a);       return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);     }       public:     modnum() : v(0) {}     modnum(ll v_) : v(int(v_ % MOD)) {       if (v < 0) v += MOD;     }     explicit operator int() const { return v; }     friend std::ostream& operator<<(std::ostream& out, const modnum& n) {       return out << int(n);     }     friend std::istream& operator>>(std::istream& in, modnum& n) {       ll v_;       in >> v_;       n = modnum(v_);       return in;     }     friend bool operator==(const modnum& a, const modnum& b) {       return a.v == b.v;     }     friend bool operator!=(const modnum& a, const modnum& b) {       return a.v != b.v;     }     modnum inv() const {       modnum res;       res.v = minv(v, MOD);       return res;     }     friend modnum inv(const modnum& m) { return m.inv(); }     modnum neg() const {       modnum res;       res.v = v ? MOD - v : 0;       return res;     }     friend modnum neg(const modnum& m) { return m.neg(); }     modnum operator-() const { return neg(); }     modnum operator+() const { return modnum(*this); }     modnum& operator++() {       v++;       if (v == MOD) v = 0;       return *this;     }     modnum& operator--() {       if (v == 0) v = MOD;       v--;       return *this;     }     modnum& operator+=(const modnum& o) {       v -= MOD - o.v;       v = (v < 0) ? v + MOD : v;       return *this;     }     modnum& operator-=(const modnum& o) {       v -= o.v;       v = (v < 0) ? v + MOD : v;       return *this;     }     modnum& operator*=(const modnum& o) {       v = int(ll(v) * ll(o.v) % MOD);       return *this;     }     modnum& operator/=(const modnum& o) { return *this *= o.inv(); }     friend modnum operator++(modnum& a, int) {       modnum r = a;       ++a;       return r;     }     friend modnum operator--(modnum& a, int) {       modnum r = a;       --a;       return r;     }     friend modnum operator+(const modnum& a, const modnum& b) {       return modnum(a) += b;     }     friend modnum operator-(const modnum& a, const modnum& b) {       return modnum(a) -= b;     }     friend modnum operator*(const modnum& a, const modnum& b) {       return modnum(a) *= b;     }     friend modnum operator/(const modnum& a, const modnum& b) {       return modnum(a) /= b;     }   };   using num = modnum<1000000007>;   const int mod = 1e9 + 7;   num power(num a, int64_t b) {     if (b == 0) return 1;     num res = power(a, b / 2);     if (b & 1) return res * res * a;     return res * res;   }   bool checkinter(pair<int, int> x, pair<int, int> y) {     if (x.first > y.first) swap(x, y);     return x.first <= y.first && y.first <= x.second;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     if (fopen( input.txt ,  r )) {       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);     }     int64_t N, M, K, R, C, Ax, Bx, Ay, By;     cin >> N >> M >> K >> R >> C >> Ax >> Ay >> Bx >> By;     if (!checkinter(make_pair(Ax, Ax + R - 1), make_pair(Bx, Bx + R - 1)) or         !checkinter(make_pair(By, By + C - 1), make_pair(Ay, Ay + C - 1))) {       num res = 0;       res = power(K, 1ll * N * M - 2ll * R * C);       res *= power(K, 1ll * R * C);       cout << res;       return 0;     }     if (Ax > Bx) swap(Ax, Bx), swap(Ay, By);     if (By < Ay) {       int diff = abs(By + C - 1 - Ay + 1);       By = Ay + C - 1 - diff + 1;     }     int64_t sharearea = 1ll * ((Ay + C - 1) - By + 1) * ((Ax + R - 1) - Bx + 1);     int64_t area = 2ll * R * C - sharearea;     int64_t remainarea = 1ll * N * M - area;     num res = power(K, remainarea);     if (Ax == Bx and Ay == By)       res *= power(K, R * C);     else       res *= power(K, 1ll * R * C - sharearea);     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   struct rangeincrease {     int l, r;   };   rangeincrease actions[100001];   rangeincrease inprogress[100001];   int actionL = 0;   int nums[100001];   int opened = 0;   int main() {     int n;     int i;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> nums[i];     }     for (i = 1; i <= n; i++) {       while (nums[i] > opened) {         opened++;         inprogress[opened].l = i;       }       while (nums[i] < opened) {         inprogress[opened].r = i - 1;         actionL++;         actions[actionL].l = inprogress[opened].l;         actions[actionL].r = inprogress[opened].r;         opened--;       }     }     while (opened > 0) {       inprogress[opened].r = n;       actionL++;       actions[actionL].l = inprogress[opened].l;       actions[actionL].r = inprogress[opened].r;       opened--;     }     cout << actionL << endl;     for (i = 1; i <= actionL; i++) {       cout << actions[i].l <<     << actions[i].r << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   bool ispoweroftwo(long long n) { return n & (!(n & (n - 1))); }   long long mod = 1000000007;   long long dx[] = {1, 0, -1, 0};   long long dy[] = {0, -1, 0, 1};   bool test = 0;   const long long inf = 1e18;   const long long N = 1e5 + 5;   long long cache[N][4][4];   long long k, n;   long long color[N][3];   vector<long long> adj[N];   long long dp(long long u, long long f = 3, long long f1 = 3, long long p = -1) {     long long &ans = cache[u][f][f1];     if (ans != -1) return ans;     long long kid1 = -1, kid2 = -1;     for (auto it : adj[u]) {       if (it == p) continue;       if (kid1 == -1)         kid1 = it;       else         kid2 = it;     }     if (kid1 == -1) return ans = 0;     if (kid2 != -1) {       vector<long long> c1, c2, c3;       for (long long i = 0; i < 3; ++i) {         if (i == f) continue;         c1.emplace_back(color[kid1][i] + dp(kid1, i, f, u));         c3.emplace_back(i);       }       for (long long i = 0; i < 3; ++i) {         if (i == f) continue;         c2.emplace_back(color[kid2][i] + dp(kid2, i, f, u));       }       ans = min(c1[0] + c2[1], c1[1] + c2[0]);       return ans;     }     ans = inf;     for (long long i = 0; i < 3; ++i) {       if (i == f or i == f1) continue;       ans = min(ans, color[kid1][i] + dp(kid1, i, f, u));     }     return ans;   }   vector<long long> col(N);   void path(long long u, long long f, long long f1 = 3, long long p = -1) {     long long &ans = cache[u][f][f1];     long long kid1 = -1, kid2 = -1;     for (auto it : adj[u]) {       if (it == p) continue;       if (kid1 == -1)         kid1 = it;       else         kid2 = it;     }     if (kid1 == -1) return;     if (kid2 != -1) {       vector<long long> c1, c2, c3;       for (long long i = 0; i < 3; ++i) {         if (i == f) continue;         c1.emplace_back(color[kid1][i] + cache[kid1][i][f]);         c3.emplace_back(i);       }       for (long long i = 0; i < 3; ++i) {         if (i == f) continue;         c2.emplace_back(color[kid2][i] + cache[kid2][i][f]);       }       if (ans != c1[0] + c2[1]) swap(kid1, kid2);       col[kid1] = c3[0] + 1;       col[kid2] = c3[1] + 1;       path(kid1, c3[0], f, u);       path(kid2, c3[1], f, u);       return;     }     for (long long i = 0; i < 3; ++i) {       if (i == f or i == f1) continue;       if (ans == color[kid1][i] + cache[kid1][i][f]) {         col[kid1] = i + 1;         path(kid1, i, f, u);       }     }   }   void solve(long long tc = 0) {     memset(cache, -1, sizeof(cache));     cin >> n;     for (long long i = 0; i < 3; ++i)       for (long long j = 1; j <= n; ++j) cin >> color[j][i];     for (long long i = 1, x, y; i < n; ++i) {       cin >> x >> y;       adj[x].emplace_back(y);       adj[y].emplace_back(x);     }     for (long long i = 1; i <= n; ++i) {       if (adj[i].size() >= 3) {         cout <<  -1 n ;         return;       }     }     adj[0].emplace_back(1);     long long ans = dp(0, 3);     cout << ans <<   n ;     path(0, 3);     for (long long i = 1; i <= n; ++i) cout << col[i] <<    ;     cout <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     if (test) cin >> t;     for (long long i = 1; i <= t; ++i) {       solve(i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MX = 200005;   long long n, m;   vector<long long> adj[2][MX];   long long st[MX], fin[MX];   long long deg[2][MX];   long long ans, tim;   long long cur = 1;   pair<long long, long long> seg[4 * MX];   long long lazy[4 * MX];   pair<long long, long long> merge(pair<long long, long long> x,                                    pair<long long, long long> y) {     if (x.first == y.first) return {x.first, x.second + y.second};     return min(x, y);   }   void build(long long node, long long l, long long r) {     if (l == r) {       seg[node] = {0, 1};       return;     }     long long mid = (l + r) / 2;     build(2 * node, l, mid);     build(2 * node + 1, mid + 1, r);     seg[node] = merge(seg[2 * node], seg[2 * node + 1]);   }   void propagate(long long node, long long l, long long r) {     seg[node].first += lazy[node];     if (l != r) {       lazy[2 * node] += lazy[node];       lazy[2 * node + 1] += lazy[node];     }     lazy[node] = 0;   }   void update(long long node, long long l, long long r, long long x, long long y,               long long val) {     propagate(node, l, r);     if (l > y or r < x) return;     if (l >= x and r <= y) {       lazy[node] += val;       propagate(node, l, r);       return;     }     long long mid = (l + r) / 2;     update(2 * node, l, mid, x, y, val);     update(2 * node + 1, mid + 1, r, x, y, val);     seg[node] = merge(seg[2 * node], seg[2 * node + 1]);   }   void dfs(long long u) {     st[u] = tim++;     for (auto v : adj[1][u]) {       dfs(v);     }     fin[u] = tim;   }   void solve(long long u) {     update(1, 0, cur - 1, st[u], fin[u] - 1, 1);     if (!seg[1].first) ans -= seg[1].second;     for (auto v : adj[0][u]) {       solve(v);     }     update(1, 0, cur - 1, st[u], fin[u] - 1, -1);   }   signed main() {     cin >> n >> m;     vector<vector<long long> > index(n, vector<long long>(m, -1));     vector<vector<char> > a(n, vector<char>(m));     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         cin >> a[i][j];         if (a[i][j] ==  L ) {           index[i][j] = cur;           index[i][j + 1] = cur;           cur++;         } else if (a[i][j] ==  U ) {           index[i][j] = cur;           index[i + 1][j] = cur;           cur++;         }       }     }     cur--;     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         if (a[i][j] ==  L  and j + 2 < m) {           adj[(i + j) % 2][index[i][j + 2]].push_back(index[i][j]);           deg[(i + j) % 2][index[i][j]]++;         }         if (a[i][j] ==  R  and j - 2 >= 0) {           adj[(i + j) % 2][index[i][j - 2]].push_back(index[i][j]);           deg[(i + j) % 2][index[i][j]]++;         }         if (a[i][j] ==  U  and i + 2 < n) {           adj[(i + j) % 2][index[i + 2][j]].push_back(index[i][j]);           deg[(i + j) % 2][index[i][j]]++;         }         if (a[i][j] ==  D  and i - 2 >= 0) {           adj[(i + j) % 2][index[i - 2][j]].push_back(index[i][j]);           deg[(i + j) % 2][index[i][j]]++;         }       }     }     ans = (n * m * n * m) / 4;     tim = 0;     for (long long i = 1; i < cur + 1; i++) {       if (!deg[1][i]) dfs(i);     }     build(1, 0, cur - 1);     for (long long i = 1; i < cur + 1; i++) {       if (!deg[0][i]) solve(i);     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 205, inf = 1e9;   int n, a[N];   int tot, lnk[N], fro[N * N * 2], nxt[N * N * 2], son[N * N * 2], c[N * N * 2],       ori[N * N * 2];   int S, T, dep[N], cur[N];   queue<int> q;   int cnt;   bool vis[N];   vector<int> ans[N];   bool isprm(int x) {     if (x == 2 || x == 3 || x == 5 || x == 7) return 1;     for (int i = 2; i <= sqrt(x); ++i)       if (x % i == 0) return 0;     return 1;   }   void add(int x, int y, int z) {     nxt[++tot] = lnk[x], lnk[x] = tot;     fro[tot] = x, son[tot] = y, c[tot] = ori[tot] = z;   }   struct Dinic {     bool bfs(int x = 0) {       memset(dep, 0, sizeof dep), dep[S] = 1;       for (; !q.empty(); q.pop())         ;       q.push(S);       for (; !q.empty();) {         x = q.front(), q.pop();         for (int j = lnk[x]; j; j = nxt[j]) {           if (!dep[son[j]] && c[j]) {             dep[son[j]] = dep[x] + 1;             q.push(son[j]);           }         }       }       return dep[T];     }     int dfs(int x, int f, int ret = 0) {       if (x == T) return f;       for (int &j = cur[x]; j; j = nxt[j]) {         if (dep[son[j]] == dep[x] + 1 && c[j]) {           int delta = dfs(son[j], min(f, c[j]));           c[j] -= delta, c[j ^ 1] += delta;           ret += delta, f -= delta;         }       }       return ret;     }     int answer(int ret = 0) {       for (; bfs();) {         for (int i = S; i <= T; ++i) cur[i] = lnk[i];         ret += dfs(S, inf);       }       return ret;     }   } network;   void dfs(int x, int s) {     vis[x] = 1, ans[cnt].push_back(x);     if (a[x] & 1) {       for (int j = lnk[x]; j; j = nxt[j]) {         if (c[j] != 0 || son[j] == S || son[j] == T) continue;         if (!vis[son[j]]) {           dfs(son[j], s);           break;         }       }     } else {       for (int j = lnk[x]; j; j = nxt[j]) {         if (c[j ^ 1] != 0 || son[j] == S || son[j] == T) continue;         if (!vis[son[j]]) {           dfs(son[j], s);           break;         }       }     }   }   int main() {     cin >> n, tot = 1, S = 0, T = n + 1;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       if (a[i] & 1)         add(S, i, 2), add(i, S, 0);       else         add(i, T, 2), add(T, i, 0);     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j)         if (isprm(a[i] + a[j]) && a[i] % 2 == 1 && a[j] % 2 == 0)           add(i, j, 1), add(j, i, 0);     }     int fl = network.answer();     if (fl != n) return puts( Impossible ), 0;     for (int i = 1; i <= n; ++i)       if (a[i] & 1) {         if (!vis[i]) ++cnt, dfs(i, i);       }     printf( %d n , cnt);     for (int i = 1; i <= cnt; ++i) {       printf( %d , ans[i].size());       for (int j = 0; j < ans[i].size(); ++j) printf(  %d , ans[i][j]);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NMax = 1003;   enum directions { EAST, NORTH };   struct point {     int x, y;   };   point a[NMax];   int n;   int test(int searchDir, point a[], long double x, long double y) {     if (searchDir == NORTH) {       int nr = 0;       for (int i = 1; i <= n; ++i) {         if (a[i].y >= y &&             (((long double)a[i].x >= x && x <= (long double)a[i + 1].x) ||              ((long double)a[i].x <= x && x >= (long double)a[i + 1].x))) {           nr++;         }       }       return (nr & 1);     } else {       int nr = 0;       for (int i = 1; i <= n; ++i) {         if (a[i].x >= x &&             (((long double)a[i].y >= y && y <= (long double)a[i + 1].y) ||              ((long double)a[i].y <= y && y >= (long double)a[i + 1].y))) {           nr++;         }       }       return (nr & 1);     }   }   int main() {     cin >> n;     for (int i = 1; i <= n + 1; ++i) {       cin >> a[i].x >> a[i].y;     }     int ans = 0;     for (int i = 2; i <= n + 1; ++i) {       if (a[i].x == a[i - 1].x) {         if (a[i].y > a[i - 1].y) {           ans += test(EAST, a, a[i].x, a[i].y + 0.5);         } else {           ans += test(EAST, a, a[i].x, a[i].y - 0.5);         }       } else {         if (a[i].x > a[i - 1].x) {           ans += test(NORTH, a, a[i].x + 0.5, a[i].y);         } else {           ans += test(NORTH, a, a[i].x - 0.5, a[i].y);         }       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1051131;   const int Inv2 = (mod + 1) >> 1;   inline void setIO(string a) {}   long long Power;   int m, s, n, nn;   int a[(1 << 25) + 23];   void work(int n, int p, int q) {     if (n == 1) {       int &An = a[1];       (p += q) %= mod;       for (long long c = Power; c; c >>= 1, p = 1ll * p * p % mod)         if (c & 1) An = 1ll * An * p % mod;       return;     }     int t = n >> 1, tt = 1ll * t * p % mod;     int ttp = (p + q + mod - tt) % mod, tttp = 1;     for (long long c = Power; c; c >>= 1, ttp = 1ll * ttp * ttp % mod)       if (c & 1) tttp = 1ll * tttp * ttp % mod;     int xi = (1ll * t * p % mod - p + q + mod) % mod;     for (int i = (1); i <= (t); i++) {       int A = a[i], B = a[i + t];       a[i] = (A + B) % mod;       a[i + t] = (A + mod - B) % mod;       a[i + t] = 1ll * a[i + t] * tttp % mod;     }     work(n >> 1, (p + p) % mod, xi);     for (int i = (1); i <= (t); i++) {       int A = a[i], B = a[i + t];       a[i] = (A + B) % mod;       a[i + t] = (A + mod - B) % mod;       a[i] = 1ll * a[i] * Inv2 % mod;       a[i + t] = 1ll * a[i + t] * Inv2 % mod;     }   }   int main() {     scanf( %d , &m);     cin >> Power;     scanf( %d , &s);     for (int i = (1); i <= (s); i++) scanf( %d , &a[i]);     n = 1 << m;     nn = n;     for (int i = (s + 1); i <= (n); i++)       a[i] = (101ll * a[i - s] + 10007) % 1051131;     work(n, 1, 0);     int ans = 0;     for (int i = (1); i <= (n); i++) ans ^= a[i];     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, arr[30010], book[30010];   bool judge() {     int ps, gap;     int t1 = 1, t2;     while (t1 <= n && book[t1]) t1++;     t2 = t1 + 1;     if (t1 > n) return false;     while (t2 <= n && book[t2]) t2++;     if (t2 > n) return true;     gap = arr[t2] - arr[t1];     ps = t2;     for (int i = t2 + 1; i <= n; i++)       if (!book[i]) {         if (arr[i] - arr[ps] == gap)           ps = i;         else           return false;       }     return true;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &arr[i]);     if (n == 2)       printf( %d n%d , arr[1], arr[2]);     else {       int x[3] = {arr[2] - arr[1], arr[3] - arr[2], arr[3] - arr[1]};       int flag = 0;       for (int i = 0; i < 3; i++) {         int st = 4, tmp = arr[3];         memset(book, 0, sizeof(book));         if (i == 0) {           book[2] = book[1] = 1;           st = 3;           tmp = arr[2];         } else if (i == 1)           book[2] = book[3] = 1;         else           book[1] = book[3] = 1;         for (int ii = st; ii <= n; ii++)           if (arr[ii] == tmp + x[i]) {             book[ii] = 1;             tmp = arr[ii];           }         if (judge()) {           flag = 1;           break;         } else {           int p = n;           while (!book[p]) p--;           book[p] = 0;           if (judge()) {             flag = 1;             break;           }         }       }       if (flag) {         for (int i = 1; i <= n; i++)           if (book[i]) printf( %d  , arr[i]);         printf(  n );         for (int i = 1; i <= n; i++)           if (!book[i]) printf( %d  , arr[i]);       } else         printf( No solution );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ekub(int a, int b) { return b == 0 ? a : ekub(b, a % b); }   long long s[51][51];   int main() {     long long i, j, n, m, a, b, ans = 1e9;     cin >> n >> m;     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++) {         cin >> s[i][j];         s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];       }     cin >> a >> b;     for (i = a; i <= n; i++)       for (j = b; j <= m; j++)         ans = min(ans, s[i][j] - s[i - a][j] - s[i][j - b] + s[i - a][j - b]);     for (i = b; i <= n; i++)       for (j = a; j <= m; j++)         ans = min(ans, s[i][j] - s[i - b][j] - s[i][j - a] + s[i - b][j - a]);     cout << ans;   }


#include <bits/stdc++.h>   namespace P_TEMPLATE {   class fastin {    private:     int _ch, _f;       public:     inline fastin& operator>>(char& c) {       c = getchar();       return *this;     }     template <typename _Tp>     inline fastin& operator>>(_Tp& _x) {       _x = 0;       while (!isdigit(_ch)) _f |= (_ch == 45), _ch = getchar();       while (isdigit(_ch))         _x = (_x << 1) + (_x << 3) + (_ch ^ 48), _ch = getchar();       _f && (_x = -_x, _f = 0);       return *this;     }     fastin() { _ch = _f = 0; }   } fin;   class fastout {    private:     int _num[32], _head;       public:     inline fastout& operator<<(char c) {       putchar(c);       return *this;     }     template <typename _Tp>     inline fastout& operator<<(_Tp _x) {       _Tp _k;       if (_x == 0) {         putchar( 0 );         return *this;       }       if (_x < 0) putchar( - ), _x = -_x;       while (_x > 0)         _k = _x / 10, ++_head, _num[_head] = (_x - (_k << 1) - (_k << 3)) ^ 48,         _x = _k;       while (_head > 0) putchar(_num[_head]), --_head;       return *this;     }     fastout() { _head = 0; }   } fout;   inline void P_INIT() {}   }  // namespace P_TEMPLATE   using namespace P_TEMPLATE;   using namespace std;   const int maxn = 1000004, maxm = 104;   const int mod = 1000000007, inf = 1201201201;   int n, k, p;   char s[maxn][maxm];   int len[maxn];   int book[28], cnt[28];   vector<int> e[28];   queue<int> q;   int topo[28], indx;   inline bool check() {     for (register int i = 1; i <= 26; ++i)       if (!cnt[i]) q.push(i), topo[++indx] = i;     while (!q.empty()) {       int t = q.front();       q.pop();       for (register int i = 0; i < e[t].size(); ++i) {         --cnt[e[t][i]];         if (cnt[e[t][i]] == 0) q.push(e[t][i]), topo[++indx] = e[t][i];       }     }     return indx == 26;   }   signed main() {     P_INIT();     fin >> n >> k;     for (register int i = 1; i <= n; ++i) {       fin >> p;       for (register int j = 1; j <= k; ++j) {         scanf( %s , s[p * k + j] + 1), len[p * k + j] = strlen(s[p * k + j] + 1);         for (register int t = 1; t <= len[p * k + j]; ++t)           book[s[p * k + j][t] -  a  + 1] = 1;       }     }     for (register int i = 1; i < n * k; ++i) {       bool flag = 0;       for (register int j = 1; j <= std::min(len[i], len[i + 1]); ++j)         if (s[i][j] != s[i + 1][j]) {           e[s[i][j] -  a  + 1].push_back(s[i + 1][j] -  a  + 1);           ++cnt[s[i + 1][j] -  a  + 1];           flag = 1;           break;         }       if (!flag && len[i] > len[i + 1]) {         puts( IMPOSSIBLE );         return 0;       }     }     if (check()) {       for (register int i = 1; i <= 26; ++i)         if (book[topo[i]]) fout << char(topo[i] - 1 +  a );     } else       puts( IMPOSSIBLE );     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:66777216 )   using namespace std;   const int N = 100007;   int n, a[N], cnt[N];   vector<int> D[N];   long long power(long long a, long long b) {     if (b == 0) {       return 1;     }     if (b & 1) {       return (a * power(a, b - 1)) % 1000000007LL;     }     long long ret = power(a, b >> 1);     return (ret * ret) % 1000000007LL;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);     }     sort(a, a + n);     for (int i = 1; i <= a[n - 1]; ++i) {       for (int j = i; j <= a[n - 1]; j += i) {         D[j].push_back(i);       }     }     long long ans = 0;     for (int m = 1; m <= a[n - 1]; ++m) {       vector<int> &d = D[m];       int nd = (int)(d).size();       for (int i = 0; i < nd; ++i) {         cnt[i] = n - (lower_bound(a, a + n, d[i]) - a);       }       long long cur =           (power(nd, cnt[nd - 1]) - power(nd - 1, cnt[nd - 1]) + 1000000007LL) %           1000000007LL;       for (int i = 0; i < nd - 1; ++i) {         cur = (cur * power(i + 1, cnt[i] - cnt[i + 1])) % 1000000007LL;       }       ans = (ans + cur) % 1000000007LL;     }     printf( %d n , (int)ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void init_code() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   int main() {     init_code();     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<pair<int, int>> v;       vector<pair<int, int>> v1;       for (int i = 0; i < n; i++) {         int x, y;         cin >> x >> y;         v1.push_back({x, y});         v.push_back({x, y});       }       sort(v.begin(), v.end());       int st = v[0].first;       int ed = v[0].second;       int cnt = 1;       unordered_map<int, int> mp;       mp[st] = 1;       for (int i = 1; i < n; i++) {         if (v[i].first <= ed) {           mp[v[i].first] = cnt;           ed = max(ed, v[i].second);         } else {           st = v[i].first;           ed = v[i].second;           if (cnt == 1) {             cnt++;           }           mp[v[i].first] = cnt;         }       }       if (cnt < 2) {         cout <<  -1  << endl;       } else {         for (int i = 0; i < v1.size(); i++) {           cout << mp[v1[i].first] <<    ;         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {}   void no() {     cout <<  NO  <<   n ;     exit(0);   }   const long long maxn = 100050;   long long a[maxn];   long long psa[maxn];   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> a[i];     }     long long len = n;     for (long long i = 1; i <= n; i++) {       if (a[i] != a[1]) {         len = i - 1;         break;       }     }     for (long long i = 1; i <= n; i++) {       psa[i] = psa[i - 1] + a[i];     }     if (n % len) no();     for (long long i = len; i <= n; i += len) {       long long sum = psa[i] - psa[i - len];       if (sum and sum != len) {         no();       }       if (i >= len * 2) {         if (sum == psa[i - len] - psa[i - 2 * len]) {           no();         }       }     }     cout <<  YES  <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1234567;   int pref[N], a[N], b[N];   char c[N];   int solve(vector<pair<int, int> > z, int b) {     sort(z.begin(), z.end());     int cnt = z.size();     if (cnt < 2) {       return 0;     }     pref[0] = 0;     for (int i = 0; i < cnt; i++) {       pref[i + 1] = max(pref[i], z[i].second);     }     int i = 0;     int res = 0;     for (int j = cnt - 1; j >= 0; j--) {       while (i < j && z[i].first + z[j].first <= b) {         i++;       }       i = min(i, j);       if (i > 0) {         res = max(res, pref[i] + z[j].second);       }     }     return res;   }   int same(vector<pair<int, int> > &v, int b) {     if (v.size() < 2) return 0;     sort(v.begin(), v.end());     vector<int> pre(v.size() + 1, 0);     for (int i = 0; i < v.size(); i++) pre[i + 1] = max(pre[i], v[i].second);     int i = 0, ans = 0;     for (int j = v.size() - 1; j >= 0; j--) {       while (i < j && v[i].first + v[j].first <= b) i++;       i = min(i, j);       if (i > 0) {         ans = max(ans, v[j].second + pre[i]);       }     }     return ans;   }   int main() {     int n, C, D;     scanf( %d %d %d , &n, &C, &D);     for (int i = 0; i < n; i++) {       scanf( %d %d , a + i, b + i);       c[i] = getchar();       while (c[i] !=  C  && c[i] !=  D ) {         c[i] = getchar();       }     }     int ans = 0;     {       int x = 0, y = 0;       for (int i = 0; i < n; i++) {         if (c[i] ==  C  && b[i] <= C) {           x = max(x, a[i]);         }       }       for (int i = 0; i < n; i++) {         if (c[i] ==  D  && b[i] <= D) {           y = max(y, a[i]);         }       }       if (x > 0 && y > 0) {         ans = max(ans, x + y);       }     }     {       vector<pair<int, int> > z;       for (int i = 0; i < n; i++) {         if (c[i] ==  C ) {           z.push_back(make_pair(b[i], a[i]));         }       }       ans = max(ans, same(z, C));     }     {       vector<pair<int, int> > z;       for (int i = 0; i < n; i++) {         if (c[i] ==  D ) {           z.push_back(make_pair(b[i], a[i]));         }       }       ans = max(ans, same(z, D));     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   inline int abs(int n) { return n < 0 ? -n : n; }   bool board[20][20];   int dx[] = {-3, -2, -2, -1, -1, 0, 0, 1, 1, 2, 2, 3};   int dy[] = {0, 1, -1, 2, -2, 3, -3, 2, -2, 1, -1, 0};   int dfs(int p, int n, int m) {     int mx = p, t, cnt = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (!board[i][j]) {           board[i][j] = true;           for (int k = 0; k < 12; k++) {             int ic = i + dx[k], jc = j + dy[k];             if (ic >= 0 && ic < n && jc >= 0 && jc < m && !board[ic][jc]) {               board[ic][jc] = true;               t = dfs(p + 2, n, m);               mx < t && (mx = t);               if (mx == ((m * n) | 1) - 1) return mx;               board[ic][jc] = false;             }           }           board[i][j] = false;           cnt++;           if (m * n - cnt <= mx) return mx;         }       }     }     return mx;   }   int ans[] = {0, 0, 0, 0, 2, 4};   int main() {     int m, n;     scanf( %d%d , &m, &n);     if (m < 10 && n < 10) {       printf( %d n , dfs(0, n, m));     } else if (m == 1) {       printf( %d n , n / 6 * 6 + ans[n % 6]);     } else if (n == 1) {       printf( %d n , m / 6 * 6 + ans[m % 6]);     } else {       printf( %lld n , (((long long)(m)*n) | 1) - 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using db = long double;   using pll = pair<long long, long long>;   const long long sz = 300003;   long long dp[sz][2], n;   long long a[sz];   long long dfs(long long i, long long par) {     if (i >= n) return 0;     long long &res = dp[i][par];     if (res == -1) {       res = 0;       if (par) {         res = a[i] + dfs(i + 1, par ^ 1);       } else {         res = -a[i] + dfs(i + 1, par ^ 1);       }       res = max({0LL, res, dfs(i + 1, par)});     }     return res;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t, i, x, j, y, q, z, k;     int kkr, csk;     long long tt;     cin >> tt;     for (long long _tt = 0; _tt < tt; _tt++) {       cin >> n >> q;       for (int i = 0; i < n; i++) cin >> a[i];       ;       while (q-- > 0) {         cin >> x >> y;         x--, y--;       }       for (i = 0; i < n; i += 1) {         memset(dp[i], -1, sizeof(dp[i]));       }       z = dfs(0, 1);       42;       cout << z <<   n ;       ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n];       for (int i = 0; i < n; i++) cin >> arr[i];       int counts[n + 1];       memset(counts, 0, sizeof(counts));       if (n == 1) {         cout << 0 << endl;         continue;       }       for (int i = 0; i < n; i++) counts[arr[i]]++;       int dc = 0, rc = INT_MIN;       for (int i = 0; i <= n; i++) {         if (counts[i] > 0) dc++;         rc = max(rc, counts[i]);       }       if (rc > 1) dc--;       if (rc > dc + 1)         cout << dc + 1 << endl;       else         cout << min(dc, rc) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 105;   const int inf = 10000000;   int n, k;   int l[N], r[N];   int main() {     scanf( %d%d , &n, &k);     int midx = (k + 1) / 2, midy = (k + 1) / 2;     for (int i = 0; i < n; i++) {       int m, ans = inf, x, y1, y2;       scanf( %d , &m);       for (int row = 1; row <= k; row++) {         if (l[row] == 0 && r[row] == 0) {           for (int a = 1; a + m - 1 <= k; a++) {             int tot = 0, b = a + m - 1;             for (int col = a; col <= b; col++) {               tot += abs(row - midx) + abs(col - midy);             }             if (tot < ans) ans = tot, x = row, y1 = a, y2 = b;           }         } else {           if (l[row] > m) {             int tot = 0, a = l[row] - m, b = l[row] - 1;             for (int col = a; col <= b; col++) {               tot += abs(row - midx) + abs(col - midy);             }             if (tot < ans) ans = tot, x = row, y1 = a, y2 = b;           }           if (r[row] + m <= k) {             int tot = 0, a = r[row] + 1, b = r[row] + m;             for (int col = a; col <= b; col++)               tot += abs(row - midx) + abs(col - midy);             if (tot < ans) ans = tot, x = row, y1 = a, y2 = b;           }         }       }       if (ans == inf)         puts( -1 );       else {         printf( %d %d %d n , x, y1, y2);         if (r[x] == 0 && l[x] == 0)           l[x] = y1, r[x] = y2;         else           l[x] = min(l[x], y1), r[x] = max(r[x], y2);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 500010;   const int M = 16;   const int inf = 0x3f3f3f3f;   const int S = 1 << 15;   map<string, int> mp;   int vs[15], n, m;   char s[N][12], sx[12];   int dp[S], cnt[S][16];   int cal(int st) {     int res = 0;     while (st) {       if (st & 1) res++;       st >>= 1;     }     return res;   }   void prepare() {     for (int i = 0; i < S; ++i) {       int tmp = i;       for (int j = 0; j < M; ++j) {         tmp >>= 1;         cnt[i][j] = cal(tmp);       }     }   }   int stx[N], pre[M];   int main() {     prepare();     ios::sync_with_stdio(0);     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %s , sx);       mp[sx] = i;     }     int ans1 = -1, ans2 = 0, ans3 = 0;     scanf( %d , &m);     for (int i = 0; i < m; ++i) {       int k;       scanf( %d , &k);       memset(vs, 0, sizeof vs);       for (int j = 0; j < k; ++j) {         scanf( %s , s[j]);         if (mp.find(s[j]) == mp.end()) continue;         vs[mp[s[j]]] = 1;       }       int f = 0;       for (int j = 0; j < n && !f; ++j)         if (!vs[j]) f = 1;       if (f) continue;       int v = 0;       memset(dp, 0x3f, sizeof dp);       dp[0] = 0;       int pre = 0;       for (int j = 0; j < k; ++j) {         if (mp.find(s[j]) == mp.end()) continue;         int id = mp[s[j]], vst = 1 << id;         if (pre & (1 << id)) continue;         pre = (pre & ((1 << id) - 1) | (1 << id));         for (int st = stx[j] & (vst - 1); st < (1 << n); ++st)           if ((st & vst) == 0) {             dp[st | vst] = min(dp[st | vst], dp[st] + cnt[st][id]);           }       }       int tmp = n * (n - 1) / 2 - dp[(1 << n) - 1] + 1;       if (ans1 == -1 || tmp > ans2 || (tmp == ans2 && dp[(1 << n) - 1] < ans3)) {         ans1 = i;         ans2 = tmp;         ans3 = dp[(1 << n) - 1];       }     }     if (ans1 == -1)       puts( Brand new problem! );     else {       printf( %d n , ans1 + 1);       printf( %s ,  [: );       for (int i = 0; i < ans2; ++i) putchar( | );       puts( :] );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   using V = vector<T>;   const int MM = 5e5 + 5;   using T = long long;   bool QUERY;   struct Line {     mutable T a, b, p;     T Eval(T first) const { return a * first + b; }     bool operator<(const Line& o) const { return QUERY ? p < o.p : a < o.a; }   };   struct ConvexHull : multiset<Line> {     const T kInf = numeric_limits<T>::max();     T div(T a, T b) { return a / b - ((a ^ b) < 0 && a % b); }     bool isect(iterator first, iterator second) {       if (second == end()) {         first->p = kInf;         return false;       }       if (first->a == second->a) {         first->p = first->b > second->b ? kInf : -kInf;       } else {         first->p = div(second->b - first->b, first->a - second->a);       }       return first->p >= second->p;     }     void InsertLine(T a, T b) {       auto nx = insert({a, b, 0}), it = nx++, pv = it;       while (isect(it, nx)) {         nx = erase(nx);       }       if (pv != begin() && isect(--pv, it)) {         isect(pv, it = erase(it));       }       while ((it = pv) != begin() && (--pv)->p >= it->p) {         isect(pv, erase(it));       }     }     T EvalMax(T first) {       if (empty()) {         return -2e18;       }       QUERY = 1;       auto it = lower_bound({0, 0, first});       QUERY = 0;       return it->Eval(first);     }   };   vector<vector<int>> tree;   long long sub[MM];   long long n;   long long sq(long long e) { return e * e; }   void dfs1(int cur, int par) {     sub[cur] = 1;     for (auto u : tree[cur]) {       if (u != par) {         dfs1(u, cur);         sub[cur] += sub[u];       }     }   }   long long dp1[MM];   void dfs2(int cur, int par) {     dp1[cur] = sq(sub[cur]);     for (int u : tree[cur]) {       if (u != par) {         dfs2(u, cur);         dp1[cur] = min(dp1[cur], sq(sub[cur] - sub[u]) + dp1[u]);       }     }   }   vector<long long> ans;   void dfs3(int cur, int par) {     ConvexHull CH;     ans[cur] = sq(n);     for (int u : tree[cur]) {       if (u != par) {         dfs3(u, cur);         long long val = dp1[u] - CH.EvalMax(sub[u]) + sq(sub[u]);         ans[cur] = min(ans[cur], val);         ans[cur] = min(ans[cur], dp1[u] + sq(n - sub[u]));         CH.InsertLine(2 * (n - sub[u]), -(dp1[u] + sq(n - sub[u])));       }     }     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     tree.resize(n);     ans.resize(n);     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       tree[u].push_back(v);       tree[v].push_back(u);     }     dfs1(0, -1);     dfs2(0, -1);     dfs3(0, -1);     cout << (n * n - n) / 2 +                 (sq(n) - *min_element((ans).begin(), (ans).end())) / 2          << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Item {     int x[3], y[3];   };   bool check(Item t);   inline int Dist(int x1, int y1, int x2, int y2) {     return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);   }   int main() {     Item it;     for (int i = 0; i < 3; i++) cin >> it.x[i] >> it.y[i];     if (check(it))       cout <<  RIGHT n ;     else {       bool f = false;       for (int i = 0; i < 3; i++) {         Item tmp = it;         tmp.x[i]--;         if (check(tmp)) {           f = true;           break;         }         tmp.x[i] += 2;         if (check(tmp)) {           f = true;           break;         }       }       for (int i = 0; i < 3; i++) {         Item tmp = it;         tmp.y[i]--;         if (check(tmp)) {           f = true;           break;         }         tmp.y[i] += 2;         if (check(tmp)) {           f = true;           break;         }       }       if (f == true)         cout <<  ALMOST n ;       else         cout <<  NEITHER n ;     }     return 0;   }   bool check(Item t) {     int d[3];     int xx[3], yy[3];     d[0] = Dist(t.x[0], t.y[0], t.x[1], t.y[1]);     d[1] = Dist(t.x[0], t.y[0], t.x[2], t.y[2]);     d[2] = Dist(t.x[1], t.y[1], t.x[2], t.y[3]);     if (!d[0] || !d[1] || !d[2]) return false;     if (d[0] + d[1] == d[2] || d[1] + d[2] == d[0] || d[0] + d[2] == d[1])       return false;     xx[0] = t.x[0] - t.x[1];     yy[0] = t.y[0] - t.y[1];     xx[1] = t.x[0] - t.x[2];     yy[1] = t.y[0] - t.y[2];     xx[2] = t.x[1] - t.x[2];     yy[2] = t.y[1] - t.y[2];     if (xx[0] * xx[1] + yy[0] * yy[1] == 0 ||         xx[0] * xx[2] + yy[0] * yy[2] == 0 || xx[1] * xx[2] + yy[1] * yy[2] == 0)       return true;     else       return false;   }


#include <bits/stdc++.h>   using namespace std;   void input(long long int n, long long int a[]) {     for (long long int i = 0; i < n; ++i) cin >> a[i];   }   long long int bin_expo(long long int A, long long int B, long long int M) {     long long int result = 1ll;     while (B > 0) {       if (B % 2 == 1) {         result = (result * A) % M;       }       A = (A * A) % M;       B = B / 2;     }     return result;   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long int lcm(long long int a, long long int b) {     return (a * b) / gcd(a, b);   }   long long int n, l;   long long int a[101], b[101];   long long int dp[4001][200][3];   long long int solve(long long int left, long long int prev,                       long long int flag) {     if (left < 0) return 0LL;     if (left == 0) return 1LL;     if (dp[left][prev][flag] != -1) return dp[left][prev][flag];     long long int res = 0;     if (prev == -1) {       for (long long int i = 0; i < n; ++i) {         res += solve(left - a[i], i, 2);         if (a[i] != b[i]) res += solve(left - b[i], i, 1);         res %= 1000000007;       }     } else {       for (long long int i = 0; i < n; ++i) {         if (i != prev) {           long long int cur;           if (flag == 1) cur = a[prev];           if (flag == 2) cur = b[prev];           if (a[i] == cur)             res += solve(left - a[i], i, 2);           else if (b[i] == cur)             res += solve(left - b[i], i, 1);           res %= 1000000007;         }       }     }     return dp[left][prev][flag] = res % 1000000007;   }   int main() {     memset(dp, -1, sizeof(dp));     cin >> n >> l;     for (long long int i = 0; i < n; ++i) cin >> a[i] >> b[i];     cout << solve(l, -1, 0) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int sum, t, p, pos, a[100005], b[100005], n, f, c, f1;     cin >> t;     while (t--) {       memset(a, 0, sizeof(a));       memset(b, 0, sizeof(b));       cin >> n;       f = 1;       sum = 0;       p = 0;       f1 = 1, c = 0;       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++) cin >> b[i];       for (int i = 0; i < n; i++) {         if (f == 1 && a[i] != b[i]) {           if (p == 0) pos = i, p = 1, c = b[i] - a[i];           sum++;           f = 0;         } else if (a[i] > b[i])           f1 = 0;         else if (a[i] == b[i])           f = 1;       }       if (sum >= 2) {         cout <<  NO  << endl;       } else if (f1 == 0 || c < 0)         cout <<  NO  << endl;       else {         if (sum == 0)           cout <<  YES  << endl;         else {           for (int i = pos; a[i] != b[i]; i++) {             if (b[i] - a[i] != c) f1 = 0;           }           if (f1 == 0)             cout <<  NO  << endl;           else             cout <<  YES  << endl;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int left_[105], right_[105], mark[105];   int main() {     int n, j;     std::ios::sync_with_stdio(0);     while (~scanf( %d , &n)) {       int ans = 0;       memset(left_, 0, sizeof(left_));       memset(right_, 0, sizeof(right_));       memset(mark, 0, sizeof(mark));       for (int i = 1; i <= n; i++) {         scanf( %d %d , &left_[i], &right_[i]);         if (left_[i] == 0) mark[++ans] = i;       }       for (int i = 1; i < ans; i++) {         for (j = mark[i]; right_[j] != 0; j = right_[j])           ;         left_[mark[i + 1]] = j;         right_[j] = mark[i + 1];       }       for (int i = 1; i <= n; i++) printf( %d %d n , left_[i], right_[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int f, int s) {     if (s == 0)       return f;     else       return gcd(s, f % s);   }   int const N = 1000006;   long long const M = 1020;   long double const ep = .000000000000000001;   long long arr[N], arr1[N];   int main() {     int n, m;     scanf( %d , &n);     long long sum = 0, sum1 = 0;     for (int i = 0; i < n; i++) {       scanf( %lld , arr + i);       sum += arr[i];     }     scanf( %d , &m);     for (int i = 0; i < m; i++) {       scanf( %lld , arr1 + i);       sum1 += arr1[i];     }     if (sum == sum1) {       printf( 0 n0 );       return 0;     }     long long best = abs(sum - sum1);     int ind = -1, ind1 = -1;     for (int i = 0; i < n; i++) {       long long temp = sum, temp1 = sum1;       for (int x = 0; x < m; x++) {         temp -= arr[i];         temp += arr1[x];         temp1 -= arr1[x];         temp1 += arr[i];         if (abs(temp - temp1) < best) {           ind = i + 1, ind1 = x + 1;           best = abs(temp - temp1);         }         temp = sum, temp1 = sum1;       }     }     int indd = -1, indd1 = -1, indd2 = -1, indd21 = -1;     vector<pair<long long, pair<int, int> > > v, v1;     for (int i = 0; i < n; i++)       for (int x = i + 1; x < n; x++)         v.push_back(make_pair(arr[i] + arr[x], make_pair(i, x)));     for (int i = 0; i < m; i++)       for (int x = i + 1; x < m; x++)         v1.push_back(make_pair(arr1[i] + arr1[x], make_pair(i, x)));     sort(v1.begin(), v1.end());     long long want = (sum - sum1) / 2;     long long test = 1e17;     long long num = -1;     for (int i = 0; i < v.size(); i++) {       int left = 0, right = v1.size() - 1, mid;       while (left <= right) {         mid = (left + right) / 2;         long long curr = v[i].first - v1[mid].first;         if (test > abs(curr - want)) {           test = abs(curr - want);           num = curr;           indd = v[i].second.first + 1, indd1 = v[i].second.second + 1;           indd2 = v1[mid].second.first + 1, indd21 = v1[mid].second.second + 1;         }         if (curr > want)           left = mid + 1;         else           right = mid - 1;       }     }     long long s = sum, s1 = sum1;     s -= num;     s1 += num;     if (ind == -1 && indd == -1) {       printf( %lld n0 , best);       return 0;     }     if (best > abs(s - s1)) {       printf( %lld n , abs(s - s1));       printf( 2 n%d %d n%d %d , indd, indd2, indd1, indd21);     } else {       printf( %lld n , best);       printf( 1 n%d %d , ind, ind1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fact[100005];   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = ((res % p) * (x % p)) % p;       y = y >> 1;       x = ((x % p) * (x % p)) % p;     }     return res;   }   long long modInverse(long long n, long long p) { return power(n, p - 2, p); }   long long nCrModFermat(long long n, long long r, long long p) {     if (r == 0 || r == n) return 1;     return (((fact[n] % p) * (modInverse(fact[r], p) % p)) % p *             (modInverse(fact[n - r], p) % p)) %            p;   }   void sieve(vector<bool> &isPrime) {     long long n = isPrime.size();     isPrime[0] = false;     isPrime[1] = false;     for (long long i = 2; i * i <= n; i++) {       if (isPrime[i] == true) {         for (long long j = i * i; j <= n; j += i) isPrime[j] = false;       }     }   }   void addEdge(vector<long long> adj[], long long u, long long v) {     adj[u].push_back(v);     adj[v].push_back(u);   }   void BFS(long long s, vector<long long> adj[], vector<bool> &visited) {     deque<long long> q;     q.push_back(s);     visited[s] = true;     cout << s <<    ;     while (!q.empty()) {       long long p = q.front();       q.pop_front();       for (long long i = 0; i < adj[p].size(); i++) {         if (visited[adj[p][i]] == false) {           q.push_back(adj[p][i]);           visited[adj[p][i]] = true;           cout << adj[p][i] <<    ;         }       }     }   }   void DFSUtil(long long u, vector<long long> adj[], vector<bool> &visited) {     visited[u] = true;     cout << u <<    ;     for (long long i = 0; i < adj[u].size(); i++)       if (visited[adj[u][i]] == false) DFSUtil(adj[u][i], adj, visited);   }   void DFS(vector<long long> adj[], long long V) {     vector<bool> visited(V, false);     for (long long u = 0; u < V; u++)       if (visited[u] == false) DFSUtil(u, adj, visited);   }   void ChubbyCoder() {     long long n;     cin >> n;     cout << n <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long t;     t = 1;     cin >> t;     while (t--) {       ChubbyCoder();     }   }


#include <bits/stdc++.h>   using namespace std;   bool seat[100][100] = {0};   int main() {     int n, k;     scanf( %d %d , &n, &k);     while (n--) {       int num, x, l, r, min_sum;       min_sum = 100000;       scanf( %d , &num);       for (int i = 1; i <= k; i++) {         for (int j = 1; j <= k - num + 1; j++) {           int flag, sum;           sum = 0;           flag = 0;           for (int m = j; m <= j + num - 1; m++) {             if (seat[i][m]) {               flag = 1;               break;             }             sum += abs(i - k / 2 - 1) + abs(m - k / 2 - 1);           }           if (flag == 0 && sum < min_sum) {             x = i;             l = j;             r = j + num - 1;             min_sum = sum;           }         }       }       if (min_sum == 100000)         printf( -1 n );       else {         printf( %d %d %d n , x, l, r);         for (int i = l; i <= r; i++) seat[x][i] = 1;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n % 2 == 0) {       if (n >= 8 && n % 4 == 0)         cout << ((n / 4) - 1) << endl;       else if (n > 4 && n < 8)         cout <<  1  << endl;       else if (n <= 4)         cout <<  0  << endl;       else         cout << (n / 4) << endl;     } else {       cout <<  0  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, shet = 0;     long long int ans = 0;     cin >> n;     ans = n;     int* mas = new int[n];     for (int i = 0; i < n; i++) {       cin >> mas[i];     }     for (int i = 1; i < n; i++) {       if (mas[i] == mas[i - 1]) {         shet++;         ans += shet;       } else {         shet = 0;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     int a, i, temp;     long long int sum = 0, n, fra;     cin >> a;     for (i = 2; i <= a - 1; i++) {       temp = a;       while (temp > 0) {         sum += temp % i;         temp = temp / i;       }     }     temp = a - 2;     fra = gcd(sum, temp);     while (fra != 1) {       sum = sum / fra;       temp = temp / fra;       fra = gcd(sum, temp);     }     cout << sum <<  /  << temp << endl;   }


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


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const int M = 1e5 + 5;   const int N = 1e6 + 5;   const int mod = 1e9 + 7;   const double pi = acos(-1.0);   const int INF = 0x3f3f3f3f;   const long long lINF = 0x3f3f3f3f3f3f3f3fLL;   const int sINF = 0xcfcfcfcf;   char s[M * 2], s1[M];   int mx, tmp, len;   int main() {     scanf( %s , s1);     len = strlen(s1);     mx = tmp = 1;     strcpy(s, s1);     strcat(s + len, s1);     for (int i = 1; i < len * 2; i++) {       if (s[i] == s[i - 1]) {         mx = max(mx, tmp);         tmp = 1;       } else {         tmp++;         mx = max(mx, tmp);       }     }     mx = min(mx, len);     printf( %d n , mx);   }


#include <bits/stdc++.h>   using namespace std;       #define ll long long   #define vi vector<int>   #define pii pair<int,int>   #define mii map<int,int>   #define pqb priority_queue<int>   #define pqs priority_queue<int,vi,greater<int> >       #define ff first   #define ss second   #define pb push_back   #define mp make_pair   #define PI 3.1415926535897932384626   #define MOD 1000000007   #define ps(x,y) fixed<<setprecision(y)<<x      long long int fact[200005];      long long int pwr(long long int a,long long int b){       if(b==0) return 1;       if(b==1) return a%MOD;       long long int q = pwr((a*a)%MOD,b/2);       if(b%2) return (q*a)%MOD;       return q;   }      long long int C(long long int a,long long int b){       if(b<0) return 0;       if(a<b) return 0;          long long int t1 = (fact[a])%MOD;       long long int t2 = (fact[b]*fact[a-b])%MOD;       t2 = pwr(t2,MOD-2)%MOD;          return (t1*t2)%MOD;   }      void solve(){          long long int n,l,r;       cin>>n>>l>>r;          long long int ans=0;       ans = C(n,n/2)%MOD;       if(n%2) ans = (ans*2)%MOD;       ans = (ans*(min(1-l,r-n)))%MOD;        for(long long int p=min(1-l,r-n)+1;p<=min(r,n+1-l);p++){           long long int a = p + l - 1;           if(a<=0) a = 0;           long long int b = n + p - r;           if(b<=0) b=0;              ans = (C(n-a-b,n/2-a) + ans)%MOD;           if(n%2) ans = (C(n-a-b,n/2-b) + ans)%MOD;       }       cout<<ans<<endl;          return;       }        int main(){          ios_base::sync_with_stdio(false);       cin.tie(NULL);           // freopen( input.txt ,  r , stdin);       // freopen( error.txt ,  w , stderr);       // freopen( output.txt ,  w , stdout);          fact[0]=1;       for(long long int i=1;i<200005;i++){           fact[i] = (fact[i-1]*i)%MOD;       }           int t=1;       cin>>t;           for(int i=1;i<=t;i++){           // cout<< Case # <<i<< :  ;           solve();       }           cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl;       return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[10000];   int n, m, Q;   map<string, int> mem;   map<string, int>::iterator iter;   struct Func {     string name;     int num;     int v[10];     bool operator==(const Func& A) const {       if (name != A.name) return false;       if (num != A.num) return false;       for (int i = 0; i < num; ++i)         if (v[i] * A.v[i] != 0 && v[i] != A.v[i]) return false;       return true;     }   } g[2000], pre;   int Type(string x) {     if (x ==  T ) return 0;     if (x ==  int ) return 1;     if (x ==  double ) return 2;     if (x ==  string ) return 3;     return -1;   }   void inputFunc(int gs) {     gets(str);     int i = 0, j = 0, len = strlen(str);     while (str[j] !=  d ) ++j;     ++j;     while (j < len) {       if (str[j] !=    ) str[i++] = str[j];       j++;     }     len = i;     i = 0;     g[gs].name =   ;     while (str[i] !=  ( ) {       g[gs].name += str[i];       i++;     }     string temp =   ;     i++;     for (;;) {       if (str[i] ==  ,  || str[i] ==  ) ) {         g[gs].v[g[gs].num++] = Type(temp);         temp =   ;         if (str[i] ==  ) ) break;       } else         temp += str[i];       i++;     }   }   void inputType() {     string a, b;     cin >> a >> b;     mem[b] = Type(a);   }   void solve() {     gets(str);     int i = 0, j = 0, len = strlen(str);     for (j = 0; j < len; ++j) {       if (str[j] !=    ) str[i++] = str[j];     }     len = i;     i = 0;     pre.name =   ;     pre.num = 0;     while (str[i] !=  ( ) {       pre.name += str[i];       i++;     }     string temp =   ;     i++;     for (;;) {       if (str[i] ==  ,  || str[i] ==  ) ) {         pre.v[pre.num++] = mem.find(temp)->second;         temp =   ;         if (str[i] ==  ) ) break;       } else         temp += str[i];       i++;     }     int ans = 0;     for (int i = 0; i < n; ++i)       if (pre == g[i]) ++ans;     printf( %d n , ans);   }   int main() {     scanf( %d , &n);     gets(str);     for (int i = 0; i < n; ++i) inputFunc(i);     scanf( %d , &m);     gets(str);     mem.clear();     while (m--) inputType();     scanf( %d , &Q);     gets(str);     while (Q--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   int main() {     long long n, a;     long long fuck = 0, fucck = 0;     cin >> n;     priority_queue<int> prio1, prio2;     for (int i = 0; i < n; ++i) {       cin >> a;       prio1.push(a);       fuck += a;     }     for (int i = 0; i < n; ++i) {       cin >> a;       prio2.push(a);       fucck += a;     }     prio1.push(-1);     prio2.push(-1);     long long sum1 = 0, sum2 = 0;     int mark = 1;     for (int i = 0; i < 2 * n; ++i) {       if (mark == 1) {         if (prio1.top() >= prio2.top()) {           fuck -= prio1.top();           sum1 += prio1.top();           prio1.pop();         } else {           fucck -= prio2.top();           prio2.pop();         }         mark = 2;       } else {         if (prio2.top() >= prio1.top()) {           fucck -= prio2.top();           sum2 += prio2.top();           prio2.pop();         } else {           fuck -= prio1.top();           prio1.pop();         }         mark = 1;       }     }     cout << (sum1 - sum2) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<char, int> check(string s) {     map<char, int> used;     int l = s.size(), i, maxVal = 0;     char ans;     for (i = 0; i < l; i++) {       used[s.at(i)]++;       if (used[s.at(i)] > maxVal) {         maxVal = used[s.at(i)];         ans = s.at(i);       }     }     return make_pair(ans, maxVal);   }   int execute() {     int n, i, diff[4] = {0}, minVal = 10e8 + 7;     cin >> n;     vector<pair<char, int> > val(4);     string a[3];     for (i = 0; i < 3; i++) {       cin >> a[i];       val[i] = check(a[i]);       diff[i] = a[i].size() - val[i].second;       diff[i] = max(0 + (diff[i] + 1 == n && !diff[i]), diff[i] - n);       minVal = min(minVal, diff[i]);     }     int index;     for (i = 0; i < 3; i++) {       if (minVal == diff[i]) {         index = i;       }     }     sort(diff, diff + 3);     if (diff[0] == diff[1])       cout <<  Draw  << endl;     else {       switch (index) {         case (0):           cout <<  Kuro  << endl;           break;         case (1):           cout <<  Shiro  << endl;           break;         default:           cout <<  Katie  << endl;       }     }     return 0;   }   char mtest = false;   unsigned short TE = 1;   int main() {     ios_base::sync_with_stdio(false);     if (mtest) cin >> TE;     while (TE--) execute();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 1;   long long a[4], mn = 1e12 + 1;   char b, c, d;   int main() {     cin >> a[0] >> a[1] >> a[2] >> a[3];     cin >> b >> c >> d;     sort(a, a + 4);     do {       long long first, second, temp;       if (b ==  + )         first = a[0] + a[1];       else         first = a[0] * a[1];       long long a1[3];       a1[0] = first;       a1[1] = a[2];       a1[2] = a[3];       sort(a1, a1 + 3);       do {         if (c ==  + )           second = a1[0] + a1[1];         else           second = a1[0] * a1[1];         if (d ==  + )           temp = second + a1[2];         else           temp = second * a1[2];         mn = min(mn, temp);       } while (next_permutation(a1, a1 + 3));     } while (next_permutation(a, a + 4));     cout << mn;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[100010];   typedef struct record {     char ch;     int po;   } rec;   int main() {     int leng, ans, l, r;     rec tmp1, tmp2;     int tmp3;     bool flag;     stack<rec> st;     while (~scanf( %s , s)) {       flag = false;       while (!st.empty()) st.pop();       leng = strlen(s);       for (int i = 0; i < leng; i++) {         if (!st.empty()) tmp2 = st.top();         if (!st.empty() && ((tmp2.ch ==  (  && s[i] ==  ) ) ||                             (tmp2.ch ==  [  && s[i] ==  ] ))) {           st.pop();         } else {           tmp1.ch = s[i];           tmp1.po = i;           st.push(tmp1);         }       }       ans = 0;       if (st.empty()) {         for (int i = 0; i < leng; i++)           if (s[i] ==  [ ) ans++;         printf( %d n%s n , ans, s);       } else {         bool once = true;         flag = false;         ans = -1;         int tmpr, tmpl;         while (st.size() != 0) {           tmp3 = 0;           if (once) {             tmpr = leng - 1;             tmpl = st.top().po + 1;             once = false;           } else {             if (st.size() != 1) {               tmpr = st.top().po - 1;               st.pop();               tmpl = st.top().po + 1;             } else {               tmpr = st.top().po - 1;               tmpl = 0;               st.pop();             }           }           if (tmpl < tmpr) {             flag = true;             for (int j = tmpl; j <= tmpr; j++)               if (s[j] ==  [ ) tmp3++;           }           if (tmp3 > ans) {             ans = tmp3;             l = tmpl;             r = tmpr;           }         }         if (flag) {           printf( %d n , ans);           for (int i = l; i <= r; i++) printf( %c , s[i]);           printf(  n );         } else           printf( 0 n );       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int INF = 0x3f3f3f3f;   const long long inf = 0x3f3f3f3f3f3f3f3f;   const int mod = 1e9 + 7;   const int maxn = 1e3 + 5;   int n, m, qq, s[maxn][maxn], f[maxn][maxn];   bool vis[maxn][maxn];   int a[4] = {0, 1, 0, -1};   int b[4] = {-1, 0, 1, 0};   bool judge(int x, int y) {     for (int i = 0; i <= 3; i++) {       int xx = x + a[i], yy = y + b[i];       if (xx <= 0 || xx > n || yy <= 0 || yy > m) continue;       if (s[xx][yy] == s[x][y]) return true;     }     return false;   }   void bfs() {     queue<pair<int, int> > q;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (judge(i, j)) {           vis[i][j] = 1;           f[i][j] = 0;           q.push({i, j});         }       }     }     while (!q.empty()) {       int x = q.front().first;       int y = q.front().second;       q.pop();       for (int i = 0; i <= 3; i++) {         int xx = x + a[i], yy = y + b[i];         if (xx <= 0 || xx > n || yy <= 0 || yy > m) continue;         if (vis[xx][yy]) continue;         f[xx][yy] = f[x][y] + 1;         vis[xx][yy] = 1;         q.push({xx, yy});       }     }   }   int main() {     scanf( %d%d%d , &n, &m, &qq);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %1d , &s[i][j]);       }     }     bfs();     while (qq--) {       int x, y;       long long t;       scanf( %d%d%lld , &x, &y, &t);       if (vis[x][y]) {         if (t < f[x][y])           printf( %d n , s[x][y]);         else           printf( %d n , s[x][y] ^ ((t - f[x][y]) & 1));       } else {         printf( %d n , s[x][y]);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> adj[100005];   vector<int> vis(100005, 1);   vector<int> ans;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int T = 1;     for (int qq = 1; qq <= T; qq++) {       cin >> n >> m;       for (int i = 0; i < m; i++) {         int x, y;         cin >> x >> y;         adj[x].push_back(y);         adj[y].push_back(x);       }       priority_queue<int> v;       v.push(-1);       vis[1] = 0;       while (!v.empty()) {         int u = -v.top();         v.pop();         ans.push_back(u);         for (auto i : adj[u])           if (vis[i]) v.push(-i), vis[i] = 0;       }       for (auto i : ans) cout << i <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18 + 1e17;   const long long mod = 1e9 + 7;   long long modInverse(long long a, long long m) {     long long m0 = m;     long long y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       long long q = a / m;       long long t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += m0;     return x;   }   long long powm(long long a, long long b) {     a = a % mod;     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return (res % mod);   }   const long long N = 5e3 + 6;   int n, k, water;   vector<int> v;   int dp[N][2], dpr[N][2];   int arr[N];   bool brr[N];   int ip = 1e9;   void makedp() {     dp[0][0] = 1;     dp[0][1] = -1;     for (int i = 0; i < n; i++) {       int x = arr[i] % k;       memset(dpr, -1, sizeof(dpr));       dpr[0][0] = 1;       for (int j = 1; j < k; j++) {         if (dp[j][0] == 0 && dp[(j - x + k) % k][0] == 1) {           dpr[j][0] = 1;           dpr[j][1] = i;         } else {           dpr[j][0] = dp[j][0];           dpr[j][1] = dp[j][1];         }       }       swap(dpr, dp);     }   }   bool check() {     int tt = 0;     for (int i = 0; i < n; i++) tt += arr[i];     if (tt < water || dp[water % k][0] == 0) {       cout <<  NO n ;       return true;       ;     }     return false;   }   void find() {     int val = water % k;     int x = dp[val][1];     while (x != -1) {       v.push_back(dp[val][1]);       val = (val - arr[x] % k + k) % k;       x = dp[val][1];     }   }   void seperate() {     memset(brr, 0, sizeof(brr));     int tt = 0;     for (int i : v) {       brr[i] = 1;       tt += arr[i];     }     for (int i = 1; i < v.size(); i++)       cout << ip <<     << v[i] + 1 <<     << v[0] + 1 <<   n ;     int mark = -1;     int tc = 0;     for (int i = 0; i < n; i++)       if (!brr[i]) {         mark = i;         tc += arr[i];       }     for (int i = 0; i < n; i++)       if (!brr[i] && mark != i)         cout << ip <<     << i + 1 <<     << mark + 1 <<   n ;     if (v.size() == 0) v.push_back(0);     if (tt > water)       cout << (tt - water) / k <<     << v[0] + 1 <<     << (0 == v[0] ? 2 : 1)            <<   n ;     else if (tt < water)       cout << (water - tt) / k <<     << mark + 1 <<     << v[0] + 1 <<   n ;   }   void solve() {     cin >> n >> k >> water;     for (int i = 0; i < n; i++) cin >> arr[i];     makedp();     if (check()) return;     cout <<  YES n ;     find();     seperate();   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     for (long long i = 1; i <= t; i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int freq[27];   char sent[101];   int main() {     int n;     scanf( %d , &n);     scanf( %s , sent);     while (n--) {       if (isupper(sent[n])) sent[n] = tolower(sent[n]);       freq[sent[n] -  a ]++;     }     for (int i = 0; i < 26; i++)       if (!freq[i]) {         printf( NO n );         return 0;       }     printf( YES n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const int INF = 1e9 + 5;   int read(int base = 10) {     int x = 0;     char ch = getchar();     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) x = x * base + ch -  0 , ch = getchar();     return x;   }   struct Node {     int num[12][2];   } tree[N << 2];   void push_up(int o, int l, int r) {     int tmp[4];     for (int ii = 1; ii <= 11; ii++) {       tmp[0] = tree[o << 1].num[ii][0];       tmp[1] = tree[o << 1].num[ii][1];       tmp[2] = tree[o << 1 | 1].num[ii][0];       tmp[3] = tree[o << 1 | 1].num[ii][1];       sort(tmp, tmp + 4);       tree[o].num[ii][0] = tmp[0];       tree[o].num[ii][1] = tmp[1];     }   }   void build(int o, int l, int r) {     if (l == r) {       int x = read();       int tmp = x;       for (int ii = 1; ii <= 11; tmp /= 10, ii++) {         if (tmp % 10 == 0) {           tree[o].num[ii][0] = tree[o].num[ii][1] = INF;           continue;         }         tree[o].num[ii][0] = x;         tree[o].num[ii][1] = INF;       }       return;     }     int mid = (l + r) >> 1;     build(o << 1, l, mid);     build(o << 1 | 1, mid + 1, r);     push_up(o, l, r);   }   int id, x;   void update(int o, int l, int r) {     if (l == r) {       int tmp = x;       for (int ii = 1; ii <= 11; ii++, tmp /= 10) {         if (tmp % 10) {           tree[o].num[ii][0] = x;           tree[o].num[ii][1] = INF;         } else {           tree[o].num[ii][0] = tree[o].num[ii][1] = INF;         }       }       return;     }     int mid = (l + r) >> 1;     if (id <= mid)       update(o << 1, l, mid);     else       update(o << 1 | 1, mid + 1, r);     push_up(o, l, r);   }   int L, R, ans[12][2];   int tmp[4];   void query_up(int o, int i) {     tmp[0] = ans[i][0];     tmp[1] = ans[i][1];     tmp[2] = tree[o].num[i][0];     tmp[3] = tree[o].num[i][1];     sort(tmp, tmp + 4);     ans[i][0] = tmp[0];     ans[i][1] = tmp[1];   }   void query(int o, int l, int r) {     if (L <= l && r <= R) {       for (int ii = 1; ii <= 11; ii++) {         query_up(o, ii);       }       return;     }     int mid = (l + r) >> 1;     if (L <= mid) query(o << 1, l, mid);     if (R > mid) query(o << 1 | 1, mid + 1, r);   }   int main() {     int n = read(), m = read();     build(1, 1, n);     while (m--) {       int op = read();       if (op == 1) {         id = read(), x = read();         update(1, 1, n);       } else {         L = read(), R = read();         for (int i = 1; i <= 11; i++) ans[i][0] = ans[i][1] = INF;         query(1, 1, n);         int all = INF * 2;         ;         for (int i = 1; i <= 11; i++) {           if (ans[i][0] == INF || ans[i][1] == INF) continue;           all = min(all, ans[i][0] + ans[i][1]);         }         if (all == INF * 2) {           cout <<  -1 n ;         } else {           cout << all <<   n ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<  :   << arg1 << endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<  :   << arg1 <<   | ;     __f(comma + 1, args...);   }   const int INF = 1 << 30;   const int MOD = 1e9 + 7;   const int N = 1e6;   int a[N];   double sqr(double x) { return x * x; }   int main() {     int cas;     scanf( %d , &cas);     double ret = 0;     for (int num = 0; num < cas; ++num) {       int n = 250;       double ave = 0;       for (int i = 0; i < n; ++i) {         scanf( %d , &a[i]);         ave += a[i];       }       ave /= n;       double V = 0;       for (int i = 0; i < n; ++i) {         V += sqr(ave - a[i]);       }       V /= n;       double ratio = ave / V;       ret = max(ret, abs(ratio - 1));       puts(abs(ratio - 1) < 0.5 ?  poisson  :  uniform );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     string s;     cin >> s;     int ans = 0;     for (int i = 1; i < n; i++)       if (s[i - 1] ==  .  && s[i] ==  . ) ans++;     while (m--) {       int k;       char c;       cin >> k >> c;       if (c != s[k - 1]) {         if (c ==  . ) {           if (k > 1 && s[k - 2] ==  . ) ans++;           if (k < n && s[k] ==  . ) ans++;         }         if (s[k - 1] ==  . ) {           if (k > 1 && s[k - 2] ==  . ) ans--;           if (k < n && s[k] ==  . ) ans--;         }         s[k - 1] = c;       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int me;     int bebia;     int iliko = 0;     int ilarioni = 0;     cin >> me;     for (int i = 0; i < me; i++) {       cin >> bebia;       if (bebia > 0) iliko += bebia;       if (bebia == -1) {         if (iliko - 1 < 0) {           ilarioni++;         } else           iliko--;       }     }     cout << ilarioni;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, t;     int n;     int a[105];     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     int b[105] = {0};     int cnt = 1;     for (i = 0; i < n; i++) {       for (j = 0; j <= cnt; j++) {         if (!b[j]) {           b[j]++;           break;         } else if (b[j] <= a[i]) {           b[j]++;           break;         }       }       if (j == cnt) cnt++;     }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int i;     cin >> s;     for (i = 0; i < s.size(); i++) {       if (s[i] ==  r ) cout << i + 1 <<   n ;     }     for (i = s.size() - 1; i >= 0; i--) {       if (s[i] ==  l ) cout << i + 1 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long a, b, c, d;     cin >> a >> b >> c >> d;     long long sum = a + b + c + d;     if (sum % 2 == 0) {       if (a + b == sum / 2 || a + c == sum / 2 || a + d == sum / 2 ||           b + c == sum / 2 || b + d == sum / 2 || c + d == sum / 2 ||           a == sum / 2 || b == sum / 2 || c == sum / 2 || d == sum / 2)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     } else       cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, r, n, x;     cin >> x;     r = x % 4;     if (r == 0) {       cout <<  1             <<   A ;     }     if (r == 1) {       cout <<  0             <<   A ;     }     if (r == 2) {       cout <<  1             <<   B ;     }     if (r == 3) {       cout <<  2             <<   A ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline bool SR(int &x) { return scanf( %d , &x) == 1; }   inline bool SR(long long &x) { return scanf( %lld , &x) == 1; }   inline bool SR(double &x) { return scanf( %lf , &x); }   inline bool SR(char *s) { return scanf( %s , s); }   inline bool RI() { return 1; }   template <typename I, typename... T>   bool RI(I &x, T &...tail) {     return SR(x) && RI(tail...);   }   inline void SP(const int x) { printf( %d , x); }   inline void SP(const long long x) { printf( %lld , x); }   inline void SP(const double x) { printf( %.10f , x); }   inline void SP(const char *s) { printf( %s , s); }   inline void PL() { puts(  ); }   template <typename I, typename... T>   void PL(const I x, const T... tail) {     SP(x);     if (sizeof...(tail)) putchar(   );     PL(tail...);   }   template <typename I>   inline void _DOING(const char *s, I &&x) {     cerr << s <<   =   << x <<   n ;   }   template <typename I, typename... T>   void _DOING(const char *s, I &&x, T &&...tail) {     int c = 0;     while (*s !=  ,  || c != 0) {       if (*s ==  (  || *s ==  [  || *s ==  { ) c++;       if (*s ==  )  || *s ==  ]  || *s ==  } ) c--;       cerr << *s++;     }     cerr <<   =   << x <<   ,  ;     _DOING(s + 1, tail...);   }   const int INF = 0x3f3f3f3f;   const long long INF64 = 0x3f3f3f3f3f3f3f3fll;   inline int RAND() {     static int x = 880301;     return x = (x * 0xdefacedll + 1ll) % 0x7fffffffll;   }   int n;   map<pair<int, int>, int> rd;   inline bool check(long long a, int b) {     long long x = 1;     while (b) {       if (a >= n) return 0;       if (b & 1) x = x * a;       if (x >= n) return 0;       a = a * a;       b >>= 1;     }     return 1;   }   int dfs(int a, int b) {     if (rd.count(make_pair(a, b))) return rd[make_pair(a, b)];     if (!check(a, b)) return rd[make_pair(a, b)] = 1;     if (a == 1) {       if (!check(a + 1, b))         return rd[make_pair(a, b)] = 0;       else if (dfs(a + 1, b) == -1 || dfs(a, b + 1) == -1)         return rd[make_pair(a, b)] = 1;       else if (dfs(a + 1, b) == 0 || dfs(a, b + 1) == 0)         return rd[make_pair(a, b)] = 0;       else         return rd[make_pair(a, b)] = -1;     } else if (b == 1) {       if (1ll * a * a >= n) {         if ((n - a) & 1)           return rd[make_pair(a, b)] = -1;         else           return rd[make_pair(a, b)] = 1;       } else if (dfs(a + 1, b) == -1 || dfs(a, b + 1) == -1)         return rd[make_pair(a, b)] = 1;       else if (dfs(a + 1, b) == 0 || dfs(a, b + 1) == 0)         return rd[make_pair(a, b)] = 0;       else         return rd[make_pair(a, b)] = -1;     } else {       if (dfs(a + 1, b) == -1 || dfs(a, b + 1) == -1)         return rd[make_pair(a, b)] = 1;       else         return rd[make_pair(a, b)] = -1;     }   }   int main() {     int a, b;     RI(a, b, n);     int res = dfs(a, b);     if (res == 1)       PL( Masha );     else if (res == -1)       PL( Stas );     else       PL( Missing );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 50000 + 10;   int n;   int B[maxN];   vector<pair<int, int>> VB;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &B[i]);     for (int i = 0; i < n; i++) {       VB.push_back(make_pair(B[i] + B[(i + 1) % n], i));     }     sort(VB.begin(), VB.end());     for (int i = 0; i < n; i++) {       auto p = VB[i];       B[p.second] = i;     }     for (int i = 0; i < n; i++) printf( %d%c , B[i], (i == n - 1) ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int arr[5001], k = 0;     string s, in;     stack<int> s1;     while (getline(cin, s)) {       in = in + s;     }     for (int i = 0; i < in.size(); i++) {       char st[5001] = {  0 };       if (in[i] ==  < ) {         i++;         int j = 0;         while (in[i] !=  > ) {           st[j++] = in[i];           i++;         }       }       string st1 =  table , st2 =  tr , st3 =  td , st4 =  /table , st5 =  /tr ,              st6 =  /td ;       if (st1.compare(st) == 0) arr[k++] = 1;       if (st2.compare(st) == 0) arr[k++] = 2;       if (st3.compare(st) == 0) arr[k++] = 3;       if (st4.compare(st) == 0) arr[k++] = 4;       if (st5.compare(st) == 0) arr[k++] = 5;       if (st6.compare(st) == 0) arr[k++] = 6;     }     int z = -1, max = z;     vector<int> v, v1;     for (int i = 0; i < k; i++) {       if (arr[i] == 1) {         s1.push(arr[i]);         v.push_back(0);       }       if (arr[i] == 2) s1.push(arr[i]);       if (arr[i] == 3) s1.push(arr[i]);       if (arr[i] == 4) {         s1.pop();         v1.push_back(v.back());         v.pop_back();       }       if (arr[i] == 5) s1.pop();       if (arr[i] == 6) {         s1.pop();         v.back()++;       }     }     sort(v1.begin(), v1.end());     for (int i = 0; i < v1.size(); i++) cout << v1[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char *argv[]) {     int n, tmp = 1, res = 1;     cin >> n;     int A[n][2];     for (int i = 0; i < n; i++) cin >> A[i][0] >> A[i][1];     for (int i = 0; i < n - 1; i++) {       if ((A[i][0] == A[i + 1][0]) && (A[i][1] == A[i + 1][1])) {         tmp++;         if (res < tmp) res = tmp;       } else         tmp = 1;     }     cout << res << endl;     return EXIT_SUCCESS;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long int expo_fast(long long int a, long long int b) {     a = a;     long long int result = 1;     while (b) {       if (b & 1) result = (result * a);       b >>= 1;       a = (a * a);     }     return (result);   }   void take_in(vector<long long int> *arr) {     for (int i = 0; i < arr->size(); i++) cin >> (*(arr))[i];   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   unsigned long long int power(long long int x, unsigned long long int y,                                long long int p) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, x1, x2, done = 0;     cin >> n >> x1 >> x2;     vector<pair<long long int, long long int> > arr;     vector<long long int> dp(n + 1);     for (int i = 0; i < n; i++) {       long long int x;       cin >> x;       arr.push_back({x, i});     }     sort(arr.begin(), arr.end());     dp[n] = arr[n - 1].first;     for (int i = n - 1; i > 0; i--) {       dp[i] = max(dp[i + 1], arr[i - 1].first * (n - i + 1));     }     auto bs = [n](long long int x, long long int tar) -> long long int {       int low = 1, high = n, ans = n + 1;       while (low <= high) {         int mid = (low + high) / 2;         if (x * mid >= tar) {           ans = mid;           high = mid - 1;         } else           low = mid + 1;       }       return ans;     };     for (int i = 1; i <= n; i++) {       vector<int> indx;       long long int len = bs(arr[i - 1].first, x1);       if (i + len - 1 < n && dp[i + len] >= x2) {         done = 1;         cout <<  Yes n ;         for (int j = n; j >= 1; j--) {           if (dp[j] >= x2) {             indx.push_back(j);             indx.push_back(n);             break;           }         }         cout << len <<     << indx[1] - indx[0] + 1 <<   n ;         for (int k = i; k < i + len; k++) cout << arr[k - 1].second + 1 <<    ;         cout <<   n ;         for (int k = indx[0]; k <= n; k++) cout << arr[k - 1].second + 1 <<    ;         break;       }       if (!done) {         len = bs(arr[i - 1].first, x2);         if (i + len - 1 < n && dp[i + len] >= x1) {           done = 1;           cout <<  Yes n ;           for (int j = n; j >= 1; j--) {             if (dp[j] >= x1) {               indx.push_back(j);               indx.push_back(n);               break;             }           }           cout << indx[1] - indx[0] + 1 <<     << len <<   n ;           for (int k = indx[0]; k <= n; k++) cout << arr[k - 1].second + 1 <<    ;           cout <<   n ;           for (int k = i; k < i + len; k++) cout << arr[k - 1].second + 1 <<    ;           break;         }       }     }     if (!done) cout <<  No ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, l[100100], c[100100];   vector<int> g[100100];   vector<int> s;   void dfs(int t) {     s.push_back(t);     l[t] = s.size();     for (auto v : g[t]) {       if (!l[v])         dfs(v);       else {         if (l[t] - l[v] + 1 >= k) {           printf( 2 n%d n , l[t] - l[v] + 1);           for (int i = l[v] - 1; i < l[t]; i++) printf( %d  , s[i]);           exit(0);         }       }     }     if (!c[t])       for (auto v : g[t]) c[v] = 1;     s.pop_back();   }   int main() {     int i, a, b;     scanf( %d %d , &n, &m);     for (i = 0; i < m; i++) {       scanf( %d %d , &a, &b);       g[a].push_back(b);       g[b].push_back(a);     }     while (k * k < n) k++;     dfs(1);     printf( 1 n );     for (i = 1; k; i++) {       if (!c[i]) {         printf( %d  , i);         k--;       }     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[200008];   int val[200008];   int n, tk;   int dp[200008];   int lim;   int siz[200008];   int cnt, tot;   int no[200008];   void dfs(int x, int p) {     no[x] = val[x] < lim;     dp[x] = 0;     int b1 = 0, b2 = 0, b3 = 0;     siz[x] = 1;     for (int i = 0; i < v[x].size(); i++) {       int y = v[x][i];       if (y == p) continue;       dfs(y, x);       siz[x] += siz[y], no[x] += no[y];       if (no[y] == 0)         b3 += siz[y];       else {         if (dp[y] > b1)           b2 = b1, b1 = dp[y];         else           b2 = max(b2, dp[y]);       }     }     if (val[x] < lim) return;     dp[x] = b1 + b3 + 1;     if (tot == no[x])       cnt = max(cnt, 1 + n - siz[x] + b1 + b2 + b3);     else       cnt = max(cnt, 1 + b1 + b2 + b3);   }   int check(int mid) {     lim = mid;     cnt = 0;     tot = 0;     for (int i = 1; i <= n; i++)       if (val[i] < lim) tot++;     dfs(1, 0);     return cnt >= tk;   }   int main() {     scanf( %d%d , &n, &tk);     for (int i = 1; i <= n; i++) scanf( %d , &val[i]);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       v[x].push_back(y);       v[y].push_back(x);     }     int l = 0, r = 1000000;     int ans = -1;     while (l <= r) {       int mid = (l + r) / 2;       if (check(mid))         ans = mid, l = mid + 1;       else         r = mid - 1;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int mini(long long int p, long long int q) {     if (p < q) return p;     return q;   }   int main() {     long long int k2, k3, k5, k6, total = 0;     cin >> k2 >> k3 >> k5 >> k6;     int m = 0;     m = mini(k2, k5);     m = mini(m, k6);     total = m * 256;     m = mini(k2 - m, k3);     total += m * 32;     cout << total << endl;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 2.0 * acos(0.0);   inline int getInt() {     int x;     scanf( %d , &x);     return x;   }   inline long long getLL() {     long long x;     scanf( %lld , &x);     return x;   };   inline int NUM(char c) { return (int)c - 48; }   inline char CHR(int n) { return (char)(n + 48); }   template <class T>   inline T MAX(T a, T b) {     if (a > b) return a;     return b;   }   template <class T>   inline T MIN(T a, T b) {     if (a < b) return a;     return b;   }   inline void OPEN(const string &s) {     freopen((s +  .in ).c_str(),  r , stdin);     freopen((s +  .out ).c_str(),  w , stdout);   }   map<string, int> score, sco, mis;   map<string, int> times;   int main() {     vector<string> v;     for (int k = 0, _n = (5); k < _n; k++) {       string A, B, C;       cin >> A >> B;       cin >> C;       for (int i = 0, _n = ((C).size()); i < _n; i++)         if (C[i] ==  : ) C[i] =    ;       stringstream ss(C);       int s, m;       ss >> s >> m;       if (s > m)         score[A] += 3;       else if (s < m)         score[B] += 3;       else {         score[A]++;         score[B]++;       }       sco[A] += s;       mis[A] += m;       sco[B] += m;       mis[B] += s;       v.push_back(A);       v.push_back(B);       times[A]++;       times[B]++;     }     sort((v).begin(), (v).end());     v.resize(unique((v).begin(), (v).end()) - v.begin());     string OTHER;     for (int i = 0, _n = ((v).size()); i < _n; i++) {       if (times[v[i]] == 2 && v[i] !=  BERLAND ) OTHER = v[i];     }     vector<pair<int, pair<int, pair<int, string> > > > sorted;     for (int d = (1), _b = (50); d <= _b; d++) {       for (int m = (0), _b = (50); m <= _b; m++) {         int s = m + d;         string A, B;         A =  BERLAND , B = OTHER;         score[A] += 3;         sco[A] += s;         sco[B] += m;         mis[B] += s;         mis[A] += m;         sorted.clear();         for (int i = 0, _n = ((v).size()); i < _n; i++) {           sorted.push_back(make_pair(               -score[v[i]],               make_pair(-sco[v[i]] + mis[v[i]], make_pair(-sco[v[i]], v[i]))));         }         sort((sorted).begin(), (sorted).end());         if (sorted[0].second.second.second ==  BERLAND  ||             sorted[1].second.second.second ==  BERLAND ) {           cout << s <<  :  << m << endl;           return 0;         }         score[A] -= 3;         sco[A] -= s;         sco[B] -= m;         mis[B] -= s;         mis[A] -= m;       }     }     cout <<  IMPOSSIBLE  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1 << 20, KOR = 32000;   const long long INF = 1e18;   int n;   int p[MAX];   int sito[KOR];   int bezp[MAX], sp[MAX];   int cijseg, cijprom;   vector<int> Pr;   void Eratosten() {     for (int i = 2; i < KOR; i++) {       if (!sito[i]) {         Pr.push_back(i);         for (int j = 2 * i; j < KOR; j += i) sito[j] = i;       }     }   }   vector<int> Fak(int x) {     vector<int> R;     for (int i = 0; i < (int)Pr.size(); i++) {       if (!(x % Pr[i])) R.push_back(Pr[i]);       for (; !(x % Pr[i]); x /= Pr[i])         ;     }     if (x > 1) R.push_back(x);     return R;   }   long long Rijesi(int x) {     memset(bezp, 0, sizeof bezp);     memset(sp, 0, sizeof sp);     int prvi = n, zadnji = 0;     int ukprom = 0;     for (int i = 0; i < n; i++) {       if (!(p[i] % x)) bezp[i] = 1;       if (!((p[i] + 1) % x) || !((p[i] - 1) % x)) sp[i] = 1;       if (!bezp[i] && !sp[i]) {         prvi = min(prvi, i);         zadnji = max(zadnji, i);       }       if (!bezp[i] && sp[i]) ukprom++;     }     if (!ukprom && prvi == n) return 0;     long long ret = INF;     if (prvi == n) ret = (long long)cijprom * ukprom;     long long maxx = -cijseg;     int tprom = 0;     for (int i = 0; i < n; i++) {       if (!bezp[i] && sp[i]) tprom++;       if (i >= zadnji)         ret = min(ret, (long long)i * cijseg - maxx +                            ((long long)ukprom - tprom) * cijprom);       if (i < prvi)         maxx = max(maxx, (long long)-tprom * cijprom + (long long)i * cijseg);     }     return ret;   }   int main() {     Eratosten();     scanf( %d%d%d , &n, &cijseg, &cijprom);     for (int i = 0; i < n; i++) scanf( %d , &p[i]);     long long rje = INF;     vector<int> Bitni;     for (int i = -1; i <= 1; i++) {       vector<int> T = Fak(p[0] + i);       for (int j = 0; j < (int)T.size(); j++) Bitni.push_back(T[j]);     }     for (int i = -1; i <= 1; i++) {       vector<int> T = Fak(p[n - 1] + i);       for (int j = 0; j < (int)T.size(); j++) Bitni.push_back(T[j]);     }     sort(Bitni.begin(), Bitni.end());     Bitni.resize(unique(Bitni.begin(), Bitni.end()) - Bitni.begin());     for (int i = 0; i < (int)Bitni.size(); i++) rje = min(rje, Rijesi(Bitni[i]));     printf( %lld n , rje);     return 0;   }