#include <bits/stdc++.h>   int const MAXN = 300100;   char a[MAXN];   int n, x, y;   long long solve() {     if (n == 1) return a[0] ==  0  ? y : 0;     long long cc = 1;     for (int i = 1; i < n; ++i) {       if (a[i - 1] != a[i]) ++cc;     }     if (a[0] ==  1 ) --cc;     if (a[n - 1] ==  1 ) --cc;     if (cc <= 0) return 0;     long long price = ((cc + 1) / 2) * y;     long long rot = cc / 2;     long long ans = price;     while (rot > 0) {       price -= y;       price += x;       ans = std::min(ans, price);       --rot;     }     return ans;   }   int main() {     scanf( %d %d %d , &n, &x, &y);     scanf( %s , a);     long long ans = solve();     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     int hired = 0, untreated, counter = 0, counter2 = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] != -1) {         hired += a[i];       } else if (a[i] == -1 && hired != 0) {         counter++;         hired--;       }       if (a[i] == -1) {         counter2++;       }     }     untreated = counter2 - counter;     cout << untreated;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> sorted_pair(int x, int y) {     if (x > y) {       return pair<int, int>(y, x);     } else {       return pair<int, int>(x, y);     }   }   int main() {     int n;     cin >> n;     vector<vector<int>> graph(n + 1, vector<int>());     set<pair<int, int>> pairs;     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       graph[x].push_back(y);       graph[y].push_back(x);     }     for (int i = 1; i <= n; i++) {       queue<pair<int, int>> q;       q.push(pair<int, int>(i, 0));       vector<bool> visited(n + 1, false);       while (!q.empty()) {         int v = q.front().first;         int lvl = q.front().second;         visited[v] = true;         if (lvl < 2) {           for (int k = 0; k < graph[v].size(); k++) {             if (!visited[graph[v][k]]) {               q.push(pair<int, int>(graph[v][k], lvl + 1));             }           }         } else if (lvl == 2) {           pairs.insert(sorted_pair(i, v));         }         q.pop();       }     }     cout << pairs.size() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct quad {     pair<int, int> points[4];     void read() {       for (int i = 0; i < 4; i++) {         cin >> points[i].first >> points[i].second;       }     }     int cross(int a, int b, int c, int d) { return a * d - b * c; }     int sgn(int x) {       if (x < 0) return -1;       if (x > 0) return 1;       return 0;     }     bool contains(int x, int y) {       int side = 0;       for (int i = 0; i < 4; i++) {         int j = (i + 1) % 4;         int a = points[j].first - points[i].first;         int b = points[j].second - points[i].second;         int c = x - points[i].first;         int d = y - points[i].second;         int v = sgn(cross(a, b, c, d));         if (v == 0) {           continue;         }         if (side == 0) {           side = v;         } else if (side != v) {           return false;         }       }       return true;     }   };   int main() {     quad A, B;     A.read();     B.read();     for (int x = -100; x <= 100; x++) {       for (int y = -100; y <= 100; y++) {         if (A.contains(x, y) && B.contains(x, y)) {           cout <<  YES n ;           return 0;         }       }     }     cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long m, n;     cin >> m >> n;     double sum;     sum = m;     for (double i = m - 1; i > 0; i--) {       sum -= pow(i / m, n);     }     cout << fixed;     cout << setprecision(12) << sum <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100007, dx[8] = {1, 1, 1, 0, 0, -1, -1, -1},             dy[8] = {1, 0, -1, 1, -1, 1, 0, -1};   int xs, ys, xt, yt, n, r[maxn], a[maxn], b[maxn], d[maxn] = {}, cnt = 0;   bool vis[maxn] = {};   vector<int> row, col[maxn];   vector<pair<int, int> > seg[maxn], cells[maxn];   int dist(int x, int y) {     x = lower_bound(row.begin(), row.end(), x) - row.begin() + 1;     y = lower_bound(cells[x].begin(), cells[x].end(), make_pair(y, 0)) -         cells[x].begin();     return d[cells[x][y].second];   }   void set_dist(int x, int y, int val) {     x = lower_bound(row.begin(), row.end(), x) - row.begin() + 1;     y = lower_bound(cells[x].begin(), cells[x].end(), make_pair(y, 0)) -         cells[x].begin();     d[cells[x][y].second] = val;   }   bool valid(int x, int y) {     if (!binary_search(row.begin(), row.end(), x)) return 0;     x = lower_bound(row.begin(), row.end(), x) - row.begin() + 1;     if (!binary_search(col[x].begin(), col[x].end(), y)) return 0;     return 1;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> xs >> ys >> xt >> yt >> n;     for (int i = 1; i <= n; ++i) {       cin >> r[i] >> a[i] >> b[i];       row.push_back(r[i]);     }     sort(row.begin(), row.end());     for (int i = 1; i <= n; ++i)       r[i] = lower_bound(row.begin(), row.end(), r[i]) - row.begin() + 1;     for (int i = 1; i <= n; ++i) seg[r[i]].push_back({a[i], b[i]});     for (int i = 1; i <= n; ++i) {       if (vis[r[i]]) continue;       sort(seg[r[i]].begin(), seg[r[i]].end());       int cur = 1;       for (auto it : seg[r[i]]) {         cur = max(it.first, cur);         for (int j = cur; j <= it.second; ++j)           cells[r[i]].push_back({j, ++cnt}), col[r[i]].push_back(j);       }       vis[r[i]] = 1;     }     queue<pair<int, int> > q;     q.push({xs, ys});     set_dist(xs, ys, 1);     while (q.size()) {       int x = q.front().first, y = q.front().second;       q.pop();       for (int i = 0; i < 8; ++i) {         int xx = dx[i] + x, yy = dy[i] + y;         if (valid(xx, yy) && dist(xx, yy) == 0)           set_dist(xx, yy, dist(x, y) + 1), q.push({xx, yy});       }     }     cout << dist(xt, yt) - 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, i, j, c = 0, d = 0, a, b, k = 0, sum = 0, sum1 = 0;     cin >> t;     string s;     stack<char> st;     cin >> s;     for (i = 0; i < s.size(); i++) {       if (s[i] ==  ( ) {         sum++;       } else {         sum1++;       }       if (s[i] ==  ( ) {         st.push(s[i]);       } else if (s[i] ==  ) ) {         if (st.size() > 0 && st.top() ==  ( ) {           st.pop();         } else {           c++;         }       }     }     if (sum != sum1) {       cout <<  NO  << endl;     } else if (st.size() <= 1 && c <= 1) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int nxt() {     int x;     scanf( %d , &x);     return x;   }   int main() {     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());     int n = nxt();     vector<int> a(n);     for (int i = 0; i < n; ++i) {       a[i] = nxt();     }     int s = accumulate((a).begin(), (a).end(), 0);     int k = *max_element((a).begin(), (a).end());     int t = k * n;     int need = 2 * s + 1;     if (need > t) {       k += (need - t + n - 1) / n;     }     printf( %d n , k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     size_t found;     vector<string> str;     string a, b, c, in, out;     long long i, j, k, m, n, l, t;     cin >> t;     while (t--) {       cin >> in;       for (i = 0, j = 0, k = 0; i < in.size(); i++) {         if (in[i] ==  :  && i == 0) {           i++;           j = 1;         }         if (in[i] ==  : ) {           b = in.substr(j, i - j);           if (b ==   ) k++;           str.push_back(b);           j = i + 1;         }       }       if (in[in.size() - 1] !=  : ) {         b = in.substr(j, in.size() - j);         str.push_back(b);       }       for (i = 0; i < str.size(); i++) {         if (i > 0) cout <<  : ;         if (str[i] ==   ) {           for (j = 0; j < 8 - str.size() + k; j++) {             if (j > 0) cout <<  : ;             cout <<  0000 ;           }         } else {           if (str[i].size() < 4) {             for (l = str[i].size(); l < 4; l++) cout <<  0 ;           }           cout << str[i];         }       }       cout << endl;       str.clear();       in.clear();       k = 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 100000 + 5;   int N;   map<int, int> Numbers;   int main(void) {     scanf( %d , &N);     if (N % 2) {       printf( NO n );       return 0;     }     for (int i = 0; i < N; i++) {       int Number;       scanf( %d , &Number);       Numbers[Number]++;     }     while (!Numbers.empty()) {       while (!Numbers.begin()->second) Numbers.erase(Numbers.begin());       int Number = Numbers.begin()->first;       if (N == 2) {         if (Numbers[Number + 1] == 1)           printf( YES n );         else           printf( NO n );         return 0;       }       if (Numbers[Number + 1] < 2) {         printf( NO n );         return 0;       }       Numbers[Number]--;       Numbers[Number + 1]--;       N -= 2;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, i, c = 1;     cin >> a >> b;     if (b < a) a = b;     for (i = 2; i <= a; i++) c *= i;     cout << c << endl;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 100 * 1000 + 5;   int n, m, cnt;   short int mark[N];   bool visited[N];   vector<int> in[N], out[N], comp[N];   void input() {     cin.tie(0);     cin >> n >> m;     int v, u;     for (int i = 0; i < m; i++) {       cin >> v >> u;       v--, u--;       out[v].push_back(u);       in[u].push_back(v);     }     return;   }   void getComp(int v) {     visited[v] = true;     for (int u : in[v])       if (!visited[u]) getComp(u);     for (int u : out[v])       if (!visited[u]) getComp(u);     comp[cnt].push_back(v);     return;   }   bool isDAG(int v) {     bool res = true;     mark[v]++;     for (int u : out[v])       if (!mark[u])         res &= isDAG(u);       else if (mark[u] == 1)         return false;     mark[v]++;     return res;   }   void solve() {     for (int i = 0; i < n; i++)       if (!visited[i]) {         getComp(i);         cnt++;       }     for (int i = 0; i < cnt; i++) {       bool check = true;       for (int v : comp[i])         if (!mark[v]) check &= isDAG(v);       if (check) n--;     }   }   int main() {     ios::sync_with_stdio(false);     input();     solve();     cout << n << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   long long n, m, f, t, d, val;   vector<long long> a, c;   set<pair<long long, long long> > s;   int main() {     cin.tie(0);     cout.tie(0);     ios::sync_with_stdio(0);     cin >> n >> m;     a.resize(n);     c.resize(n);     for (auto& i : a) cin >> i;     for (auto& i : c) cin >> i;     for (int i = 0; i < n; i++) s.insert(make_pair(c[i], i));     while (m--) {       cin >> t >> d;       t--;       long long bill = 0;       val = min(a[t], d);       bill += val * c[t];       a[t] -= val;       d -= val;       while (d) {         if (s.empty()) break;         val = min(a[s.begin()->second], d);         bill += val * (s.begin()->first);         a[s.begin()->second] -= val;         d -= val;         if (a[s.begin()->second] == 0) s.erase(s.begin());       }       if (d)         cout <<  0 n ;       else         cout << bill <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     register long long w = 1, x = 0, ch = getchar();     for (; ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) w = -1;     for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch -  0 ;     return x * w;   }   const long long MAXN = (long long)7e2 + 10;   const long long MOD = (long long)1e9 + 7;   const long long INF = 0x3f3f3f3f3f3f3f3f;   char s[MAXN];   long long n, ans, digit[MAXN], Dec[MAXN], divv[MAXN][10], f[MAXN][MAXN][10][2];   inline void Init() {     cin >> s + 1;     n = strlen(s + 1);     for (register long long i = 1; i <= n; i++) {       digit[i] = s[i] -  0 ;     }   }   inline void DP() {     Dec[0] = 1;     for (register long long i = 1; i <= n; i++) {       Dec[i] = Dec[i - 1] * 10 % MOD;     }     for (register long long i = 0; i <= 9; i++) {       f[0][0][i][1] = 1;     }     for (register long long i = 0; i < n; i++) {       for (register long long j = 0; j <= i; j++) {         for (register long long x = 1; x <= 9; x++) {           for (register long long l = 0; l <= 1; l++) {             for (register long long k = 0; k <= (l ? digit[i + 1] : 9); k++) {               f[i + 1][j + (k >= x)][x][(k == digit[i + 1]) && l] +=                   f[i][j][x][l];               f[i + 1][j + (k >= x)][x][(k == digit[i + 1]) && l] %= MOD;             }           }         }       }     }     for (register long long x = 1; x <= 9; x++) {       for (register long long j = 1; j <= n; j++) {         for (register long long i = j; i <= n; i++)           divv[j][x] = (divv[j][x] + f[n][i][x][1] + f[n][i][x][0]) % MOD;       }     }     for (register long long i = 1; i <= n; i++) {       for (register long long x = 1; x <= 9; x++) {         ans = (ans + (divv[i][x] - divv[i][x + 1] + MOD) % MOD * Dec[i - 1] %                          MOD * x % MOD) %               MOD;       }     }     printf( %lld n , ans);   }   signed main() {     Init();     DP();     return 0;   }


