#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,avx,avx2 )   const long long maxn = 64, mod = 1e9 + 7, INF = 1e9, lg = 15 + 1, SQRT = 400;   int n, a[maxn], par[maxn], SZ_T[maxn], FAC[maxn], INV[maxn];   vector<int> adj1[maxn], adj2[maxn], cmp;   long long dp[(1 << lg)][maxn], ans[maxn];   bool mark[maxn];   inline long long power(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) {         res = (res * a) % mod;       }       b /= 2;       a = (a * a) % mod;     }     return res;   }   inline void make_graph() {     sort(a, a + n);     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         if (a[j] % a[i] == 0) {           adj1[i].push_back(j);           adj1[j].push_back(i);         }       }     }   }   void dfs(int v) {     mark[v] = 1;     cmp.push_back(a[v]);     for (auto u : adj1[v]) {       if (!mark[u]) {         dfs(u);       }     }   }   inline void get(int cnt) {     memset(dp, 0, sizeof dp);     sort(cmp.begin(), cmp.end());     vector<int> s, t;     for (int i = 0; i < cmp.size(); ++i) {       bool is = 0;       for (int j = 0; j < i; ++j) {         if (cmp[i] % cmp[j] == 0) is = 1;       }       if (!is) {         s.push_back(cmp[i]);       } else {         t.push_back(cmp[i]);       }     }     for (int i = 0; i < t.size(); ++i) {       par[i] = 0;       for (int j = 0; j < s.size(); ++j) {         if (t[i] % s[j] == 0) {           par[i] |= (1 << j);         }       }     }     SZ_T[cnt] = t.size();     if (!t.size()) {       ans[cnt] = 1;       return;     }     for (int i = 0; i < t.size(); ++i) {       dp[par[i]][1]++;     }     for (int mask = 0; mask < (1 << s.size()); ++mask) {       for (int i = 0; i < t.size(); ++i) {         int counter = 0;         for (int j = 0; j < t.size(); ++j) {           if ((mask | par[j]) == mask) {             counter++;           } else if (mask & par[j]) {             dp[mask | par[j]][i + 1] =                 (dp[mask][i] + dp[mask | par[j]][i + 1]) % mod;           }         }         if (counter > i)           dp[mask][i + 1] =               (dp[mask][i + 1] + (dp[mask][i] * (counter - i)) % mod) % mod;       }     }     ans[cnt] = dp[(1 << s.size()) - 1][t.size()];   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     FAC[0] = INV[0] = 1;     for (int i = 1; i < maxn; ++i) {       FAC[i] = (FAC[i - 1] * i) % mod;       INV[i] = power(FAC[i], mod - 2);     }     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     make_graph();     int cnt = 0;     for (int i = 0; i < n; ++i) {       if (!mark[i]) {         dfs(i);         get(cnt);         cnt++;         cmp.clear();       }     }     long long res = 1, SZ = 0;     for (int i = 0; i < cnt; ++i) {       res = (res * ans[i]) % mod;       SZ += max(SZ_T[i] - 1, 0);     }     long long h = FAC[SZ];     for (int i = 0; i < cnt; ++i) {       h = (h * INV[max(SZ_T[i] - 1, 0)]) % mod;     }     res = (res * h) % mod;     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, s = 0, c = 0;     cin >> n;     for (long long int i = 0; i < n; i++) {       long long x;       cin >> x;       s += x;       if (x % 2 != 0) c = 1;     }     if (s % 2 != 0) {       cout <<  First ;     } else {       if (c)         cout <<  First ;       else         cout <<  Second ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d, moves = 0;     int* b;     cin >> n >> d;     b = new int[n];     cin >> b[0];     for (int i = 1; i < n; i++) {       cin >> b[i];       if (b[i] <= b[i - 1]) {         int time = (b[i - 1] - b[i]) / d + 1;         b[i] += time * d;         moves += time;       }     }     delete[] b;     cout << moves;   }


#include <bits/stdc++.h>   using std::cerr;   using std::endl;   const int N = 2005, INF = 1e9, P = 998244353;   int n, G[N][N];   char str[N];   int deg[N];   inline int binom(int x) { return x * (x - 1) / 2; }   inline bool check() {     std::sort(deg + 1, deg + n + 1);     int sum = 0;     for (int i = 1; i < n; ++i) {       sum += deg[i];       if (sum == binom(i)) return 0;     }     return 1;   }   namespace SOL1 {   inline bool Check(int s) {     for (int i = 1; i <= n; ++i) deg[i] = 0;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) {         int cnt = ((s >> (i - 1)) & 1) + ((s >> (j - 1)) & 1);         if (cnt == 1) {           if (G[i][j]) ++deg[i];         } else {           if (G[j][i]) ++deg[i];         }       }     return check();   }   inline void solve() {     int min = INF, cnt = 0;     for (int s = 0; s < 1 << n; ++s) {       if (__builtin_popcount(s) > min) continue;       if (Check(s)) {         if (__builtin_popcount(s) < min) min = __builtin_popcount(s), cnt = 0;         if (__builtin_popcount(s) == min) {           ++cnt;         }       }     }     if (min == INF)       puts( -1 );     else {       for (int i = 1; i <= min; ++i) cnt = 1ll * cnt * i % P;       printf( %d %d n , min, cnt);     }   }   }  // namespace SOL1   namespace SOL2 {   int buc[N];   inline void solve() {     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j)         if (G[j][i]) ++deg[i], ++buc[i];     if (check()) {       std::cout << 0 <<     << 1 << std::endl;       return;     }     int cnt = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) deg[j] = buc[j];       for (int j = 1; j <= n; ++j) {         if (G[j][i]) --deg[i], ++deg[j];         if (G[i][j]) ++deg[i], --deg[j];       }       cnt += check();     }     std::cout << 1 <<     << cnt << std::endl;   }   }  // namespace SOL2   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %s , str + 1);       for (int j = 1; j <= n; ++j) G[i][j] = str[j] -  0 ;     }     if (n <= 6)       SOL1::solve();     else       SOL2::solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class TaskD {    public:     unsigned long long compute(vector<pair<int, int> >& a,                                const vector<unsigned long long>& tag) {       vector<pair<int, int> > events;       for (int i = 0; i < a.size(); ++i) {         events.emplace_back(a[i].first, -(i + 1));         events.emplace_back(a[i].second, i + 1);       }       sort(events.begin(), events.end());       unsigned long long sum = 0;       unsigned long long res = 0;       for (const auto& e : events) {         if (e.second < 0) {           res += sum * tag[-e.second - 1];           sum += tag[-e.second - 1];         } else {           sum -= tag[e.second - 1];         }       }       return res;     }     void solveOne(istream& in, ostream& out) {       auto seed = std::chrono::system_clock::now().time_since_epoch().count();       mt19937 rng(seed);       uniform_int_distribution<unsigned long long> distrib;       int n;       in >> n;       vector<pair<int, int> > a(n);       vector<pair<int, int> > b(n);       vector<unsigned long long> tag(n);       for (int i = 0; i < n; ++i) {         in >> a[i].first >> a[i].second >> b[i].first >> b[i].second;         tag[i] = distrib(rng) * 2 + 1;       }       auto ha = compute(a, tag);       auto hb = compute(b, tag);       if (ha == hb) {         out <<  YES n ;       } else {         out <<  NO n ;       }     }     void solve(std::istream& in, std::ostream& out) {       int nt = 1;       for (int it = 0; it < nt; ++it) {         solveOne(in, out);       }     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     TaskD solver;     std::istream& in(std::cin);     std::ostream& out(std::cout);     solver.solve(in, out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, res, t, k, o;   long long a[1000100], b[1000100];   priority_queue<int, vector<int>, greater<int> > q;   int main() {     scanf( %lld %lld , &n, &k);     for (long long i = 1; i <= n; i++) {       scanf( %lld , &a[i]);     }     scanf( %lld , &m);     for (long long i = 1; i <= n; i++) {       scanf( %lld , &b[i]);     }     res = 0;     for (int i = 1; i <= n; i++) {       q.push(b[i]);       while (k < a[i] && !q.empty()) {         k = k + m;         res += q.top();         q.pop();       }       if (k < a[i]) {         res = -1;         break;       }     }     printf( %lld n , res);   }


