#include <bits/stdc++.h>   using namespace std;   struct congressman {     int votes;     int last_vote;     int nr_of_order;     bool operator<(const congressman &other) const {       if (votes == other.votes) return last_vote > other.last_vote;       return votes < other.votes;     };   } v[105];   int n, k, m, a, pos[105];   bool elected(int i) {     int better = n - i;     int t = m - a;     for (int j = i - 1; j >= 1; j--)       if (t >= v[i].votes - v[j].votes + 1)         t -= v[i].votes - v[j].votes + 1, better++;       else         break;     return (better < k && v[i].votes != 0);   }   bool notelectible(int i) {     int last = i;     for (int j = i + 1; j <= n; j++)       if (v[i].votes + m - a > v[j].votes)         last = j;       else         break;     if (v[i].votes + m - a == 0) return 1;     return (last < n - k + 1);   }   int main() {     int i, j;     cin >> n >> k >> m >> a;     for (i = 1; i <= a; i++) {       cin >> j;       v[j].votes++;       v[j].last_vote = max(v[j].last_vote, i);     }     for (i = 1; i <= n; i++) v[i].nr_of_order = i;     sort(v + 1, v + n + 1);     for (i = 1; i <= n; i++) pos[v[i].nr_of_order] = i;     for (i = 1; i <= n; i++) {       int r = 0;       if (elected(pos[i]))         r = 1;       else if (notelectible(pos[i]))         r = 3;       else         r = 2;       cout << r <<    ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   const int N = (int)(2e6 + 20);   const int L = 1 << 6;   const long long int M = (long long int)(1e9 + 7);   const double E = 1e-7;   int a[N];   int main() {     ios_base::sync_with_stdio(0);     long long int n, m;     cin >> n >> m;     int tm = m;     if (n > 3) {       int f = 0, l = n - 1;       m--;       vector<int> v(n - 1);       for (int i = 0; i < n - 1; ++i) {         v[i] = m & 1;         m /= 2;       }       for (int i = 0; i < n - 1; ++i) {         if (v[n - i - 2])           a[l--] = i + 1;         else           a[f++] = i + 1;       }       a[f] = n;       for (int i = 0; i < n; ++i) cout << a[i] <<    ;       cout << endl;       return 0;     }     m = tm;     long long int maxV = 0;     vector<int> v(n);     for (int i = 0; i < n; ++i) v[i] = i + 1;     do {       long long int curV = 0;       for (int i = 0; i < n; ++i) {         int minV = v[i];         for (int j = i; j < n; ++j) {           minV = min(minV, v[j]);           curV += minV;         }       }       maxV = max(curV, maxV);     } while (next_permutation(v.begin(), v.end()));     for (int i = 0; i < n; ++i) v[i] = i + 1;     int cnt = 0;     do {       long long int curV = 0;       for (int i = 0; i < n; ++i) {         int minV = v[i];         for (int j = i; j < n; ++j) {           minV = min(minV, v[j]);           curV += minV;         }       }       if (curV == maxV) {         ++cnt;       }       if (cnt == m && true) {         for (int i = 0; i < n; ++i) cout << v[i] <<    ;         return 0;       }     } while (next_permutation(v.begin(), v.end()));     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2020;   vector<int> g[MAXN];   int maxDep = -1;   void DFS(int v, int depth) {     if (depth > maxDep) maxDep = depth;     for (int i = 0; i < g[v].size(); i++) DFS(g[v][i], depth + 1);   }   int main() {     int n, a;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a;       if (a != -1) g[i].push_back(a);     }     for (int i = 1; i <= n; i++) DFS(i, 1);     cout << maxDep << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool f[110][110][2][60];   int main() {     string str;     cin >> str;     int n = str.size();     int m;     cin >> m;     memset(f, 0, sizeof(f));     f[0][0][1][0] = 1;     for (int i = 0; i < n; i++) {       char ch = str[i];       for (int dist = 0; dist <= n; dist++)         for (int dir = 0; dir <= 1; dir++)           for (int opr = 0; opr <= m; opr++)             if (f[i][dist][dir][opr])               if (ch ==  F ) {                 int delta = dir ? 1 : -1;                 if (dist == 0)                   f[i + 1][1][1][opr] = 1;                 else                   f[i + 1][dist + delta][dir][opr] = 1;                 f[i + 1][dist][1 - dir][opr + 1] = 1;               } else {                 f[i + 1][dist][1 - dir][opr] = 1;                 int delta = dir ? 1 : -1;                 if (dist == 0)                   f[i + 1][1][1][opr + 1] = 1;                 else                   f[i + 1][dist + delta][dir][opr + 1] = 1;               }     }     int ans = 0;     for (int dist = 0; dist <= n; dist++)       for (int dir = 0; dir <= 1; dir++)         for (int opr = m; opr >= 0; opr -= 2)           if (f[n][dist][dir][opr]) ans = ((ans) > (dist) ? (ans) : (dist));     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     int p = n - a[0];     for (int i = 1; i < n; i++) {       if (i & 1) {         a[i] -= p;         a[i] += (n * 1000000);         a[i] = a[i] % n;         if (a[i] != i) {           cout <<  No ;           return 0;         }       } else {         a[i] += p;         a[i] %= n;         if (a[i] != i) {           cout <<  No ;           return 0;         }       }     }     cout <<  Yes ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> v[1001];     int n, k, r;     while (scanf( %d , &n) != EOF) {       for (int i = 1; i <= n; i++) {         v[i].clear();         scanf( %d , &k);         while (k--) {           scanf( %d , &r);           v[i].push_back(r);         }         sort(v[i].begin(), v[i].end());       }       int ans = 0;       for (int i = 1; i <= n; i++) {         int pre = i - 1;         pre = pre == 0 ? n : pre;         int next = i + 1;         next = next == n + 1 ? 1 : next;         for (int j = 1; j < v[i].size(); j++) {           int x = upper_bound(v[pre].begin(), v[pre].end(), v[i][j]) -                   upper_bound(v[pre].begin(), v[pre].end(), v[i][j - 1]);           int y = upper_bound(v[next].begin(), v[next].end(), v[i][j]) -                   upper_bound(v[next].begin(), v[next].end(), v[i][j - 1]);           if (x != y) ans++;         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0;   const double eps = 0;   const int ms = 0;   const int md = 0;   const int MAX_N = 1e5 + 5;   const int MAX_L = 20;   const long long MOD = 1e9 + 7;   const long long INF = 1e9 + 7;   long long mpow(long long k) {     long long ans = 1;     while (k > 0) {       ans *= 10;       k--;     }     return ans;   }   long long countNines(long long n) {     long long ans = 0;     while (n > 0) {       if (n % 10 == 9) {         ans++;       } else         break;       n /= 10;     }     return ans;   }   int main() {     long long p, d;     cin >> p >> d;     int k = 1;     long long ans = -1;     while ((p - p % mpow(k) - 1) > 0) {       if ((p - p % mpow(k) - 1) >= p - d) {         ans = p - p % mpow(k) - 1;       }       k++;     }     if (countNines(ans) > countNines(p))       cout << ans << endl;     else       cout << p << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 5;   int main() {     int num, r;     cin >> num >> r;     vector<pair<int, int>> arr(num + 1);     vector<bool> visited(r + 2, 0);     for (int i = 1; i <= num; ++i) {       cin >> arr[i].first >> arr[i].second;       for (int j = arr[i].first; j <= arr[i].second; ++j) {         visited[j] = 1;       }     }     long long ans = 0;     for (int k = 1; k <= r; ++k) {       if (visited[k] == 0) ans++;     }     cout << ans <<   n ;     for (int k = 1; k <= r; ++k) {       if (visited[k] == 0) cout << k <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long mod1 = 998244353;   const double pie = 3.1415926535;   long long power(long long x, long long y) {     if (y == 0)       return 1;     else {       if (y % 2 == 0)         return power(x * x, y / 2);       else         return x * power(x * x, (y - 1) / 2);     }   }   long long mod_power(long long x, long long y, long long m) {     long long r = 1;     x = x % m;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) r = (r * x) % m;       y = y / 2;       x = (x * x) % m;     }     return r;   }   long long gcd(long long x, long long y) {     if (y == 0) return x;     return gcd(y, x % y);   }   vector<long long> extended_Euclid(long long a, long long b) {     vector<long long> v(3);     if (b == 0) {       v[0] = a;       v[1] = 1;       v[2] = 0;       return v;     } else {       vector<long long> v1 = extended_Euclid(b, a % b);       v[0] = v1[0];       v[1] = v1[2];       v[2] = v1[1] - (a / b) * v1[2];       return v;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int TESTS = 1;     while (TESTS--) {       int n;       cin >> n;       map<int, vector<int> > M;       for (int i = 1; i <= n; i++) {         int x, y;         cin >> x >> y;         M[i].push_back(x);         M[i].push_back(y);       }       vector<int> ans;       ans.push_back(1);       int x = M[1][0];       int y = M[1][1];       int j;       if (find(M[x].begin(), M[x].end(), y) != M[x].end()) {         ans.push_back(x);         ans.push_back(y);         j = x;       } else {         ans.push_back(y);         ans.push_back(x);         j = y;       }       for (int i = 1; i <= n; i++) {         if (ans.size() == n)           break;         else {           if (M[j][0] == ans[ans.size() - 1])             ans.push_back(M[j][1]);           else             ans.push_back(M[j][0]);           j = ans[ans.size() - 2];         }       }       for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100012, H = 20;   vector<int> e[N], g[N];   stack<int> Z;   int n, m, tot, tim, low[N], rea[N], f[N], d[N];   int fa[N][H], k;   bool v[N];   void dfs(int fa, int now) {     low[now] = rea[now] = tim++;     v[now] = true;     Z.push(now);     int top = int(e[now].size());     for (int i = 0; i < top; ++i) {       int next = e[now][i];       if (next != fa) {         if (!v[next]) dfs(now, next);         low[now] = min(low[now], low[next]);       }     }     if (low[now] == rea[now]) {       int last = -1;       ++tot;       while (last != now) {         last = Z.top();         f[last] = tot;         Z.pop();       }     }   }   void work(int now, int p) {     fa[now][0] = p;     int top = int(g[now].size());     for (int j = 0; j < top; ++j)       if (fa[now][0] != g[now][j])         d[g[now][j]] = d[now] + 1, work(g[now][j], now);   }   void gao() {     for (int j = 1; j < H; ++j)       for (int i = 1; i <= tot; ++i) fa[i][j] = fa[fa[i][j - 1]][j - 1];   }   inline int find(int x, int y) {     if (d[x] < d[y]) swap(x, y);     for (int i = H - 1; i >= 0; --i)       if (d[fa[x][i]] >= d[y]) x = fa[x][i];     if (x == y) return x;     for (int i = H - 1; i >= 0; --i)       if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];     return fa[x][0];   }   int main() {     scanf( %d%d , &n, &m);     int a, b;     for (int i = 1; i <= m; ++i) {       scanf( %d%d , &a, &b);       e[a].push_back(b);       e[b].push_back(a);     }     for (int i = 1; i <= n; ++i)       if (!v[i]) dfs(-1, i);     for (int a = 1; a <= n; ++a)       for (int j = 0, top = int(e[a].size()); j < top; ++j) {         b = e[a][j];         if (f[a] != f[b]) {           g[f[a]].push_back(f[b]);           g[f[b]].push_back(f[a]);         }       }     d[0] = 0;     d[f[1]] = 1;     work(f[1], 0);     gao();     scanf( %d n , &k);     for (int i = 1; i <= k; ++i) {       scanf( %d%d , &a, &b);       a = f[a];       b = f[b];       int c = find(a, b);       printf( %d n , d[a] + d[b] - 2 * d[c]);     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6;   vector<vector<int>> g(N);   bool isDeleted[N];   vector<int> res;   void del(int s, int p) {     res.push_back(s);     isDeleted[s] = true;     for (auto I : g[s]) {       if (!isDeleted[I] && I != p) {         del(I, s);       }     }   }   bool dfs(int s, int p) {     int siz = g[s].size();     for (auto I : g[s]) {       if (I != p) {         bool isDeleted = dfs(I, s);         if (isDeleted) {           --siz;         }       }     }     if (siz % 2 == 0) {       del(s, p);       return true;     } else       return false;   }   int main() {     int n, x;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &x);       if (x) {         g[i].push_back(x - 1);         g[x - 1].push_back(i);       }     }     bool ans = dfs(0, -1);     if (ans) {       printf( YES n );       for (auto I : res) {         printf( %d n , I + 1);       }     } else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long sum = 0;     string s;     cin >> s;     s +=  a ;     int now_number = 0, buf_number = 0, size_buf = 0, point = 0;     for (int i = 0; i < s.size(); ++i) {       if (s[i] >=  a  && s[i] <=  z ) {         now_number = now_number * pow(10, size_buf) + buf_number;         buf_number = 0;         if (size_buf != 2 || !point) {           now_number *= 100;         }         size_buf = 0;         sum += now_number;         now_number = 0;         point = 0;       } else {         if (s[i] ==  . ) {           now_number = now_number * pow(10, size_buf) + buf_number;           buf_number = 0;           size_buf = 0;           point = 1;         } else {           buf_number = buf_number * 10 + (s[i] -  0 );           size_buf++;         }       }     }     int kop = sum % 100;     sum /= 100;     if (sum == 0) {       cout <<  0.  << kop / 10 << kop % 10;       return 0;     }     vector<string> ss;     while (sum != 0) {       int tri = sum % 1000;       sum /= 1000;       string ans =   ;       if (sum != 0) {         ans = (char)(tri % 10 + 48) + ans;         tri /= 10;         ans = (char)(tri % 10 + 48) + ans;         tri /= 10;         ans = (char)(tri % 10 + 48) + ans;         tri /= 10;       } else {         ans = to_string(tri);       }       ss.push_back(ans);     }     reverse(ss.begin(), ss.end());     for (int i = 0; i < ss.size(); ++i) {       if (i == ss.size() - 1) {         cout << ss[i];       } else {         cout << ss[i] <<  . ;       }     }     if (kop != 0) {       cout <<  .  << kop / 10 << kop % 10;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1024;   int n;   int a[maxn], b[maxn], c[maxn];   vector<int> g[maxn];   vector<pair<pair<int, int>, int> > ans;   void add(int v, int u, int x) { ans.push_back({{v, u}, x}); }   int gfs(int v, int par, int d) {     if (g[v].size() == 1) return v;     for (int i : g[v]) {       int u = a[i] + b[i] - v;       if (u != par and u != d) {         int res = gfs(u, v, d);         if (res != -1) return res;       }     }     return -1;   }   pair<int, int> gpr(int v, int d) {     pair<int, int> ret = {-1, -1};     for (int i : g[v]) {       int u = a[i] + b[i] - v;       if (u != d) {         int l = gfs(u, v, d);         if (l != -1) {           if (ret.first == -1)             ret.first = l;           else             ret.second = l;         }       }     }     return ret;   }   void see(int v, int u, int x) {     pair<int, int> vp = gpr(v, u);     pair<int, int> up = gpr(u, v);     add(vp.first, up.first, x / 2);     add(vp.second, up.second, x / 2);     add(vp.first, vp.second, -x / 2);     add(up.first, up.second, -x / 2);   }   void zee(int v, int d, int x) {     pair<int, int> vp = gpr(d, v);     add(vp.first, v, x / 2);     add(vp.second, v, x / 2);     add(vp.first, vp.second, -x / 2);   }   void dfs(int v, int par = -1, int lst = -1, int x = 0) {     if (g[v].size() > 2) {       if (lst != -1) see(v, lst, x);       lst = v;     } else if (g[v].size() == 1) {       zee(v, lst, x);     }     for (int i : g[v]) {       int u = a[i] + b[i] - v;       if (u != par) {         dfs(u, v, lst, c[i]);       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < n - 1; i++) {       cin >> a[i] >> b[i] >> c[i];       a[i]--, b[i]--;       g[a[i]].push_back(i);       g[b[i]].push_back(i);     }     for (int i = 0; i < n; i++)       if (g[i].size() == 2) {         if (c[g[i][0]] != c[g[i][1]]) {           cout <<  NO  << endl;           return 0;         }       }     cout <<  YES  << endl;     vector<int> lv;     int r = -1;     for (int i = 0; i < n; i++)       if (g[i].size() > 2)         r = i;       else if (g[i].size() == 1)         lv.push_back(i);     if (r == -1) {       cout << 1 << endl;       cout << lv[0] + 1 <<     << lv[1] + 1 <<     << c[0] << endl;       return 0;     }     dfs(r);     cout << ans.size() << endl;     for (auto p : ans)       cout << p.first.first + 1 <<     << p.first.second + 1 <<     << p.second            <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     puts( INTERCAL );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int t = 0, ans = 100000, a;     for (int i = (0); i < (n); ++i)       if (s[i] ==  T ) t++;     for (int i = (0); i < (n); ++i) {       a = 0;       for (int j = (i); j < (i + t); ++j) {         if (s[j % n] ==  H ) a++;       }       ans = min(ans, a);     }     cout << ans << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5, M = 5;   int cc[N][M], sz[N], k;   long long ret[N], sum = 0;   vector<int> adj[N];   long long dfs(int x, int p) {     int t, v, j, u, i;     sz[x] = 1;     long long R = 0, temp;     for (i = 0; i < adj[x].size(); ++i) {       u = adj[x][i];       if (u != p) {         temp = dfs(u, x);         sum += sz[u] * R;         R += temp;         sum += temp * sz[x];         for (j = 0; j < k; ++j)           for (t = 0; t < k; ++t) {             if (j + t + 2 <= k) sum -= (long long)cc[x][j] * cc[u][t];           }         for (j = 0; j < k; ++j) cc[x][j] += cc[u][j];         sz[x] += sz[u];       }     }     u = ++cc[x][k - 1];     for (i = k - 2; i >= 0; --i) cc[x][i + 1] = cc[x][i];     cc[x][0] = u;     ret[x] = R + u;     return ret[x];   }   int main() {     int n, i, j, u, v, a, b;     cin >> n >> k;     for (i = 0; i < n - 1; ++i) {       scanf( %d%d , &a, &b);       adj[a].push_back(b);       adj[b].push_back(a);     }     dfs(1, 0);     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int sum = 0;     for (int i = 0; i < n; i++) {       int c;       cin >> c;       sum = sum + c;     }     n = n + 1;     int count = 0;     for (int j = 1; j <= 5; j++) {       int flag = 0;       int s = sum + j;       if (s % n == 1) flag = 1;       if (flag == 0) count++;     }     cout << count;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v;   long long n, m, w, ai;   long long cnt[300005];   bool go(long long mx) {     memset(cnt, 0, sizeof cnt);     long long use = m;     long long add = 0;     for (int i = 0; i < n; i++) {       add += cnt[i];       long long curr = v[i] + add;       if (curr >= mx) continue;       if (mx - curr > use) return 0;       add += (mx - curr);       cnt[i + w] -= (mx - curr);       use -= (mx - curr);     }     return 1;   }   int main() {     cin >> n >> m >> w;     for (int i = 0; i < n; i++) {       cin >> ai;       v.push_back(ai);     }     long long l = 1, r = 10000000000ll, bst = -1;     while (l <= r) {       long long mid = (l + r) / 2ll;       if (go(mid)) {         bst = mid;         l = mid + 1;       } else         r = mid - 1;     }     cout << bst;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 200;   int num[MAX], vis[MAX];   int main() {     int n, m, a;     while (scanf( %d %d , &n, &m) == 2) {       memset(vis, 0, sizeof(vis));       for (int i = 0; i < m; i++) {         scanf( %d , &a);         for (int i = a; i <= n; i++)           if (!vis[i]) {             num[i] = a;             vis[i] = 1;           }       }       for (int i = 1; i <= n; i++) {         if (i == 1)           printf( %d , num[i]);         else           printf(  %d , num[i]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5, inf = 9e8;   int n, a[N];   array<int, 3> vals[N];   void compress(int arr[]) {     vector<int> all;     for (int i = 1; i <= n; i++) all.push_back(arr[i]);     sort(all.begin(), all.end());     for (int i = 1; i <= n; i++)       arr[i] = lower_bound(all.begin(), all.end(), arr[i]) - all.begin(),       ++arr[i];   }   class segTree {    private:     int n;     vector<int> st;       public:     void init(int _n) {       n = _n;       st = vector<int>(4 * n + 5, 0);     }     void pointUpdate(int node, int tl, int tr, int pos, int val) {       if (tl == tr) {         st[node] = max(st[node], val);       } else {         int mid = (tl + tr) / 2;         if (pos <= mid)           pointUpdate(2 * node, tl, mid, pos, val);         else           pointUpdate(2 * node + 1, mid + 1, tr, pos, val);         st[node] = max(st[2 * node], st[2 * node + 1]);       }     }     int rangeQuery(int node, int tl, int tr, int l, int r) {       if (l > r) return -inf;       if ((l == tl) && (r == tr)) return st[node];       int mid = (tl + tr) / 2;       int left_ans = rangeQuery(2 * node, tl, mid, l, min(r, mid));       int right_ans = rangeQuery(2 * node + 1, mid + 1, tr, max(l, mid + 1), r);       return max(left_ans, right_ans);     }     void update(int pos, int val) { pointUpdate(1, 1, n, pos, val); }     int query(int l, int r) {       r = min(r, n);       return rangeQuery(1, 1, n, l, r);     }   } rangeMax;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     compress(a);     for (int i = 1; i <= n; i++) vals[i][0] = a[i];     for (int i = 1; i <= n; i++) cin >> a[i];     compress(a);     for (int i = 1; i <= n; i++) vals[i][1] = a[i];     for (int i = 1; i <= n; i++) cin >> a[i];     compress(a);     for (int i = 1; i <= n; i++) vals[i][2] = a[i];     rangeMax.init(N);     sort(vals + 1, vals + n + 1);     reverse(vals + 1, vals + n + 1);     int ans = 0;     int j = 1;     for (int i = 1; i <= n; i = j) {       while (j <= n && vals[i][0] == vals[j][0]) ++j;       for (int k = i; k < j; k++) {         int max_c_for_all_valid_b = rangeMax.query(vals[k][1] + 1, inf);         if (max_c_for_all_valid_b > vals[k][2]) ++ans;       }       for (int k = i; k < j; k++) {         rangeMax.update(vals[k][1], vals[k][2]);       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int mod = 1000000007;   int gcd(int a, int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int prime(long long int n) {     long long int i;     for (i = 2; i <= sqrt(n); i++) {       if (n % i == 0) return 0;     }     return 1;   }   long long int ans[1000000], c = 0;   void get_num(long long int n) {     long long int i;     for (i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         if (prime(i)) ans[c++] = i;         if (prime(n / i)) {           if (n / i != i) ans[c++] = i;         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int n;     cin >> n;     get_num(n);     if (c == 0)       cout << n;     else if (c == 1)       cout << ans[0];     else       cout << 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool viz[105][105];   int dx[4] = {0, 1, 0, -1};   int dy[4] = {1, 0, -1, 0};   int main() {     cin.tie(0)->sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int T = 1;     while (T--) {       int n, m, x, y;       cin >> n >> m >> x >> y;       vector<pair<int, int> > sol;       viz[x][y] = 1;       cout << x <<     << y <<   n ;       int cnt = 1;       for (int j = 1; j <= m; j++) {         if (j != y) {           cout << x <<     << j <<   n ;         }       }       for (int i = x + 1; i <= n; i++) {         if (cnt % 2 == 1) {           for (int j = m; j >= 1; j--) {             cout << i <<     << j <<   n ;           }         } else {           for (int j = 1; j <= m; j++) {             cout << i <<     << j <<   n ;           }         }         cnt++;       }       for (int i = x - 1; i >= 1; i--) {         if (cnt % 2 == 1) {           for (int j = m; j >= 1; j--) {             cout << i <<     << j <<   n ;           }         } else {           for (int j = 1; j <= m; j++) {             cout << i <<     << j <<   n ;           }         }         cnt++;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ;     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int t;     cin >> t;     while (t--) {       long long a, b, c;       cin >> a >> b >> c;       long long cnt = 0;       while (1) {         if (a > c || b > c) break;         if (a > b) {           b += a;         } else           a += b;         cnt++;       }       cout << cnt << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   char s[200];   vector<pair<int, int> > v;   int main() {     scanf( %s , s);     int len = strlen(s);     pair<int, int> cur(0, 0);     v.push_back(cur);     for (int i = 0; i < len; i++) {       if (s[i] ==  L ) {         cur.first--;       } else if (s[i] ==  R ) {         cur.first++;       } else if (s[i] ==  U ) {         cur.second++;       } else if (s[i] ==  D ) {         cur.second--;       }       v.push_back(cur);     }     bool res = false;     len = v.size();     for (int i = 0; i < len; i++) {       for (int j = i + 2; j < len; j++) {         if (abs(v[i].first - v[j].first) + abs(v[i].second - v[j].second) <= 1) {           res = true;           goto zzz;         }       }     }   zzz:     if (res) {       printf( BUG );     } else {       printf( OK );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, cnt, a[2010], b[2010], bel[2010], ans[2010 * 2010 / 2][2];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) {       scanf( %d , &b[i]);       bel[b[i]] = i;     }     for (int i = 1; i <= n; i++) {       a[i] = bel[a[i]];       cnt += abs(a[i] - i);     }     cnt /= 2;     printf( %d n , cnt);     cnt = 0;     for (int i = 1; i <= n; i++) bel[a[i]] = i;     for (int i = n, now = bel[n]; i; i--, now = bel[i])       for (int j = bel[i] + 1; j <= n; j++)         if (a[j] <= now) {           ans[++cnt][0] = j;           ans[cnt][1] = now;           swap(a[now], a[j]);           now = j;         }     printf( %d n , cnt);     for (int i = 1; i <= cnt; i++) printf( %d %d n , ans[i][0], ans[i][1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, page;     cin >> n;     vector<int> pages(7);     for (int i = 0; i < 7; i++) {       cin >> page;       pages[i] = page;     }     int ans = 0;     while (true) {       n -= pages[ans];       if (n <= 0) {         break;       }       ans = (ans + 1) % 7;     }     cout << ans + 1;   }