#include <bits/stdc++.h>   #pragma gcc optimize( Ofast )   using namespace std;   inline void input(int &_x) {     _x = 0;     int _tmp = 1;     char _tc = getchar();     while ((_tc <  0  || _tc >  9 ) && _tc !=  - ) _tc = getchar();     if (_tc ==  - ) _tc = getchar(), _tmp = -1;     while (_tc >=  0  && _tc <=  9 ) _x = _x * 10 + (_tc - 48), _tc = getchar();     _x *= _tmp;   }   int root[400009], tag[400009];   int aa[100009];   inline void build(int id, int l, int r) {     if (l == r) {       root[id] = aa[l];       return;     }     int mid = (l + r) >> 1;     build((id << 1), l, mid);     build((id << 1) + 1, mid + 1, r);     root[id] = max(root[(id << 1)], root[(id << 1) + 1]);   }   inline void push(int id) {     root[id] += tag[id];     tag[(id << 1)] += tag[id];     tag[(id << 1) + 1] += tag[id];     tag[id] = 0;   }   inline void modify(int id, int l, int r, int ql, int qr, int v) {     if (tag[id]) push(id);     if (ql <= l && r <= qr) {       tag[id] += v;       push(id);       return;     }     if (qr < l || r < ql) return;     int mid = (l + r) >> 1;     modify((id << 1), l, mid, ql, qr, v);     modify((id << 1) + 1, mid + 1, r, ql, qr, v);     root[id] = max(root[(id << 1)], root[(id << 1) + 1]);   }   int n, m;   vector<int> seg[100009];   bitset<100009> vis;   inline bool cmp(int a, int b) { return aa[a] < aa[b]; }   signed main() {     int ma = -1;     input(n);     input(m);     for (int i = 1; i < n + 1; ++i) input(aa[i]), ma = max(ma, aa[i]);     vector<pair<int, int> > v(m), w;     for (auto &i : v) input(i.first), input(i.second);     for (int i = 1; i < n + 1; ++i) w.emplace_back(aa[i], i);     sort((w).begin(), (w).end());     int ans = -1, p = 0;     build(1, 1, n);     for (int i = 1; i < n + 1; ++i)       for (int j = 0; j < m; ++j)         if (v[j].first <= i && i <= v[j].second) seg[i].emplace_back(j);     for (int _ = 0; _ < n; ++_) {       int i = w[_].second;       if (ans > ma - (aa[i] - (int)(seg[i]).size())) continue;       int cnt = 0;       for (auto &j : seg[i]) modify(1, 1, n, v[j].first, v[j].second, -1), ++cnt;       if (root[1] - (aa[i] - cnt) > ans) {         ans = root[1] - (aa[i] - cnt);         p = i;       }       for (auto &j : seg[i]) modify(1, 1, n, v[j].first, v[j].second, 1);     }     cout << ans <<   n  << (int)(seg[p]).size() <<   n ;     for (auto &i : seg[p]) cout << i + 1 <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k = 100000000, t;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 1; i < n; i++) {       t = max(a[i - 1], a[i]);       k = min(t, k);     }     cout << min(min(a[0], a[n - 1]), k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int ar1[100], ar2[100];     memset(ar1, 0, sizeof(ar1));     memset(ar2, 0, sizeof(ar2));     string s1, s2;     cin >> s1 >> s2;     int t;     cin >> t;     vector<pair<pair<int, char>, pair<int, char> > > v(t);     for (int i = 0; i < t; i++)       cin >> v[i].first.first >> v[i].first.second >> v[i].second.first >>           v[i].second.second;     sort(v.begin(), v.end());     for (int i = 0; i < t; i++) {       if (v[i].first.second ==  a ) {         if (ar2[v[i].second.first] < 2) {           ar2[v[i].second.first] += (v[i].second.second ==  y ) ? 1 : 2;           if (ar2[v[i].second.first] >= 2)             cout << s2 <<     << v[i].second.first <<     << v[i].first.first                  << endl;         }       } else if (v[i].first.second ==  h ) {         if (ar1[v[i].second.first] < 2) {           ar1[v[i].second.first] += (v[i].second.second ==  y ) ? 1 : 2;           if (ar1[v[i].second.first] >= 2)             cout << s1 <<                      <<     << v[i].second.first <<     << v[i].first.first << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int arrmax = 200005;   char str[arrmax];   int reversetimes[arrmax / 2];   int main() {     int m, a, sum, len;     while (~scanf( %s %d , str, &m)) {       len = strlen(str);       memset(reversetimes, 0, 2 * len);       while (m--) {         scanf( %d , &a);         reversetimes[a - 1]++;       }       sum = 0;       for (int i = 0; i < len / 2; i++) {         sum += reversetimes[i];         if (sum & 1) swap(str[i], str[len - i - 1]);       }       printf( %s n , str);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   string res[101];   int dx[] = {0, 0, -1, 1};   int dy[] = {-1, 1, 0, 0};   inline bool in(int x, int y) {     if (x < 0 || y < 0 || x >= n || y >= m) return 0;     return 1;   }   int main(int argc, char **argv) {     cin >> n >> m;     for (int i = 0; i <= n - 1; i++) {       cin >> res[i];     }     int c = 1;     for (int i = 0; i <= n - 1; i++) {       c = i % 2;       for (int j = 0; j <= m - 1; j++) {         if (res[i][j] ==  . ) {           if (c)             res[i][j] =  B ;           else             res[i][j] =  W ;         }         if (c == 1)           c = 0;         else           c = 1;       }     }     for (int i = 0; i <= n - 1; i++) cout << res[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x, y, a, b, c, ans;   int main() {     cin >> x >> y;     if (x > y) swap(x, y);     a = b = c = x;     while (true) {       a = b + c - 1;       ans++;       if (a >= y) break;       b = a + c - 1;       ans++;       if (b >= y) break;       c = a + b - 1;       ans++;       if (c >= y) break;     }     cout << ans + 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a[500011], L[500011], R[500011], aL[500011], aR[500011],       ans[500011];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (long long i = 1; i <= n; i++) cin >> a[i];     stack<pair<long long, long long> > st;     for (long long i = 1; i <= n; i++) {       while (!st.empty() && st.top().first >= a[i]) st.pop();       if (st.empty())         L[i] = 0;       else {         L[i] = st.top().second;       }       st.push(pair<long long, long long>(a[i], i));     }     while (!st.empty()) st.pop();     for (long long i = n; i >= 1; i--) {       while (!st.empty() && st.top().first >= a[i]) st.pop();       if (st.empty())         R[i] = n + 1;       else         R[i] = st.top().second;       st.push(pair<long long, long long>(a[i], i));     }     for (long long i = 1; i <= n; i++) {       aL[i] = aL[L[i]] + a[i] * (i - L[i]);     }     for (long long i = n; i >= 1; i--) {       aR[i] = aR[R[i]] + a[i] * (R[i] - i);     }     long long A = 0, pos = 0;     for (long long i = 1; i <= n; i++) {       if (aL[i] + aR[i] - a[i] > A) {         A = aL[i] + aR[i] - a[i];         pos = i;       }     }     ans[pos] = a[pos];     long long cur_min = ans[pos];     for (long long i = pos - 1; i >= 1; i--) {       ans[i] = min(a[i], cur_min);       cur_min = min(a[i], cur_min);     }     cur_min = ans[pos];     for (long long i = pos + 1; i <= n; i++) {       ans[i] = min(a[i], cur_min);       cur_min = min(a[i], cur_min);     }     for (long long i = 1; i <= n; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   char buf[100], name[100], op[100], tmp[100];   struct widget {     long long x, y;     bool finish;     int type, border, spacing;     vector<int> w;     widget(long long xx = 0, long long yy = 0, int t = 0) {       x = xx;       y = yy;       type = t;       w = vector<int>();       finish = false;       border = spacing = 0;     }     void gao(){};   } wid[110];   map<string, int> mp;   void gao(int id) {     if (wid[id].finish || wid[id].type == 0) return;     long long &x = wid[id].x;     long long &y = wid[id].y;     x = y = 0;     for (int i = 0; i < ((int)wid[id].w.size()); ++i) {       int z = wid[id].w[i];       gao(z);       if (wid[id].type == 1) {         x += wid[z].x + wid[id].spacing;         y = max(y, wid[z].y);       } else {         y += wid[z].y + wid[id].spacing;         x = max(x, wid[z].x);       }     }     wid[id].finish = true;     if (((int)wid[id].w.size()) == 0) return;     if (wid[id].type == 1) {       x += wid[id].border * 2 - wid[id].spacing;       y += wid[id].border * 2;     } else {       y += wid[id].border * 2 - wid[id].spacing;       x += wid[id].border * 2;     }   }   void solve() {     mp.clear();     int x, y, tot = 0;     for (int i = 0; i < n; ++i) {       scanf( %s , buf);       if (string(buf) ==  Widget ) {         scanf( %s , buf);         sscanf(buf,  %[^(](%d,%d) , name, &x, &y);         mp[name] = tot;         wid[tot++] = widget(x, y, 0);       } else if (string(buf) ==  HBox ) {         scanf( %s , buf);         mp[buf] = tot;         wid[tot++] = widget(-1, -1, 1);       } else if (string(buf) ==  VBox ) {         scanf( %s , buf);         mp[buf] = tot;         wid[tot++] = widget(-1, -1, 2);       } else {         sscanf(buf,  %[^.].%[^(](%[^)] , name, op, tmp);         int id = mp[name];         if (string(op) ==  set_border ) {           sscanf(tmp,  %d , &x);           wid[id].border = x;         } else if (string(op) ==  set_spacing ) {           sscanf(tmp,  %d , &x);           wid[id].spacing = x;         } else {           wid[id].w.push_back(mp[tmp]);         }       }     }     map<string, int>::iterator it = mp.begin();     for (; it != mp.end(); ++it) {       int id = it->second;       gao(id);       printf(            %s              %I64d                           %I64d              n ,           it->first.c_str(), wid[id].x, wid[id].y);     }     puts(  );   }   int main() {     while (scanf( %d , &n) != EOF) {       solve();     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   bool b[150000] = {0};   bool dfs(int n, vector<set<int>>& v) {     b[n] = 1;     for (auto itr = v[n].begin(); itr != v[n].end(); itr++) {       if (!b[*itr])         if (v[n] != v[*itr]) return 0;       if (!b[*itr]) dfs(*itr, v);     }     return 1;   }   int main() {     int n, m;     cin >> n >> m;     vector<set<int>> v(n);     for (int i = 0; i < n; i++) v[i].insert(i);     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       v[a].insert(b);       v[b].insert(a);     }     bool r = 1;     for (int i = 0; i < n && r; i++) {       if (!b[i]) {         if (!dfs(i, v)) r = 0;       }     }     cout << (r ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3 * 1e5 + 10, maxm = (1 << 17), mod = 1e9 + 7;   const double PI = 3.14159265359;   vector<int> g[maxn];   int d[maxn];   bool r[maxn];   set<int> s;   int main() {     ios::sync_with_stdio(0);     int n, a, b, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> a >> b;       a--, b--;       g[a].push_back(b), g[b].push_back(a);     }     for (int i = 0; i < n; i++) {       d[i] = g[i].size();       if (g[i].size() > 1) s.insert(i);     }     while (s.size()) {       a = *s.begin();       s.erase(s.begin());       r[a] = !r[a], d[a] = g[a].size() - d[a];       for (int i = 0; i < g[a].size(); i++) {         b = g[a][i];         d[b] += (r[a] == r[b] ? 1 : -1);         if (d[b] > 1)           s.insert(b);         else           s.erase(b);       }     }     for (int i = 0; i < n; i++) cout << r[i];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int t, d, p, id;   } s[110];   int dp[2010];   vector<int> v[2010];   int cmp(node a, node b) { return a.d < b.d; }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d%d , &s[i].t, &s[i].d, &s[i].p), s[i].id = i;     }     sort(s + 1, s + n + 1, cmp);     for (int i = 1; i <= n; i++) {       if (s[i].d - s[i].t <= 0) continue;       for (int j = s[i].d - 1; j - s[i].t >= 0; j--) {         if (dp[j] < dp[j - s[i].t] + s[i].p) {           dp[j] = dp[j - s[i].t] + s[i].p;           v[j] = v[j - s[i].t];           v[j].push_back(s[i].id);         }       }     }     int best = 0, bestI = 0;     for (int i = 0; i <= 2000; i++) {       if (dp[i] > best) {         best = dp[i];         bestI = i;       }     }     printf( %d n , best);     printf( %d n , v[bestI].size());     for (int i = 0; i < v[bestI].size(); i++) printf( %d  , v[bestI][i]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a;     int cnt = 0;     int sum = 0;     for (int i = 0; i < 2 * n - 1; ++i) {       int x;       cin >> x;       a.push_back(abs(x));       if (x < 0) cnt++;       sum += abs(x);     }     cnt %= n;     queue<int> q;     vector<bool> used(n + 1, false);     used[cnt] = 1;     q.push(cnt);     int c = cnt;     while (!q.empty()) {       int u = q.front();       q.pop();       if (!used[n - u]) {         used[n - u] = 1;         q.push(n - u);         c = min(c, n - u);       }       for (int i = 1; i <= u; ++i) {         int to = u - i + n - i;         to %= n;         if (to >= 0 && !used[to]) {           used[to] = 1;           q.push(to);           c = min(c, to);         }       }     }     sort(a.begin(), a.end());     if (c == 0) {       cout << sum;     } else {       for (int i = 0; i < c; ++i) {         sum -= 2 * a[i];       }       cout << sum;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char **argv) {     ios_base::sync_with_stdio(false);     cin.tie(0);     int m, n;     cin >> n >> m;     vector<string> s(n);     vector<pair<int, int>> t(n, {-1, -1});     for (int i = 0; i < n; i++) cin >> s[i];     bool ok = true;     for (int i = 0; i < n; i++) {       int k = 0;       for (int j = 0; j < m; j++) {         if (s[i][j] ==  X ) {           if (!j || s[i][j - 1] ==  . ) k++;           if (t[i].first < 0) t[i].first = j;           t[i].second = j;         }       }       if (k > 1) ok = false;     }     int k = 0;     pair<int, int> u({-1, -1});     for (int i = 0; i < n; i++) {       if (t[i].first < 0) continue;       if (!i || t[i - 1].first < 0) k++;       if (u.first < 0) u = t[i];       if (u != t[i]) ok = false;     }     if (k > 1) ok = false;     cout << (ok ?  YES  :  NO ) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ii = pair<int, int>;   using vi = vector<int>;   using vvi = vector<vi>;   using vii = vector<ii>;   using vb = vector<bool>;   using ll = long long;   template <typename A, typename B>   istream &operator>>(istream &in, pair<A, B> &p) {     in >> p.first >> p.second;     return in;   }   template <typename T>   istream &operator>>(ifstream &in, vector<T> &v) {     for (int i = 0; i < (int)v.size(); ++i) {       in >> v[i];     }     return in;   }   int main() {     int n, k;     cin >> n >> k;     vector<set<int>> times(n);     for (int i = 0; i < k; ++i) {       int x;       cin >> x;       x--;       times[x].insert(i);     }     int res = 0;     for (int x = 0; x < n; ++x) {       if (times[x].empty()) {         res += 3;         if (x == 0) res--;         if (x == n - 1) res--;       } else {         int t = *times[x].begin();         if (x != n - 1 && times[x + 1].lower_bound(t) == times[x + 1].end())           res++;         if (x != 0 && times[x - 1].lower_bound(t) == times[x - 1].end()) res++;       }     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   bool fun(int x, int y) { return x > y; }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     ;     int n, s;     cin >> n >> s;     if (s <= n) {       cout << 1 <<   n ;     }     if (s > n && s % n == 0) {       cout << s / n <<   n ;     }     if (s > n && s % n != 0) {       cout << s / n + 1 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream& operator<<(ostream& os, vector<T> V) {     os <<  [  ;     for (auto v : V) os << v <<    ;     return os <<  ] ;   }   template <class T>   ostream& operator<<(ostream& os, set<T> S) {     os <<  {  ;     for (auto s : S) os << s <<    ;     return os <<  } ;   }   template <class L, class R>   ostream& operator<<(ostream& os, pair<L, R> P) {     return os <<  (  << P.first <<  ,  << P.second <<  ) ;   }   template <class L, class R>   ostream& operator<<(ostream& os, map<L, R> M) {     os <<  {  ;     for (auto m : M) os <<  (  << m.F <<  :  << m.S <<  ) ;     return os <<  } ;   }   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   long long const M = 1e9;   bool check(long long v, long long n, long long k) {     long long s = n;     long long d = k;     while (n / k >= 1) {       s = s + n / k;       k = k * d;     }     return (s >= v);   }   int main() {     long long n, k;     cin >> n >> k;     long long l = 0;     long long r = M;     while (r - l > 1) {       long long mid = (l + r) >> 1;       if (check(n, mid, k))         r = mid;       else         l = mid;     }     cout << r <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long double ans;   long long one, two;   map<pair<long long, long long>, pair<long long, long long> > o, t;   map<pair<long long, long long>, pair<long long, long long> >::iterator ii;   void add(long long a, long long b, long long c, long long ind) {     pair<long long, long long> p = make_pair(a, b);     if (c > o[p].first && ind != t[p].second) {       t[p] = o[p];       o[p] = {c, ind};     }     if (c > t[p].first && ind != o[p].second) t[p] = {c, ind};   }   int main() {     long long n, i, j;     cin >> n;     for (i = 1; i <= n; i++) {       long long a, b, c;       cin >> a >> b >> c;       long long t = min(a, min(b, c));       long double cur = 1.0 * t / 2;       if (cur > ans) {         ans = cur;         one = i;       }       add(a, b, c, i);       add(a, c, b, i);       add(b, a, c, i);       add(b, c, a, i);       add(c, a, b, i);       add(c, b, a, i);     }     for (ii = t.begin(); ii != t.end(); ii++) {       long long cur = ii->second.first + o[ii->first].first;       long long Min = min(cur, min(ii->first.first, ii->first.second));       long double curans = 1.0 * Min / 2;       if (curans > ans) {         ans = curans;         one = ii->second.second;         two = o[ii->first].second;       }     }     if (one != 0 && two != 0)       cout <<  2 n  << one <<     << two;     else       cout <<  1 n  << one;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     for (int i = 0; i < t; ++i) {       int n, a[150000]{};       cin >> n;       for (int j = 0; j < n; ++j) {         cin >> a[j];       }       int min = a[n - 1], cnt = 0;       for (int j = n - 2; j >= 0; --j) {         if (a[j] < min) {           min = a[j];         } else if (a[j] > min) {           ++cnt;         }       }       cout << cnt <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   long long k;   long long a[21][21];   map<long long, int> mp[21][21];   int Color[21][21];   queue<pair<int, int>> q;   void BFS(int x, int y, int depthMax, vector<pair<int, int>> d) {     Color[x][y] = 1;     mp[x][y][a[x][y]] = 1;     q.push(make_pair(x, y));     while (!q.empty()) {       tie(x, y) = q.front();       q.pop();       if (Color[x][y] == depthMax) {         continue;       }       for (auto i : d) {         int u = x + i.first, v = y + i.second;         if (u > 0 && u <= n && v > 0 && v <= m) {           for (auto it : mp[x][y]) {             mp[u][v][a[u][v] ^ it.first] += it.second;           }           if (Color[u][v] == 0) {             Color[u][v] = Color[x][y] + 1;             q.push(make_pair(u, v));           }         }       }     }   }   long long GetMap(map<long long, int> &mp, long long x) {     auto it = mp.find(x);     return (it == mp.end() ? 0 : it->second);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> a[i][j];       }     }     if (n == 1 && m == 1) {       cout << (a[1][1] == k ? 1 : 0);       return 0;     }     int numStep = (n + m - 1) / 2;     BFS(1, 1, numStep,         vector<pair<int, int>>({make_pair(1, 0), make_pair(0, 1)}));     BFS(n, m, (n + m - 1) - numStep,         vector<pair<int, int>>({make_pair(-1, 0), make_pair(0, -1)}));     long long Ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (i + j - 1 == numStep && Color[i][j] == numStep) {           for (auto x : mp[i][j]) {             long long tmp = 0;             if (i + 1 <= n) {               tmp += GetMap(mp[i + 1][j], x.first ^ k);             }             if (j + 1 <= m) {               tmp += GetMap(mp[i][j + 1], x.first ^ k);             }             Ans += 1LL * tmp * x.second;           }           break;         }       }     }     cout << Ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a, b[101];   void read() {     int c, d, k = 0;     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a, b[i] = a + b[i - 1];     for (int i = 0; i < m; i++) {       cin >> c >> d;       k += (b[d] - b[c - 1] > 0 ? b[d] - b[c - 1] : 0);     }     cout << k;   }   int main() { read(); }