#include <bits/stdc++.h>   using namespace std;   long long mod_v(long long num) {     if (num >= 0)       return (num % 1000000007);     else       return (num % 1000000007 + 1000000007) % 1000000007;   }   long long bigmod(long long b, long long p, long long m) {     long long res = 1 % m, x = b % m;     while (p) {       if (p & 1) res = (res * x) % m;       x = (x * x) % m;       p >>= 1;     }     return res;   }   class node {    public:     int s, w;     node(){};     node(int s, int w) {       this->s = s;       this->w = w;     };   };   bool operator<(node a, node b) {     if (a.w < b.w)       return true;     else       return false;   }   bool vol[100005] = {0};   int vis[100005] = {0};   vector<int> adj[100005];   int n;   bool solve(int q, int s, int d) {     memset(vis, 0, sizeof(vis));     vis[s] = q;     priority_queue<node> pq;     pq.push(node(s, q));     while (!pq.empty()) {       s = pq.top().s;       pq.pop();       if (s == d) return true;       for (int i = 0, ns; i < adj[s].size(); i++) {         ns = adj[s][i];         if (ns == d) return true;         if (vol[ns] == 1 && vis[ns] < q) {           vis[ns] = q;           pq.push(node(ns, vis[ns]));         } else if (vis[ns] < vis[s] - 1) {           vis[ns] = vis[s] - 1;           pq.push(node(ns, vis[ns]));         }       }     }     return false;   }   int main() {     int m, k, u, v, s, d;     scanf( %d %d %d , &n, &m, &k);     for (int i = 1; i <= k; i++) {       scanf( %d , &u);       vol[u] = 1;     }     for (int i = 1; i <= m; i++) {       scanf( %d %d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     scanf( %d %d , &s, &d);     int l = 1, r = n, mid;     while (l < r) {       mid = (l + r) / 2;       if (solve(mid, s, d))         r = mid;       else         l = mid + 1;     }     if (l == n)       printf( -1 n );     else       cout << l << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a[3000], b[3000], w[500], pos[500][5000], ans;   string second;   int ispal(int x, int y) {     int t = y;     while (x != y) {       if (second[x] != second[y]) return 0;       if (y - x == 1 || y - x == 2) {         b[t]++;         return 1;       }       x++, y--;     }   }   int main() {     cin >> second;     for (int i = second.size() - 1; i >= 0; i--) {       a[i] = a[i + 1] + 1;       for (int j = 0; j < w[second[i] - 97]; j++) {         a[i] += ispal(i, pos[second[i] - 97][j]);       }       pos[second[i] - 97][w[second[i] - 97]] = i;       w[second[i] - 97]++;     }     for (int i = 0; i < second.size() - 1; i++) {       b[i]++;       ans += b[i] * a[i + 1];     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, int> Id;   char Name[107][15], Str[107][150];   int dp[107][107], last[107][107], record[107][107], vis[107];   void Show(int Step, int k) {     if (Step - 1) Show(Step - 1, last[Step][k]);     int pos = 0;     while (Str[Step][pos] !=  : ) pos++;     printf( %s%s n , Name[k], Str[Step] + pos);   }   bool Judge(char t) {     if (t >=  a  && t <=  z )       return true;     else if (t >=  A  && t <=  Z )       return true;     else if (t >=  0  && t <=  9 )       return true;     else       return false;   }   int main() {     int t, n, m;     string tmp;     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       Id.clear();       for (int i = 1; i <= n; i++) {         scanf( %s , Name[i]);         Id[string(Name[i])] = i;       }       memset(record, 0, sizeof(record));       memset(vis, 0, sizeof(vis));       scanf( %d , &m);       getchar();       for (int i = 1; i <= m; i++) {         gets(Str[i]);         int pos = 0;         if (Str[i][0] !=  ? ) {           while (Str[i][pos] !=  : ) pos++;           int re = Id[string(Str[i], pos)];           record[i][re] = 1;           vis[re] = 1;           continue;         } else {           for (int j = 1; j <= n; j++) record[i][j] = 1;           while (1) {             while (!Judge(Str[i][pos]) && Str[i][pos]) pos++;             if (Str[i][pos] ==   0 ) break;             int tt = pos;             while (Judge(Str[i][pos])) pos++;             int re = Id[string(Str[i], tt, pos - tt)];             if (re || vis[re]) record[i][re] = 0;           }         }       }       memset(dp, 0, sizeof(dp));       memset(last, 0, sizeof(last));       for (int i = 1; i <= m; i++) {         if (i == 1) {           for (int j = 1; j <= n; j++) dp[i][j] = record[i][j];         } else {           for (int j = 1; j <= n; j++) {             if (!record[i][j]) continue;             for (int k = 1; k <= n; k++) {               if (j == k || !dp[i - 1][k]) continue;               last[i][j] = k;               dp[i][j] = 1;             }           }         }       }       int flag = true;       for (int i = 1; i <= n; i++) {         if (dp[m][i]) {           Show(m, i);           flag = false;           break;         }       }       if (flag) printf( Impossible n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100000 + 10;   const int INF = 1000000000;   const int MOD = (int)(1e9) + 7;   int main() {     int n;     cin >> n;     int m = (1 << (n + 1)) - 1;     vector<int> a(m + 10, 0);     for (int i = 2; i <= m; i++) cin >> a[i];     vector<int> s(m + 10, 0), c(m + 10, 0), add(m + 10, 0);     int l = 0;     for (int i = 2; i <= m; i++) {       s[i] = s[i / 2] + a[i];       l = max(l, s[i]);     }     for (int i = m; i >= 1; i--) {       if (i + i + 1 > m)         c[i] = s[i];       else         c[i] = max(c[i + i], c[i + i + 1]);     }     int res = 0;     for (int i = 2; i <= m; i++) {       int cur = c[i] + add[i / 2];       int inc = l - cur;       add[i] = add[i / 2] + inc;       res += inc;     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   void test_case() {     int n;     long long k;     cin >> n >> k;     int l, r[2] = {-1, -1};     long long curr[2] = {k, k}, ans[2] = {0, 0}, monsters;     for (int i = 0; i < n; i++) {       int old_r[2] = {r[0], r[1]}, tmp_r;       long long old_curr[2] = {curr[0], curr[1]}, old_ans[2] = {ans[0], ans[1]};       cin >> l >> tmp_r >> monsters;       ans[0] = -1;       for (int j = 0; j < 2; j++) {         if (old_ans[j] == -1) continue;         if (old_curr[j] + (tmp_r - l) * k < monsters) continue;         if (ans[0] != -1 && ans[0] < old_ans[j] + monsters) continue;         ans[0] = old_ans[j] + monsters;         if (old_curr[j] >= monsters) {           r[0] = l;           curr[0] = old_curr[j] - monsters;         } else {           int turns = (monsters - old_curr[j] + k - 1) / k;           r[0] = l + turns;           curr[0] = k * turns + old_curr[j] - monsters;         }       }       ans[1] = -1;       for (int j = 0; j < 2; j++) {         if (old_ans[j] == -1) continue;         if ((tmp_r - l + 1) * k < monsters) continue;         if (old_r[j] == l) continue;         if (ans[1] != -1 && ans[1] < old_ans[j] + old_curr[j] + monsters)           continue;         ans[1] = old_ans[j] + old_curr[j] + monsters;         int turns = (monsters + k - 1) / k;         r[1] = l + turns - 1;         curr[1] = k * turns - monsters;       }     }     if (ans[0] == -1)       cout << ans[1] <<   n ;     else if (ans[1] == -1)       cout << ans[0] <<   n ;     else       cout << min(ans[0], ans[1]) <<   n ;   }   int main(void) {     ios::sync_with_stdio(0);     cin.tie(0);     int Case = 1;     for (int i = 0; i < Case; i++) {       test_case();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int r, c, n, k, x, y;   int flag[101][101];   int main() {     cin >> r >> c >> n >> k;     for (int i = 0; i < n; i++) {       cin >> x >> y;       flag[x][y] = 1;     }     int cnt = 0;     for (int i = 1; i <= r; i++) {       for (int i1 = 1; i1 <= c; i1++) {         for (int i2 = 1; i2 <= r; i2++) {           for (int i3 = 1; i3 <= c; i3++) {             int sum = 0;             for (int i5 = i; i5 <= i2; i5++) {               for (int i6 = i1; i6 <= i3; i6++) {                 if (flag[i5][i6] == 1) sum++;               }             }             if (sum >= k) cnt++;           }         }       }     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int MAX = 1e5 + 55;   const int INF = 1e9 + 77;   const long long INFINF = 1e18 + 1e17;   const double PI = acos(-1.0);   long long power(long long x, long long y) {     if (y == 0) return 1;     long long s = power(x, y / 2);     s *= s;     if (y & 1) s *= x;     return s;   }   int n;   long long e[4000][4000];   long long dis[4000];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     int node = 1;     for (int p = 1; p <= ((1 << n + 1) - 1) / 2; p++) {       int dis1;       int dis2;       cin >> dis1;       cin >> dis2;       e[node * 2][node] = dis1;       e[node * 2 + 1][node] = dis2;       node++;     }     long long ans = 0;     node = ((1 << n + 1) - 1);     while (node != 1) {       int node1 = node;       int node2 = node - 1;       int par = node / 2;       int max1 = dis[node1] + e[node1][par];       int max2 = dis[node2] + e[node2][par];       dis[par] = max(max1, max2);       ans += (dis[par] - min(max1, max2));       node -= 2;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Int() {     int x;     scanf( %d , &x);     return x;   }   long long Long() {     long long x;     scanf( %lld , &x);     return x;   }   void err(istream_iterator<string> it) { cout << endl; }   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<    ;     err(++it, args...);   }   const int N = (int)2e5 + 5;   const int maxN = (int)1e6 + 6;   const long long Mod = (long long)1e9 + 7;   const int inf = (int)2e9;   const long long Inf = (long long)1e18;   int deg[N], vis[N];   vector<int> g[N];   int par[N];   int Find(int s) { return par[s] == s ? s : Find(par[s]); }   int main() {     int test = 1, tc = 0;     while (test--) {       int n = Int(), m = Int(), mx = 0, node = 0;       for (int i = 1; i <= m; ++i) {         int x = Int(), y = Int();         deg[x]++, deg[y]++;         if (deg[x] > mx) {           mx = deg[x], node = x;         }         if (deg[y] > mx) {           mx = deg[y], node = y;         }         g[x].push_back(y);         g[y].push_back(x);       }       priority_queue<pair<int, int> > pp;       pp.push({mx, node});       while (!pp.empty()) {         pair<int, int> c = pp.top();         pp.pop();         vis[c.second] = 1;         for (int i : g[c.second]) {           if (vis[i]) continue;           printf( %d %d n , i, c.second);           vis[i] = 1;           pp.push({deg[i], i});         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string s, t;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> t;     int ph = 0;     pair<int, int> mh = {0, 0};     for (int i = 0; i < n; i++) {       if (t[i] ==  ( )         ph++;       else         ph--;       mh = min(mh, make_pair(ph, i + 1));     }     if (ph != 0) {       cout <<  0 n1 1 n ;       return 0;     }     string s;     for (int i = mh.second; i < n; i++) {       s.push_back(t[i]);     }     for (int i = 0; i < mh.second; i++) {       s.push_back(t[i]);     }     int shift = mh.second;     int h = 0, cnt = 0, one = 0, two = 0, piv = 0, piv2 = -1;     pair<int, pair<int, int>> opt = {-1, {-1, -1}};     pair<int, pair<int, int>> opt2 = {-1, {-1, -1}};     for (int i = 0; i < n; i++) {       if (s[i] ==  ( )         h++;       else         h--;       if (h == 0) {         cnt++;         opt = max(opt, make_pair(one, make_pair(piv, i)));         one = 0;         piv = i + 1;         piv2 = -1;       } else if (h == 1) {         one++;         if (piv2 != -1) opt2 = max(opt2, make_pair(two, make_pair(piv2, i)));         two = 0;         piv2 = i + 1;       } else if (h == 2)         two++;     }     if (opt.first <= cnt + max(0, opt2.first)) {       if (opt2.first == -1) {         cout << cnt <<   n1 1 n ;         return 0;       }       cout << cnt + opt2.first <<   n ;       cout << (opt2.second.first + shift) % n + 1 <<    ;       cout << (opt2.second.second + shift) % n + 1 <<   n ;       return 0;     }     cout << opt.first <<   n           << (opt.second.first + shift) % n + 1 <<              << (opt.second.second + shift) % n + 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int main() {     int t;     cin >> t;     while (t--) {       cin >> s;       int n = s.length();       if (s[n - 2] ==  p  && s[n - 1] ==  o ) {         cout <<  FILIPINO  << endl;       } else if (s[n - 1] ==  u  && s[n - 2] ==  s  &&                  (s[n - 3] ==  e  || s[n - 3] ==  a ) &&                  (s[n - 4] ==  d  || s[n - 4] ==  m )) {         cout <<  JAPANESE  << endl;       } else {         cout <<  KOREAN  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const int INF = 1e9, MOD = INF - 1755647;   int gcd(int a, int b) { return (b ? gcd(b, a % b) : a); }   int power(int a, int b) {     return (!b ? 1 : power(a, b / 2) * power(a, b / 2) * (b % 2 ? a : 1));   }   int mod(int a) { return (a % MOD + MOD) % MOD; }   const int N = 2e5 + 20;   struct node {     int val = 0;     bool marked = false;     vector<int> adj;   };   int a[N];   node g[N];   set<int> ans;   void run(int src) {     g[src].marked = true;     queue<int> q;     q.push(src);     while (!q.empty()) {       int v = q.front();       q.pop();       g[v].val++;       ans.insert(v);       for (int u : g[v].adj) {         g[u].val++;         if (!g[u].marked && g[u].val == a[u]) q.push(u);       }     }   }   int32_t main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int v, u;       cin >> v >> u;       g[v].adj.push_back(u);       g[u].adj.push_back(v);     }     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++)       if (g[i].val == a[i]) run(i);     cout << ans.size() <<   n ;     for (int v : ans) cout << v <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000000 + 10;   char b[maxn];   int a[maxn];   int ccc[20];   int main() {     long long n;     long long sum = 0;     cin >> n;     if (n % 2 == 0)       sum = n / 2;     else       sum = (-n - 1) / 2;     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x[3], y[3];   map<pair<int, int>, bool> cleaned;   int cost(int cx, int cy) {     int sum = 0;     for (int i = 0; i < (3); i++)       sum += ((cx - x[i]) > 0 ? (cx - x[i]) : -(cx - x[i])) +              ((cy - y[i]) > 0 ? (cy - y[i]) : -(cy - y[i]));     return sum;   }   void clean(int x1, int y1, int x2, int y2) {     cleaned[pair<int, int>(x1, y1)] = true;     if (x1 == x2 && y1 == y2) return;     if (x1 < x2)       clean(x1 + 1, y1, x2, y2);     else if (x1 > x2)       clean(x1 - 1, y1, x2, y2);     else if (y1 < y2)       clean(x1, y1 + 1, x2, y2);     else       clean(x1, y1 - 1, x2, y2);   }   int main() {     ios_base::sync_with_stdio(false);     int bestX = 0, bestY = 0, bestCost;     for (int i = 0; i < (3); i++) cin >> x[i] >> y[i];     bestCost = cost(0, 0);     for (int ix = 0; ix < (1001); ix++)       for (int iy = 0; iy < (1001); iy++) {         int curCost = cost(ix, iy);         if (curCost < bestCost) {           bestCost = curCost;           bestX = ix;           bestY = iy;         }       }     for (int i = 0; i < (3); i++) clean(x[i], y[i], bestX, bestY);     cout << ((cleaned).size()) << endl;     for (map<pair<int, int>, bool>::iterator it = cleaned.begin();          it != cleaned.end(); ++it) {       cout << it->first.first <<     << it->first.second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-7;   struct segtree {     struct node {       double sum;       double mul, add;       node() {         sum = 0;         mul = 1;         add = 0;       }       void apply_mul(int l, int r, double v) {         mul *= v;         add *= v;         sum *= v;       }       void apply_add(int l, int r, double v) {         add += v;         sum += v * (r - l + 1);       }     };     inline void push(int x, int l, int r) {       int m = (l + r) >> 1;       int z = x + ((m - l + 1) << 1);       if (fabs(tree[x].mul - 1) > eps) {         tree[x + 1].apply_mul(l, m, tree[x].mul);         tree[z].apply_mul(m + 1, r, tree[x].mul);         tree[x].mul = 1;       }       if (fabs(tree[x].add) > eps) {         tree[x + 1].apply_add(l, m, tree[x].add);         tree[z].apply_add(m + 1, r, tree[x].add);         tree[x].add = 0;       }     }     node unite(const node &a, const node &b) const {       node res;       res.sum = a.sum + b.sum;       return res;     }     inline void pull(int x, int z) { tree[x] = unite(tree[x + 1], tree[z]); }     int n;     vector<node> tree;     void build(int x, int l, int r, const vector<double> &v) {       if (l == r) {         tree[x].sum = v[l];         return;       }       int m = (l + r) >> 1;       int z = x + ((m - l + 1) << 1);       build(x + 1, l, m, v);       build(z, m + 1, r, v);       pull(x, z);     }     node get(int x, int l, int r, int ll, int rr) {       if (ll <= l && r <= rr) {         return tree[x];       }       int y = (l + r) >> 1;       int z = x + ((y - l + 1) << 1);       push(x, l, r);       node res;       if (rr <= y) {         res = get(x + 1, l, y, ll, rr);       } else {         if (ll > y) {           res = get(z, y + 1, r, ll, rr);         } else {           res = unite(get(x + 1, l, y, ll, rr), get(z, y + 1, r, ll, rr));         }       }       pull(x, z);       return res;     }     void modify_mul(int x, int l, int r, int ll, int rr, double v) {       if (ll <= l && r <= rr) {         tree[x].apply_mul(l, r, v);         return;       }       int m = (l + r) >> 1;       int z = x + ((m - l + 1) << 1);       push(x, l, r);       if (ll <= m) {         modify_mul(x + 1, l, m, ll, rr, v);       }       if (rr > m) {         modify_mul(z, m + 1, r, ll, rr, v);       }       pull(x, z);     }     void modify_add(int x, int l, int r, int ll, int rr, double v) {       if (ll <= l && r <= rr) {         tree[x].apply_add(l, r, v);         return;       }       int m = (l + r) >> 1;       int z = x + ((m - l + 1) << 1);       push(x, l, r);       if (ll <= m) {         modify_add(x + 1, l, m, ll, rr, v);       }       if (rr > m) {         modify_add(z, m + 1, r, ll, rr, v);       }       pull(x, z);     }     segtree() {}     template <typename M>     segtree(const vector<M> &v) {       n = v.size();       assert(n > 0);       tree.resize(2 * n - 1);       build(0, 0, n - 1, v);     }     node get(int ll, int rr) {       assert(0 <= ll && ll <= rr && rr <= n - 1);       return get(0, 0, n - 1, ll, rr);     }     void modify_mul(int ll, int rr, double v) {       assert(0 <= ll && ll <= rr && rr <= n - 1);       modify_mul(0, 0, n - 1, ll, rr, v);     }     void modify_add(int ll, int rr, double v) {       assert(0 <= ll && ll <= rr && rr <= n - 1);       modify_add(0, 0, n - 1, ll, rr, v);     }   };   int main() {     int n, q;     scanf( %d%d , &n, &q);     vector<double> a(n);     for (int i = 0; i < n; i++) {       scanf( %lf , &a[i]);     }     segtree st(a);     while (q--) {       int tp, l1, r1, l2, r2, l, r;       scanf( %d , &tp);       if (tp == 1) {         scanf( %d%d%d%d , &l1, &r1, &l2, &r2);         l1--;         r1--;         l2--;         r2--;         int lena = r1 - l1 + 1;         int lenb = r2 - l2 + 1;         double suma = st.get(l1, r1).sum;         double sumb = st.get(l2, r2).sum;         st.modify_mul(l1, r1, 1.0 * (lena - 1) / lena);         st.modify_add(l1, r1, sumb / lena / lenb);         st.modify_mul(l2, r2, 1.0 * (lenb - 1) / lenb);         st.modify_add(l2, r2, suma / lena / lenb);       } else {         scanf( %d%d , &l, &r);         l--;         r--;         printf( %.8f n , st.get(l, r).sum);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const int mod = 1e9 + 7;   int n, l[N], t[N];   long long r;   int main() {     scanf( %d%lld , &n, &r);     for (int i = 0; i < n; i++) scanf( %d , l + i);     for (int i = 0; i < n; i++) {       scanf( %d , t + i);       if (t[i] < l[i]) return puts( -1 );     }     vector<long long> out;     long long cur = 0, time = 0;     long long ans = 0;     for (int i = 0; i < n; i++) {       int x = min((long long)l[i], cur);       cur -= x;       l[i] -= x;       t[i] -= x;       time += x;       x = l[i] + l[i];       time += min(x, t[i]);       int d = x - t[i];       if (d <= 0) continue;       int need = (d + r - 1) / r;       ans += need;       long long lo = time - d;       for (int j = 0; j < need; j++) {         if (out.size() > 100000) break;         out.push_back(lo);         lo += r;       }       cur = need * r - d;     }     printf( %lld n , ans);     if (ans <= 100000) {       for (int i = 0; i < ans; i++) printf( %lld  , out[i]);     }   }