#include <bits/stdc++.h>   using namespace std;   int n, q;   int C[500001];   vector<pair<int, int> > P[500001];   int ans[500001];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) cin >> C[i];     cin >> q;     for (int i = 0; i < q; ++i) {       int l, r;       cin >> l >> r;       P[r].emplace_back(l, i);     }     pair<int, int> basis[20] = {};     for (int R = 1; R <= n; ++R) {       pair<int, int> v(C[R], R);       for (int i = 20; i--;) {         if (v.first >> i) {           if (v.second < basis[i].second)             v.first ^= basis[i].first;           else if (basis[i].first == 0) {             basis[i] = v;             break;           } else {             swap(v, basis[i]);             v.first ^= basis[i].first;           }         }       }       for (pair<int, int> _ : P[R]) {         int L, idx;         tie(L, idx) = _;         int v = 0;         for (int i = 20; i--;) {           if (basis[i].second < L) continue;           if (((v >> i) & 1) == 0) v ^= basis[i].first;         }         ans[idx] = v;       }     }     for (int i = 0; i < q; ++i) {       printf( %d n , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int OO = 1e9;   const double EPS = 1e-9;   template <class T>   void _db(const char* dbStr, T e) {     cout << dbStr <<   =   << e << endl;   }   template <class T, class... L>   void _db(const char* dbStr, T e, L... r) {     while (*dbStr !=  , ) cout << *dbStr++;     cout <<   =   << e <<  , ;     _db(dbStr + 1, r...);   }   template <class S, class T>   ostream& operator<<(ostream& o, const map<S, T>& v) {     o <<  [ ;     int i = 0;     for (const pair<S, T>& pr : v)       o << (!i++ ?    :  ,  ) <<  {  << pr.first <<   :   << pr.second <<  } ;     return o <<  ] ;   }   template <template <class, class...> class S, class T, class... L>   ostream& operator<<(ostream& o, const S<T, L...>& v) {     o <<  [ ;     int i = 0;     for (const auto& e : v) o << (!i++ ?    :  ,  ) << e;     return o <<  ] ;   }   template <class S, class T>   ostream& operator<<(ostream& o, const pair<S, T>& pr) {     return o <<  (  << pr.first <<  ,   << pr.second <<  ) ;   }   ostream& operator<<(ostream& o, const string& s) {     for (const char& c : s) o << c;     return o;   }   template <class T>   using V = vector<T>;   template <class T>   using VV = V<V<T>>;   template <class T>   using VVV = VV<V<T>>;   using ll = long long;   using pii = pair<int, int>;   using vi = V<int>;   using vii = V<pii>;   using vvi = VV<int>;   using mii = map<int, int>;   using umii = unordered_map<int, int>;   using si = set<int>;   using usi = unordered_set<int>;   int n;   vi c;   vvi adj;   pii dfs(int u, int par) {     int mxH[] = {0, 0, 0}, diam = 0;     for (auto& v : adj[u])       if (v != par) {         pii pr = dfs(v, u);         diam = max(diam, pr.first);         mxH[0] = pr.second + (c[u] != c[v]);         sort(mxH, mxH + 3);       }     diam = max(diam, mxH[1] + mxH[2]);     return make_pair(diam, mxH[2]);   }   int main() {     ios::sync_with_stdio(false);     cout.precision(10);     cin.tie(0);     cin >> n;     c.assign(n + 1, 0);     adj.assign(n + 1, vi());     for (int i = 1; i <= n; ++i) {       cin >> c[i];     }     for (int i = 1; i <= n - 1; ++i) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     cout << (dfs(1, -1).first + 1) / 2 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long xorsum[(1L << 16)];   long long deg[(1L << 16)];   int main(void) {     long long n;     cin >> n;     queue<long long> q;     long long td = 0;     for (long long i = 0; i < n; i++) {       cin >> deg[i] >> xorsum[i];       if (deg[i] == 1) {         q.push(i);       }       td += deg[i];     }     vector<pair<long long, long long> > ans;     while (!q.empty()) {       long long u = q.front();       q.pop();       if (deg[u] == 0) continue;       long long v = xorsum[u];       xorsum[v] ^= u;       ans.push_back(make_pair(u, v));       deg[v]--;       if (deg[v] == 1) q.push(v);     }     cout << (td / 2) << endl;     for (long long i = 0; i < ans.size(); i++) {       cout << ans[i].first <<     << ans[i].second << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)1e6 + 5;   const int INF = (int)1e9 + 7;   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int a, b, c, d;     cin >> a >> b >> c >> d;     if (a + b == c + d or a + c == b + d or a + d == c + b or a + b + c == d or         a + c + d == b or a + b + d == c or a == b + c + d) {       cout <<  YES ;       return 0;     }     cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.length();     bool ok = false;     for (int i = 0; i < n - 1; i++) {       if (s[i] ==  A  && s[i + 1] ==  B ) {         for (int j = i + 2; j < n - 1; j++) {           if (s[j] ==  B  && s[j + 1] ==  A ) {             ok = true;             break;           }         }       }       if (ok) break;     }     if (ok) {       cout <<  YES n ;       return 0;     }     for (int i = 0; i < n - 1; i++) {       if (s[i] ==  B  && s[i + 1] ==  A ) {         for (int j = i + 2; j < n - 1; j++) {           if (s[j] ==  A  && s[j + 1] ==  B ) {             ok = true;             break;           }         }       }       if (ok) break;     }     if (ok)       cout <<  YES n ;     else       cout <<  NO n ;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     long long r;     while (b != 0) {       r = a % b;       a = b;       b = r;     }     return a;   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   long long fpow(long long n, long long k, int p = (int)1e9 + 7) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   const int MOD = (int)1e9 + 7;   const int INF = (int)1e9;   const long long LINF = (long long)1e18;   const long double PI = 2 * acos((long double)0);   const int maxn = 500010;   int n, w, h;   char s[maxn];   int xmin[maxn];   int xmax[maxn];   int ymin[maxn];   int ymax[maxn];   long long alox[maxn];   long long aloy[maxn];   long long tot[maxn];   void solve() {     scanf( %d%d%d%s , &n, &h, &w, s);     int dx = 0, dy = 0;     for (int i = (0); i < (n); i++) {       if (s[i] ==  L )         dx--;       else if (s[i] ==  R )         dx++;       else if (s[i] ==  U )         dy--;       else         dy++;       if (!i) {         xmin[i] = xmax[i] = dx;         ymin[i] = ymax[i] = dy;       } else {         xmin[i] = min(xmin[i - 1], dx);         xmax[i] = max(xmax[i - 1], dx);         ymin[i] = min(ymin[i - 1], dy);         ymax[i] = max(ymax[i - 1], dy);       }     }     for (int i = (0); i < (w); i++) {       int c = 0;       if (i + xmin[n - 1] >= 0 && i + xmax[n - 1] < w) {         int l = 0, r = INF;         while (l < r) {           int m = (l + r) >> 1;           if (dx >= 0) {             if (i + xmax[n - 1] + 1LL * m * dx < w)               l = m + 1;             else               r = m;           } else {             if (i + xmin[n - 1] + 1LL * m * dx >= 0)               l = m + 1;             else               r = m;           }         }         c = l;       }       if (c == INF) {         alox[i] = -1;         continue;       }       int l = 0, r = n - 1;       while (l < r) {         int m = (l + r) >> 1;         if (i + xmin[m] + 1LL * c * dx >= 0 && i + xmax[m] + 1LL * c * dx < w)           l = m + 1;         else           r = m;       }       alox[i] = 1LL * c * n + l + 1;     }     for (int i = (0); i < (h); i++) {       int c = 0;       if (i + ymin[n - 1] >= 0 && i + ymax[n - 1] < h) {         int l = 0, r = INF;         while (l < r) {           int m = (l + r) >> 1;           if (dy >= 0) {             if (i + ymax[n - 1] + 1LL * m * dy < h)               l = m + 1;             else               r = m;           } else {             if (i + ymin[n - 1] + 1LL * m * dy >= 0)               l = m + 1;             else               r = m;           }         }         c = l;       }       if (c == INF) {         aloy[i] = -1;         continue;       }       int l = 0, r = n - 1;       while (l < r) {         int m = (l + r) >> 1;         if (i + ymin[m] + 1LL * c * dy >= 0 && i + ymax[m] + 1LL * c * dy < h)           l = m + 1;         else           r = m;       }       aloy[i] = 1LL * c * n + l + 1;     }     int flagx = 0, flagy = 0;     for (int i = (0); i < (w); i++) {       if (!~alox[i]) {         flagx = 1;         alox[i] = LINF;       }     }     for (int i = (0); i < (h); i++) {       if (!~aloy[i]) {         flagy = 1;         aloy[i] = LINF;       }     }     if (flagx && flagy) {       printf( -1 );       return;     }     int ans = 0;     sort(aloy, aloy + h);     for (int i = (0); i < (h); i++) {       if (!i)         tot[i] = aloy[i] % MOD;       else         tot[i] = (tot[i - 1] + aloy[i]) % MOD;     }     for (int i = (0); i < (w); i++) {       int k = upper_bound(aloy, aloy + h, alox[i]) - aloy - 1;       if (~k) ans = (ans + tot[k]) % MOD;       ans = (ans + 1LL * (h - k - 1) * alox[i]) % MOD;     }     printf( %d , ans);   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e12 + 1, maxn = 2 * (1e5 + 5), mod = 1e9 + 7;   const double eps = 1e-9;   long long m, i, j, k, n, answer, t, l, r;   string s;   bool f(long long l0, long long r0, long long i0) {     if (r0 - i0 + 1 < i0 - l0) {       return 1;     }     if (r0 - i0 + 1 > i0 - l0) {       return 0;     }     long long jd = 0;     for (long long i1 = l0; i1 < i0; ++i1) {       if (s[i1] > s[i1 + i0]) {         jd = 1;         break;       }       if (s[i1] < s[i1 + i0]) {         if (!jd) {           return 0;         }         break;       }     }     if (jd) {       return 1;     }   }   int main() {     cin >> s;     n = s.size();     l = 0;     r = n - 1;     for (i = n - 1; i >= 0; --i) {       j = 0;       while (i >= 0 && s[i] ==  0 ) {         j = 1;         i--;       }       if (f(l, r, i)) {         r = i - 1;         answer++;       } else {         break;       }     }     cout << answer + 1;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-8;   const int mod = 1e9 + 7;   const int N = 1e6 + 10;   const long long INF = 1e18;   long long power(long long x, long long y) {     long long t = 1;     while (y > 0) {       if (y % 2)         y -= 1, t = t * x % mod;       else         y /= 2, x = x * x % mod;     }     return t;   }   long long val[N];   vector<pair<long long, long long> > G[N];   int vk[N];   set<pair<long long, long long> > S[N];   int ans[N];   int tl = 0;   void merge(int &p, int nw, long long cs) {     if (S[nw].size() == 0) return;     set<pair<long long, long long> >::iterator it = S[nw].end();     vector<pair<long long, long long> > z;     while (1) {       it--;       if ((*it).first > cs) {         z.push_back(*it);       } else         break;       if (it == S[nw].begin()) break;     }     for (int i = 0; i < z.size(); ++i) S[nw].erase(z[i]);     if (p == -1) {       p = nw;       return;     }     if (S[p].size() < S[nw].size()) swap(p, nw);     it = S[nw].begin();     while (it != S[nw].end()) {       S[p].insert(*it);       it++;     }   }   int dfs1(int v, long long c) {     int my = -1;     for (int i = 0; i < G[v].size(); ++i) {       int x = dfs1(G[v][i].first, G[v][i].second + c);       merge(my, x, c);     }     if (my == -1) my = tl++;     ans[v] = S[my].size();     S[my].insert(make_pair(c - val[v], v));     return my;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %lld , &val[i]);     for (int i = 0; i < n - 1; ++i) {       long long x, y;       scanf( %lld%lld , &x, &y);       x--;       G[x].push_back(make_pair(i + 1, y));     }     dfs1(0, 0);     for (int i = 0; i < n; ++i) printf( %d  , ans[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   int n, m;   int k[200010];   int rem[200010];   int idx[200010];   vector<int> special[200010];   vector<int> days[200010];   bool pos(const long long M) {     long long coins = 0;     memset(idx, 0, sizeof(idx));     for (int i = 0; i < n; i++) rem[i] = k[i];     for (int i = 1; i <= min((long long)200000, M); i++) {       coins++;       for (int j = 0; j < int(special[i].size()) && coins; j++) {         int item = special[i][j];         auto it = upper_bound(days[item].begin(), days[item].end(), i);         if (it == days[item].end() || *it > M) {           long long temp = rem[item];           rem[item] -= min((long long)rem[item], coins);           coins -= min(temp, coins);         }       }     }     if (M > 200000) coins += M - 200000;     for (int i = 0; i < n && coins >= 0; i++) {       if (rem[i]) coins -= 2 * rem[i];     }     return coins >= 0;   }   int main() {     scanf( %d %d , &n, &m);     long long sum = 0;     for (int i = 0; i < n; i++) scanf( %d , &k[i]), sum += k[i];     long long L = sum, M, R = 2 * sum, res;     int d, t;     while (m--) {       scanf( %d %d , &d, &t);       special[d].push_back(t - 1), days[t - 1].push_back(d);     }     for (int i = 0; i < n; i++) sort(days[i].begin(), days[i].end());     while (L <= R) {       M = (L + R) / 2;       if (pos(M))         res = M, R = M - 1;       else         L = M + 1;     }     printf( %I64d n , res);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:200000000 )   using namespace std;   const int INF = (int)1E8;   const long long INF64 = (long long)1E18;   const double EPS = 1E-9;   const double PI = acos((double)0) * 2;   const int MAXN = 160;   int n, cost[MAXN];   string s;   bool read() {     if (!(cin >> n)) return false;     for (int i = 0; i < int(n); ++i) {       cin >> cost[i + 1];       if (cost[i + 1] == -1) cost[i + 1] = -INF;     }     cin >> s;     return true;   }   int d[MAXN][MAXN][MAXN];   bool u[MAXN][MAXN][MAXN];   int get_d(int l, int r, int len) {     if (l > r) return cost[len];     if (l == r) return max(cost[len] + cost[1], cost[len + 1]);     int& my = d[l][r][len];     bool& myu = u[l][r][len];     if (myu) return my;     myu = true;     my = -INF;     if (len != 0) my = max(my, cost[len] + get_d(l, r, 0));     for (int i = int(l); i < int(r); ++i)       my = max(my, get_d(l, i, 0) + get_d(i + 1, r, len));     for (int i = int(l + 1); i < int(r + 1); ++i)       my = max(my, get_d(i, r, 0) + get_d(l, i - 1, len));     for (int i = int(l); i < int(r + 1); ++i)       my = max(my, get_d(l, i - 1, 0) + cost[len + 1] + get_d(i + 1, r, 0));     if (s[l] == s[r]) my = max(my, get_d(l + 1, r - 1, len + 2));     return my;   }   int d2[MAXN];   void solve() {     memset(u, 0, sizeof u);     int x = get_d(0, n - 1, 0);     for (int i = 0; i < int(n); ++i) {       d2[i] = i ? d2[i - 1] : 0;       for (int j = 0; j < int(i + 1); ++j)         d2[i] = max(d2[i], get_d(j, i, 0) + (j ? d2[j - 1] : 0));     }     cout << d2[n - 1] << endl;   }   int main() {     if (!read()) throw;     solve();   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     while (b) {       int tmp = a % b;       a = b;       b = tmp;     }     return a;   }   int main() {     int a, b;     cin >> a >> b;     int k = gcd(a, b);     if (abs(a / k - b / k) <= 1)       cout <<  Equal n ;     else if (a < b)       cout <<  Dasha n ;     else       cout <<  Masha n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long const M = 1000000007;   double const pi = acos(-1);   long long const inf = 2e18;   long long const N = 200001;   long long comb(long long n) {     if (n <= 0) return 0;     return (n * (n - 1)) / 2;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long i, j, t, n, d, ans = 0, curr, prev = 0;     cin >> n >> d;     vector<long long> a(n);     for (i = 0; i < n; i++) cin >> a[i];     for (curr = 2; curr < n;) {       while (curr < n && a[curr] - a[prev] <= d) {         ans += comb(curr - prev);         curr++;       }       if (a[curr] - a[prev] > d) prev++;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   long long int a[1004][1004];   long long int b[1005];   long long int c[1005];   long long int ci, cj;   int main() {     long long int i, j;     scanf( %d %d , &n, &m);     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) scanf( %I64d , &a[i][j]);     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) b[i] += a[i][j];     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) c[j] += a[i][j];     long long int mm = -1, tt;     long long int res = 0;     long long int mi;     for (i = 0; i <= n; i++) {       tt = 0;       for (j = 0; j < n; j++) {         tt += b[j] * (4 * i - 4 * j - 2) * (4 * i - 4 * j - 2);       }       if (mm < 0 || mm > tt) {         mm = tt;         mi = i;       }     }     ci = mi;     res += mm;     mm = -1;     for (i = 0; i <= m; i++) {       tt = 0;       for (j = 0; j < m; j++) {         tt += c[j] * (4 * i - 4 * j - 2) * (4 * i - 4 * j - 2);       }       if (mm < 0 || mm > tt) {         mm = tt;         mi = i;       }     }     cj = mi;     res += mm;     printf( %I64d n , res);     printf( %I64d %I64d n , ci, cj);   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const int mod = 1e9 + 7;   long long int powmod(long long int a, long long int b) {     long long int res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   int nxt() {     int x;     scanf( %d , &x);     return x;   }   vector<string> type;   vector<vector<int> > edge;   vector<bool> ans;   void dfs(int u) {     if (type[u] ==  IN ) {       ans[u] = edge[u][0];       return;     }     if (type[u] ==  NOT ) {       dfs(edge[u][0]);       ans[u] = !ans[edge[u][0]];       return;     }     dfs(edge[u][0]);     dfs(edge[u][1]);     if (type[u] ==  AND ) {       ans[u] = ans[edge[u][0]] & ans[edge[u][1]];     }     if (type[u] ==  OR ) {       ans[u] = ans[edge[u][0]] | ans[edge[u][1]];     }     if (type[u] ==  XOR ) {       ans[u] = ans[edge[u][0]] ^ ans[edge[u][1]];     }   }   void dfs2(int u, vector<int>& a) {     if (type[u] ==  IN ) {       a.push_back(u);       return;     }     if (type[u] ==  NOT ) {       dfs2(edge[u][0], a);       return;     }     bool l = ans[edge[u][0]];     bool r = ans[edge[u][1]];     int x = edge[u][0];     int y = edge[u][1];     if (type[u] ==  AND ) {       if (!l && r) {         dfs2(x, a);       }       if (l && !r) {         dfs2(y, a);       }       if (l && r) {         dfs2(x, a);         dfs2(y, a);       }     }     if (type[u] ==  OR ) {       if (!r && !l) {         dfs2(x, a);         dfs2(y, a);       }       if (!l && r) {         dfs2(y, a);       }       if (l && !r) {         dfs2(x, a);       }     }     if (type[u] ==  XOR ) {       dfs2(x, a);       dfs2(y, a);     }   }   int main() {     int n = nxt();     type.resize(n);     edge.resize(n);     ans.resize(n);     vector<int> q;     for (int i = 0; i < n; i++) {       cin >> type[i];       if (type[i] ==  IN ) {         edge[i].push_back(nxt());         q.push_back(i);       } else if (type[i] ==  NOT ) {         edge[i].push_back(nxt() - 1);       } else {         edge[i].push_back(nxt() - 1);         edge[i].push_back(nxt() - 1);       }     }     dfs(0);     vector<int> req;     dfs2(0, req);     set<int> s;     for (int x : req) s.insert(x);     for (int x : q) {       if (s.count(x))         printf( %d , ans[0] ^ 1 ? 1 : 0);       else         printf( %d , ans[0] ? 1 : 0);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using tpl = tuple<int, int, int>;   using pcc = pair<char, char>;   const ll inf = 2e18;   const ll mod = 1e9 + 7;   int dr[] = {-1, 0, 1, 0};   int dc[] = {0, 1, 0, -1};   int kr[] = {-1, 1, -2, -2, -1, 1, 2, 2};   int kc[] = {-2, -2, -1, 1, 2, 2, -1, 1};   int dgr[] = {-1, -1, 1, 1};   int dgc[] = {1, -1, -1, 1};   const int lim = 10000005;   bool isPrime[lim];   ll prime[lim];   ll pal[lim];   bool ok(string str) {     for (int i = str.size() - 1, j = 0; i > j; i--, j++)       if (str[i] != str[j]) return false;     return true;   }   void sieve() {     memset(isPrime, true, sizeof isPrime);     for (int i = 4; i < lim; i += 2) isPrime[i] = false;     for (ll i = 3; i <= lim; i += 2) {       if (isPrime[i]) {         for (ll j = i * i; j < lim; j += i) {           isPrime[j] = false;         }       }     }     pal[1] = 1;     pal[2] = 2;     prime[2] = 1;     ll cnt = 1, cnt2 = 2;     string str, rev;     for (ll i = 3; i < lim; i++) {       if (isPrime[i]) cnt++;       prime[i] = cnt;       str = to_string(i);       if (ok(str)) cnt2++;       pal[i] = cnt2;     }   }   int solve(int p, int q) {     int ans = 0;     for (int i = 1; i <= 10000000; i++) {       if ((q * prime[i]) <= (p * pal[i])) ans = i;     }     return ans;   }   int main() {     int ans = 0, p, q;     sieve();     cin >> p >> q;     cout << solve(p, q) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int w, h;     cin >> w >> h;     int u1, d1, u2, d2;     cin >> u1 >> d1 >> u2 >> d2;     for (int i = h; i >= 0; i--) {       w = w + i;       if (i == d1 || i == d2) {         if (i == d1) {           w = w - u1;           if (w < 0) {             w = 0;           }         } else {           w = w - u2;           if (w < 0) {             w = 0;           }         }       }     }     cout << w << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const int N = 2 * maxn;   int n, m, a[maxn];   int v[N];   void jl(int x) {     for (int i = x; i < N; i += i & -i) {       v[i]++;     }   }   long long s(int x) {     long long sum = 0;     for (int i = x; i > 0; i -= i & -i) {       sum += v[i];     }     return sum;   }   long long cal(int k) {     memset(v, 0, sizeof(v));     jl(n + 1);     int dp = 0;     long long sum = 0;     for (int i = 0; i < n; i++) {       if (a[i] <= k)         dp -= 1;       else         dp += 1;       sum += s(dp + n);       jl(dp + n + 1);     }     return sum;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     cout << cal(m - 1) - cal(m) << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   const int maxn = 1001000;   const int mod = 1000000007;   int a[maxn], f[maxn], r[maxn];   int main() {     int n;     scanf( %d , &n);     for (int e = 1; e <= n; e++) scanf( %d , a + e);     auto mul = [](int x, int y) { return 1ll * x * y % mod; };     f[0] = 1;     for (int e = 1; e <= n; e++) f[e] = mul(e, f[e - 1]);     r[n + 1] = 1;     for (int e = n; e >= 1; e--) r[e] = mul(e, r[e + 1]);     sort(a + 1, a + 1 + n);     int small = 0;     int i = 1, j = 1;     int ans = 0;     while (i <= n) {       while (j <= n && a[i] == a[j]) j++;       if (j == n + 1) break;       ans += mul(j - i, mul(a[i], mul(f[n - small - 1], r[n - small + 1])));       small += j - i;       if (ans >= mod) ans -= mod;       i = j;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double pi = 3.1415926535897932384626433832795;   long long int inp() {     long long int n = 0, s = 1;     char c;     for (c = getchar(); c < 48 || c > 58; c = getchar())       if (c ==  - ) s = -1;     for (; c > 47 && c < 59; c = getchar()) n = n * 10 + c - 48;     return n * s;   }   long long int gcd(long long int a, long long int b) {     if (b == 0)       return a;     else       gcd(b, a % b);   }   long long int square(long long int n) { return n * n; }   long long int bigmod(long long int b, long long int p, long long int m) {     if (p == 0)       return 1;     else if (p % 2 == 0)       return square(bigmod(b, p / 2, m)) % m;     else       return ((b % m) * bigmod(b, p - 1, m)) % m;   }   long long mulmod(long long a, long long b, long long c) {     long long x = 0, y = a % c;     while (b > 0) {       if (b % 2 == 1) {         x = (x + y) % c;       }       y = (y * 2) % c;       b /= 2;     }     return x % c;   }   long long int vis[55][55], n, m;   char ch[55][55];   long long int fun(long long int i, long long int j, char z, char d) {     long long int p = 0;     vis[i][j] = 1;     if ((j + 1) < m && vis[i][j + 1] == 0 && ch[i][j + 1] == z && d !=  l ) {       p = fun(i, j + 1, z,  r );     } else if ((j + 1) < m && vis[i][j + 1] == 1 && ch[i][j + 1] == z &&                d !=  l ) {       return 1;     }     if ((i + 1) < n && vis[i + 1][j] == 0 && ch[i + 1][j] == z && d !=  u ) {       p = fun(i + 1, j, z,  d );     } else if ((i + 1) < n && vis[i + 1][j] == 1 && ch[i + 1][j] == z &&                d !=  u ) {       return 1;     }     if ((j - 1) >= 0 && vis[i][j - 1] == 0 && ch[i][j - 1] == z && d !=  r ) {       p = fun(i, j - 1, z,  l );     } else if ((j - 1) >= 0 && vis[i][j - 1] == 1 && ch[i][j - 1] == z &&                d !=  r ) {       return 1;     }     if ((i - 1) >= 0 && vis[i - 1][j] == 0 && ch[i - 1][j] == z && d !=  d ) {       p = fun(i - 1, j, z,  u );     } else if ((i - 1) >= 0 && vis[i - 1][j] == 1 && ch[i - 1][j] == z &&                d !=  d ) {       return 1;     }     return p;   }   int main() {     long long int t, ans = 0, i, j, k;     cin >> n >> m;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) cin >> ch[i][j];     }     long long int f = 0;     for (k = 0; k < 25; k++) {       f = 0;       for (i = 0; i < n; i++) {         f = 0;         for (j = 0; j < m; j++) {           if (ch[i][j] == (char)( A  + k) && vis[i][j] != 1 &&               fun(i, j, (char)( A  + k),  a )) {             cout <<  Yes n ;             f = 1;             break;           }         }         if (f == 1) break;       }       if (f == 1) {         break;       }     }     if (f == 0) cout <<  No n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000100;   const int M = 20;   vector<int> g[N];   vector<int> gr[N];   vector<int> ord;   int sp[N][M];   int tin[N];   int tout[N];   int timer;   void pre_dfs(int v, int p = -1) {     sp[v][0] = (p == -1 ? v : p);     for (int i = 1; i < M; i++) {       sp[v][i] = sp[sp[v][i - 1]][i - 1];     }     tin[v] = timer++;     for (int to : g[v]) {       pre_dfs(to, v);     }     tout[v] = timer++;   }   inline bool anc(int u, int v) {     return (tin[u] <= tin[v] && tout[u] >= tout[v]);   }   int get_par(int v, int k) {     for (int i = 0; i < M; i++) {       if ((k >> i) & 1) {         v = sp[v][i];       }     }     return v;   }   bool mark[N];   void dfs1(int v) {     mark[v] = 1;     for (int to : g[v]) {       if (!mark[to]) {         dfs1(to);       }     }     ord.push_back(v);   }   bool good[N];   int comp[N];   int val[N];   int cur;   void dfs2(int v) {     comp[v] = cur;     val[cur] += good[v];     for (int to : gr[v]) {       if (comp[to] == -1) {         dfs2(to);       }     }   }   int dp[N];   int dfs_end(int v) {     if (dp[v] != -1) return dp[v];     dp[v] = val[v];     for (int to : g[v]) {       dp[v] = max(dp[v], dfs_end(to) + val[v]);     }     return dp[v];   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, k;     cin >> n >> k;     vector<pair<int, int>> ed;     for (int i = 1; i < n; i++) {       int p;       cin >> p;       --p;       g[p].push_back(i);       gr[i].push_back(p);       ed.emplace_back(p, i);     }     pre_dfs(0);     for (int i = 0; i < n; i++) {       good[i] = g[i].empty();       if (!good[i]) continue;       int up = get_par(i, k);       g[i].push_back(up);       gr[up].push_back(i);     }     for (int i = 0; i < n; i++) {       if (!mark[i]) {         dfs1(i);       }     }     memset(comp, -1, sizeof(comp));     for (int i = n - 1; i >= 0; i--) {       int v = ord[i];       if (comp[v] == -1) {         dfs2(v);         ++cur;       }     }     for (int i = 0; i < n; i++) {       g[i].clear();       gr[i].clear();     }     for (auto u : ed) {       int x = comp[u.first];       int y = comp[u.second];       if (x != y) {         g[x].push_back(y);       }     }     memset(dp, -1, sizeof(dp));     cout << dfs_end(comp[0]) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, s, i, l = 0, k = 0, j = 0, t = 0, p = 0, max = 0;     cin >> n;     int a[n];     for (i = 0; i < n; i++) {       k++;       cin >> a[i];       if (a[i] == 1) {         l++;       }       if (a[i] == 2) {         j++;       }       if (a[i] == 3) {         t++;       }       if (l > j) {         max = l;       }       if (j > max) {         max = j;       } else if (t > max) {         max = t;       }     }     cout << (n - max) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, n;   long long mod = 1000000007;   vector<long long> factorial(1000005);   bool excellent(long long z) {     while (z != 0) {       if (z % 10 != a && z % 10 != b) return false;       z /= 10;     }     return true;   }   long long pow(long long a, long long p) {     if (p == 0) return 1;     if (p % 2 == 1) return (a * pow(a, p - 1)) % mod;     long long v = pow(a, p >> 1);     return (v * v) % mod;   }   int calc(int n, int m) {     return (factorial[n] * (pow(factorial[m], mod - 2) % mod) % mod *             (pow(factorial[n - m], mod - 2) % mod) % mod);   }   int main() {     cin >> a >> b >> n;     factorial[1] = 1;     for (int i = 2; i <= n; i++) factorial[i] = (factorial[i - 1] * i) % mod;     long long count = 0;     for (int i = 0; i <= n; i++) {       if (excellent(a * i + b * (n - i))) {         if (n - i != 0 && i != 0) {           count += calc(n, i);           count = count % mod;         } else           count++;       }     }     cout << count << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1 << 30;   struct line {     int a, b;     line() {}     line(int a, int b) : a(a), b(b) {}     bool operator<(const line& o) const { return a < o.a; }     friend line operator+(const line& first, const line& second) {       if (second < first) return second + first;       if (first.b >= second.a && first.b < second.b)         return line(first.a, second.b);       return first;     }     void print() { printf( (%d, %d)  , a, b); }   };   struct node {     vector<line> box;     node() {}     node(line first) { box = {first}; }     int size() { return (int)(box).size(); }     friend node operator+(const node& X, const node& Y) {       const vector<line>& first = X.box;       const vector<line>& second = Y.box;       int l = 0, r = 0;       node T;       vector<line>& t = T.box;       while (l < first.size() && r < second.size()) {         if (first[l] < second[r])           t.push_back(first[l++]);         else           t.push_back(second[r++]);       }       while (l < first.size()) t.push_back(first[l++]);       while (r < second.size()) t.push_back(second[r++]);       vector<line> Stack;       Stack.push_back(t.back());       for (int i = ((int)(t).size() - 2); i >= (0); --i) {         line& c = t[i];         while (!Stack.empty() && Stack.back().a <= c.b) {           c.b = max(c.b, Stack.back().b);           Stack.pop_back();         }         Stack.push_back(c);       }       Stack.clear();       return T;     }     line search(int a) {       int l = 0, r = size();       while (l < r) {         int m = (l + r) >> 1;         if (box[m].a < a)           l = m + 1;         else           r = m;       }       if (l != size()) return box[l];       return line(inf, inf);     }     void print() {       printf( {  );       for (line& e : box) {         e.print();         cout <<    ;       }       printf( } n );     }   };   const int N = 100005;   line rope[N];   node seg[N << 2];   void build(int l, int r, int now) {     if (l == r) {       seg[now] = node(rope[l]);       return;     }     int m = (l + r) >> 1;     int L = (now << 1), R = (now << 1 | 1);     build(l, m, L);     build(m + 1, r, R);     seg[now] = seg[L] + seg[R];   }   line get(int ll, int rr, int l, int r, int now) {     if (ll <= l && r <= rr) {       return seg[now].search(ll);     }     if (rr < l || r < ll) return line(inf, inf);     int m = (l + r) >> 1;     return get(ll, rr, l, m, now << 1) + get(ll, rr, m + 1, r, now << 1 | 1);   }   void solve() {     int n, m;     cin >> n >> m;     for (int i = (1); i <= (m); ++i) {       int a, b;       cin >> a >> b;       rope[b] = {a, b};     }     build(1, n, 1);     int q;     cin >> q;     while (q--) {       int a, b;       cin >> a >> b;       line ans = get(a, b, 1, n, 1);       if (ans.a != a)         printf( %d n , a);       else         printf( %d n , ans.b);     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   const int N = 4000090, M = 1000000007;   int t[N];   void add(int x, int l, int r, int p, int v) {     if (p > r or p < l) return;     if (l == r) {       t[x] += v;       return;     }     int m = (l + r) / 2;     add(2 * x, l, m, p, v);     add(2 * x + 1, m + 1, r, p, v);     t[x] = t[2 * x] + t[2 * x + 1];     return;   }   int kth(int x, int l, int r, int k) {     if (l == r) return l;     int m = (l + r) / 2;     if (t[2 * x] >= k)       return kth(2 * x, l, m, k);     else       return kth(2 * x + 1, m + 1, r, k - t[2 * x]);   }   int main() {     int n, q, x;     scanf( %d %d , &n, &q);     for (int i = 0; i < n; ++i) scanf( %d , &x), add(1, 1, n, x, 1);     for (int Q = 0; Q < q; ++Q) {       scanf( %d , &x);       if (x > 0)         add(1, 1, n, x, 1);       else         add(1, 1, n, kth(1, 1, n, -x), -1);     }     if (!t[1])       puts( 0 );     else       printf( %d , kth(1, 1, n, 1));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, t;     cin >> s >> t;     int n = s.size();     char c;     vector<pair<char, char>> a;     for (int i = 0; i < n; i++)       if (s[i] != t[i]) {         c = t[i];         for (int j = 0; j < n; j++)           if (t[j] == c && s[j] == s[i] || t[j] == s[i] && s[j] == c) {             if (t[j] == c)               t[j] = s[i];             else               t[j] = c;           } else if (t[j] == c || s[j] == s[i] || t[j] == s[i] || s[j] == c) {             cout << -1;             return 0;           }         a.push_back(make_pair(c, s[i]));       }     cout << a.size() << endl;     for (int i = 0; i < a.size(); i++)       cout << a[i].first <<     << a[i].second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double ans = 1;   int p, d, h;   int main() {     cin >> p >> d >> h;     int top = 0;     int kh;     for (int i = 1; i <= d; i++) {       int x;       cin >> x;       top += x;       if (i == h) {         kh = x;       }     }     if (top < p) {       cout << -1;       return 0;     } else {       double t = 1;       int temp = top - 1;       for (int i = p - 1; i > 0; i--) {         t *= ((double)temp / (double)i);         temp--;       }       double ist = 1;       int temp2 = top - kh;       for (int i = p - 1; i > 0; i--) {         ist *= ((double)temp2 / (double)i);         temp2--;       }       double aist = t - ist;       ans = aist / t;       cout << ans;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   clock_t clk = clock();   int i, j;   void solve(void);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     int t = 1;     while (t--) solve();     return 0;   }   int n, m, a, b;   bool cnt;   bool vis[1501][1501];   char maze[1501][1501];   set<pair<int, int> > s[1501][1501];   int dfs(int x, int y, int ex, int ey, int cntx, int cnty) {     auto it = s[x][y].find({cntx, cnty});     if (vis[x][y] == 1 && it != s[x][y].end())       return 0;     else if (vis[x][y] == 1)       return -1;     vis[x][y] = 1;     s[x][y].insert({cntx, cnty});     int val = 0, valx = cntx, valy = cnty;     if (maze[x][((y - 1) % m + m) % m] !=  #  && ((y - 1) % m + m) % m != ey) {       valx = cntx, valy = cnty;       if (y - 1 == -1) --valy;       val = dfs(x, ((y - 1) % m + m) % m, x, y, valx, valy);     }     if (val == -1) return val;     if (maze[x][((y + 1) % m + m) % m] !=  #  && ((y + 1) % m + m) % m != ey) {       valx = cntx, valy = cnty;       if (y + 1 == m) ++valy;       val = dfs(x, ((y + 1) % m + m) % m, x, y, valx, valy);     }     if (val == -1) return val;     if (maze[((x - 1) % n + n) % n][y] !=  #  && ((x - 1) % n + n) % n != ex) {       valx = cntx, valy = cnty;       if (x - 1 == -1) --valx;       val = dfs(((x - 1) % n + n) % n, y, x, y, valx, valy);     }     if (val == -1) return val;     if (maze[((x + 1) % n + n) % n][y] !=  #  && ((x + 1) % n + n) % n != ex) {       valx = cntx, valy = cnty;       if (x + 1 == n) ++valx;       val = dfs(((x + 1) % n + n) % n, y, x, y, valx, valy);     }     if (val == -1) return val;     return 0;   }   void solve() {     cin >> n >> m;     for (i = 0; i <= n - 1; ++i)       for (j = 0; j <= m - 1; ++j) {         cin >> maze[i][j];         if (maze[i][j] ==  S ) a = i, b = j;       }     int val = dfs(a, b, -1, -1, 0, 0);     if (val == -1)       cout <<  Yes ;     else       cout <<  No ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const double Pi = acos(-1.0);   inline int cmp(double x, double y = 0, double tol = 1e-7) {     return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;   }   struct point {     double x, y;     point(double x = 0, double y = 0) : x(x), y(y) {}     point operator+(point q) { return point(x + q.x, y + q.y); }     point operator-(point q) { return point(x - q.x, y - q.y); }     point operator*(double t) { return point(x * t, y * t); }     point operator/(double t) { return point(x / t, y / t); }     double operator*(point q) { return x * q.x + y * q.y; }     double operator%(point q) { return x * q.y - y * q.x; }     double polar() { return ((y > -1e-7) ? atan2(y, x) : 2 * Pi + atan2(y, x)); }     double mod() { return sqrt(x * x + y * y); }     double mod2() { return (x * x + y * y); }     point rotate(double t) {       return point(x * cos(t) - y * sin(t), x * sin(t) + y * cos(t));     }     point rotate(double sin, double cos) {       return point(x * cos - y * sin, x * sin + y * cos);     }     int cmp(point q) const {       if (int t = ::cmp(x, q.x)) return t;       return ::cmp(y, q.y);     }     bool operator==(point q) const { return cmp(q) == 0; }     bool operator!=(point q) const { return cmp(q) != 0; }     bool operator<(point q) const { return cmp(q) < 0; }     static point pivot;   };   point point::pivot;   double abs(point p) { return hypot(p.x, p.y); }   double arg(point p) { return atan2(p.y, p.x); }   inline int ccw(point p, point q, point r) { return cmp((p - r) % (q - r)); }   point proj(point v, point u) { return u * ((u * v) / (u * u)); }   inline double angle(point p, point q, point r) {     point u = p - q, v = r - q;     return atan2(u % v, u * v);   }   bool between(point p, point q, point r) {     return ccw(p, q, r) == 0 && cmp((p - q) * (r - q)) <= 0;   }   bool seg_intersect(point p, point q, point r, point s) {     point A = q - p, B = s - r, C = r - p, D = s - q;     int a = cmp(A % C) + 2 * cmp(A % D);     int b = cmp(B % C) + 2 * cmp(B % D);     if (a == 3 || a == -3 || b == 3 || b == -3) return false;     if (a || b || p == r || p == s || q == r || q == s) return true;     int t = (p < r) + (p < s) + (q < r) + (q < s);     return t != 0 && t != 4;   }   double seg_distance(point p, point q, point r) {     point A = r - q, B = r - p, C = q - p;     double a = A * A, b = B * B, c = C * C;     if (cmp(b, a + c) >= 0)       return sqrt(a);     else if (cmp(a, b + c) >= 0)       return sqrt(b);     else       return fabs(A % B) / sqrt(c);   }   int in_poly(point p, vector<point>& T) {     double a = 0;     int N = T.size();     for (int i = 0; i < N; i++) {       if (between(T[i], p, T[(i + 1) % N])) return -1;       a += angle(T[i], p, T[(i + 1) % N]);     }     return cmp(a) != 0;   }   bool radial_lt(point p, point q) {     point P = p - point::pivot, Q = q - point::pivot;     double R = P % Q;     if (cmp(R)) return R > 0;     return cmp(P * P, Q * Q) < 0;   }   vector<point> convex_hull(vector<point>& T) {     int j = 0, k, n = T.size();     vector<point> U(n);     point::pivot = *min_element((T).begin(), (T).end());     sort((T).begin(), (T).end(), radial_lt);     for (k = n - 2; k >= 0 && ccw(T[0], T[n - 1], T[k]) == 0; k--)       ;     reverse((k + 1) + (T).begin(), (T).end());     for (int i = 0; i < n; i++) {       while (j > 1 && ccw(U[j - 1], U[j - 2], T[i]) >= 0) j--;       U[j++] = T[i];     }     U.erase(j + (U).begin(), (U).end());     return U;   }   point line_intersect(point p, point q, point r, point s) {     point a = q - p, b = s - r, c = point(p % q, r % s);     return point(point(a.x, b.x) % c, point(a.y, b.y) % c) / (a % b);   }   double poly_area(vector<point>& T) {     double s = 0;     int n = T.size();     for (int i = 0; i < n; i++) s += T[i] % T[(i + 1) % n];     return s / 2;   }   struct segment {     point a, b;     segment(point a = point(0, 0), point b = point(0, 0)) : a(a), b(b) {}     void input() {       cin >> a.x >> a.y >> b.x >> b.y;       if (b < a) swap(a, b);     }     void output() {       printf( a=(%.1f  %.1f)  b=(%.1f  %.1f) n , a.x, a.y, b.x, b.y);     }     bool operator<(const segment& q) const {       return a < q.a || (a == q.a && b < q.b);     }   };   bool solve(segment s[4]) {     if (s[0].a != s[1].a) return false;     if (s[0].b != s[2].a) return false;     if (s[1].b != s[3].a) return false;     if (s[2].b != s[3].b) return false;     if (cmp(s[0].a.x, s[0].b.x) != 0) return false;     if (cmp(s[1].a.y, s[1].b.y) != 0) return false;     if (cmp(s[2].a.y, s[2].b.y) != 0) return false;     if (cmp(s[3].a.x, s[3].b.x) != 0) return false;     if (s[0].a == s[0].b) return false;     if (s[1].a == s[1].b) return false;     return true;   }   int main() {     segment s[4];     for (int i = 0; i < 4; i++) {       s[i].input();     }     sort(s, s + 4);     printf( %s n , (solve(s) ?  YES  :  NO ));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     vector<int> arr(n);     for (auto& x : arr) cin >> x;     vector<int> p(m);     for (int i = 0; i < m; i++) p[i] = i;     vector<vector<int>> mp(m);     int ans = 0;     for (int i = 0; i < n; i++) {       if (i > 0 && arr[i - 1] != arr[i]) ans++;       mp[arr[i] - 1].push_back(i);     }     cout << ans << endl;     for (int i = 0; i < m - 1; i++) {       int u, v;       cin >> u >> v;       u--, v--;       while (p[u] != u) {         u = p[u];       }       while (p[v] != v) {         v = p[v];       }       if (mp[v].size() > mp[u].size()) swap(u, v);       for (int x : mp[v]) {         if (x + 1 < n && arr[x + 1] == u + 1) ans--;         if (x > 0 && arr[x - 1] == u + 1) ans--;       }       for (int x : mp[v]) {         arr[x] = u + 1;         mp[u].push_back(x);       }       mp[v].clear();       p[v] = u;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     if (n % 2 == 0)       printf(  Mahmoud );     else       printf(  Ehab );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a;     cin >> a;     map<string, long long> arr;     for (long long i = 0; i < a; i++) {       string s1;       cin >> s1;       arr[s1] = -i;       arr.insert(pair<string, long long>(s1, -i));     }     vector<pair<long long, string>> ar1;     for (auto it = arr.begin(); it != arr.end(); it++) {       ar1.push_back(make_pair(it->second, it->first));     }     sort(ar1.begin(), ar1.end());     for (auto it = ar1.begin(); it != ar1.end(); it++) {       cout << it->second << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   bool check[100];   int main() {     int n;     string s;     cin >> n;     cin >> s;     int ans = 0;     for (int x = 0; x < s.size(); ++x) {       if (!check[s[x] -  a ]) {         ans++;         check[s[x] -  a ] = 1;       }     }     cout << ((ans >= n) ?  YES  :  NO ) << endl;     if (ans >= n) {       for (int x = 0; x < s.size(); ++x) {         if (n) {           if (check[s[x] -  a ]) {             if (x) cout << endl;             cout << s[x];             check[s[x] -  a ] = 0;             n--;           } else {             cout << s[x];           }         } else           cout << s[x];       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n, x, y, c;     cin >> n >> x >> y;     int a[n];     for (i = 0; i < n; i++) cin >> a[i];     if (x > y)       cout << n << endl;     else {       c = 0;       for (i = 0; i < n; i++)         if (a[i] <= x) c++;       if (c % 2 == 1)         c = c / 2 + 1;       else         c /= 2;       cout << c << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)2e5 + 5;   const int K = 30;   int p[N];   char s[N];   int get(int l, int r, int s) {     l = max(l, s * K);     if (l > r) return 0;     return r / s - l / s;   }   int main() {     scanf( %s , s);     int n = strlen(s);     for (int i = 0; i < n; ++i) p[i + 1] = p[i] + (int)(s[i] ==  1 );     long long ans = 0;     map<int, int> cnt;     for (int k = 1; k <= K; ++k) {       cnt.clear();       for (int i = 0; i <= n; ++i) ++cnt[i - k * p[i]];       for (auto pr : cnt) ans += pr.second * (long long)(pr.second - 1) / 2;     }     vector<int> one;     for (int i = 0; i < n; ++i)       if (s[i] ==  1 ) one.push_back(i);     one.push_back(n);     reverse((one).begin(), (one).end());     for (int i = 0; i < n; ++i) {       int sz = (int)(one).size();       for (int j = 0; j < min(n / K + 1, sz - 1); ++j)         ans += get(one[sz - j - 1] - i, one[sz - (j + 1) - 1] - i, j + 1);       if (s[i] ==  1 ) one.pop_back();     }     printf( %lld n , ans);   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) {       long long int n, x = 1, ans = 0, w = 0, q;       string s;       cin >> n;       long long int p = pow(2, 32) - 1;       stack<long long int> stackstack;       for (int i = 0; i < n; i++) {         cin >> s;         if (s ==  for ) cin >> q;         if (s ==  add  && stackstack.empty() == 1) {           if (ans + 1 > p) {             cout <<  OVERFLOW!!! ;             return 0;           } else             ans += 1;         } else if (s ==  add ) {           if (stackstack.top() == p + 1) {             cout <<  OVERFLOW!!! ;             return 0;           }           if (stackstack.top() + ans > p) {             cout <<  OVERFLOW!!! ;             return 0;           }           ans += stackstack.top();         } else if (s ==  end ) {           stackstack.pop();         } else if (s ==  for ) {           if (stackstack.empty())             x = 1;           else             x = stackstack.top();           if (x * q > p)             stackstack.push(p + 1);           else             stackstack.push(x * q);         }       }       cout << ans;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct pawn {     long long int r;     long long int c;   };   struct pawn b[100], w[100];   int main() {     ios::sync_with_stdio(false);     char a;     long long int l = 0, h = 0;     for (int i = 1; i <= 8; i++) {       for (int j = 1; j <= 8; j++) {         cin >> a;         if (a ==  B ) {           b[l].r = i;           b[l].c = j;           l++;         } else if (a ==  W ) {           w[h].r = i;           w[h].c = j;           h++;         }       }     }     long long int w_r, w_c;     for (int i = 0; i < h; i++) {       int f = 0;       for (int j = 0; j < l; j++) {         if (b[j].r < w[i].r && b[j].c == w[i].c) {           f = 1;           break;         }       }       if (f == 0) {         w_r = w[i].r;         w_c = w[i].c;         break;       }     }     long long int b_r, b_c;     for (int i = l - 1; i >= 0; i--) {       int f = 0;       for (int j = h - 1; j >= 0; j--) {         if (w[j].r > b[i].r && w[j].c == b[i].c) {           f = 1;           break;         }       }       if (f == 0) {         b_r = b[i].r;         b_c = b[i].c;         break;       }     }     long long int diff_w = w_r - 1;     long long int diff_b = 8 - b_r;     if (diff_w == diff_b)       cout <<  A  << endl;     else if (diff_w < diff_b)       cout <<  A  << endl;     else       cout <<  B  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void MAIN() {     long long N;     cin >> N;     string S = to_string(N);     reverse(S.begin(), S.end());     int sz = (int)S.size();     long long ans = -2;     for (int i = 0; i < (1 << sz); i++) {       int i_c = i;       if ((i_c >> (sz - 1) & 1) || (i_c >> (sz - 2) & 1)) {         continue;       }       string T = S;       long long now = 1;       for (int j = 0; j < sz; j++) {         if (i_c >> j & 1) {           int X = 10 + (int)(T[j] -  0 );           now *= 19 - X;           if (T[j + 2] ==  0 ) {             if (i_c >> (j + 2) & 1) {               T[j + 2] =  9 ;               i_c ^= (1 << (j + 2));             } else {               now = 0;               break;             }           } else {             T[j + 2]--;           }         } else {           now *= (int)(T[j] -  0 ) + 1;           if (T[j] ==  9  && j >= 2 && (i >> (j - 2) & 1)) {             T[j + 2]--;           }         }       }       ans += now;     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int T;     cin >> T;     while (T--) {       MAIN();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long ispossible(vector<long long>& b, vector<long long>& p, int k,                               long long a) {     int n = b.size();     if (k > p.size()) return -1;     long long c = 0, s = 0, extra = 0;     for (int i = n - k; i < n; i++) {       c += p[i - n + k];       extra += max(p[i - n + k] - b[i], 0ll);     }     if (extra > a) return -1;     long long e = c - a;     return e > 0 ? e : 0;   }   int main() {     int n, m;     long long a;     cin >> n >> m >> a;     vector<long long> b(n, 0), p(m, 0);     for (int i = 0; i < n; i++) cin >> b[i];     for (int i = 0; i < m; i++) cin >> p[i];     sort(b.begin(), b.end());     sort(p.begin(), p.end());     int l, r;     long long tcost, cost = 0;     l = 0, r = n;     while (l < r) {       m = (l + r) >> 1;       tcost = ispossible(b, p, m, a);       if (tcost >= 0) {         l = m + 1;         cost = tcost;       } else         r = m;     }     if (l <= r) {       tcost = ispossible(b, p, r, a);       if (tcost >= 0) {         l = r + 1;         cost = tcost;       }     }     cout << l - 1 <<     << cost << endl;     return 0;   }