#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-9;   const long double pi = acos(-1.0);   const int inf = 1e+9;   long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }   int xabs(int a) { return a >= 0 ? a : -a; }   int sign(int a) { return (a < 0) ? -1 : 1; }   int sqr(int a) { return a * a; }   int main() {     string s;     cin >> s;     int n = s.size();     stack<pair<char, int> > q;     set<pair<char, char> > sp;     sp.insert(make_pair( [ ,  ] ));     sp.insert(make_pair( ( ,  ) ));     for (int i = 0; i < n; i++) {       if (q.size() == 0) {         q.push(make_pair(s[i], i));       } else {         if (sp.count(make_pair(q.top().first, s[i]))) {           q.pop();         } else {           q.push(make_pair(s[i], i));         }       }     }     vector<int> ans;     while (q.size() != 0) {       ans.push_back(q.top().second);       q.pop();     }     reverse(ans.begin(), ans.end());     ans.push_back(n);     int cnt = 0;     int j = 0;     int ma = 0;     string res;     while (j < ans.size()) {       int cnt = 0;       int start = (j > 0) ? ans[j - 1] + 1 : 0;       for (int i = start; i < ans[j]; i++) {         if (s[i] ==  [ ) cnt++;       }       if (cnt > ma) {         ma = cnt;         res = s.substr(start, ans[j] - start);       }       j++;     }     cout << ma << endl;     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double Pi = acos((double)-1);   const double Eps = 1E-6;   int read() {     int $x;     scanf( %d , &$x);     return $x;   }   long long sqr(long long $x) { return $x * $x; }   int x[100000], N, A, B;   int main() {     A = read(), B = read();     N = A + B + 1;     x[0] = 1;     int i = 0, t;     t = 1;     while (A--) x[++i] = ++t;     t = 1;     while (B--) x[++i] = --t;     for (i = 0; i < N; ++i) printf( %d  , x[i] - t + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         if ((i + j) % 2)           cout <<  W ;         else           cout <<  B ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   const int N = 100010;   char s[N], str[3][N];   int len;   int solve(int type, int ret) {     int ans = 0;     memcpy(str[type], s, sizeof(s));     for (int i = len - 1; i >= 0; --i) {       if ((str[type][i] -  0 ) % 3 == type) {         str[type][i] =   0 ;         ++ans;         ret = (ret - type + 3) % 3;         if (!ret) {           break;         }       }     }     for (int i = 0; i < len; ++i) {       if (str[type][i] == 0) {         continue;       }       if (str[type][i] !=  0  || len - ans == 1) {         break;       }       str[type][i] =   0 ;       ++ans;     }     return ret ? INT_MAX : ans;   }   int main() {     scanf( %s , s);     int sum = 0;     len = strlen(s);     for (int i = 0; i < len; ++i) {       sum += s[i] -  0 ;     }     if (!(sum % 3)) {       return printf( %s , s), 0;     }     int ans1 = solve(1, sum % 3), ans2 = solve(2, sum % 3);     int type = ans1 < ans2 ? 1 : 2;     int cnt = 0;     for (int i = 0; i < len; ++i) {       if (str[type][i] != 0) {         ++cnt;         putchar(str[type][i]);       }     }     if (!cnt) {       return printf( -1 n ), 0;     }     return printf(  n ), 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int h1, a1, c1, i;     int h2, a2;     scanf( %d%d%d%d%d , &h1, &a1, &c1, &h2, &a2);     vector<int> v;     while (true) {       if (h1 - a2 <= 0 && h2 - a1 <= 0) {         h1 -= a2;         h2 -= a1;         v.push_back(1);         break;       } else if (h1 - a2 > 0) {         h2 = h2 - a1;         h1 = h1 - a2;         v.push_back(1);         if (h2 <= 0 || h1 <= 0) {           break;         }       } else {         h1 += c1;         h1 -= a2;         v.push_back(0);       }     }     int n = v.size();     printf( %d n , n);     for (i = 0; i < n; i++) {       if (v[i] == 0)         printf( HEAL n );       else         printf( STRIKE n );     }   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     long long int A;     long long int B;   };   bool edgecompare(edge lhs, edge rhs) {     if (lhs.B != rhs.B)       return lhs.B < rhs.B;     else       return lhs.A < rhs.A;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, m, i, j, k, flag = 0, a[100005];     string str;     map<long long int, long long int> Map;     set<long long int> Set;     set<long long int, greater<long long int> >::iterator itr;     cin >> n >> k;     long long int ma = 0;     i = 0;     while (pow(2, i) <= n) {       i++;     }     ma = pow(2, i) - 1;     if (k == 1)       cout << n;     else       cout << ma;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> times;     int n, k;     cin >> n >> k;     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       times.push_back(x);     }     int ans = 0;     for (int i = 1; i < n; ++i) {       if (times[i] + times[i - 1] < k) {         ans += k - (times[i] + times[i - 1]);         times[i] += k - (times[i] + times[i - 1]);       }     }     cout << ans << endl;     for (int i = 0; i < n; ++i) cout << times[i] <<    ;     cout << endl;     return 0;   }