#include <bits/stdc++.h>   using ul = std::uint32_t;   using li = std::int32_t;   using ull = std::uint64_t;   using ll = std::int64_t;   std::vector<ul> v;   std::string s;   int main() {     std::getline(std::cin, s);     std::stringstream ss(s);     while (std::getline(ss, s,  , )) {       std::stringstream ss(s);       ul t;       ss >> t;       v.push_back(t);     }     std::sort(v.begin(), v.end());     bool flag = false;     for (ul i = 0, j = 0; i != v.size(); i = j) {       for (++j; j != v.size() && v[j - 1] + 1 >= v[j]; ++j)         ;       if (flag) {         std::putchar( , );       }       flag = true;       if (v[j - 1] == v[i]) {         std::printf( %u , v[i]);       } else {         std::printf( %u-%u , v[i], v[j - 1]);       }     }     std::putchar(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)4e2;   const int INF = (int)1e9;   int n, m, a[N][N], p;   int dyn[N][N], last[N];   vector<pair<int, int> > q[N * N];   int len[N][N];   int main() {     cin >> n >> m >> p;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         cin >> a[i][j];         q[a[i][j]].push_back(make_pair(i, j));         dyn[i][j] = INF;       }     }     for (int i = 0; i < m; ++i) {       dyn[0][i] = i;     }     for (int lvl = 1; lvl <= p; ++lvl) {       int x, y;       for (auto tmp : q[lvl]) {         tie(x, y) = tmp;         int ans = INF;         for (int row = 0; row < n; ++row) {           if (last[row] == lvl - 1) {             ans = min(ans, dyn[row][y] + abs(row - x));           }         }         len[x][y] = ans;       }       for (auto tmp : q[lvl]) {         tie(x, y) = tmp;         if (last[x] != lvl) {           last[x] = lvl;           for (int col = 0; col < m; ++col) {             dyn[x][col] = len[x][y] + abs(y - col);           }         } else {           for (int col = 0; col < m; ++col) {             dyn[x][col] = min(dyn[x][col], len[x][y] + abs(y - col));           }         }       }     }     cout << len[q[p][0].first][q[p][0].second] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mul(long long a, long long b) { return (a * b) % 1000000007; }   long long add(long long a, long long b) {     a += b;     if (a >= 1000000007) a -= 1000000007;     return a;   }   long long binary_expo(long long base, long long expo) {     long long res = 1;     while (expo) {       if (expo % 2) {         res = mul(res, base);       }       expo /= 2;       base = mul(base, base);     }     return res;   }   long long A[202];   void solve() {     long long n;     cin >> n;     for (long long i = 1; i <= 2 * n; i++) {       cin >> A[i];     }     long long ans = 0;     for (long long i = 1; i <= 2 * n; i += 2) {       long long index = -1;       for (long long j = i + 1; j <= 2 * n; j++) {         if (A[i] == A[j]) {           index = j;           break;         }       }       for (long long j = index - 1; j >= i + 1; j--) {         swap(A[j], A[j + 1]);         ans++;       }     }     cout << ans <<   n ;   }   signed main() {     long long t;     t = 1;     while (t--) {       solve();     }   }