#include <bits/stdc++.h>   inline int dist(int a, int b, int d) {     assert(a % d && b % d);     if (a >= 0)       a /= d;     else       a = a / d - 1;     if (b >= 0)       b /= d;     else       b = b / d - 1;     return abs(a - b);   }   int main() {     int a, b, x1, y1, x2, y2;     scanf( %d%d%d%d%d%d , &a, &b, &x1, &y1, &x2, &y2);     printf( %d n ,            ((dist(x1 + y1, x2 + y2, 2 * a)) > (dist(x1 - y1, x2 - y2, 2 * b))                 ? (dist(x1 + y1, x2 + y2, 2 * a))                 : (dist(x1 - y1, x2 - y2, 2 * b))));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pll = pair<ll, ll>;   using dd = long double;   namespace {   static bool constexpr dbg = 0;   ll constexpr N = -1;   ll n, a, b, c;   void init() { cin >> n >> a >> b >> c; }   void solve() {     if (n == 1)       cout << 0;     else if (n == 2)       cout << min(a, b);     else       cout << (min(a, b) + (n - 2) * min({a, b, c}));   }   }  // namespace   int main() {     if (!dbg) {       std::ios::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);     }     cout << fixed << setprecision(20);     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long P[200020];   long long n, m;   long long Mod = 998244353;   long long Power(long long a, long long b) {     if (b < 1) return 1;     long long Tmp = Power(a, b / 2);     Tmp = Tmp * Tmp % Mod;     if (b & 1) Tmp = Tmp * a % Mod;     return Tmp;   }   long long inv(long long a) { return Power(a, Mod - 2); }   long long C(long long a, long long b) {     if (b < 0 || a < 0 || a - b < 0) return 0;     return P[a] * inv(P[a - b] * P[b] % Mod) % Mod;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     cin >> n >> m;     P[0] = 1;     for (int i = 1; i < 200020; i++) P[i] = i * P[i - 1] % Mod;     long long Ans = C(m, n - 1) * (n - 2) % Mod * Power(2, n - 3) % Mod;     cout << Ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100100], id[100100], t, Ans, ans[100100], n, i, vis[100100], j, k;   int flag;   vector<int> vec[100100];   bool cmp(int u, int v) { return a[u] < a[v]; }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);       id[i] = i;     }     sort(id + 1, id + 1 + n, cmp);     vec[1].push_back(1);     if (n > 1) vec[1].push_back(n);     vis[1] = vis[n] = vis[0] = vis[n + 1] = 1;     ;     j = 1;     while (a[id[j]] == 1) {       if (vis[id[j]] == 0) {         vec[1].push_back(id[j]);         vis[id[j]] = 1;       }       j++;     }     for (i = 2; i <= n; i++) {       flag = 0;       while (a[id[j]] == i) {         if (vis[id[j]] == 0) {           vec[i].push_back(id[j]);           vis[id[j]] = 1;           flag = 1;         }         j++;       }       for (k = 0; k < vec[i - 1].size(); k++) {         t = vec[i - 1][k];         if (vis[t - 1] == 0) {           vis[t - 1] = 1;           vec[i].push_back(t - 1);           flag = 1;         }         if (vis[t + 1] == 0) {           vis[t + 1] = 1;           vec[i].push_back(t + 1);           flag = 1;         }       }       if (!flag) break;     }     printf( %d n , i - 1);   }