#include<iostream>   #include<string.h>   #include <fstream>   #include <string>   #include <vector>   #include <iomanip>    #include <cmath>   #include <cstdlib>   #include<map>   #include <ctime>   using namespace std;    int main(){     long long int t;    cin>>t;    for(long long int mat=0;mat<t;mat=mat+1){     long long int total;     cin>>total;     long long int median;     vector<long long int> array;     for(long long int i=0;i<total;i=i+1){      char a;      cin>>a;      if(a== * ){       array.push_back(i);      }     }     long long int n=array.size();     if(n%2==0){      median=n/2-1;     }     else{      median=n/2;     }     long long int ans=0;     for(long long int i=0;i<array.size();i=i+1){      ans+=abs(array[i]-array[median])-abs(i-median);     }      cout<<ans<<endl;               }      return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   int main() {     int n, r;     cin >> n >> r;     double deg = (1.0 / n) * pi;     double bi = sin(deg);     cout << setiosflags(ios::fixed) << setprecision(10) << (bi / (1 - bi) * r)          << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct ghost {     long long vx, vy;     long long magic;     ghost(long long x, long long y, long long a)         : vx(x), vy(y), magic((long long)a * x - y) {}   };   bool cmp1(const ghost& x, const ghost& y) { return x.magic < y.magic; }   bool cmp2(const ghost& x, const ghost& y) { return x.vx < y.vx; }   vector<ghost> G;   int main() {     long long n, a, b;     cin >> n >> a >> b;     for (long long i = 0; i < n; i++) {       long long x, vx, vy;       cin >> x >> vx >> vy;       ghost tmp(vx, vy, a);       G.push_back(tmp);     }     stable_sort(G.begin(), G.end(), cmp2);     stable_sort(G.begin(), G.end(), cmp1);     long long res = 0;     long long t_m = G[0].magic;     long long t_b = 0;     for (long long i = 0; i < G.size(); i++) {       if (G[i].magic != t_m) {         if (i - t_b > 1) {           res += ((i - t_b) * (i - t_b - 1));           long long t_vx = G[t_b].vx;           long long tt_b = t_b;           for (long long k = tt_b; k < i; k++) {             if (G[k].vx != t_vx) {               res -= ((k - tt_b) * (k - tt_b - 1));               tt_b = k;               t_vx = G[k].vx;             }           }           res -= (i - tt_b) * (i - tt_b - 1);         }         t_b = i;         t_m = G[i].magic;       }     }     res += ((n - t_b) * (n - t_b - 1));     long long t_vx = G[t_b].vx;     long long tt_b = t_b;     for (long long k = tt_b; k < n; k++) {       if (G[k].vx != t_vx) {         res -= ((k - tt_b) * (k - tt_b - 1));         tt_b = k;         t_vx = G[k].vx;       }     }     res -= (n - tt_b) * (n - tt_b - 1);     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct problem {     long long ts, tl, ss, sl, p;   } pro[1005];   pair<long long, double> f[1005][1566];   int n, t;   bool cmp(problem a, problem b) {     return a.tl * a.p * (1000000 - b.p) < b.tl * b.p * (1000000 - a.p);   }   bool better(pair<long long, double> &a, pair<long long, double> &b) {     if (a.first != b.first) return a.first > b.first;     return a.second < b.second;   }   void dp() {     for (int i = (0); i <= (n + 1); i++)       for (int j = (0); j <= (t); j++) f[i][j].first = -1;     f[1][0] = make_pair(0, 0);     for (int i = (1); i <= (n); i++)       for (int j = (0); j <= (t); j++)         if (f[i][j].first > -1) {           if (better(f[i][j], f[i + 1][j])) f[i + 1][j] = f[i][j];           pair<long long, double> P;           long long nj;           if (j + pro[i].ts <= t) {             nj = j + pro[i].ts;             P = make_pair(f[i][j].first + pro[i].ss,                           f[i][j].second + pro[i].ts * 1000000);             if (better(P, f[i + 1][nj])) f[i + 1][nj] = P;           }           if (j + pro[i].ts + pro[i].tl <= t) {             nj = j + pro[i].ts + pro[i].tl;             P.first =                 f[i][j].first + pro[i].ss + pro[i].sl * (1000000 - pro[i].p);             P.second = pro[i].ts * 1000000 +                        (1000000 - pro[i].p) * (pro[i].tl + j) +                        f[i][j].second * pro[i].p / 1.0 / 1000000;             if (better(P, f[i + 1][nj])) f[i + 1][nj] = P;           }         }     pair<long long, double> res = make_pair(0, 0);     for (int j = (0); j <= (t); j++)       if (better(f[n + 1][j], res)) {         res = f[n + 1][j];       }     printf( %.10lf %.10lf n , res.first / 1000000.0, res.second / 1000000.0);   }   long long str_ll(string &s) {     long long x = 0;     int pos = -1;     for (int i = 0; i < (s.length()); i++) {       if (s[i] ==  . ) {         pos = i + 1;       } else         x = x * 10 + s[i] -  0 ;     }     if (pos != -1)       for (int i = 0; i < (6 - s.length() + pos); i++) x = x * 10;     return x;   }   int main() {     cin >> n >> t;     for (int i = (1); i <= (n); i++) {       double p;       cin >> pro[i].ss >> pro[i].sl >> pro[i].ts >> pro[i].tl >> p;       pro[i].ss *= 1000000;       pro[i].p = (p * 1000000 + 0.5);     }     sort(pro + 1, pro + n + 1, cmp);     dp();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool Check(long long n, long long pos) { return (n & (1 << pos)); }   long long Set(long long n, long long pos) { return (n | (1 << pos)); }   string s;   long long n, mod;   long long dp[(1 << 18) + 2][102];   long long call(long long mask, long long val) {     if (mask == (1 << n) - 1) {       if (val)         return 0;       else         return 1;     }     long long &ret = dp[mask][val];     if (ret != -1) return ret;     ret = 0;     unordered_map<int, bool> mp;     for (int i = 0; i < n; i++) {       int digit = s[i] -  0 ;       if (mp[digit] || (!digit && !mask) || Check(mask, i)) continue;       mp[digit] = 1;       ret += call(Set(mask, i), (val * 10 + digit) % mod);     }     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> s >> mod;     n = s.size();     memset(dp, -1, sizeof dp);     cout << call(0, 0) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   const int MAXN = 1000005;   char a[MAXN], b[MAXN];   int mi[MAXN], ma[MAXN];   long long ans = 0;   int trs(char a, char b) {     int s = 0;     if (a ==  R )       s += 6;     else if (a ==  B )       s += 3;     if (b ==  R )       s += 2;     else if (b ==  B )       s += 1;     return s;   }   int s[MAXN][10];   int main() {     scanf( %s , a + 1);     scanf( %s , b + 1);     n = strlen(a + 1), m = strlen(b + 1);     for (int i = 2; i <= m; i++) {       for (int j = 0; j <= 9; j++) s[i][j] = s[i - 1][j];       if (b[i] != b[i - 1]) s[i][trs(b[i], b[i - 1])]++;     }     for (int i = 1; i <= n; i++) {       if (i == 1)         mi[i] = ma[i] = 1;       else         mi[i] = mi[i - 1], ma[i] = ma[i - 1];       if (i != 1 && a[i - 1] == b[mi[i]]) mi[i]++;       if (i != 1 && ma[i] != m) ma[i]++;       while (ma[i] != m && b[ma[i]] != a[i]) ma[i]++;       ans += ma[i] - mi[i] + 1;       if (i != 1) {         ans -= s[ma[i]][trs(a[i - 1], a[i])] - s[mi[i] - 1][trs(a[i - 1], a[i])];       }     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T, class L>   bool smax(T &x, L y) {     return x < y ? (x = y, 1) : 0;   }   template <class T, class L>   bool smin(T &x, L y) {     return y < x ? (x = y, 1) : 0;   }   const int maxn = 20, maxm = 1e5 + 17;   char c[maxm];   int n, m, col[maxm];   int dp[maxn + 1][1 << maxn], ans[1 << maxn];   int main() {     ios::sync_with_stdio(0), cin.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> c;       for (int j = 0; j < m; j++) col[j] |= c[j] -  0  << i;     }     for (int i = 0; i < m; i++) dp[0][col[i]]++;     for (int i = 0; i < n; i++)       for (int k = n; k; k--)         for (int mask = 0; mask < 1 << n; mask++)           dp[k][mask] += dp[k - 1][mask ^ (1 << i)];     int po = 1 << n;     for (int i = 0; i <= n; i++) {       int x = min(i, n - i);       for (int mask = 0; mask < po; mask++) ans[mask] += x * dp[i][mask];     }     cout << *min_element(ans, ans + po) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n, l, k = 0, maxi;     scanf( %d , &n);     long long int count = 0;     int a[15];     l = n;     while (l) {       a[k] = l % 10;       l = l / 10;       k++;     }     while (k > 0) {       maxi = 0;       for (i = 0; i < k; i++)         if (a[i] > maxi) maxi = a[i];       n = n - maxi;       k = 0;       l = n;       while (l) {         a[k] = l % 10;         l = l / 10;         k++;       }       count++;     }     if (n == 0)       cout << count << endl;     else       cout << count + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 1e4;   int a[maxn], mod;   int b[maxn];   int n;   int pow(int a, int b) {     if (b == 1) return a;     int t = pow(a, b >> 1);     t = 1LL * t * t % mod;     if (b & 1) t = 1LL * t * a % mod;     return t;   }   int ny(int a) { return pow(a, mod - 2); }   int ans, dd;   void solve(int a[], int n) {     if (n == 1) {       ans = a[1];       dd = 1;       return;     }     int cc = a[2] - a[1];     int s = 0;     for (int i = (1); i <= (n); ++i)       if (!binary_search(a + 1, a + n + 1, (a[i] + cc) % mod)) ++s;     cc = 1LL * cc * ny(s) % mod;     ans = -1, dd = mod - cc;     for (int i = (1); i <= (n); ++i)       if (!binary_search(a + 1, a + n + 1, (a[i] + cc) % mod)) {         if (ans == -1)           ans = a[i];         else {           ans = -1;           break;         }       }   }   void init() {     scanf( %d%d , &mod, &n);     for (int i = (1); i <= (n); ++i) scanf( %d , &a[i]);     if (n == mod) {       printf( %d %d n , 0, 1);       return;     }     sort(a + 1, a + n + 1);     if (n * 2 > mod) {       int t = 0;       for (int i = (0); i <= (mod - 1); ++i)         if (!binary_search(a + 1, a + n + 1, i)) b[++t] = i;       solve(b, t);       if (ans != -1) (ans += 1LL * dd * t % mod) %= mod;     } else       solve(a, n);     if (ans == -1)       printf( %d n , ans);     else       printf( %d %d n , ans, dd);   }   int main() {     init();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)2e5 + 5;   int seg[N], ans[N];   vector<pair<int, int> > beg[N], fin[N];   set<pair<int, int> > pending;   set<pair<int, int> >::iterator it1, it2;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> seg[i];     for (int q = 0; q < m; q++) {       int l, r, x;       cin >> l >> r >> x;       beg[l].emplace_back(x, q);       fin[r].emplace_back(x, q);     }     for (int i = 1; i <= n; i++) {       for (pair<int, int> xq : beg[i]) pending.insert(xq);       it2 = pending.lower_bound(make_pair(seg[i], 0));       it1 = pending.begin();       while (it1 != it2) {         ans[it1->second] = i;         pending.erase(it1++);       }       it1 = pending.lower_bound(make_pair(seg[i] + 1, 0));       while (it1 != pending.end()) {         ans[it1->second] = i;         pending.erase(it1++);       }       for (pair<int, int> xq : fin[i])         if ((it1 = pending.find(xq)) != pending.end()) {           ans[xq.second] = -1;           pending.erase(it1);         }     }     for (int q = 0; q < m; q++) cout << ans[q] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n, m, a, b;       cin >> n >> m >> a >> b;       long long int arr[n + 5][m + 5];       long long int i, j;       memset(arr, 0, sizeof(arr));       for (i = 0; i < n; i++) {         long long int x = a;         for (j = m - 1; j >= 0; j--) {           if (x > 0) {             arr[i][j] = 1;             x--;           } else {             break;           }         }       }       long long int flag = 0;       for (j = 0; j < m; j++) {         long long int count = 0;         for (i = 0; i < n; i++) {           if (arr[i][j] == 1) {             count++;           }         }         if (count > b) {           flag = 1;           break;         }         long long int y = count;         while (y < b) {           for (i = 0; i < n; i++) {             if (arr[i][j] == 0) {               for (int h = j + 1; h < m; h++) {                 if (arr[i][h] == 1) {                   arr[i][h] = 0;                   arr[i][j] = 1;                   y++;                   break;                 }               }             }             if (y == b || i == n - 1) {               break;             }           }           if (y == b || i == n - 1) {             break;           }         }         if (y != b) {           flag = 1;           break;         }       }       if (flag == 1) {         cout <<  NO  << endl;       } else {         cout <<  YES  << endl;         for (i = 0; i < n; i++) {           for (j = 0; j < m; j++) {             cout << arr[i][j];           }           cout << endl;         }       }     }   }