#include<bits/stdc++.h>   using namespace std;      long long t,n,k,pos;   string s;   bool mode;      char best(int pos){    char c=s[pos];        return min({c,char((c- a +1)%k+ a ),char(((c- a -1)%k+k)%k+ a )});   }      int main(){       ios::sync_with_stdio(false);    cin.tie(0);       cin>>t;        while(t--){     cin>>n>>k>>s;          mode=false;     pos=0;          while(pos<s.size()){      if(mode==false){       if((pos+1>=s.size() || best(pos)<= best(pos+1)) && (pos+2>=s.size() || best(pos)<=s[pos+2])){        s[pos]=best(pos);        pos++;        mode=false;       }else if(pos+2>=s.size() || best(pos+1)<=s[pos+2]){        if(best(pos+1)==s[pos+1]){         s[pos]=best(pos);         swap(s[pos],s[pos+1]);         pos++;         mode=true;        }else{         s[pos+1]=best(pos+1);         swap(s[pos],s[pos+1]);         mode=true;         pos++;        }       }else{        s[pos]=best(pos);        swap(s[pos+1],s[pos+2]);        swap(s[pos],s[pos+1]);        pos+=2;        mode=true;       }      }else{       if((pos+1>=s.size() || s[pos]<=s[pos+1]) && (pos+2>=s.size() || s[pos]<=s[pos+2])){        pos++;        mode=false;       }else if(pos+2>=s.size() || s[pos+1]<=s[pos+2]){        swap(s[pos],s[pos+1]);        pos++;        mode=true;       }else{        swap(s[pos+1],s[pos+2]);        swap(s[pos],s[pos+1]);        pos+=2;        mode=true;       }      }            //cout<<s<<  n ;      //cout<<pos<<   <<mode<<  ecco  n ;     }          cout<<s<<  n ;    }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int nMax = 2000005;   int p[nMax];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       p[i] = i + 1;     }     int s = 0;     for (int j = 2; j < n + 1; ++j) {       int curr = p[s];       p[n + s] = p[n + s - n % j];       for (int i = s; i <= n + s; i += j) {         int t = p[i];         p[i] = curr;         curr = t;       }       ++s;     }     for (int i = s; i < n + s; ++i) {       cout << p[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k;   bool debug = false;   int dp[1005][1005];   char a[1005], b[1005];   int main() {     scanf( %s%s , a + 1, b + 1);     int n = strlen(a + 1);     int m = strlen(b + 1);     for (int i = 1; i <= n; i++) dp[i][0] = i;     for (int i = 1; i <= m; i++) dp[0][i] = i;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         dp[i][j] = min(min(dp[i][j - 1], dp[i - 1][j]) + 1,                        dp[i - 1][j - 1] + (a[i] != b[j]));       }     }     printf( %d n , dp[n][m]);     while (n != 0 || m != 0) {       if (m != 0 && dp[n][m] == dp[n][m - 1] + 1) {         printf( INSERT %d %c n , n + 1, b[m]);         m--;       } else if (n != 0 && dp[n][m] == dp[n - 1][m] + 1) {         printf( DELETE %d n , n);         n--;       } else if (a[n--] != b[m--]) {         printf( REPLACE %d %c n , n + 1, b[m + 1]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   const long long MOD = 1e9 + 7;   long long n, m, cnt = 0;   long long a[N], comp[N], vis[N];   vector<long long> g[N], rg[N], v[N];   vector<long long> todo;   void dfs(long long k) {     vis[k] = 1;     for (auto it : g[k]) {       if (!vis[it]) {         dfs(it);       }     }     todo.push_back(k);   }   void dfs2(long long k, long long val) {     comp[k] = val;     v[val].push_back(a[k]);     for (long long w : rg[k]) {       if (comp[w] == -1) {         dfs2(w, val);       }     }   }   void sccAddE(long long from, long long to) {     g[from].push_back(to);     rg[to].push_back(from);   }   void scc() {     for (long long i = 1; i <= n; i++) {       comp[i] = -1;     }     for (long long i = 1; i <= n; i++) {       if (!vis[i]) dfs(i);     }     reverse(todo.begin(), todo.end());     for (long long i : todo) {       if (comp[i] == -1) {         dfs2(i, i);         cnt++;       }     }   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (long long i = 1; i <= n; i++) cin >> a[i];     cin >> m;     for (long long i = 1; i <= m; i++) {       long long u, v;       cin >> u >> v;       sccAddE(u, v);     }     scc();     long long ans1 = 0;     long long ans2 = 1;     for (long long i = 1; i <= n; i++) {       if (!v[i].size()) continue;       sort(v[i].begin(), v[i].end());       long long min1 = v[i][0];       ans1 += min1;       cnt = 0;       for (auto it : v[i])         if (it == min1) cnt++;       ans2 *= cnt;       ans2 %= MOD;     }     cout << ans1 <<     << ans2;   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   unsigned long long min(unsigned long long x, unsigned long long y) {     if (x < y) return x;     return y;   }   unsigned long long max(unsigned long long x, unsigned long long y) {     if (x < y) return y;     return x;   }   long long min(long long x, long long y) {     if (x < y) return x;     return y;   }   long long max(long long x, long long y) {     if (x < y) return y;     return x;   }   double min(double x, double y) {     if (x < y) return x;     return y;   }   double max(double x, double y) {     if (x < y) return y;     return x;   }   unsigned long long gcd(unsigned long long x, unsigned long long y) {     if (!x) return y;     if (!y) return x;     if (x > y) swap(x, y);     return gcd(x, y % x);   }   unsigned long long inv(unsigned long long a, unsigned long long c) {     if (a == 1) {       return 1;     }     return ((c - (c / a)) * inv(c % a, c)) % c;   }   void printv(vector<int> &a) {     int n = a.size();     for (int i = 0; i < n; ++i) {       cout << a[i] <<    ;     }     cout <<   END n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int T;     cin >> T;     for (int t = 1; t <= T; ++t) {       int n;       cin >> n;       int a[n + 1];       for (int i = 1; i <= n; ++i) {         cin >> a[i];       }       bool sorted = true;       for (int i = 1; i < n; ++i) {         if (a[i] > a[i + 1]) sorted = false;       }       int ans = 0;       while (!sorted) {         ans++;         if (ans & 1) {           for (int i = 1; i <= n - 2; i += 2) {             if (a[i] > a[i + 1]) {               swap(a[i], a[i + 1]);             }           }         } else {           for (int i = 2; i <= n - 1; i += 2) {             if (a[i] > a[i + 1]) {               swap(a[i], a[i + 1]);             }           }         }         sorted = true;         for (int i = 1; i < n; ++i) {           if (a[i] > a[i + 1]) sorted = false;         }       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     char a[n][m];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];       }     }     int str1 = n;     int str2 = -1;     int st1 = m;     int st2 = -1;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  B ) {           if (str1 > i) {             str1 = i;           }           if (str2 < i) {             str2 = i;           }           if (st1 > j) {             st1 = j;           }           if (st2 < j) {             st2 = j;           }         }       }     }     if (str2 == -1) {       cout << 1;     } else {       if (str2 - str1 + 1 > m || st2 - st1 + 1 > n) {         cout << -1;       } else {         int b = 0;         for (int i = 0; i < n; i++) {           for (int j = 0; j < m; j++) {             if (a[i][j] ==  B ) {               b++;             }           }         }         int ma = max(str2 - str1 + 1, st2 - st1 + 1);         cout << ma * ma - b;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<long long> no;     long long int n, m, s = 0, a[100000], l = 1, i;     cin >> n >> m;     for (i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + 1 + n);     for (i = 1; i <= m; i++) {       if (a[l] == i)         l++;       else {         s += i;         if (s <= m)           no.push_back(i);         else           break;       }     }     cout << no.size() << endl;     for (int j = 0; j < no.size(); j++) cout << no[j] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       long long total = n * k;       std::vector<long long> v(total);       for (long long i = 0; i < total; i++) {         cin >> v[i];       }       long long med;       if (n % 2 == 0) {         med = n / 2;       } else {         med = n / 2 + 1;       }       sort(v.begin(), v.end());       long long sum = 0;       if (n == 1) {         for (int i = 0; i < total; i++) {           sum += v[i];         }       } else {         for (long long i = total - n + med - 1; i >= ((med - 1) * k) - 1;              i -= (n - med + 1)) {           sum += v[i];         }       }       cout << sum << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     long long int a[n];     long long int sum = 0;     for (long int i = 0; i < n; i++) scanf( %lld , &a[i]), sum += a[i];     long long int ans[n];     long long int l = 0, r = 1e12;     long long int mid = 0;     while (l <= r) {       mid = (l + r) / 2;       long long int temp1 = mid * n;       long long int temp2 = temp1 + (n * (n - 1)) / 2;       if (temp1 <= sum && temp2 >= sum) {         r = mid - 1;       }       if (temp2 < sum)         l = mid + 1;       else         r = mid - 1;     }     mid = l;     long long int aa = 0;     for (long int i = 0; i < n; i++) {       long long int temp1 = mid * (n - i);       long long int temp2 = temp1 + ((n - i) * (n - i - 1)) / 2;       if (temp1 <= sum - aa && temp2 >= sum - aa)         ans[i] = mid;       else         ans[i] = ++mid;       aa += ans[i];     }     for (long int i = 0; i < n; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2005;   int n, k;   int a[maxn], b[maxn];   map<int, bool> MAP;   int main() {     int ans = 0;     scanf( %d%d , &k, &n);     for (int i = 0; i < k; i++) {       scanf( %d , &a[i]);     }     for (int i = 0; i < n; i++) {       scanf( %d , &b[i]);     }     vector<int> p;     if (k < n) {       cout << 0 << endl;       return 0;     }     for (int i = 0; i < k; i++) {       MAP.clear();       for (int i = 1; i < n; i++) {         MAP[b[i]] = true;       }       bool ok = true;       int t = b[0];       for (int j = i; j > 0; j--) {         t -= a[j];         MAP.find(t)->second = false;       }       int m = t - a[0];       t = b[0];       for (int j = i + 1; j < k; j++) {         t += a[j];         MAP.find(t)->second = false;       }       for (map<int, bool>::iterator it = MAP.begin(); it != MAP.end(); it++) {         if (it->second) {           ok = false;           break;         }       }       if (ok) {         p.push_back(m);       }     }     sort(p.begin(), p.end());     for (int i = 0; i < p.size(); i++) {       if (i == p.size() - 1 || p[i] != p[i + 1]) ans++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[15];   void f(int fg, int x) {     if (fg == 1) {       for (int i = 0; i <= 10; i++) {         if (((x >> i) & 1) != 0) {           a[i] = 1;         }       }     } else if (fg == 2) {       for (int i = 0; i <= 10; i++) {         if (((x >> i) & 1) == 0) {           a[i] = 0;         }       }     } else {       for (int i = 0; i <= 10; i++) {         if (((x >> i) & 1) != 0) {           if (a[i] == 0 || a[i] == 1)             a[i] ^= 1;           else             a[i] = -a[i];         }       }     }   }   int main() {     while (~scanf( %d , &n)) {       for (int i = 0; i <= 10; i++) a[i] = 5;       for (int i = 0; i < n; i++) {         char ch;         int tp;         getchar();         scanf( %c , &ch);         scanf( %d , &tp);         if (ch ==  | )           f(1, tp);         else if (ch ==  & )           f(2, tp);         else           f(3, tp);       }       int ansor = 0;       int ansand = 1023;       int ansxor = 0;       for (int i = 0; i < 10; i++) {         if (a[i] == 1) {           ansor += (1 << i);         } else if (a[i] == 0) {           ansand -= (1 << i);         } else if (a[i] == -5) {           ansxor += (1 << i);         }       }       printf( 3 n );       printf( | %d n , ansor);       printf( & %d n , ansand);       printf( ^ %d n , ansxor);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long limita = 998244353;   long long n, v[200], st, dr, mij, mul, ans, maxDegree;   long long GCD(long long x, long long y) {     if (y != 0)       return GCD(y, x % y);     else       return x;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> v[i];     }     for (int i = 1; i <= n; i++) {       ans = 180 / GCD(180LL, v[i]);       mul = 0;       st = 1;       dr = limita / ans;       while (st <= dr) {         mij = (st + dr) / 2;         maxDegree = (mij * ans - 2) * 180 / (mij * ans);         if (maxDegree >= v[i]) {           dr = mij - 1;           mul = mij;         } else           st = mij + 1;       }       if (mul == 0)         cout << -1 <<   n ;       else         cout << mul * ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, arr[200000 + 5], x[200000 + 5], ada[35];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &arr[i]);       if (i > 0)         x[i] = x[i - 1] ^ arr[i];       else         x[i] = arr[i];     }     if (x[n - 1] == 0)       printf( -1 n );     else {       for (int i = 0; i < n; i++) {         for (int j = 30; j >= 0; j--) {           if (x[i] & (1 << j)) {             if (!ada[j]) {               ada[j] = x[i];               break;             } else               x[i] ^= ada[j];           }         }       }       int res = 0;       for (int i = 0; i <= 30; i++) {         if (ada[i]) {           res++;         }       }       printf( %d n , res);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int l, r, x, y, k;     cin >> l >> r >> x >> y >> k;     for (long long int i = x; i <= y; ++i) {       if (k * i >= l && k * i <= r) {         cout <<  YES  << endl;         exit(0);       }     }     cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   void solutionC();   int main() {     solutionC();     return EXIT_SUCCESS;   }   int n, a[500002], b[500002];   bool check() {     for (int i = 1; i < n - 1; ++i) {       int s = a[i] + a[i - 1] + a[i + 1];       if (s == 2 && a[i] != 1) return false;       if (s == 1 && a[i] != 0) return false;     }     return true;   }   void change() {     b[0] = a[0];     b[n - 1] = a[n - 1];     for (int i = 1; i < n - 1; ++i) {       int s = a[i] + a[i - 1] + a[i + 1];       if (s == 2 && a[i] != 1) {         b[i] = 1;         continue;       }       if (s == 1 && a[i] != 0) {         b[i] = 0;         continue;       }       b[i] = a[i];     }     for (int i = 0; i < n; ++i) a[i] = b[i];   }   void out() {     for (int i = 0; i < n; ++i) {       if (i) cout <<    ;       cout << a[i];     }     cout << endl;   }   void solve() {     int l = 1;     vector<pair<int, int>> e;     for (int i = 1; i < n; ++i) {       if (a[i] != a[i - 1]) {         ++l;       } else {         if (l >= 3) e.emplace_back(i - l, i - 1);         l = 1;       }     }     if (l >= 3) e.emplace_back(n - l, n - 1);     int ans = 0;     for (auto it : e) {       int d = it.second - it.first;       if (d % 2 == 0) {         ans = max(ans, d / 2);         assert(a[it.first] == a[it.second]);         for (int i = it.first; i <= it.second; ++i) a[i] = a[it.first];       } else {         assert(a[it.first] != a[it.second]);         ans = max(ans, (d - 1) / 2);         for (int i = it.first; i <= it.second; ++i)           if (i - it.first < it.second - i)             a[i] = a[it.first];           else             a[i] = a[it.second];       }     }     cout << ans << endl;     out();   }   void bf() {     for (int l = 3; l < 24; ++l) {       n = l;       int mx = 0;       cout <<  n:   << l << endl;       for (int bm = 0; bm < (1 << l); ++bm) {         for (int i = 0; i < n; ++i) a[i] = (bm & (1 << i)) > 0;         int cnt = 0;         while (!check()) {           cnt++;           change();           if (cnt > n * n * 2) {             cout <<  fnd:  ;             out();             break;           }         }         mx = max(mx, cnt);       }       cout <<  mx:   << mx << endl;     }   }   void solutionC() {     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     solve();   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int hx, hy;     int tx, ty;     int dep;     long dir;     int zt[15];   };   queue<node> q;   int n, m, len;   int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};   bool v[15][15][262144];   char c[30][30];   bool init(int a, int b) {     if (a < 0 || a >= n || b < 0 || b >= m) return 0;     return 1;   }   int update(int d, int nd) {     d = d | (nd << ((len - 1) * 2));     d >>= 2;     return d;   }   void out(int d) {     for (int i = 1; i < len; i++) {       int t = d % 4;       if (t == 0) cout <<  w ;       if (t == 1) cout <<  d ;       if (t == 2) cout <<  s ;       if (t == 3) cout <<  a ;       d /= 4;     }   }   void zut(int x) {     for (int i = 1; i <= m; i++) {       cout << x % 2;       x /= 2;     }   }   int ax, ay;   node fst;   int main() {     cin >> n >> m;     int fhx, fhy, ftx, fty;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> c[i][j];         if (c[i][j] >=  1  && c[i][j] <=  9 ) len = max(len, c[i][j] -  0 );         if (c[i][j] ==  1 ) {           fhx = i;           fhy = j;         }         if (c[i][j] == len +  0 ) {           ftx = i;           fty = j;         }         if (c[i][j] ==  @ ) {           ax = i;           ay = j;         }       }     int fdir = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (c[i][j] >=  1  && c[i][j] <=  9 ) {           for (int k = 0; k < 4; k++) {             int nx = i + dx[k], ny = j + dy[k];             if (init(nx, ny) && c[nx][ny] == c[i][j] - 1) {               int nk = k;               fdir = fdir | (nk << ((len - (c[i][j] -  0 )) * 2));               break;             }           }           fst.zt[i] |= (1 << j);         }     fst.dir = fdir, fst.hx = fhx, fst.hy = fhy, fst.tx = ftx, fst.ty = fty,     fst.dep = 0;     q.push(fst);     while (!q.empty()) {       node f = q.front();       q.pop();       if (f.hx == ax && f.hy == ay) {         cout << f.dep;         return 0;       } else {         for (int i = 0; i < 4; i++) {           int nx = f.hx + dx[i], ny = f.hy + dy[i];           if (!init(nx, ny)) continue;           if (c[nx][ny] ==  # ) continue;           if (f.zt[nx] & (1 << ny) && !(nx == f.tx && ny == f.ty)) continue;           node nf = f;           nf.hx = nx;           nf.hy = ny;           nf.tx = dx[f.dir & (3)] + f.tx;           nf.ty = dy[f.dir & (3)] + f.ty;           nf.zt[f.tx] ^= (1 << f.ty);           nf.zt[nx] |= (1 << ny);           nf.dir = update(f.dir, i);           nf.dep++;           if (v[nx][ny][nf.dir]) continue;           v[nx][ny][nf.dir] = 1;           q.push(nf);         }       }     }     cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vb = vector<bool>;   using vvb = vector<vb>;   using vi = vector<int>;   using vvi = vector<vi>;   using vl = vector<ll>;   using vvl = vector<vl>;   using vc = vector<char>;   using vvc = vector<vc>;   using vs = vector<string>;   const ll mod = 1e9 + 7, inf = 1e18;   void setIO() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;   }   int main() {     setIO();     int t;     cin >> t;     while (t--) {       ll n;       cin >> n;       ll m = 1;       for (int i = 3; i <= 2 * n; i++) m = m * i % 1000000007;       cout << m << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int ara[n];     int temp = n;     int k = 0;     while (n--) {       cin >> ara[k++];     }     sort(ara, ara + temp);     queue<int> Q;     for (int i = 0; i < temp; i++) {       Q.push(ara[i]);     }     int i;     for (i = 1; i < 1000000; i++) {       while (!Q.empty() && Q.front() < i) {         Q.pop();       }       if (Q.empty()) break;       Q.pop();     }     cout << i << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   long long eq(long long start, long long k) {     long long num = k - (start - 1);     return ((num * (start + k)) / 2) - (num - 1);   }   void solve() {     long long n, k;     cin >> n >> k;     long long q = eq(2, k);     if (n == 1)       cout << 0 <<   n ;     else if (n <= k)       cout << 1 <<   n ;     else if (q < n)       cout << -1 <<   n ;     else {       long long en = k;       long long st = 2;       long long res = -1;       while (st < en && st > 1) {         long long mid = st + en >> 1;         if (eq(mid, k) < n) {           en = mid;         } else {           st = mid + 1;           res = mid;         }       }       res--;       cout << k - res <<   n ;     }   }   int main() {     ios::sync_with_stdio(0), cin.tie(nullptr), cout.tie(nullptr);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = (1 << 30);   const double Exp = 1e-8;   const int maxm = 1e5 + 7;   const int maxn = 1e5 + 7;   const int inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const double pi = 3.1415926535898;   string s;   int q, n, sum1, sum2, sum3;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     ;     cin >> q;     while (q--) {       cin >> n;       sum1 = sum2 = sum3 = 0;       for (int i = 1; i <= n; ++i) {         cin >> s;         if (s.size() % 2) sum3++;         for (int j = 0; j < s.size(); ++j) {           if (s[j] ==  1 )             sum1++;           else             sum2++;         }       }       if (sum1 % 2 && sum2 % 2 && !sum3)         cout << n - 1 << endl;       else         cout << n << endl;     }     return 0;   }