#include <bits/stdc++.h>   const int N = 3e5 + 10;   const int mod = 1e9 + 7;   int n;   std::vector<int> edge[N];   std::pair<int, int> v[N];   int q;   std::pair<int, int> query[N];   int queue[N];   std::pair<int, int> range[N];   int father[N];   int degree[N];   int fastPower(int x, int y) {     int ret = 1;     for (; y; y >>= 1) {       if (y & 1) {         ret = (long long)ret * x % mod;       }       x = (long long)x * x % mod;     }     return ret;   }   int inv(int x) { return fastPower(x, mod - 2); }   int lowbit(int x) { return x & (-x); }   struct FenwickTree {     int e[N];     void build(int size) {       for (int i = 1; i <= size; i++) {         e[i] = 1;       }     }     void change(int x, int value) {       for (int i = x; i <= n; i += lowbit(i)) {         e[i] = (long long)e[i] * value % mod;       }     }     int getValue(int x) {       int ret = 1;       for (int i = x; i >= 1; i -= lowbit(i)) {         ret = (long long)ret * e[i] % mod;       }       return ret;     }   };   FenwickTree ft;   struct SegmentTree {     struct Node {       int sum;       int tag;     };     Node tree[N << 2];     void update(int root, int left, int right) {       tree[root].sum = (long long)tree[root].sum * tree[root].tag % mod;       if (left != right) {         tree[root << 1].tag =             (long long)tree[root << 1].tag * tree[root].tag % mod;         tree[root << 1 | 1].tag =             (long long)tree[root << 1 | 1].tag * tree[root].tag % mod;       }       tree[root].tag = 1;     }     void change(int root, int left, int right, int pos, int value) {       update(root, left, right);       if (left == pos && right == pos) {         tree[root].sum = value;         return;       }       int mid = (left + right) >> 1;       if (pos <= mid) {         change(root << 1, left, mid, pos, value);       } else {         change(root << 1 | 1, mid + 1, right, pos, value);       }       update(root << 1, left, mid);       update(root << 1 | 1, mid + 1, right);       tree[root].sum = tree[root << 1].sum + tree[root << 1 | 1].sum;     }     void change2(int root, int left, int right, int ql, int qr, int value) {       update(root, left, right);       if (left == ql && right == qr) {         tree[root].tag = value;         update(root, left, right);         return;       }       int mid = (left + right) >> 1;       if (qr <= mid) {         change2(root << 1, left, mid, ql, qr, value);       } else if (ql > mid) {         change2(root << 1 | 1, mid + 1, right, ql, qr, value);       } else {         change2(root << 1, left, mid, ql, mid, value);         change2(root << 1 | 1, mid + 1, right, mid + 1, qr, value);       }       update(root << 1, left, mid);       update(root << 1 | 1, mid + 1, right);       tree[root].sum = tree[root << 1].sum + tree[root << 1 | 1].sum;     }     int getSum(int root, int left, int right, int ql, int qr) {       update(root, left, right);       if (left == ql && right == qr) {         return tree[root].sum;       }       int mid = (left + right) >> 1;       if (qr <= mid) {         return getSum(root << 1, left, mid, ql, qr);       } else if (ql > mid) {         return getSum(root << 1 | 1, mid + 1, right, ql, qr);       } else {         return (getSum(root << 1, left, mid, ql, mid) +                 getSum(root << 1 | 1, mid + 1, right, mid + 1, qr)) %                mod;       }     }   };   SegmentTree st;   void init() {     std::cin >> v[1].second >> q;     n = 1;     for (int i = 1; i <= q; i++) {       scanf( %d%d , &query[i].first, &query[i].second);       if (query[i].first == 1) {         father[++n] = query[i].second;         scanf( %d , &v[n].second);         edge[father[n]].push_back(n);       }     }   }   void dfs(int u) {     static int tot = 0;     queue[++tot] = u;     range[u].first = tot;     for (int i = 0; i < (int)edge[u].size(); i++) {       dfs(edge[u][i]);     }     range[u].second = tot;   }   void work() {     dfs(1);     std::fill(degree + 1, degree + n + 1, 1);     ft.build(n);     int tmp = 1;     v[1].first = v[1].second;     st.change(1, 1, n, range[1].first, v[1].first);     for (int i = 1; i <= q; i++) {       if (query[i].first == 1) {         int fa = query[i].second;         tmp++;         v[tmp].first = v[tmp].second;         degree[fa]++;         int cc = (long long)degree[fa] * inv(degree[fa] - 1) % mod;         ft.change(range[fa].first, cc);         ft.change(range[fa].second + 1, inv(cc));         st.change2(1, 1, n, range[fa].first, range[fa].second, cc);         st.change(1, 1, n, range[tmp].first,                   (long long)v[tmp].first * ft.getValue(range[tmp].first) % mod);       } else {         int u = query[i].second;         int answer = st.getSum(1, 1, n, range[u].first, range[u].second);         if (u != 1) {           answer =               (long long)answer * inv(ft.getValue(range[father[u]].first)) % mod;         }         printf( %d n , answer);       }     }   }   int main() {     init();     work();     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int dp[5005][5005];   string s;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> s;     memset(dp, -1, sizeof dp);     int ans = 0;     for (int i = 0; i < s.size(); i++) {       int can_rev = 0;       int cur = 0;       for (int j = i; j < s.size(); j++) {         if (cur == 0) ans++;         if (s[j] ==  ( ) {           cur++;         } else if (s[j] ==  ) ) {           cur--;           if (cur < 0) {             if (can_rev == 0) break;             can_rev--;             cur += 2;           }         } else {           if (cur > 0) {             cur--;             can_rev++;           } else {             cur++;           }         }       }       if (cur == 0) ans++;       ans--;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     ;     long long int t, i;     cin >> t;     while (t--) {       long long int n, x, tt = 0;       vector<pair<long long int, long long int>> v, v1;       multimap<long long int, long long int> m, u;       multiset<long long int> s;       cin >> n;       for (long long int i = 0; i < n; i++) {         cin >> x;         v.push_back({x, i});         m.insert({x, i});       }       long long int c = 0, a, b, min = INT_MAX, j, k;       if (n < 2) {         cout <<  -1  <<   n ;         continue;       } else {         sort((v).begin(), (v).end());         for (long long int j = 0; j < v.size() - 1; j++) {           if (v[j].first != v[j + 1].first)             continue;           else {             tt = 1;             for (long long int k = j + 1; k < v.size(); k++) {               if (v[j].first == v[k].first)                 c = v[k].second - v[j].second;               else                 break;               if (c == 1) {                 min = c;                 break;               } else if (c < min)                 min = c;             }           }         }         if (tt == 0)           cout <<  -1  <<   n ;         else           cout << min + 1 <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 10;   const long long inf = 1e15;   const int mod = 1e6;   void faster() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   const long long N = 3e5 + 10;   int n, m;   string s;   pair<long long, long long> p[N];   long long prefix[N];   int main() {     faster();     int n;     cin >> n;     prefix[0] = 1;     for (int i = 0; i < n; i++) {       cin >> p[i].first >> p[i].second;     }     sort(p, p + n);     long long mini = p[0].first;     long long maxi = prefix[0];     for (int i = 1; i < n; i++) {       if (p[i].first - p[i].second >= mini) {         auto q = lower_bound(p, p + i, make_pair(p[i].first - p[i].second, 0ll));         q--;         int ind = q - p;         prefix[i] = prefix[ind] + 1;       } else         prefix[i] = 1;       maxi = max(maxi, prefix[i]);     }     cout << n - maxi << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     long long n;     cin >> n;     long long nmax = 9999999999;     while ((nmax / 2) >= n) nmax /= 10;     int inc = nmax + 1;     long long ans = 0;     if (nmax == 0) {       ans = (n * (n - 1)) / 2;       cout << ans << endl;       return 0;     }     while (n >= (nmax / 2)) {       cerr <<  ans             <<   is   << ans << endl;       ;       if (n >= nmax)         ans += (nmax / 2);       else         ans += n - (nmax / 2);       nmax += inc;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   char a[99];   char b[99];   int n;   int c, d;   int get(char p, char q, char r, char s) {     if (p == r) return 0;     if (p ==  ( ) {       if (r ==  [ ) return -1;       return 1;     } else if (p ==  [ ) {       if (r ==  ( ) return 1;       return -1;     } else {       if (r ==  ( ) return -1;       return 1;     }   }   int main() {     int i, j;     scanf( %s %s , a, b);     n = strlen(a);     for (i = 0; i < n; i += 2) {       j = get(a[i], a[i + 1], b[i], b[i + 1]);       if (j == 1)         c++;       else if (j == -1)         c--;     }     if (c == 0)       printf( TIE n );     else if (c > 0)       printf( TEAM 1 WINS n );     else       printf( TEAM 2 WINS n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int x = 0;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       string statement;       cin >> statement;       if (statement.find( + ) != std::string::npos) {         x += 1;       } else {         x -= 1;       }     }     cout << x << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, h, i, j, t, m, l, r, q;     long long p = 0, k, w, z, x, y, d;     string s =   , st =   , s1 =   , s2 =   ;     q = 1;     for (l = 0; l < q; l++) {       int x1, y1, x2, y2;       std::cin >> x1 >> y1 >> x2 >> y2 >> x >> y;       p = x2 - x1;       h = y2 - y1;       z = 0;       if (p % x == 0 && h % y == 0) {         if (p / x == h / y)           z = 1;         else {           p = p / x;           h = h / y;           d = abs(p - h);           if (d % 2 == 0) z = 1;         }       }       if (z == 0)         std::cout <<  NO  << std::endl;       else         std::cout <<  YES  << std::endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1E9;   const long long LINF = (long long)1E18;   int INP, AM;   char BUF[(1 << 10) + 1], *inp = BUF;   template <typename T>   T gcd(T a, T b) {     return (b == 0) ? abs(a) : gcd(b, a % b);   }   template <typename T>   inline T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <typename T>   inline T sqr(T x) {     return x * x;   }   const char DEBUG_PARAM[] =  __LOCAL_TESTING ;   const char IN[] =  input.txt ;   const char OUT[] =  output.txt ;   int ntest = 0, test;   inline void init();   inline void run();   inline void stop() { ntest = test - 1; }   int main(int argc, char* argv[]) {     if (argc > 1 && strcmp(argv[1], DEBUG_PARAM) == 0) {       freopen(IN,  r , stdin);     }     init();     if (ntest == 0) {       puts( ntest = ? );       return 0;     }     for (test = 1; test <= ntest; test++) {       run();     }     return 0;   }   const int dx[] = {-1, 0, 0, 1};   const int dy[] = {0, -1, 1, 0};   const long double EPS = 1E-9;   const long long MODULO = 1000000007LL;   inline void init() { ntest = 1; }   const int maxn = 100000 + 5;   pair<int, int> p[maxn];   int n;   vector<int> X, Y;   int sumX, sumY;   void solve() {     int limit = ceil((double)n / 2);     for (int i = (n); i >= (1); i--) {       if (((int)(X).size()) == limit) {         Y.push_back(p[i].second);         sumY += p[i].first;       } else if (((int)(Y).size()) == limit) {         X.push_back(p[i].second);         sumX += p[i].first;       } else {         if (sumX < sumY) {           X.push_back(p[i].second);           sumX += p[i].first;         } else {           Y.push_back(p[i].second);           sumY += p[i].first;         }       }     }     cout << ((int)(X).size()) << endl;     for (int i = 0; i < (((int)(X).size())); i++) {       cout << X[i];       if (i != ((int)(X).size()) - 1) cout <<    ;     }     cout << endl;     cout << ((int)(Y).size()) << endl;     for (int i = 0; i < (((int)(Y).size())); i++) {       cout << Y[i];       if (i != ((int)(Y).size()) - 1) cout <<    ;     }   }   inline void run() {     cin >> n;     for (int i = (1); i <= (n); i++) {       cin >> p[i].first;       p[i].second = i;     }     sort(p + 1, p + 1 + n);     solve();   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   template <typename... Args>   void writeln(Args... args) {     ((cout << args <<    ), ...);     cout << endl;   }   template <typename... Args>   void _db(Args... args) {     ((cerr << args <<   ;;  ), ...);     cout << endl;   }   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     vector<pair<ll, ll>> v(n);     for (int i = 0; i < n; ++i) {       cin >> v[i].first >> v[i].second;     }     sort(v.begin(), v.end(), [](const pair<ll, ll>& f, const pair<ll, ll>& s) {       return abs(f.first) + abs(f.second) < abs(s.first) + abs(s.second);     });     int count = n * 2;     for (auto [x, y] : v) {       if (x != 0) {         count += 2;       }       if (y != 0) {         count += 2;       }     }     cout << count << endl;     for (auto [x, y] : v) {       if (x != 0) {         char dir = x > 0 ?  R  :  L ;         cout << 1 <<     << abs(x) <<     << dir <<   n ;       }       if (y != 0) {         char dir = y > 0 ?  U  :  D ;         cout << 1 <<     << abs(y) <<     << dir <<   n ;       }       cout << 2 <<   n ;       if (x != 0) {         char dir = x > 0 ?  L  :  R ;         cout << 1 <<     << abs(x) <<     << dir <<   n ;       }       if (y != 0) {         char dir = y > 0 ?  D  :  U ;         cout << 1 <<     << abs(y) <<     << dir <<   n ;       }       cout << 3 <<   n ;     }     flush(cout);     return 0;   }