#include <bits/stdc++.h>   const int maxn = 200005, maxm = maxn << 1;   int n, m, e, s1, s2, s, maxx, col, flg, mid;   int start[maxn], to[maxm], then[maxm], dep[maxn], f[maxn], ans[maxn],       flen[maxn], slen[maxn];   inline void add(int x, int y) { then[++e] = start[x], start[x] = e, to[e] = y; }   void dfs(int x, int last) {     f[x] = last, dep[x] = dep[last] + 1;     flen[x] = slen[x] = 0;     if (dep[x] > maxx) maxx = dep[x], s = x;     for (int i = start[x]; i; i = then[i]) {       int y = to[i];       if (y == last) continue;       dfs(y, x);     }   }   void getlen(int x, int last) {     for (int i = start[x]; i; i = then[i]) {       int y = to[i];       if (y == last || ans[y]) continue;       getlen(y, x);       if (flen[y] + 1 > flen[x])         slen[x] = flen[x], flen[x] = flen[y] + 1;       else if (flen[y] + 1 > slen[x])         slen[x] = flen[y] + 1;       if (slen[y] + 1 > slen[x]) slen[x] = slen[y] + 1;     }   }   void solve(int x, int c, int d, int t) {     ans[x] = c;     c = (c + t + m - 1) % m + 1;     for (int i = start[x]; i; i = then[i]) {       int y = to[i];       if (ans[y] != 0) continue;       solve(y, c, d + 1, t);     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       add(x, y), add(y, x);     }     maxx = -1000000000, dfs(1, 0), s1 = s;     maxx = -1000000000, dfs(s, 0), s2 = s;     if (m == 2) {       puts( Yes );       for (int i = 1; i <= n; i++)         printf( %d%c , dep[i] % 2 + 1, i == n ?   n  :    );       return 0;     }     for (int i = s2; i != 0; i = f[i]) {       col = col % m + 1;       if ((dep[s1] + dep[s2]) / 2 == dep[i]) mid = i;       ans[i] = col;     }     for (int i = s2; i != 0; i = f[i]) {       getlen(i, 0);       if (ans[i] && flen[i] && dep[i] + flen[i] >= m &&           (dep[s2] - dep[i] + 1) + flen[i] >= m) {         puts( No );         return 0;       }     }     for (int i = 1; i <= n; i++)       if (flen[i] + slen[i] + 1 >= m) {         puts( No );         return 0;       }     for (int i = s2; i != mid; i = f[i]) solve(i, ans[i], 1, -1);     for (int i = mid; i != 0; i = f[i]) solve(i, ans[i], 1, 1);     puts( Yes );     for (int i = 1; i <= n; i++) printf( %d%c , ans[i], i == n ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   const int MAXN = 100000;   int n, mxdepth, MOD;   int INV2;   int inv[2 * MAXN + 1];   vector<int> parts;   void rec(int l, int r, int h) {     if (l > r) return;     if (h == 1 || l == r) {       parts.push_back(r - l + 1);       return;     }     int m = (l + r) / 2;     rec(l, m, h - 1);     rec(m + 1, r, h - 1);   }   int cntpairs(int sz) { return (long long)sz * (sz - 1) / 2 % MOD; }   int calc(int sz) { return (long long)cntpairs(sz) * INV2 % MOD; }   int calc(int sza, int szb) {     int ret = 0;     for (int den = (2); den <= (sza + szb); ++den) {       int lo = max(1, den - szb), hi = min(sza, den - 1), cnt = hi - lo + 1;       if (lo > hi) continue;       int cur = (long long)(den - 2) % MOD * inv[den] % MOD * INV2 % MOD;       ret = (ret + (long long)cnt * cur) % MOD;     }     return ret;   }   int solve() {     INV2 = (MOD + 1) / 2;     inv[1] = 1;     for (int i = (2); i <= (2 * n); ++i)       inv[i] = (long long)(MOD - MOD / i) * inv[MOD % i] % MOD;     parts.clear();     rec(1, n, mxdepth);     int sz1 = -1, cnt1 = 0, sz2 = -1, cnt2 = 0;     for (int i = (0); i < (((int)(parts).size())); ++i) {       int x = parts[i];       if (x == sz1)         ++cnt1;       else if (x == sz2)         ++cnt2;       else if (sz1 == -1)         sz1 = x, ++cnt1;       else if (sz2 == -1)         sz2 = x, ++cnt2;       else         assert(false);     }     int ret = 0;     if (cnt1 != 0) ret = (ret + (long long)cnt1 * calc(sz1)) % MOD;     if (cnt2 != 0) ret = (ret + (long long)cnt2 * calc(sz2)) % MOD;     if (cnt1 != 0) ret = (ret + (long long)cntpairs(cnt1) * calc(sz1, sz1)) % MOD;     if (cnt1 != 0 && cnt2 != 0)       ret = (ret + (long long)cnt1 * cnt2 % MOD * calc(sz1, sz2)) % MOD;     if (cnt2 != 0) ret = (ret + (long long)cntpairs(cnt2) * calc(sz2, sz2)) % MOD;     return ret;   }   void run() {     scanf( %d%d%d , &n, &mxdepth, &MOD);     printf( %d n , solve());   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100;   int a[maxn], s[maxn], f[maxn], n, ans;   int pmin, pmax;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , a + i), f[i] = -1;     sort(a, a + n);     swap(a[0], a[n - 1]);     for (int i = 0; i < n; i++) printf( %d  , a[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NMAX = 210, INF = 0x3f3f3f3f, VMAX = 20010;   int N, A[NMAX], Source, Sink, Flow[NMAX][NMAX], Cap[NMAX][NMAX], Father[NMAX],       Even, Odd;   bool Used[NMAX], Prime[VMAX];   vector<int> G[NMAX], FlowG[NMAX], CurrentTable;   vector<vector<int> > Ans;   bool BFS() {     queue<int> Q;     for (int i = 0; i <= N + 1; ++i) Used[i] = Father[i] = 0;     Used[Source] = 1;     Q.push(Source);     while (!Q.empty()) {       int Node = Q.front();       Q.pop();       if (Node == Sink) return 1;       for (int i = 0; i < G[Node].size(); ++i) {         int Vec = G[Node][i];         if (!Used[Vec] && Cap[Node][Vec] > Flow[Node][Vec])           Used[Vec] = 1, Father[Vec] = Node, Q.push(Vec);       }     }     return Used[Sink];   }   void DFS(int Node, int StartNode) {     if (Node == StartNode && CurrentTable.size() >= 3) return;     CurrentTable.push_back(Node);     Used[Node] = 1;     for (int i = 0; i < FlowG[Node].size(); ++i)       if (!Used[FlowG[Node][i]]) DFS(FlowG[Node][i], StartNode);   }   void BuildGraph() {     Source = 0;     Sink = N + 1;     for (int i = 1; i <= N; ++i)       if (A[i] % 2 == 1) {         G[Source].push_back(i);         G[i].push_back(Source);         Cap[Source][i] = 2;       } else {         G[i].push_back(Sink);         G[Sink].push_back(i);         Cap[i][Sink] = 2;       }     for (int i = 1; i <= N; ++i)       for (int j = 1; j <= N; ++j)         if (A[i] % 2 == 1 && A[j] % 2 == 0 && Prime[A[i] + A[j]]) {           G[i].push_back(j);           G[j].push_back(i);           Cap[i][j] = 1;         }   }   void MaxFlow() {     int CntFlow = 0;     while (BFS()) {       for (int i = 0; i < G[Sink].size(); ++i) {         int Vec = G[Sink][i];         if (Used[Vec] && Cap[Vec][Sink] != Flow[Vec][Sink]) {           int MinFlow = INF;           Father[Sink] = Vec;           for (int Node = Sink; Node != Source; Node = Father[Node])             MinFlow =                 min(MinFlow, Cap[Father[Node]][Node] - Flow[Father[Node]][Node]);           for (int Node = Sink; Node != Source; Node = Father[Node]) {             Flow[Father[Node]][Node] += MinFlow;             Flow[Node][Father[Node]] -= MinFlow;           }           CntFlow += MinFlow;         }       }     }     if (CntFlow != N)       printf( Impossible n );     else {       for (int i = 1; i <= N; ++i)         for (int j = 1; j <= N; ++j)           if (A[i] % 2 == 1 && A[j] % 2 == 0 && Prime[A[i] + A[j]] &&               Flow[i][j] == 1)             FlowG[i].push_back(j), FlowG[j].push_back(i);       for (int i = 1; i <= N; ++i) Used[i] = 0;       for (int i = 1; i <= N; ++i)         if (!Used[i]) {           CurrentTable.clear();           DFS(i, i);           Ans.push_back(CurrentTable);         }       printf( %i n , Ans.size());       for (int i = 0; i < Ans.size(); ++i) {         printf( %i  , Ans[i].size());         for (int j = 0; j < Ans[i].size(); ++j) printf( %i  , Ans[i][j]);         printf(  n );       }       return;     }   }   int main() {     for (int i = 2; i < VMAX; ++i) Prime[i] = 1;     for (int i = 2; i < VMAX; ++i)       if (Prime[i])         for (int j = i + i; j < VMAX; j += i) Prime[j] = 0;     scanf( %i , &N);     for (int i = 1; i <= N; ++i) {       scanf( %i , &A[i]);       Even += (A[i] % 2 == 0);       Odd += (A[i] % 2 == 1);     }     if (Even != Odd) {       printf( Impossible n );       return 0;     }     BuildGraph();     MaxFlow();     return 0;   }