#include<bits/stdc++.h>   using  namespace std;      #define  ll                  long long   #define  inf                  1e18      #define  memset(a , b)       memset((a) , (b) , sizeof(a))   #define  mod                 1000000007   #define  rep(i , n)          for((i) = 0 ; (i) < n ; (i)++)   #define  N                   200005               ll t , d , ct  , q, ans , l ,m , r , n , mx , mn , i, j , k , x , y , z , s  ;        char ch ;           string ss =    ,  str =    ;        ll a[N] ,  b[N] ;               void dbg(ll x, ll y = 0, ll z = 0, ll a = 0)     { cout <<  Dbg:   << x <<     << y <<     << z <<     << a <<   n ;   }           /*---------------------------------------Main Code----------------------------------------------------- */                  int main(){                                 ios_base::sync_with_stdio (false),            cin.tie(nullptr);                          cin >> x >> y >> k;             if (y == 1)         {             if (k)             {                 cout <<  No n ;                 return 0;             }             cout <<  Yes n ;                 cout <<  1 ;             rep(i, x)                     cout                 <<  0 ;             cout <<   n ;                 cout <<  1 ;             rep(i, x)                     cout                 <<  0 ;             return 0;         }                 if (!x)         {             if (k)             {                 cout <<  No n ;                 return 0;             }                 cout <<  Yes n ;             rep(i, y)                     cout                 <<  1 ;             cout <<   n ;             rep(i, y)                     cout                 <<  1 ;             return 0;         }            if (k > x + y - 2)         {             cout <<  No ;             return 0;         }            cout <<  Yes n ;            rep(i, y)                 cout             <<  1 ;         rep(i, x)                 cout             <<  0 ;            cout <<   n ;            if (k <= x)         {             rep(i, y - 1)                     cout                 <<  1 ;             rep(i, k)                     cout                 <<  0 ,                 x--;                cout <<  1 ;                rep(i, x)                     cout                 <<  0 ;                return 0;         }            k -= x;            rep(i, y  - k -1)                 cout             <<  1 ;            cout <<  0 ;            y -= (y -k-  1);            rep(i, y - 1)                 cout             <<  1 ;            rep(i, x - 1)                 cout             <<  0 ;            cout <<  1 ;            return 0;   }


#include <bits/stdc++.h>   using namespace std;   int D, m, x, y;   vector<vector<long double>> e;   const long double oo = 1e13;   vector<long double> mns(vector<long double> a, vector<long double> b) {     vector<long double> ret;     ret.resize(D);     for (int i = 0; i < D; i++) ret[i] = a[i] - b[i];     return ret;   }   vector<long double> tms(vector<long double> a, long double c) {     for (int i = 0; i < D; i++) a[i] *= c;     return a;   }   vector<long double> perp(vector<long double> a, vector<long double> b) {     long double norma = 0, normb = 0, dot = 0;     for (int i = 0; i < D; i++) {       norma += a[i] * a[i];       normb += b[i] * b[i];       dot += a[i] * b[i];     }     if (normb < 1e-9) return a;     long double tmp = dot / normb;     vector<long double> bb = tms(b, tmp);     return mns(a, bb);   }   struct subspace {     vector<vector<long double>> vectors;     vector<vector<long long>> canon;     subspace(vector<vector<long double>> _vectors) {       int d = _vectors.size();       vectors = _vectors;       for (int i = 0; i < d; i++)         for (int j = 0; j < i; j++) vectors[i] = perp(vectors[i], vectors[j]);       for (int i = 0; i < D; i++) {         vector<long double> x = e[i];         for (int j = 0; j < d; j++) x = perp(x, vectors[j]);         vector<long long> y(D);         for (int i = 0; i < D; i++) {           y[i] = llround(x[i] * oo);         }         canon.push_back(y);       }     }   };   map<vector<vector<long long>>, int> mp;   int cnt = 1;   int main() {     std::ios::sync_with_stdio(false);     cin >> m >> D;     e.resize(D);     for (int i = 0; i < D; i++) {       e[i].resize(D);       e[i][i] = 1;     }     for (int i = 1; i <= m; i++) {       vector<vector<long double>> tmp;       cin >> x;       for (int j = 0; j < x; j++) {         vector<long double> v;         for (int k = 0; k < D; k++) {           cin >> y;           v.push_back(y);         }         tmp.push_back(v);       }       auto c = subspace(tmp).canon;       if (mp.count(c))         cout << mp[c] <<    ;       else         cout << (mp[c] = cnt++) <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 233333;   int par[N][25], dep[N];   int u, v, ans;   int n;   inline int lca(int u, int v) {     if (dep[u] < dep[v]) {       u ^= v;       v ^= u;       u ^= v;     }     for (int i = 0; i < 25; i++)       if (((dep[u] - dep[v]) >> i) & 1) u = par[u][i];     if (u == v) return u;     for (int i = 24; i >= 0; i--)       if (par[u][i] != par[v][i]) {         u = par[u][i];         v = par[v][i];       }     return par[u][0];   }   int main() {     scanf( %d , &n);     par[1][0] = 0;     dep[1] = 0;     u = v = 1;     for (int i = 2; i <= n; i++) {       int w;       scanf( %d , &w);       par[i][0] = w;       dep[i] = dep[w] + 1;       for (int j = 1; j < 24; j++) par[i][j] = par[par[i][j - 1]][j - 1];       w = i;       int l = lca(u, w);       int dst = dep[u] - dep[l] + dep[w] - dep[l];       int nu = u, nv = v;       if (dst > ans) {         ans = dst;         nu = u;         nv = w;       }       l = lca(v, w);       dst = dep[v] - dep[l] + dep[w] - dep[l];       if (dst > ans) {         ans = dst;         nu = w;         nv = v;       }       printf( %d%c , ans, i == n ?   n  :    );       u = nu;       v = nv;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long llINF = 1e18;   const int MAXN = 1e5 + 5;   int n, Q;   int a[MAXN];   namespace SegmentTree {   struct Node {     int lmax, rmax, lmin, rmin, maxl, maxr, minl, minr, sum, maxsum, minsum,         maxposl, minposl, maxposr, minposr;     Node(int pos = 0, int v = 0) {       maxl = maxr = minl = minr = maxposl = maxposr = minposl = minposr = pos;       lmax = rmax = lmin = rmin = sum = maxsum = minsum = v;     }     friend Node operator+(const Node &lhs, const Node &rhs) {       Node res;       if (lhs.lmax > lhs.sum + rhs.lmax)         res.lmax = lhs.lmax, res.maxl = lhs.maxl;       else         res.lmax = lhs.sum + rhs.lmax, res.maxl = rhs.maxl;       if (rhs.rmax > rhs.sum + lhs.rmax)         res.rmax = rhs.rmax, res.maxr = rhs.maxr;       else         res.rmax = rhs.sum + lhs.rmax, res.maxr = lhs.maxr;       if (lhs.lmin < lhs.sum + rhs.lmin)         res.lmin = lhs.lmin, res.minl = lhs.minl;       else         res.lmin = lhs.sum + rhs.lmin, res.minl = rhs.minl;       if (rhs.rmin < rhs.sum + lhs.rmin)         res.rmin = rhs.rmin, res.minr = rhs.minr;       else         res.rmin = rhs.sum + lhs.rmin, res.minr = lhs.minr;       res.sum = lhs.sum + rhs.sum;       res.maxsum = lhs.rmax + rhs.lmax;       res.maxposl = lhs.maxr;       res.maxposr = rhs.maxl;       if (res.maxsum < lhs.maxsum)         res.maxsum = lhs.maxsum, res.maxposl = lhs.maxposl,         res.maxposr = lhs.maxposr;       if (res.maxsum < rhs.maxsum)         res.maxsum = rhs.maxsum, res.maxposl = rhs.maxposl,         res.maxposr = rhs.maxposr;       res.minsum = lhs.rmin + rhs.lmin;       res.minposl = lhs.minr;       res.minposr = rhs.minl;       if (res.minsum > lhs.minsum)         res.minsum = lhs.minsum, res.minposl = lhs.minposl,         res.minposr = lhs.minposr;       if (res.minsum > rhs.minsum)         res.minsum = rhs.minsum, res.minposl = rhs.minposl,         res.minposr = rhs.minposr;       return res;     }     void rev() {       sum = -sum;       swap(lmax, lmin);       swap(maxl, minl);       lmax = -lmax;       lmin = -lmin;       swap(rmax, rmin);       swap(maxr, minr);       rmax = -rmax;       rmin = -rmin;       swap(maxsum, minsum);       swap(maxposl, minposl);       swap(maxposr, minposr);       maxsum = -maxsum;       minsum = -minsum;     }   };   struct Tree {     int l, r;     int tag;     Node val;   } tree[MAXN << 2];   void update(int k) { tree[k].val = tree[k << 1].val + tree[k << 1 | 1].val; }   void apply(int k) {     tree[k].tag ^= 1;     tree[k].val.rev();   }   void down(int k) {     if (tree[k].tag) {       apply(k << 1);       apply(k << 1 | 1);       tree[k].tag = 0;     }   }   void Build(int k, int l, int r) {     tree[k].l = l;     tree[k].r = r;     if (l == r) {       tree[k].val = Node(l, a[l]);       return;     }     int mid = (l + r) >> 1;     Build(k << 1, l, mid);     Build(k << 1 | 1, mid + 1, r);     update(k);   }   void Modify(int k, int x, int v) {     if (tree[k].l == tree[k].r) {       tree[k].val = Node(tree[k].l, v);       return;     }     down(k);     int mid = (tree[k].l + tree[k].r) >> 1;     if (x <= mid)       Modify(k << 1, x, v);     else       Modify(k << 1 | 1, x, v);     update(k);   }   void Reverse(int k, int l, int r) {     if (tree[k].l >= l && tree[k].r <= r) {       apply(k);       return;     }     down(k);     int mid = (tree[k].l + tree[k].r) >> 1;     if (l <= mid) Reverse(k << 1, l, r);     if (r > mid) Reverse(k << 1 | 1, l, r);     update(k);   }   Node Query(int k, int l, int r) {     if (tree[k].l >= l && tree[k].r <= r) return tree[k].val;     down(k);     int mid = (tree[k].l + tree[k].r) >> 1;     if (r <= mid) return Query(k << 1, l, r);     if (l > mid) return Query(k << 1 | 1, l, r);     return Query(k << 1, l, r) + Query(k << 1 | 1, l, r);   }   }  // namespace SegmentTree   using SegmentTree::Node;   vector<Node> vec;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     SegmentTree::Build(1, 1, n);     scanf( %d , &Q);     while (Q--) {       int op, l, r, k, x, ans;       scanf( %d , &op);       if (op == 0) {         scanf( %d%d , &x, &k);         SegmentTree::Modify(1, x, k);       } else {         scanf( %d%d%d , &l, &r, &k);         vec.clear();         ans = 0;         for (int i = 1; i <= k; i++) {           Node tmp = SegmentTree::Query(1, l, r);           if (tmp.maxsum <= 0) break;           SegmentTree::Reverse(1, tmp.maxposl, tmp.maxposr);           vec.push_back(tmp);           ans += tmp.maxsum;         }         for (auto x : vec) SegmentTree::Reverse(1, x.maxposl, x.maxposr);         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   unsigned long long mulmod(unsigned long long a, unsigned long long b,                             unsigned long long c) {     unsigned long long x = 0, y = a % c;     while (b > 0) {       if (b % 2 == 1) {         x = (x + y) % c;       }       y = (y * 2) % c;       b /= 2;     }     return x % c;   }   unsigned long long pow(unsigned long long a, unsigned long long b,                          unsigned long long c) {     unsigned long long x = 1, y = a;     while (b > 0) {       if (b & 1) x = mulmod(x, y, c);       y = mulmod(y, y, c);       b >>= 1;     }     return x;   }   bool Miller(unsigned long long p, int iteration) {     if (p < 2) {       return false;     }     if (p != 2 && p % 2 == 0) {       return false;     }     unsigned long long second = p - 1;     while (second % 2 == 0) {       second /= 2;     }     for (int i = 0; i < iteration; i++) {       unsigned long long a = rand() % (p - 1) + 1, temp = second;       unsigned long long mod = pow(a, temp, p);       while (temp != p - 1 && mod != 1 && mod != p - 1) {         mod = mulmod(mod, mod, p);         temp *= 2;       }       if (mod != p - 1 && temp % 2 == 0) {         return false;       }     }     return true;   }   using namespace std;   int main() {     int n;     scanf( %d , &n);     int pos = 0;     string ans =   ;     string text[2][10] = {{ zero ,  one ,  two ,  three ,  four ,  five ,  six ,                             seven ,  eight ,  nine },                           {  ,  ten- ,  twenty- ,  thirty- ,  forty- ,  fifty- ,                             sixty- ,  seventy- ,  eighty- ,  ninety- }};     string tens[9] = { ten ,    twenty ,   thirty ,  forty ,  fifty ,                        sixty ,  seventy ,  eighty ,  ninety };     if (n % 10 == 0 && n != 0) {       cout << tens[(n / 10) - 1] <<   n ;       return 0;     } else if (n < 20) {       if (n < 10) {         cout << text[0][n] <<   n ;       } else {         switch (n) {           case 11:             cout <<  eleven n ;             break;           case 12:             cout <<  twelve n ;             break;           case 13:             cout <<  thirteen n ;             break;           case 14:             cout <<  fourteen n ;             break;           case 15:             cout <<  fifteen n ;             break;           case 16:             cout <<  sixteen n ;             break;           case 17:             cout <<  seventeen n ;             break;           case 18:             cout <<  eighteen n ;             break;           case 19:             cout <<  nineteen n ;         }       }       return 0;     }     while (n) {       int d = n % 10;       ans.insert(0, text[pos][d]);       pos++;       n /= 10;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long s[n][n];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> s[i][j];       }     }     long long ans = sqrt((long long)((s[0][1] * s[0][2]) / s[1][2]));     cout << ans;     for (int i = 1; i < n; i++) {       cout <<     << s[0][i] / ans;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string str(string s) {     if (s.size() % 2) return s;     string a = str(s.substr(0, s.size() / 2));     string b = str(s.substr(s.size() / 2, s.size() / 2));     if (a < b)       return a + b;     else       return b + a;   }   int main() {     ios_base::sync_with_stdio(0);     string s1, s2;     cin >> s1 >> s2;     if (str(s1) == str(s2))       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   long long mod = 1000000007;   using namespace std;   int n;   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   int a[100005];   int main() {     int i, j, fl, test, pos = 0, mx = 0;     scanf( %d , &n);     long long ans = 0;     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);       if (a[i] > mx) {         mx = a[i];         pos = i;       }     }     for (i = pos; i < n; i++) {       ans = ans + (mx - a[i]);     }     int sofar[100005];     sofar[0] = 0;     for (i = 1; i < pos; i++) {       sofar[i] = max(sofar[i - 1], a[i]);     }     for (i = pos - 1; i >= 0; i--) {       mx--;       mx = max(mx, a[i]);       ans = ans + max((mx - a[i]), (sofar[i] - a[i]));     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename _T>   inline void _DBG(const char *s, _T x) {     cerr << s <<   =   << x <<   n ;   }   template <typename _T, typename... args>   void _DBG(const char *s, _T x, args... a) {     while (*s !=  , ) cerr << *s++;     cerr <<   =   << x <<  , ;     _DBG(s + 1, a...);   }   const int N = 307;   int n, m, p[] = {1, 0, 0, 1, -1, 0, 0, -1};   char s[N][N];   long long P, q;   long long val[N][N];   queue<pair<pair<int, int>, long long> > Q;   bool vis[N][N];   vector<pair<int, int> > kto;   void bfs(int x, int y, long long v) {     Q.push({{x, y}, v});     for (auto xx : kto) vis[xx.first][xx.second] = 0;     kto.clear();     vis[x][y] = 1;     while (!Q.empty()) {       int xx = Q.front().first.first, yy = Q.front().first.second;       long long vv = Q.front().second;       val[xx][yy] += vv;       Q.pop();       kto.push_back({xx, yy});       vv /= 2;       if (vv == 0) continue;       for (int i = 0; i < 8; i += 2) {         int ux = xx + p[i], uy = yy + p[i + 1];         if (s[ux][uy] ==  * ) continue;         if (1 > ux || ux > n || 1 > uy || uy > m) continue;         if (!vis[ux][uy]) {           vis[ux][uy] = 1;           Q.push({{ux, uy}, vv});         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> q >> P;     for (int i = 1; i <= n; i++) cin >> (s[i] + 1);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if ( A  <= s[i][j] && s[i][j] <=  Z ) {           long long vv = (long long)(s[i][j] -  A  + 1) * q;           bfs(i, j, vv);         }       }     }     int ans = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         if (val[i][j] > P) ans++;       }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int parent[200005], par[200005], root;   int find(int i) {     if (parent[i] != i) parent[i] = find(parent[i]);     return parent[i];   }   void merge(int x, int y) {     int xroot = find(x);     int yroot = find(y);     if (xroot == yroot) {       if (!root) root = xroot;       par[x] = root;     } else       parent[xroot] = yroot;   }   int main() {     int n, temp[200005], dsu[200005], k = 0, cnt = 0;     cin >> n;     for (int i = 1; i <= n; i++) parent[i] = i;     for (int i = 1; i <= n; i++) {       cin >> par[i];       temp[i] = par[i];       if (par[i] == i) root = i;     }     for (int i = 1; i <= n; i++) {       if (par[i] == i) {         if (i == root) {         } else           par[i] = root;       } else         merge(i, par[i]);     }     for (int i = 1; i <= n; i++)       if (temp[i] != par[i]) cnt++;     cout << cnt <<   n ;     for (int i = 1; i <= n; i++) cout << par[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void pr(vector<T> &v) {     for (int i = 0; i < (int)(v).size(); i++) cout << v[i] <<    ;     cout <<   n ;     ;   }   template <typename T>   void pr(vector<vector<T>> &v) {     for (int i = 0; i < (int)(v).size(); i++) {       pr(v[i]);     }   }   template <typename T>   void re(T &x) {     cin >> x;   }   template <typename T>   void re(vector<T> &a) {     for (int i = 0; i < (int)(a).size(); i++) re(a[i]);   }   template <class Arg, class... Args>   void re(Arg &first, Args &...rest) {     re(first);     re(rest...);   }   template <typename T>   void pr(T x) {     cout << x <<   n ;     ;   }   template <class Arg, class... Args>   void pr(const Arg &first, const Args &...rest) {     cout << first <<    ;     pr(rest...);     cout <<   n ;     ;   }   void ps() {     cout <<   n ;     ;   }   template <class T, class... Ts>   void ps(const T &t, const Ts &...ts) {     cout << t;     if (sizeof...(ts)) cout <<    ;     ps(ts...);   }   const long long MOD = 998244353;   long double PI = 4 * atan(1);   long double eps = 1e-12;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, A, cf, cm, m;     cin >> n >> A >> cf >> cm >> m;     vector<pair<long long, int>> a(n + 1);     for (int i = 1; i < n + 1; i++) {       cin >> a[i].first;       a[i].second = i;     }     vector<long long> pre(n + 1);     vector<long long> pre2(n + 1);     sort(a.begin(), a.end());     vector<long long> ac(n);     long long minv = MOD;     for (int i = 0; i < n; i++) {       ac[i] = a[i + 1].first;       minv = min(minv, ac[i]);     }     pre[0] = 0;     pre2[0] = 0;     for (int i = 1; i < n + 1; i++) {       pre[i] = a[n - i + 1].first + pre[i - 1];       pre2[i] = a[i].first + pre2[i - 1];     }     long long ans = cm * minv;     long long ind = 0;     long long besti = 0;     long long bestm = 0;     for (int i = 0; i < n + 1; i++) {       long long cost = (i)*A - pre[i];       if (cost > m) {         break;       }       long long lo = 0;       long long hi = A;       while (lo != hi) {         long long mid = (lo + hi + 1) / 2;         vector<long long>::iterator high =             upper_bound(ac.begin(), ac.begin() + n - i, mid);         long long ntm = high - ac.begin();         long long cost2 = cost + (mid * ntm - pre2[ntm]);         if (cost2 <= m) {           if (i * cf + cm * mid > ans) {             ans = i * cf + cm * mid;             besti = i;             bestm = mid;           }           lo = mid;         } else {           hi = mid - 1;         }       }     }     for (int i = 0; i < besti; i++) {       a[n - i].first = A;     }     for (int i = 1; i < n + 1; i++) {       if (a[i].first < bestm) a[i].first = bestm;     }     vector<long long> out(n + 1);     for (int i = 1; i < n + 1; i++) {       out[a[i].second] = a[i].first;     }     cout << ans <<   n ;     ;     for (int i = 1; i < n + 1; i++) {       cout << out[i] <<    ;     }     cout <<   n ;     ;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 105;   const int N = 200;   int f[maxn][maxn][maxn];   int g[maxn][maxn][maxn];   bool usedf[maxn][maxn];   bool usedg[maxn][maxn];   int n, m, K, ans, c[N + 5][N + 5];   int main() {     scanf( %d %d %d , &n, &m, &K);     if (K == 0) {       puts( 0 );       return 0;     }     for (int i = 0; i <= N; i++) {       c[i][0] = c[i][i] = 1;       for (int j = 1; j < i; j++) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;     }     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++)         for (int k = 1; k <= K; k++)           if (usedg[j][k]) memset(g[j][k], 0, sizeof(g[j][k]));       memset(usedg, 0, sizeof usedg);       for (int t = 1; t <= n; t++) usedg[t][1] = true, g[t][1][t] = 1;       for (int j = 1; j <= n; j++)         for (int k = 1; k <= K; k++)           if (usedf[j][k]) {             for (int l = 1; l <= n; l++)               if (int val = f[j][k][l]) {                 int tmp;                 for (int t = l; t <= n - j; t++)                   if (c[t - 1][l - 1] <= K && (tmp = k * c[t - 1][l - 1]) <= K)                     (g[j + t][tmp][t - l] += val) %= mod,                         usedg[j + t][tmp] = true;               }           }       swap(f, g);       swap(usedf, usedg);       for (int j = 1; j <= n; j++)         for (int k = 1; k <= K; k++) (ans += f[j][k][0]) %= mod;     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod(long long x) {     return ((x % 1000000007 + 1000000007) % 1000000007);   }   long long add(long long a, long long b) { return mod(mod(a) + mod(b)); }   long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); }   template <class T>   void print(T a) {     cerr << a;   }   template <class T, class V>   void print(pair<T, V> p);   template <class T>   void print(vector<T> v);   template <class T>   void print(set<T> v);   template <class T, class V>   void print(map<T, V> v);   template <class T>   void print(multiset<T> v);   template <class T, class V>   void print(pair<T, V> p) {     cerr <<  { ;     print(p.first);     cerr <<  , ;     print(p.second);     cerr <<  } ;   }   template <class T>   void print(vector<T> v) {     cerr <<  [  ;     for (T i : v) {       print(i);       cerr <<  , ;     }     cerr <<  ] ;   }   template <class T>   void print(set<T> v) {     cerr <<  [  ;     for (T i : v) {       print(i);       cerr <<  , ;     }     cerr <<  ] ;   }   template <class T>   void print(multiset<T> v) {     cerr <<  [  ;     for (T i : v) {       print(i);       cerr <<  , ;     }     cerr <<  ] ;   }   template <class T, class V>   void print(map<T, V> v) {     cerr <<  [  ;     for (auto i : v) {       print(i);       cerr <<  , ;     }     cerr <<  ] ;   }   long long modPow(long long a, long long b) {     if (b == 0) return 1LL;     if (b == 1) return a % 1000000007;     long long res = 1;     while (b) {       if (b % 2 == 1) res = mul(res, a);       a = mul(a, a);       b = b / 2;     }     return res;   }   const long long N = 2e5 + 2;   long long fact[N];   void precalc() {     fact[0] = 1;     for (long long i = 1; i < N; i++) {       fact[i] = mul(fact[i - 1], i);     }   }   long long inv(long long x) { return modPow(x, 1000000007 - 2); }   long long divide(long long a, long long b) { return mul(a, inv(b)); }   long long nCr(long long n, long long r) {     return divide(fact[n], mul(fact[r], fact[n - r]));   }   void solve() {     long long n;     cin >> n;     string s;     cin >> s;     for (long long i = 0; i < n; i++) {       if (s[i] ==  0 ) {         if ((i + 1) <= n / 2) {           cout << i + 1 <<     << n <<     << i + 2 <<     << n << endl;           return;         } else {           cout << 1 <<     << i + 1 <<     << 1 <<     << i << endl;           return;         }       }     }     cout << 1 <<     << n - 1 <<     << 2 <<     << n << endl;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1000000007;   const long long int inf = 9e18;   void __print(long long int x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     long long int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   void tc() {     long long int n;     cin >> n;     string a, b;     cin >> a >> b;     for (long long int i = 0; i < n; i++) {       if (a[i] > b[i]) {         cout << -1 << endl;         return;       }     }     long long int ans = 0;     for (char ch =  a ; ch <=  z ; ch++) {       set<long long int> idx;       char mini =  z ;       for (long long int i = 0; i < n; i++) {         if (a[i] == ch && a[i] != b[i]) {           idx.insert(i);           mini = min(mini, b[i]);         }       }       bool done = false;       for (auto it = idx.begin(); it != idx.end(); it++) {         a[(*it)] = mini;         done = true;       }       if (done) {         ans++;       }     };     cout << ans << endl;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1;     cin >> t;     while (t--) {       tc();     }   }