#include <bits/stdc++.h>   const double eps = 1e-3;   const double PI = 3.1415926535897932384626433832795;   const int maxn = 9999999;   using namespace std;   char name[1001][40];   int grade[1001];   int main() {     int n;     while (~scanf( %d , &n)) {       map<string, int> mp;       for (int i = 1; i <= n; i++) {         scanf( %s %d , name[i], &grade[i]);         mp[name[i]] += grade[i];       }       int max = -9999999;       for (map<string, int>::iterator it = mp.begin(); it != mp.end(); it++)         if (it->second > max) max = it->second;       map<string, int> mp2;       for (int i = 1; i <= n; i++) {         mp2[name[i]] += grade[i];         if (mp[name[i]] == max && mp2[name[i]] >= max) {           puts(name[i]);           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>      using namespace std;   typedef long long ll;   #define all(x) (x).begin(), (x).end()   typedef vector<bool> vb;   typedef vector<int> vi;   typedef vector<ll> vl;   typedef vector<vector<bool>> vvb;   typedef vector<vector<int>> vvi;   typedef vector<vector<ll>> vvl;   typedef pair<int,int> pii;   typedef pair<ll,ll> pll;   void debugF(ostream &os) {os << endl;}   template <typename Head, typename... Tail>   void debugF(ostream &os, Head H, Tail... T) { os <<     << H; debugF(os, T...); }   #define debug(...) cerr <<  [  << #__VA_ARGS__ <<  ]: , debugF(cerr, __VA_ARGS__)   template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }   template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); os << (i>0 ?    :  ) << v[i++]); return os;}   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int mod = 998244353;      ll expMod(ll a, ll b, ll mod){       ll ans = 1;       while(b){           if(b&1) ans = (ans*a)%mod;           a = (a*a)%mod;           b >>= 1;       }       return ans;   }      int calc(vector<string> &M, vi &dp2){       int n = M.size(); int m = M[0].size();       int i,j;       int ans = 0;       for(i=0;i<n;i++){           int cc = 0;           for(j=0;j<m;j++){               if(M[i][j] ==  o ){                   cc++;                   if(j+1 >= m || M[i][j+1] !=  o ){                       ans += dp2[cc-1];                       ans %= mod;                   }               }               else                    cc = 0;           }       }       return ans;   }      void transpose(vector<string> &M){       int n = M.size(); int m = M[0].size();       vector<string> M2(m, string(n, . ));       int i,j;       for(i=0;i<n;i++){           for(j=0;j<m;j++){               M2[j][i] = M[i][j];           }       }       M = M2;   }      void solve(){       int n, m, i, j;       cin >> n >> m;       vector<string> M(n);       cin >> M;       int nw = 0;       for(i=0;i<n;i++){           nw += count(all(M[i]),  o );       }       if(nw < 2){           cout << 0 <<   n ;           return;       }          int N = max(n,m);          vi p2(nw+1);       p2[0] = 1;       for(i=1;i<=nw;i++){           p2[i] = (p2[i-1]*2)%mod;       }       ll div4 = expMod(4, mod-2, mod);              vi dp(N);       vi dp2(N); //dp2[i] = dp[0] + ... + dp[i-1]       dp[0] = p2[nw-2];       dp2[0] = 0;       for(i=1;i<N;i++){           dp[i] = p2[nw-3];           if(i-2 >= 0){               dp[i] += (dp[i-2]*div4)%mod;               dp[i] %= mod;             }           dp2[i] = (dp2[i-1] + dp[i-1])%mod;       }          auto ans = calc(M, dp2);       transpose(M);       ans += calc(M, dp2);       ans %= mod;       cout << ans <<   n ;   }      int main(){       ios::sync_with_stdio(false);       cin.tie(0);       int nt = 1;       for(int tt=1;tt<=nt;tt++){           solve();       }       return 0;   }


#include <bits/stdc++.h>   int main() {     int n, k, i, j;     int hols, arr[1000];     int temp, loop, flag = 0;     scanf( %d%d , &n, &k);     scanf( %d , &hols);     for (i = 0; i <= n; i++) {       arr[i] = 0;     }     for (i = 0; i < hols; i++) {       scanf( %d , &temp);       arr[temp] = 2;     }     for (i = 0; i <= n;) {       for (j = i; j < i + k; j++) {         if (arr[j] == 2) {           flag = 1;           loop = j;         }       }       if (flag == 1) {         flag = 0;         i = loop;       } else {         i = i + k;       }       arr[i] = 1;     }     int min = 0;     for (i = 1; i <= n; i++) {       if (arr[i] == 1 || arr[i] == 2) min++;     }     printf( %d , min);     return 0;   }


#include <bits/stdc++.h>   const double eps = 1e-9;   const double pi = acos(-1);   using namespace std;   struct sx {};   bool cmp(int a, int b) { return a > b; }   long long t1, t2, t3;   int main() {     int n, m;     cin >> n >> m;     int x = (n + m) / 3;     while (t1 < x && ((n >= 1 && m >= 2) || (n >= 2 && m >= 1))) {       if (n > m) {         n -= 2;         m -= 1;       } else {         m -= 2;         n -= 1;       }       t1++;     }     cout << t1;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str1, str2;     cin >> str1 >> str2;     for (int i = 0; i < str1.size(); i++) {       str1[i] = tolower(str1[i]);       str2[i] = tolower(str2[i]);     }     if (str1 == str2)       cout <<  0 ;     else if (str1 < str2)       cout <<  -1 ;     else       cout <<  1 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> v;   set<int> g[100005];   vector<pair<int, int> > f;   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i * i <= n; i++) {       if (n % i == 0) {         v.push_back(i);         if (i * i != n && i != 1) v.push_back(n / i);       }     }     int a, b;     for (int i = 1; i <= m; i++) {       cin >> a >> b;       g[a].insert(a);       g[b].insert(a);       f.push_back(make_pair(a, b));     }     for (auto x : v) {       bool flag = 1;       for (auto y : f) {         int l = y.first, r = y.second;         l += x, r += x;         if (l > n) l -= n;         if (r > n) r -= n;         if (g[l].count(r) || g[r].count(l))           continue;         else {           flag = 0;           break;         }       }       if (flag) {         cout <<  Yes  << endl;         exit(0);       }     }     cout <<  No ;   }