#include <bits/stdc++.h>   using namespace std;   int N;   char S[100005];   int main() {     scanf( %d , &N);     scanf( %s , S);     string ANS =   ;     int a = (N - 11) / 2, b = a;     for (int i = 0; i < N; i++) {       if (S[i] ==  8 ) {         if (a)           --a;         else           ANS += S[i];       } else {         if (b)           --b;         else           ANS += S[i];       }     }     if (ANS[0] ==  8 )       printf( YES n );     else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   istream &operator>>(istream &in, vector<T> &arr) {     for (T &i : arr) {       in >> i;     }     return in;   }   template <class T>   ostream &operator<<(ostream &in, vector<T> &arr) {     for (T &i : arr) {       in << i <<    ;     }     return in;   }   long long debb = 1;   long long next(vector<long long> &t) {     long long c = (t[1] / t[2] + 1) * (t[1] / t[2] + 1) * (t[1] % t[2]);     long long u = (t[1] / t[2]) * (t[1] / t[2]) * (t[2] - (t[1] % t[2]));     long long su = c + u;     t[2] += 1;     c = (t[1] / t[2] + 1) * (t[1] / t[2] + 1) * (t[1] % t[2]);     u = (t[1] / t[2]) * (t[1] / t[2]) * (t[2] - (t[1] % t[2]));     long long su1 = c + u;     t[2] -= 1;     return su - su1;   }   signed main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     long long n, k;     cin >> n >> k;     long long co = k - n;     multiset<vector<long long>, greater<vector<long long>>> u;     for (int i = 0; i < n; ++i) {       long long x;       cin >> x;       vector<long long> k = {x, x, 1};       long long ra = next(k);       u.insert({ra, x, x, 1});     }     for (int i = 0; i < co; ++i) {       vector<long long> r = *(u.begin());       u.erase(u.begin());       vector<long long> o = {r[1], r[2], r[3]};       o[2] += 1;       o[0] = o[1] / o[2] + min(o[1] % o[2], 1ll);       long long ra = next(o);       u.insert({ra, o[0], o[1], o[2]});     }     long long ans = 0;     for (auto r : u) {       vector<long long> t = {r[1], r[2], r[3]};       for (int i = 0; i < t[2]; ++i) {         long long c = t[1] / t[2] + max(min(t[1] % t[2] - i, 1ll), 0ll);         ans += c * c;       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, ans, up, top;   unsigned long long k;   unsigned long long st[201], ed[201], sum[201], num[201];   int s[300010];   inline void init() {     unsigned long long mi = 1;     st[0] = 0;     ed[0] = 0;     for (int i = 1; i <= 64; i++) {       st[i] = ed[i - 1] + i;       num[i] = ((mi * 10 - 1) - mi + 1);       ed[i] = st[i] + i * (num[i] - 1);       sum[i] = sum[i - 1] + (st[i] + ed[i]) * num[i] / 2;       up = i;       if (sum[i] >= 1e18) break;       mi *= 10;     }   }   inline void prework() { scanf( %lld , &k); }   inline int findans(unsigned long long x, int pos) {     top = 0;     while (x > 0) {       s[++top] = x % 10;       x /= 10;     }     return s[top - pos + 1];   }   inline void mainwork() {     unsigned long long mi = 1, id;     for (int i = 1; i <= up; i++) {       if (sum[i] >= k) {         id = i;         break;       }       mi *= 10;     }     k -= sum[id - 1];     unsigned long long l = 0, r = num[id] - 1, mid;     unsigned long long t, d;     while (l + 1 < r) {       mid = (l + r) >> 1;       t = (st[id] + id * (mid - 1) + st[id]) * mid / 2;       if (t < k)         l = mid;       else         r = mid;     }     if ((st[id] + id * (r - 1) + st[id]) * r / 2 < k)       d = r;     else       d = r - 1;     k -= (st[id] + id * (d - 1) + st[id]) * d / 2;     unsigned long long len = st[id] + d, sum = 0;     for (int i = 1; i <= up; i++) {       if (k <= num[i] * i) {         id = i;         break;       }       k -= num[i] * i;       sum += num[i];     }     unsigned long long val = k / id;     if (k % id == 0)       ans = findans(val + sum, id);     else       ans = findans(val + sum + 1, k % id);   }   inline void print() { printf( %d n , ans); }   int main() {     init();     int t = 1;     scanf( %d , &t);     for (int i = 1; i <= t; i++) {       prework();       mainwork();       print();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[10][10];   int main() {     int bl = 0, wh = 0;     for (int i = 0; i < 8; i++) scanf( %s , s[i]);     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++) {         if (s[i][j] ==  Q )           wh += 9;         else if (s[i][j] ==  R )           wh += 5;         else if (s[i][j] ==  B )           wh += 3;         else if (s[i][j] ==  N )           wh += 3;         else if (s[i][j] ==  P )           wh += 1;         else if (s[i][j] ==  q )           bl += 9;         else if (s[i][j] ==  r )           bl += 5;         else if (s[i][j] ==  b )           bl += 3;         else if (s[i][j] ==  n )           bl += 3;         else if (s[i][j] ==  p )           bl += 1;       }     if (bl > wh)       printf( Black n );     else if (bl == wh)       printf( Draw n );     else       printf( White n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5, maxm = 1e4 + 5, maxe = maxn * 4 + maxm,             maxp = 4 * maxe;   int n, m, b[maxe], id[maxe], tot, cnt, d;   double p[maxp], ans;   int read() {     int ret = 0, f = 1;     char ch = getchar();     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) f = -f;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) ret = ret * 10 + ch -  0 , ch = getchar();     return ret * f;   }   struct tree {     int x, h, l, r;   } a[maxn];   struct mogu {     int x, v;   } c[maxn];   int find(int x) {     int L = 1, R = cnt, mid;     while (L <= R) {       mid = L + R >> 1;       if (id[mid] == x) return mid;       id[mid] < x ? L = mid + 1 : R = mid - 1;     }   }   void build(int l, int r, int k) {     p[k] = 1, d++;     if (l == r) return;     int mid = l + r >> 1;     build(l, mid, k << 1), build(mid + 1, r, k << 1 | 1);   }   void change(int L, int R, int k, int l, int r, double x) {     if (L > r || R < l) return;     if (l <= L && R <= r) {       p[k] *= x / 100.0;       return;     }     if (L == R) return;     int mid = L + R >> 1;     change(L, mid, k << 1, l, r, x), change(mid + 1, R, k << 1 | 1, l, r, x);   }   double ask(int l, int r, int k, int x) {     if (l == r) return p[k];     int mid = l + r >> 1;     if (mid >= x)       return ask(l, mid, k << 1, x) * p[k];     else       return ask(mid + 1, r, k << 1 | 1, x) * p[k];   }   int main() {     n = read(), m = read();     for (int i = 1; i <= n; i++) {       a[i].x = read(), a[i].h = read(), a[i].l = read(), a[i].r = read();       b[++tot] = a[i].x - a[i].h, b[++tot] = a[i].x - 1, b[++tot] = a[i].x + 1,       b[++tot] = a[i].x + a[i].h;     }     for (int i = 1; i <= m; i++) {       c[i].x = read(), c[i].v = read();       b[++tot] = c[i].x;     }     sort(b + 1, b + 1 + tot);     for (int i = 1; i <= tot; i++)       if (b[i] != b[i + 1]) id[++cnt] = b[i];     build(1, cnt, 1);     for (int i = 1; i <= n; i++) {       int L = find(a[i].x - a[i].h), midl = find(a[i].x - 1),           midr = find(a[i].x + 1), R = find(a[i].x + a[i].h);       change(1, cnt, 1, L, midl, (double)100.0 - a[i].l),           change(1, cnt, 1, midr, R, (double)100.0 - a[i].r);     }     for (int i = 1; i <= m; i++) {       int x = find(c[i].x);       ans += (double)ask(1, cnt, 1, x) * c[i].v;     }     printf( %.10lf n , ans);     return 0;   }