#include <bits/stdc++.h>   using namespace std;   using ull = unsigned long long;   using ll = long long;   using ld = long double;   const int mod = 1e9 + 7;   const double pi = acos(-1.0);   const int inf = INT_MAX;   const int N = (1 << 22);   int h, g, a[N];   bool ok(int i) {     while (true) {       if (a[i << 1] == 0 && a[i << 1 | 1] == 0) {         break;       }       if (a[i << 1] > a[i << 1 | 1]) {         i = i << 1;       } else {         i = i << 1 | 1;       }     }     int msb = 32 - __builtin_clz(i) - 1;     return msb >= g;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int t;     cin >> t;     while (t--) {       cin >> h >> g;       for (int i = 1; i < (1 << h); i++) cin >> a[i];       fill(a + (1 << h), a + (1 << (h + 1)), 0);       vector<int> ops;       for (int i = 1; i < (1 << g); i++) {         while (ok(i)) {           ops.push_back(i);           int j;           for (j = i; a[j << 1] || a[j << 1 | 1];) {             if (a[j << 1] > a[j << 1 | 1]) {               a[j] = a[j << 1];               j = j << 1;             } else {               a[j] = a[j << 1 | 1];               j = j << 1 | 1;             }           }           a[j] = 0;         }       }       ll ans = 0;       for (int i = 1; i < (1 << g); i++) {         ans += a[i];       }       cout << ans <<   n ;       for (int i : ops) cout << i <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int v[1000000];   int buggy_sorting(int n) {     if (n == 1 || n == 2) return 0;     v[0] = 5;     v[1] = 6;     v[2] = 1;     for (int i = 3; i < n; i++) v[i] = i;     return 1;   }   void median() {     int t, n, k, pas, cnt;     long long int s;     cin >> t;     for (int z = 0; z < t; z++) {       cin >> n >> k;       pas = n / 2;       for (int i = 0; i < n * k; i++) cin >> v[i];       cnt = 0;       s = 0;       for (int i = n * k - 1 - pas; i >= 0; i -= pas + 1)         if (cnt < k) {           s += v[i];           cnt++;         }       cout << s <<   n ;     }   }   int main() {     int n;     cin >> n;     if (buggy_sorting(n))       for (int i = 0; i < n; i++) cout << v[i] <<    ;     else       cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool used[100001];   int ans[100001], a[100001];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] <= n && !used[a[i]]) {         used[a[i]] = 1;         ans[i] = a[i];       }     }     int first = 1;     for (int i = 1; i <= n; i++) {       if (ans[i] == 0) {         while (used[first]) first++;         ans[i] = first;         first++;       }     }     for (int i = 1; i <= n; i++) {       cout << ans[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int s = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) s = s * 10 + ch -  0 , ch = getchar();     return s * f;   }   const int maxn = 1e5 + 10;   int n, tot, head[maxn], d[maxn], a[maxn], ans, sz[maxn];   struct data {     int to, next, w;   } edge[maxn];   void calc(int x) {     sz[x] = 1;     for (int i = head[x]; i; i = edge[i].next) {       int y = edge[i].to;       calc(y);       sz[x] += sz[y];     }   }   void dfs(int x) {     if (d[x] > a[x]) {       ans += sz[x];       return;     }     for (int i = head[x]; i; i = edge[i].next) {       int y = edge[i].to;       d[y] = d[x] + edge[i].w;       if (d[y] < 0) d[y] = 0;       dfs(y);     }   }   inline void make(int u, int v, int w) {     edge[++tot] = (data){v, head[u], w};     head[u] = tot;   }   int main() {     n = read();     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 2; i <= n; i++) {       int x = read(), y = read();       make(x, i, y);     }     calc(1);     dfs(1);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, p, d, x;     cin >> n >> k >> d;     p = n - k;     for (int i = 0; i < d; i++) {       cin >> x;       x--;       if (p <= k) {         if (x % 2 == 0 && x / 2 < p) {           cout <<  . ;         } else {           cout <<  X ;         }       } else {         if (n % 2 == 0) {           if ((x % 2 == 1) && (n - 1 - x) / 2 < k) {             cout <<  X ;           } else {             cout <<  . ;           }         } else {           if (x != n - 1) {             if ((x % 2 == 1) && (n - 2 - x) / 2 < (k - 1)) {               cout <<  X ;             } else {               cout <<  . ;             }           } else {             if (k > 0)               cout <<  X ;             else               cout <<  . ;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n;     cin >> n;     string s;     vector<long long int> arr(n + 1);     for (long long int i = 1; i <= n; i++) cin >> arr[i];     cin >> s;     vector<long long int> pre(n, 0);     if (s.back() ==  1 ) pre[n - 1] = 1;     for (int i = n - 2; i >= 0; i--) {       if (s[i] ==  1 )         pre[i] = 1 + pre[i + 1];       else         pre[i] = 0;     }     for (int i = 1; i <= n; i++) {       if (i > arr[i]) {         if (arr[i] + pre[arr[i] - 1] < i) {           cout <<  NO n ;           return;         }       } else if (i < arr[i]) {         if (i + pre[i - 1] < arr[i]) {           cout <<  NO n ;           return;         }       }     }     cout <<  YES n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   unsigned char G[301][301];   unsigned char bv[301];   int ints[301];   int main() {     int n;     cin >> n;     for (register int i = 1; i <= n; i++) cin >> ints[i];     for (register int i = 1; i <= n; i++) {       for (register int j = 1; j <= n; j++) {         char c;         cin >> c;         G[i][j] = c -  0 ;       }     }     for (register int k = 1; k <= n; k++) {       for (register int i = 1; i <= n; i++) {         for (register int j = 1; j <= n; j++) {           G[i][j] = G[i][j] || (G[i][k] && G[k][j]);         }       }     }     for (register int i = 1; i <= n; i++) {       G[i][i] = 1;     }     ints[0] = 0x7fffffff;     for (register int i = 1; i <= n; i++) {       int minn = 0;       for (register int j = 1; j <= n; j++) {         if (ints[j] < ints[minn] && G[i][j] && bv[j] == 0) minn = j;       }       printf( %d  , ints[minn]);       bv[minn] = 1;     }     return (0);   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int INF = 0x3f3f3f3f;   const long long MOD = 1e9 + 7;   long long n, sum[100002][2], sqsum[100002][2], cnt[100002][2], all_7[100002],       s[100002], ten[200002];   long long solve(string str) {     n = str.length();     memset(all_7, 0, sizeof(all_7));     memset(sum, 0, sizeof(sum)), memset(sqsum, 0, sizeof(sqsum)),         memset(cnt, 0, sizeof(cnt));     cnt[0][1] = 1;     all_7[n + 1] = 1;     for (long long i = n; i >= 1; --i)       all_7[i] = all_7[i + 1] & (str[i - 1] ==  7 );     long long rest = 0;     for (long long i = 1; i <= n; ++i) {       long long num = str[i - 1] ^ 48;       for (long long j = 0; j < 2; ++j) {         for (long long jj = 4; jj <= 7; jj += 3) {           if (j && (jj > num)) break;           long long new_j = j & (jj == num);           (cnt[i][new_j] += cnt[i - 1][j]) %= MOD;           (sum[i][new_j] +=            (1ll * cnt[i - 1][j] * jj % MOD + 10ll * sum[i - 1][j])) %= MOD;           (sqsum[i][new_j] +=            (100ll * sqsum[i - 1][j] + 20ll * jj * sum[i - 1][j] +             1ll * jj * jj * cnt[i - 1][j])) %= MOD;         }       }       long long tmp = 0, A, B;       bool smaller = (str[i - 1] ==  7 );       A = 7ll * ten[n - i] % MOD + 4ll * s[n - i] % MOD;       A %= MOD;       B = 4ll * ten[n - i] % MOD + 7ll * s[n - i] % MOD;       B %= MOD;       long long Sum = sum[i - 1][0], Sqsum = sqsum[i - 1][0], Cnt = cnt[i - 1][0];       if (smaller) {         Sum += sum[i - 1][1], Sqsum += sqsum[i - 1][1], Cnt += cnt[i - 1][1];         Sum %= MOD, Sqsum %= MOD, Cnt %= MOD;       }       (tmp += (1ll * Sqsum * ten[(n - i + 1) * 2] % MOD)) %= MOD;       (tmp +=        (1ll * Sum * A % MOD + 1ll * Sum * B % MOD) * ten[n - i + 1] % MOD) %= MOD;       (tmp += 1ll * A * B % MOD * Cnt % MOD) %= MOD;       (rest += tmp) %= MOD;     }     return rest;   }   signed main() {     ios::sync_with_stdio(false);     string l, r;     s[0] = 0;     s[1] = 1;     ten[0] = 1;     ten[1] = 10;     for (long long i = 2; i <= 100000; ++i) s[i] = (10ll * s[i - 1] + 1) % MOD;     for (long long i = 2; i <= 200000; ++i) ten[i] = (10ll * ten[i - 1]) % MOD;     cin >> l >> r;     cout << (solve(r) - solve(l) + MOD) % MOD << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, i, j, x, k;     cin >> n >> k;     string s, t;     cin >> s;     t = s;     for (i = 0; i < n; i++) {       if (i - k >= 0) t[i] = t[i - k];     }     if (t > s) {       cout << n <<   n  << t;       return 0;     }     for (i = 0; i < n; i++) {       if (s[i] > t[i]) {         for (j = k - 1; j >= 0; j--) {           if (t[j] !=  9 ) break;         }         for (; j < n; j += k) t[j]++;         break;       }     }     for (j = 0; j < k; j++)       if (s[j] < t[j]) break;     for (i = j + 1; i < k; i++) {       for (long long p = i; p < n; p += k) t[p] =  0 ;     }     cout << n <<   n  << t;   }


#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) { cerr << endl; }   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a << endl;     err(++it, args...);   }   const int N = 1000 + 5, mod = 1000000007;   int n, edges;   vector<pair<int, int>> graph[N];   bool cycle;   bool vis[N];   int mxmDepth, indx, mnmDiameter;   void dfs(int node, int dep) {     vis[node] = true;     if (mxmDepth < dep) {       mxmDepth = dep;       indx = node;     }     for (auto child : graph[node]) {       if (vis[child.first]) {         cycle = true;         return;       }       mnmDiameter = min(mnmDiameter, child.second);       dfs(child.first, dep + 1);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> edges;     set<int> st;     for (int i = 1; i <= n; i++) st.insert(i);     for (int i = 1; i <= edges; i++) {       int u, v, c;       cin >> u >> v >> c;       graph[u].push_back({v, c});       st.erase(v);     }     vector<pair<int, pair<int, int>>> ans;     for (auto par : st) {       if (graph[par].empty()) continue;       cycle = false;       mxmDepth = 0;       mnmDiameter = 1e9;       indx = -1;       dfs(par, 0);       if (cycle) continue;       ans.push_back({par, {indx, mnmDiameter}});     }     cout << ans.size() <<   n ;     for (auto it : ans) {       cout << it.first <<     << it.second.first <<     << it.second.second            <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int n, r, an;       cin >> n >> r;       if (r < n)         an = (r) * (r + 1) / 2;       else {         an = (n) * (n - 1) / 2;         an++;       }       cout << an;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5;   int n;   long long seg[4 * N], lazy[4 * N];   void update(int st, int en, long long v, int idx = 1, int L = 0,               int R = n - 1) {     if (L > en || R < st) {       return;     }     if (L >= st && R <= en) {       seg[idx] += v;       lazy[idx] += v;       return;     }     seg[2 * idx] += lazy[idx];     seg[2 * idx + 1] += lazy[idx];     lazy[2 * idx] += lazy[idx];     lazy[2 * idx + 1] += lazy[idx];     lazy[idx] = 0;     update(st, en, v, 2 * idx, L, (L + R) / 2);     update(st, en, v, 2 * idx + 1, (L + R) / 2 + 1, R);     seg[idx] = min(seg[2 * idx], seg[2 * idx + 1]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     int a[n], c[n];     for (int i = 0; i < n; ++i) {       cin >> a[i], --a[i];     }     for (int i = 0; i < n; ++i) {       cin >> c[a[i]];     }     long long s = 0;     for (int i = 0; i < n; ++i) {       update(i, i, s);       s += c[i];     }     long long ans = 9e18;     for (int i = 0; i < n - 1; ++i) {       update(0, a[i], c[a[i]]);       update(a[i], n - 1, -c[a[i]]);       ans = min(ans, seg[1]);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     bool val = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         int a;         scanf( %d , &a);         if (i == j) {           val ^= a;         }       }     }     int q;     scanf( %d , &q);     while (q--) {       int t;       scanf( %d , &t);       if (t == 3) {         printf( %d , val);       } else {         int i;         scanf( %d , &i);         val ^= 1;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long BINF = 1e18 + 10;   signed main() {     ios_base::sync_with_stdio(false);     long long T;     cin >> T;     while (T--) {       long long n, a, b;       cin >> n >> a >> b;       vector<long long> c(n);       for (auto &it : c) {         char kek;         cin >> kek;         it = kek -  0 ;       }       vector<vector<long long>> dp(n + 1, vector<long long>(2, BINF));       dp[0][0] = b;       for (long long i = 0; i < n; i++) {         dp[i + 1][1] = min(dp[i][0] + 2 * (a + b), dp[i][1] + a + 2 * b);         if (!c[i] && (i + 1 == n || !c[i + 1])) {           dp[i + 1][0] = min(dp[i][0] + a + b, dp[i][1] + 2 * a + b);         }       }       cout << dp[n][0] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int N;   typedef struct Nodo {     long long int v, l;   } Nodo;   int S;   Nodo segtree[2000024];   inline void st_init(int N) {     if (__builtin_popcount(N) <= 1) {       S = N;     } else {       for (; __builtin_popcount(N) > 1; N -= N & -N)         ;       S = N << 1;     }     memset(segtree, 0, (sizeof(Nodo) * S) << 1);   }   inline void st_deflag(int p) {     long long int l = segtree[p].l;     if (!l) {       return;     }     if (p < S) {       long long int &a = segtree[p << 1].l;       long long int &b = segtree[(p << 1) + 1].l;       a = l;       b = l;     }     segtree[p].v = l;     segtree[p].l = 0;   }   inline void st_update(int n) {     long long int l = segtree[n << 1].v;     long long int r = segtree[(n << 1) + 1].v;     segtree[n].v = (l > r ? l : r);   }   void st_set(int n, int a, int b, int i, int f, long long int v) {     st_deflag(n);     if (i >= a && f <= b) {       segtree[n].l = v;       st_deflag(n);       return;     } else if (f < a || i > b) {       return;     }     int d = ((f - i) >> 1) + 1;     st_set(n << 1, a, b, i, f - d, v);     st_set((n << 1) + 1, a, b, i + d, f, v);     st_update(n);   }   long long int st_query(int n, int a, int b, int i, int f) {     st_deflag(n);     if (i >= a && f <= b) {       return segtree[n].v;     } else if (f < a || i > b) {       return -0x3f3f3f3f3f3f3f3fll;     }     int d = ((f - i) >> 1) + 1;     long long int r1 = st_query(n << 1, a, b, i, f - d);     long long int r2 = st_query((n << 1) + 1, a, b, i + d, f);     return (r1 > r2 ? r1 : r2);   }   int M;   int W, H;   int main() {     int i, a;     long long R;     scanf( %d , &N);     st_init(N);     for (i = 0; i < N; i++) {       scanf( %d , &a);       st_set(1, i, i, 0, S - 1, (long long)a);     }     scanf( %d , &M);     for (i = 0; i < M; i++) {       scanf( %d %d , &W, &H);       R = st_query(1, 0, (W - 1 < N - 1 ? W - 1 : N - 1), 0, S - 1);       printf( %I64d n , R);       st_set(1, 0, (W - 1 < N - 1 ? W - 1 : N - 1), 0, S - 1, R + (long long)H);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = (long long)1e9 + 7;   const long double PI = 3.141592653589793238462643383279502884197;   priority_queue<int, vector<int>, greater<int> > pq;   vector<int> v;   int cnt[512];   pair<int, int> vec[512];   pair<int, int> sec[512];   int main() {     memset(vec, 0x3f, sizeof(vec));     memset(vec, 0x3f, sizeof(vec));     int n, m;     scanf( %d %d , &n, &m);     int t;     for (int i = 0; i < n; i++) {       scanf( %d , &t);       vector<int> kk;       int k, bit = 0;       while (t--) {         scanf( %d , &k);         k--;         bit |= 1 << k;       }       for (int j = 0; j < 512; j++)         if ((bit & j) == bit) cnt[j]++;     }     for (int i = 0; i < m; i++) {       int p, t, bit = 0;       scanf( %d %d , &p, &t);       while (t--) {         int k;         scanf( %d , &k);         k--;         bit |= (1 << k);       }       if (vec[bit].first > p) {         sec[bit] = vec[bit];         vec[bit] = {p, i + 1};       } else if (sec[bit].first > p) {         sec[bit] = {p, i + 1};       }     }     int mav = -1, mivp = 1e9, u, v;     for (int i = 0; i < 512; i++) {       if (vec[i].first > 1e9) continue;       for (int j = i + 1; j < 512; j++) {         if (i == j || vec[j].first > 1e9) continue;         int k = i | j;         if (mav < cnt[k]) {           mav = cnt[k];           mivp = vec[i].first + vec[j].first;           u = vec[i].second;           v = vec[j].second;         } else if (mav == cnt[k] && mivp > vec[i].first + vec[j].first) {           mivp = vec[i].first + vec[j].first;           u = vec[i].second;           v = vec[j].second;         }       }       if (sec[i].first > 1e9) continue;       if (mav < cnt[i]) {         mav = cnt[i];         mivp = vec[i].first + sec[i].first;         u = vec[i].second, v = sec[i].second;       } else if (mav == cnt[i] && mivp > vec[i].first + sec[i].first) {         mivp = vec[i].first + sec[i].first;         u = vec[i].second, v = sec[i].second;       }     }     printf( %d %d , u, v);   }