#include <bits/stdc++.h>   constexpr static int MAXD = 20000;   using namespace std;   bool check() {     int n;     cin >> n;     int dist = 0;     bool r = true;     for (int i = 0; i < n; i++) {       int t;       string dir;       cin >> t >> dir;       if (dist == 0 && dir !=  South ) r = false;       if (dist == MAXD && dir !=  North ) r = false;       if (dir ==  North ) {         dist -= t;         if (dist < 0) r = false;       }       if (dir ==  South ) {         dist += t;         if (dist > MAXD) r = false;       }     }     if (dist != 0) r = false;     return r;   }   int main() {     if (check())       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }


/*    #include <ext/pb_ds/assoc_container.hpp>    #include <ext/pb_ds/priority_queue.hpp>       using namespace __gnu_pbds;         __gnu_pbds::priority_queue<int, less<int>> pq;   gp_hash_table<int, int> mp;   */      /** Begin fast allocation */   /*   const int mx_MEM = 10 * 1e7;   int mpos = 0;   char mem[mx_MEM];      inline void *operator new(size_t n) {       assert((mpos += n) <= mx_MEM);       return (void *) (mem + mpos - n);   }      inline void operator delete(void *) noexcept {} // must have!   */   /** End fast allocation */      /** Pragmas */   // mt19937 gen(2281337);      //#pragma GCC optimize( O3 ,  Ofast ,  unroll-loops ,  unswitch-loops ,  fast-math ,  no-stack-protector )      //#pragma GCC target( sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,abm,mmx,avx )   // sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,abm,mmx,   //#pragma comment(linker,  /STACK:66777216 )      /*    * @author kamil.sharipov    */      #include <bits/stdc++.h>      //#define int long long   #define all(x) (x).begin(), (x).end()   #define fo(i, a, b) for (int i = a; i < b; ++i)   #define ll long long   #define pii pair<int, int>      using namespace std;      int n, m, inf = 2e9, dst = 51;      vector<vector<pii > > adj;      vector<vector<vector<int> > > we;      int dist[100001][51];      signed main() {   #ifdef _LOCAL       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);   #endif          cin >> n >> m;          adj.resize(n), we.resize(n);       for (int i = 0; i < n; ++i) {           we[i].resize(dst);       }          for (int i = 0; i < m; ++i) {           int u, v, w;           cin >> u >> v >> w;           --u, --v;           adj[u].push_back({v, w});           adj[v].push_back({u, w});       }          for (int i = 0; i < n; ++i) {           for (int j = 0; j < dst; ++j) {               dist[i][j] = inf;           }       }          dist[0][0] = 0;          set<pair<int, pii > > st;       st.insert({0, {0, 0}});          while (!st.empty()) {           auto[w, p] = *st.begin();           st.erase(st.begin());           int v = p.first;           int d = p.second;              if (w > dist[v][d]) continue;              if (d == 0) {               for (int i = 0; i < adj[v].size(); ++i) {                   int to = adj[v][i].first;                   int wei = adj[v][i].second;                      if (dist[to][wei] > w) {                       dist[to][wei] = w;                       st.insert({dist[to][wei], {to, wei}});                   }               }           } else {               for (int i = 0; i < adj[v].size(); ++i) {                   int to = adj[v][i].first;                   int wei = adj[v][i].second;                      int len = (d + wei) * (d + wei) + w;                      if (dist[to][0] > len) {                       dist[to][0] = len;                       st.insert({dist[to][0], {to, 0}});                   }               }           }       }          for (int i = 0; i < n; ++i) {           if (dist[i][0] == inf) cout <<  -1  ;           else cout << dist[i][0] <<    ;       }   }


#include <bits/stdc++.h>   using namespace std;   int L, R;   int main() {     int n, m, i, j, u, v;     cin >> n >> m;     int ans = 100001;     for (i = 0; i < m; i++) {       scanf( %d%d , &L, &R);       ans = min(ans, R - L + 1);     }     cout << ans << endl;     for (i = 1; i <= n; i++) cout << i % ans <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 100005, INF = 2000000000000000000;   vector<long long> g[N];   long long power(long long a, long long b, long long p) {     if (a == 0) return 0;     long long res = 1;     a %= p;     while (b > 0) {       if (b & 1) res = (res * a) % p;       b >>= 1;       a = (a * a) % p;     }     return res;   }   vector<long long> prime;   bool isprime[N];   void pre() {     for (long long i = 2; i < N; i++) {       if (isprime[i]) {         for (long long j = i * i; j < N; j += i) isprime[j] = false;         prime.push_back(i);       }     }     return;   }   bool isPowerOfTwo(long long n) {     if (n == 0) return false;     return (ceil(log2(n)) == floor(log2(n)));   }   long long gcd(long long a, long long b) {     if (a < b)       return gcd(b, a);     else if (a % b == 0)       return b;     else       return gcd(b, a % b);   }   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   long long spf[N + 1];   void spfFun() {     for (long long i = 0; i <= N; i++) spf[i] = i;     for (long long i = 2; i * i <= N; i++) {       if (spf[i] == i) {         for (long long j = i * i; j <= N; j += i) {           spf[j] = min(spf[j], i);         }       }     }   }   bool isPerfectSquare(long double x) {     long double sr = sqrt(x);     return ((sr - floor(sr)) == 0);   }   void print(bool n) {     if (n) {       cout <<  YES ;     } else {       cout <<  NO ;     }   }   int32_t main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n;     cin >> n;     long long l[n], r[n];     for (long long i = 0; i < n; i++) {       cin >> l[i] >> r[i];     }     long long k;     cin >> k;     k--;     long long ans = n;     for (long long i = 0; i < n; i++) {       if (r[i] > k) {         ans = i;         break;       }     }     cout << n - ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int num;     bool flag = true;     int* numbers = new int[n];     for (int i = 0; i < n; i++) {       cin >> num;       numbers[i] = num;       if (i == n - 1) break;     }     for (int i = 0; i < n - 1; i++)       for (int j = i + 1; j < n; j++) {         if (numbers[i] > numbers[j]) swap(numbers[i], numbers[j]);       }     int s;     if (n == 1)       flag = false;     else {       for (int i = 0; i < n; i++) {         if (numbers[i] > numbers[0]) {           flag = true;           s = numbers[i];           break;         }         flag = false;       }     }     if (flag)       cout << s << endl;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     if (n % 2 == 1)       printf( black );     else       printf( white n1 2 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   inline T1 max(T1 a, T2 b) {     return b < a ? a : b;   }   template <typename T1, typename T2>   inline T1 min(T1 a, T2 b) {     return a < b ? a : b;   }   namespace ae86 {   const int bufl = 1 << 15;   char buf[bufl], *s = buf, *t = buf;   inline int fetch() {     if (s == t) {       t = (s = buf) + fread(buf, 1, bufl, stdin);       if (s == t) return EOF;     }     return *s++;   }   inline int ty() {     int a = 0, b = 1, c = fetch();     while (!isdigit(c)) b ^= c ==  - , c = fetch();     while (isdigit(c)) a = a * 10 + c - 48, c = fetch();     return b ? a : -a;   }   }  // namespace ae86   using ae86::ty;   const int _ = 300007;   int n, val[_] = {0}, cho[_] = {0};   long long f[_];   vector<int> ans;   inline void gay(int x) {     if (val[x] <= 0 || val[x + 1] <= 0) return;     int dlt = min(val[x], val[x + 1]);     ans.push_back(x), val[x] -= dlt, val[x + 1] -= dlt;   }   int main() {     n = ty();     for (int i = 1; i <= n; i++) val[i] = ty();     for (int i = 1; i <= n; i++) {       long long a = f[max(i - 2, 0)] + val[i],                 b = f[max(i - 3, 0)] + max(val[i - 1], val[i]);       f[i] = min(a, b);       if (f[i] == b) cho[i] = 1;     }     for (int i = (min(f[n], f[n - 1]) == f[n]) ? (n) : (n - 1); i >= 1;          i -= 2 + cho[i]) {       gay(i - 1);       if (cho[i]) gay(i - 2);       gay(i);     }     printf( %lu n , ans.size());     for (auto i : ans) printf( %d n , i);     return 0;   }