#include <bits/stdc++.h>   using namespace std;   int N, K;   struct Level {     int lo[10 + 5], hi[10 + 5], sz;     bool operator<(const Level &l) const {       for (int i = 0; i < K; i++) {         if (hi[i] >= l.lo[i]) return false;       }       return true;     }   };   Level s[50000 + 5];   set<Level> ps;   void merge(Level &tar, const Level &src) {     for (int i = 0; i < K; i++) {       tar.lo[i] = min(tar.lo[i], src.lo[i]);       tar.hi[i] = max(tar.hi[i], src.hi[i]);     }     tar.sz += src.sz;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> N >> K;     for (int i = 0; i < N; i++) {       s[i].sz = 1;       for (int j = 0; j < K; j++) {         cin >> s[i].lo[j];         s[i].hi[j] = s[i].lo[j];       }       auto it1 = ps.lower_bound(s[i]), it2 = ps.upper_bound(s[i]);       while (!ps.empty() && it1 != it2) {         merge(s[i], *it1);         ps.erase(it1);         it1 = ps.lower_bound(s[i]);         it2 = ps.upper_bound(s[i]);       }       ps.insert(s[i]);       cout << (--ps.end())->sz <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int arr[100005], lazy[4 * 100005], num, value;   bool flag;   struct Node {     int maxi, mini, one, two;   } tree[4 * 100005];   Node merge(Node a, Node b) {     Node temp;     int num = max(a.maxi, b.maxi);     temp.maxi = num, temp.one = num == a.maxi ? a.one : b.one;     num = min(a.mini, b.mini);     temp.mini = num, temp.two = num == a.mini ? a.two : b.two;     return temp;   }   void build(int node, int a, int b) {     if (a > b) return;     if (a == b) {       tree[node] = (Node){arr[a], arr[a], a, a};       return;     }     int left, right;     left = 2 * node + 1, right = 2 * node + 2;     build(left, a, (a + b) / 2);     build(right, (a + b) / 2 + 1, b);     tree[node] = merge(tree[left], tree[right]);   }   void lazy_update(int node, int a, int b) {     int left, right;     left = 2 * node + 1, right = 2 * node + 2;     tree[node].maxi -= lazy[node];     tree[node].mini -= lazy[node];     if (a != b) {       lazy[left] += lazy[node];       lazy[right] += lazy[node];     }     lazy[node] = 0;   }   void update(int node, int a, int b, int i, int j, int val) {     if (lazy[node]) lazy_update(node, a, b);     if (a > b || a > j || b < i) return;     if (a >= i && b <= j) {       lazy[node] = val;       lazy_update(node, a, b);       return;     }     int left, right;     left = 2 * node + 1, right = 2 * node + 2;     update(left, a, (a + b) / 2, i, j, val);     update(right, (a + b) / 2 + 1, b, i, j, val);     tree[node] = merge(tree[left], tree[right]);   }   void query(int node, int a, int b, int i, int j, int val) {     if (lazy[node]) lazy_update(node, a, b);     if (flag) return;     if (a > b || a > j || b < i) return;     if (val > tree[node].mini) {       if (a == b) {         flag = true;         num = a;         return;       }       int left, right;       left = 2 * node + 1, right = 2 * node + 2;       query(left, a, (a + b) / 2, i, j, val);       query(right, (a + b) / 2 + 1, b, i, j, val);     }   }   void find(int node, int a, int b, int i, int j) {     if (lazy[node]) lazy_update(node, a, b);     if (a > b || a > j || b < i) return;     if (a == b) {       value = tree[node].mini;       return;     }     int left, right;     left = 2 * node + 1, right = 2 * node + 2;     find(left, a, (a + b) / 2, i, j);     find(right, (a + b) / 2 + 1, b, i, j);   }   int main() {     int n, a, b, one, two, k = 0, diff;     scanf( %d , &n);     set<int> zero;     for (int i = 0; i < n; i++) {       scanf( %d , &arr[i]);       if (!arr[i]) zero.insert(i);     }     build(0, 0, n - 1);     zero.insert(n);     vector<pair<int, int> > vec;     while (true) {       if (lazy[0]) lazy_update(0, 0, n - 1);       if (tree[0].maxi == 0) break;       int index = tree[0].one, x, y;       y = *zero.upper_bound(index);       flag = false;       query(0, 0, n - 1, index + 1, y - 1, tree[0].maxi);       if (flag)         a = index, b = num - 1;       else         a = index, b = min(n - 1, y - 1);       update(0, 0, n - 1, a, b, 1);       vec.push_back(make_pair(a + 1, b + 1));     }     printf( %d n , vec.size());     for (int i = 0; i < vec.size(); i++)       printf( %d %d n , vec[i].first, vec[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 50;   int x[N][N], y[N], True[N], False[N], ans;   int n, m;   bool flag = false;   void dfs(int pos) {     if (pos > n) {       ans++;       return;     }     bool f = true;     for (int i = 1; i <= m; i++) {       if (!x[i][pos])         True[i]++;       else         False[i]++;       if (True[i] > y[i] || False[i] > n - y[i]) f = false;     }     if (f) dfs(pos + 1);     f = true;     for (int i = 1; i <= m; i++) {       if (!x[i][pos])         True[i]--, False[i]++;       else         False[i]--, True[i]++;       if (True[i] > y[i] || False[i] > n - y[i]) f = false;     }     if (f) dfs(pos + 1);     for (int i = 1; i <= m; i++) {       if (!x[i][pos])         False[i]--;       else         True[i]--;     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++) scanf( %1d , &x[i][j]);       scanf( %d , &y[i]);     }     dfs(1);     printf( %d , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300010, mod = 998244353;   int a[N];   int n;   int fac[N], inv[N];   inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }   inline int del(int a, int b) { return a < b ? a - b + mod : a - b; }   inline int mul(int a, int b) { return a * 1ll * b % mod; }   inline int qpow(int a, int b) {     int s = 1;     while (b) {       if (b & 1) s = mul(s, a);       a = mul(a, a);       b >>= 1;     }     return s;   }   int main() {     scanf( %d , &n);     int m = 2 * n;     fac[0] = fac[1] = 1;     for (int i = 2; i <= m; ++i) fac[i] = mul(fac[i - 1], i);     inv[m] = qpow(fac[m], mod - 2);     for (int i = m - 1; i >= 1; --i) inv[i] = mul(inv[i + 1], i + 1);     inv[0] = 1;     for (int i = 1; i <= m; ++i) scanf( %d , &a[i]);     sort(a + 1, a + 1 + m);     for (int i = 1; i <= m; ++i)       if (a[i] >= mod) a[i] %= mod;     int ans = 0;     for (int i = 1; i <= n; ++i) ans = del(ans, a[i]);     for (int i = n + 1; i <= m; ++i) ans = add(ans, a[i]);     printf( %d n , mul(ans, mul(fac[m], mul(inv[n], inv[n]))));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> return_digit(long long num) {     vector<long long> arr;     while (num != 0) {       long long rem = num % 10;       arr.push_back(rem);       num /= 10;     }     return arr;   }   long long product_minmax(vector<long long> v) {     long long max_val = v[0];     long long min_val = v[0];     for (long long i = 1; i < v.size(); i++) {       max_val = max(max_val, v[i]);       min_val = min(min_val, v[i]);     }     return max_val * min_val;   }   long long compute(long long num) {     return num + product_minmax(return_digit(num));   }   int main() {     long long t;     cin >> t;     while (t--) {       long long a1, k;       cin >> a1 >> k;       long long temp = a1;       long long i = 0;       long long prev = a1;       while (i < k - 1) {         prev = temp;         temp = compute(temp);         if (prev == temp) {           break;         }         i += 1;       }       cout << temp << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n, T, a, b;       cin >> n >> T >> a >> b;       vector<pair<int, int>> qstn(n);       int totA = 0, totB = 0;       for (auto& i : qstn) {         cin >> i.second;         totB += i.second;       }       totA = n - totB;       for (auto& i : qstn) {         cin >> i.first;       }       sort(qstn.begin(), qstn.end());       int sol = 0, ctA = 0, ctB = 0, i = -1;       do {         if (i >= 0 && i < n) {           if (qstn[i].second) {             ++ctB;           } else {             ++ctA;           }         }         int t = (i + 1 < n ? qstn[i + 1].first - 1 : T);         if ((long long)ctA * a + (long long)ctB * b > t) continue;         t -= ctA * a + ctB * b;         int xtra = min(totA - ctA, t / a);         t -= xtra * a;         xtra += min(totB - ctB, t / b);         sol = max(sol, xtra + ctA + ctB);       } while (++i < n);       cout << sol <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int s[1000 * 1000];   int main() {     int cnt = 1;     for (int i = 1; i <= 1005; i++) {       int t = i;       int a[10];       int cnt1 = 1;       while (t) {         int tmp = t % 10;         a[cnt1++] = tmp;         t = t / 10;       }       for (cnt1--; cnt1; cnt1--) s[cnt++] = a[cnt1];     }     int n;     while (scanf( %d , &n) != EOF) printf( %d , s[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   void solve() {     int n, m;     cin >> n >> m;     map<vector<int>, int> tiles;     for (int i = 0; i < n; i++) {       vector<int> temp;       for (int j = 0; j < 4; j++) {         int a;         cin >> a;         temp.push_back(a);       }       tiles[temp]++;     }     if (m & 1) {       cout <<  NO n ;       return;     }     for (auto &i : tiles) {       if (i.first[1] == i.first[2]) {         cout <<  YES n ;         return;       }     }     cout <<  NO n ;   }   int main() {     fast();     int t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       long long ar[n];       for (int i = 0; i < n; i++) cin >> ar[i];       int maxi = -1000000001;       long long sum = 0;       for (int i = 0; i < n; i++) {         if (ar[i] > maxi) maxi = ar[i];         sum += ar[i];       }       float ans = (sum - maxi) / (float)(n - 1) + maxi;       printf( %.9f , ans);       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int m = 1;     while (m * (m - 1) <= 2 * n) m++;     m = m - 1;     cout << m <<   n ;     int arr[m + 4][m + 3];     long long k = 1;     for (int i = 0; i < m; i++) {       long long count = 0;       for (int j = i; j < m - 1; j++) {         arr[i][j] = k + count++;       }       count = 0;       for (long long j = i + 1; j < m; j++) {         arr[j][i] = k + count++;       }       k = k + m - i - 1;     }     for (long long i = 0; i < m; i++) {       for (long long j = 0; j < m - 1; j++) {         cout << arr[i][j] <<    ;       }       cout <<   n ;     }   }