#include <bits/stdc++.h>   int arr[500005], st[500005][25], fa[500005][25], bit[500005];   inline int calc(int x, int y) {     if (arr[x] <= arr[y]) return x;     return y;   }   inline int query(int l, int r) {     if (l < 0 || l > r) return 0;     int len = bit[r - l + 1];     return calc(st[l][len], st[r - (1 << len) + 1][len]);   }   int main() {     for (int i = 2; i < 500005; i++) bit[i] = bit[i >> 1] + 1;     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , arr + i);       arr[i + n] = arr[i];     }     for (int i = 0; i < n << 1; i++) {       arr[i] = i - arr[i];       st[i][0] = i;     }     for (int i = 1; i < 22; i++) {       for (int j = 0; j + (1 << i) <= n << 1; j++)         st[j][i] = calc(st[j][i - 1], st[j + (1 << i - 1)][i - 1]);     }     for (int i = 0; i < n << 1; i++) fa[i][0] = query(arr[i], i);     for (int i = 1; i < 20; i++) {       for (int j = 0; j < n << 1; j++) fa[j][i] = fa[fa[j][i - 1]][i - 1];     }     long long ans = 0;     for (int i = n; i < n << 1; i++) {       int x = i;       ans += (arr[i] > i - n + 1) + 1;       for (int j = 19; j >= 0; j--) {         if (arr[fa[x][j]] > i - n + 1) {           x = fa[x][j];           ans += 1 << j;         }       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int num = 0;   int cnt[1000] = {0};   int candidate[400005] = {0};   string s;   bool check(int added) {     if (added % 2) return false;     if (n % (added + num)) return false;     if ((n / (added + num)) % 2 == 0) return false;     return true;   }   int main() {     cin >> n >> s;     for (int i = 0; i < n; ++i) cnt[s[i]]++;     for (int i = 0; i < 200; ++i) {       if (cnt[i] % 2) {         cnt[i] -= 1;         candidate[num++] = i;       }     }     if (num == 0) {       string before =   ;       string after =   ;       for (int j = 40; j < 130; ++j) {         while (cnt[j] >= 2) {           cnt[j] -= 2;           before += j;           after += j;         }       }       cout << 1 << endl;       reverse(before.begin(), before.end());       cout << before + after << endl;       return 0;     }     int added = 0;     while (!check(added)) ++added;     for (int i = 40; i < 130; ++i) {       if (!added) break;       if (cnt[i] > added) {         for (int j = 0; j < added; ++j) candidate[num++] = i;         cnt[i] -= added;         added = 0;       } else {         for (int j = 0; j < cnt[i]; ++j) candidate[num++] = i;         added -= cnt[i];         cnt[i] = 0;       }     }     cout << num << endl;     for (int i = 0; i < num; ++i) {       string before =   ;       string after =   ;       after += char(candidate[i]);       int remain = (n / num) - 1;       for (int j = 40; j < 130; ++j) {         if (!remain) break;         if (cnt[j] >= remain) {           for (int k = 0; k < remain / 2; ++k) {             before += char(j);             after += char(j);           }           cnt[j] -= remain;           remain = 0;         } else {           for (int k = 0; k < cnt[j] / 2; ++k) {             before += char(j);             after += char(j);           }           remain -= cnt[j];           cnt[j] = 0;         }       }       reverse(before.begin(), before.end());       cout << before + after <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int r1, c1, r2, c2, a[505][505], N, M, dx[4] = {-1, 0, 1, 0},                                          dy[4] = {0, 1, 0, -1};   bool viz[505][505];   char c;   queue<pair<int, int> > Q;   bool bfs(int x, int y, int xx, int yy) {     Q.push(make_pair(x, y));     while (Q.size()) {       pair<int, int> nod = Q.front();       Q.pop();       for (int i = 0; i < 4; ++i) {         int nx = nod.first + dx[i], ny = nod.second + dy[i];         if (a[nx][ny] == 1 && nx == xx && ny == yy) {           return 1;         } else if (a[nx][ny] == 2) {           --a[nx][ny];           Q.push(make_pair(nx, ny));         }       }     }     return 0;   }   int main() {     cin.sync_with_stdio(false);     cin >> N >> M;     for (int i = 1; i <= N; ++i)       for (int j = 1; j <= M; ++j) {         cin >> c;         if (c ==  . )           a[i][j] = 2;         else           a[i][j] = 1;       }     cin >> r1 >> c1 >> r2 >> c2;     if (bfs(r1, c1, r2, c2))       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Line {     long long a, b;     int id;     Line(long long a, long long b, int id) : a(a), b(b), id(id) {}     bool before(const Line &A, const Line B) {       long long p1 = A.b - b, p2 = B.b - b;       long long q1 = a - A.a, q2 = a - B.a;       if (q1 < 0) {         p1 *= -1;         q1 *= -1;       }       if (q2 < 0) {         p2 *= -1;         q2 *= -1;       }       return p1 * q2 <= p2 * q1;     }     long long value(int x) { return a * x + b; }   };   struct Hull {     vector<int> a;     vector<bool> taken;     vector<Line> h;     vector<int> order;     int ptr;     int size = 0;     long long sum = 0;     Hull() {}     Hull(const vector<int> &a) : a(a) {       taken.resize(a.size(), false);       for (int i = 0; i < (int)a.size(); ++i) {         order.push_back(i);       }       sort((order).begin(), (order).end(),            [&](int i, int j) { return a[i] < a[j]; });       Build();     }     void Build() {       const int n = (int)a.size();       ptr = 0;       vector<long long> val(n);       long long suf = sum;       int cnt = 0;       for (int i = 0; i < n; ++i) {         if (taken[i]) {           suf -= a[i];           ++cnt;         } else {           val[i] = suf + a[i] * 1ll * (cnt + 1);         }       }       vector<Line> sorted;       for (int i : order) {         if (!taken[i]) {           sorted.push_back(Line(a[i], val[i], i));         }       }       h.clear();       for (Line &C : sorted) {         if (!h.empty() && h.back().a == C.a) {           if (C.b <= h.back().b)             continue;           else             h.pop_back();         }         while ((int)h.size() >= 2) {           Line &A = h[(int)h.size() - 2];           Line &B = h[(int)h.size() - 1];           if (A.before(B, C)) break;           h.pop_back();         }         h.push_back(C);       }     }     pair<long long, int> best(int before) {       if (h.empty()) return {-1ll, -1};       while (ptr <= (int)h.size() - 2 &&              h[ptr].value(before) < h[ptr + 1].value(before)) {         ++ptr;       }       return make_pair(h[ptr].value(before), h[ptr].id);     }     void Remove(const int i) {       taken[i] = true;       sum += a[i];       ++size;       Build();     }   } h[1010];   const int N = 1e5 + 5;   int a[N];   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     for (int _n(n), i(0); i < _n; i++) cin >> a[i];     int block = max(1, int(sqrt(n)));     for (int i = 0; i < n; i += block) {       vector<int> b;       for (int j = i; j < min(n, i + block); ++j) {         b.push_back(a[j]);       }       h[i / block] = Hull(b);     }     long long best = 0, score = 0;     while (true) {       pair<long long, int> m = make_pair(-1ll, -1);       long long suf = 0;       int cnt = 0;       for (int i = 0; i < n; i += block) {         suf += h[i / block].sum;       }       for (int i = 0; i < n; i += block) {         suf -= h[i / block].sum;         pair<long long, int> p = h[i / block].best(cnt);         p.first += suf;         if (p.second != -1)           if (m.second == -1 || p.first > m.first)             m = make_pair(p.first, i + p.second);         cnt += h[i / block].size;       }       if (m.second == -1) break;       score += m.first;       best = max(best, score);       int i = m.second;       h[i / block].Remove(i - i / block * block);     }     cout << best << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const long double eps = 1e-7;   const int inf = 1000000010;   const long long INF = 10000000000000010LL;   const int mod = 1000000007;   const int MAXN = 100010;   long long n, m, k, x, y, z, a, b, c, t1, t2, cnt, p;   long long X[MAXN];   long long Y[MAXN];   bool X2[MAXN];   bool Y2[MAXN];   long long powmod(long long a, long long b) {     if (!b) return 1;     if (b & 1) return a * powmod(a, b - 1) % p;     return powmod(a * a % p, b >> 1);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     if ((m ^ n) & 1) return cout << 0 <<   n , 0;     ;     for (int i = 0; i < k; i++) {       cin >> a >> b >> c;       X[a]++;       Y[b]++;       if (c == -1) {         X2[a] ^= 1;         Y2[b] ^= 1;       }     }     for (int i = 1; i <= n; i++)       if (X[i] == m) {         if (!X2[i]) return cout << 0 <<   n , 0;         ;         t1++;       }     for (int i = 1; i <= m; i++)       if (Y[i] == n) {         if (!Y2[i]) return cout << 0 <<   n , 0;         ;         t2++;       }     cnt = (n - t1 - 1) * (m - t2 - 1) - (k - t1 * m - t2 * n + t1 * t2);     cin >> p;     cout << powmod(2, cnt) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int deg[10000 + 10];   int main() {     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       deg[a - 1]++, deg[b - 1]++;     }     int ans = 0;     for (int i = 0; i < n; i++) ans += deg[i] * (deg[i] - 1) / 2;     cout << ans;   }


#include <bits/stdc++.h>   void build(const std::vector<std::pair<int, int>>& values,              std::vector<int64_t>& seg, int node, int start, int end) {     if (start == end) {       seg[node] = values[start].second;     } else if (start < end) {       int mid = (start + end) / 2;       build(values, seg, 2 * node, start, mid);       build(values, seg, 2 * node + 1, mid + 1, end);       seg[node] = seg[2 * node] + seg[2 * node + 1];     }   }   int64_t query(const std::vector<int64_t>& seg, int node, int start, int end,                 int l, int r) {     if (r < start || end < l) {       return 0;     }     if (l <= start && end <= r) {       return seg[node];     }     int mid = (start + end) / 2;     int64_t p1 = query(seg, 2 * node, start, mid, l, r);     int64_t p2 = query(seg, 2 * node + 1, mid + 1, end, l, r);     return (p1 + p2);   }   int getUpperBound(const std::vector<std::pair<int, int>>& values, int v,                     int start, int end) {     int l = start;     int r = end;     while (l < r) {       int m = (l + r + 1) / 2;       if (v >= values[m].first) {         l = m;       } else {         r = m - 1;       }     }     if (values[r].first <= v) return r;     return -1;   }   int main() {     std::ios::sync_with_stdio(false);     int s, b;     std::cin >> s >> b;     std::vector<int> a(s, 0);     for (int i = 0; i < s; ++i) std::cin >> a[i];     std::vector<std::pair<int, int>> dg(b, {0, 0});     for (int i = 0; i < b; ++i) std::cin >> dg[i].first >> dg[i].second;     std::sort(dg.begin(), dg.end());     std::vector<int64_t> seg(4 * b, 0);     build(dg, seg, 1, 0, b - 1);     for (int i = 0; i < s; ++i) {       auto offset = getUpperBound(dg, a[i], 0, b - 1);       if (offset != -1) {         std::cout << query(seg, 1, 0, b - 1, 0, offset) <<    ;       } else {         std::cout << 0 <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   const long long int mod = 1000000007;   const long long int AM = 2e5 + 5;   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       string s[n + 1];       for (__typeof(0) i = 0; i < n; ++i) cin >> s[i];       long long int cnt[200] = {0};       for (__typeof(0) i = 0; i < n; ++i) {         for (__typeof(0) j = 0; j < s[i].size(); ++j) {           cnt[s[i][j] -  a ]++;         }       }       long long int flag = 1;       for (__typeof(0) i = 0; i < 26; ++i) {         if (cnt[i] % n != 0) flag = 0;       }       if (flag)         cout <<  YES n ;       else         cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1);   long long n, a[103][2601] = {}, ans = 0, mod = 1000000007, tmp = 0;   string second;   char c;   vector<pair<int, int> > vp;   bool first, f1;   bool cmpvp(pair<int, int> p1, pair<int, int> p2) {     if (p1.first < p2.first) return 1;     if (p1.first == p2.first)       if (p1.second < p2.second) return 1;     return 0;   }   int main() {     for (int i = 0; i < 26; ++i) a[1][i] = 1;     for (int i = 2; i <= 100; ++i) {       for (int j = 0; j <= 2600; ++j) {         for (int k = 0; k < 26; ++k)           a[i][j + k] = (a[i][j + k] + a[i - 1][j]) % mod;       }     }     cin >> n;     for (int i = 0; i < n; ++i) {       tmp = 0;       cin >> second;       for (int j = 0; second[j]; ++j) tmp += second[j] -  a ;       cout << a[second.size()][tmp] - 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;            int main()   {       int t;       cin>>t;       while(t--)       {           long long int n;           cin>>n;           long long int sum=0;           for(int i=0;i<n;i++)           {               long long int a;               cin>>a;               sum+=a;           }           sum%=n;           long long int k=n-sum;           cout<<sum*k<<endl;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[200005];   map<int, int> mp;   int temp, largest_num;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       mp[a[i]] = max(mp[a[i]], mp[a[i] - 1] + 1);       if (temp < mp[a[i]]) {         largest_num = a[i];         temp = mp[a[i]];       }     }     cout << temp << endl;     int start = largest_num - temp + 1;     for (int i = 0; i < n; i++) {       if (a[i] == start) {         cout << i + 1 <<    ;         start++;       }     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string second;     cin >> second;     map<string, string> mp1;     for (int i = 0; i < 10; i++) {       string s1;       cin >> s1;       mp1[s1] = to_string(i);     }     string p =   ;     string ans =   ;     for (int i = 0; i < second.length(); i++) {       if (i % 10 == 0) {         p =   ;       }       p += second[i];       if (i % 10 == 9)         if (p.length() != 0) ans += mp1[p];     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     cin >> a >> b;     int x = 0, y = 0, z = 0;     for (int i = 0; i < a.length(); i++) {       if (a[i] != b[i]) {         if (a[i] ==  4 )           x++;         else           y++;       }     }     cout << min(x, y) + abs(x - y);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 1;   int a[MAXN], pre[MAXN], num[MAXN];   int main() {     int n, m;     cin >> n >> m;     int i;     int Biggest = -1, Smallest = 0x7ffffff;     for (i = 1; i <= n; i++) {       cin >> a[i];       Biggest = max(Biggest, a[i]);       Smallest = min(Smallest, a[i]);       num[a[i] - 1]++;     }     if (Biggest == Smallest) {       cout << 0 << endl;       return 0;     }     for (i = Biggest - 1; i >= Smallest; i--) {       pre[i] = pre[i + 1] + num[i];     }     int ans = 1;     int now = 0;     for (i = Biggest; i >= Smallest; i--) {       now += pre[i];       if (now > m) {         now = pre[i];         ans++;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   struct Node {     int value;     struct Node *next;   } *head = NULL, *tail;   struct Query {     int index, ans1, ans2;     long long round;   } queries[maxn];   bool cmp_by_round(const Query &lhs, const Query &rhs) {     return lhs.round < rhs.round;   }   bool cmp_by_index(const Query &lhs, const Query &rhs) {     return lhs.index < rhs.index;   }   int a[maxn], b[maxn];   int main() {     int n, q, maxv = 0;     scanf( %d%d , &n, &q);     struct Node *last = NULL;     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       struct Node *node = (Node *)malloc(sizeof(Node));       node->value = a[i];       node->next = NULL;       if (head == NULL) head = node;       if (last) last->next = node;       last = tail = node;       if (a[i] > a[maxv]) maxv = i;     }     for (int i = 0; i < q; i++) {       scanf( %lld , &queries[i].round);       queries[i].index = i;     }     sort(queries, queries + q, cmp_by_round);     int index_query = 0;     for (int i = 0; i < maxv; i++) {       struct Node *node1 = (Node *)malloc(sizeof(Node));       struct Node *node2 = (Node *)malloc(sizeof(Node));       int v1 = head->value, v2 = head->next->value;       while (1LL * i == queries[index_query].round - 1) {         queries[index_query].ans1 = head->value;         queries[index_query].ans2 = head->next->value;         index_query++;       }       if (v1 < v2) swap(v1, v2);       node1->value = v1;       if (head->next->next)         node1->next = head->next->next;       else         node1->next = node2;       node2->value = v2;       node2->next = NULL;       tail->next = node2;       tail = node2;       free(head->next);       free(head);       head = node1;     }     struct Node *node = head;     for (int i = 0; i < n; i++) {       b[i] = node->value;       node = node->next;     }     while (index_query < q) {       long long temp_round = queries[index_query].round - maxv;       queries[index_query].ans1 = b[0];       queries[index_query].ans2 = b[int((temp_round - 1) % (n - 1) + 1)];       index_query++;     }     sort(queries, queries + q, cmp_by_index);     for (int i = 0; i < q; i++)       printf( %d %d n , queries[i].ans1, queries[i].ans2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     map<char, char> mp = {{ A ,  A }, { T ,  T }, { b ,  d }, { d ,  b },                           { H ,  H }, { I ,  I }, { M ,  M }, { O ,  O },                           { o ,  o }, { p ,  q }, { q ,  p }, { V ,  V },                           { v ,  v }, { W ,  W }, { w ,  w }, { X ,  X },                           { x ,  x }, { Y ,  Y }, { U ,  U }};     string s;     cin >> s;     int n = s.size();     for (int i = 0; i <= n / 2 - (n % 2 == 0); ++i) {       if (!mp.count(s[i]) or mp[s[i]] != s[n - i - 1]) {         cout <<  NIE  <<   n ;         return 0;       }     }     cout <<  TAK  <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 0, 1, -1, -1, 1, -1, 1};   int dy[] = {-1, 1, 0, 0, 1, 1, -1, -1};   int dz[] = {0, 0, 1, -1, -1, 1, -1, 1};   int kx[] = {2, 2, -2, -2, 1, -1, 1, -1};   int ky[] = {1, -1, 1, -1, 2, 2, -2, -2};   double _distance(double x1, double y1, double x2, double y2) {     double x1x2 = x1 - x2;     double y1y2 = y1 - y2;     return sqrt((x1x2 * x1x2) + (y1y2 * y1y2));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     long long c[n];     long long sum = 0;     for (int i = 0; i < n; i++) cin >> c[i];     sum += c[n - 1];     for (int i = n - 2; i >= 0; i--) {       if (c[i] < c[i + 1])         sum += c[i];       else {         c[i] = max(0LL, c[i + 1] - 1);         sum += c[i];       }     }     cout << sum << 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 q;     cin >> q;     while (q--) {       int n;       cin >> n;       int a = 100000, b = 100000, c = -100000, d = -100000;       vector<bool> ok(4, false);       for (int i = 0; i < n; i++) {         int x, y;         cin >> x >> y;         int f[4];         for (int j = 0; j < 4; j++) cin >> f[j];         if (f[0] == 0) d = max(d, x), ok[0] = true;         if (f[1] == 0) a = min(a, y), ok[1] = true;         if (f[2] == 0) b = min(b, x), ok[2] = true;         if (f[3] == 0) c = max(c, y), ok[3] = true;       }       if (a < c || d > b)         cout << 0;       else         cout << 1 <<     << (d + b) / 2 <<     << (a + c) / 2;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, r, R, k, l, A[100005];   string cad, aux;   char x, y;   map<int, int> M;   struct Res {     int X, Y, Z;     Res() {}     Res(int a, int b, int c) {       int F[5];       F[0] = a;       F[1] = b;       F[2] = c;       sort(F, F + 3);       X = F[2];       Y = F[1];       Z = F[0];     }   };   vector<Res> Sol;   struct node {     int elem, prio;     node() {}     node(int e, int p) {       elem = e;       prio = p;     }     bool operator<(const node &b) const {       if (prio != b.prio) return prio < b.prio;       return elem < b.elem;     }   };   priority_queue<node> q;   void calc() {     node n1, n2, n3;     int r;     Sol.clear();     while (1) {       if (q.empty()) return;       n1 = q.top();       q.pop();       if (q.empty()) return;       n2 = q.top();       q.pop();       if (q.empty()) return;       n3 = q.top();       q.pop();       r = 1;       for (int i = 0; i < r; i++) {         Sol.push_back(Res(n1.elem, n2.elem, n3.elem));       }       if (r != n1.prio) q.push(node(n1.elem, n1.prio - r));       if (r != n2.prio) q.push(node(n2.elem, n2.prio - r));       if (r != n3.prio) q.push(node(n3.elem, n3.prio - r));     }   }   int main() {     scanf( %d , &n);     M.clear();     for (int i = 0; i < n; i++) {       scanf( %d , &A[i]);     }     sort(A, A + n);     int c = 1;     for (int i = 1; i < n; i++)       if (A[i] != A[i - 1]) {         q.push(node(A[i - 1], c));         c = 1;       } else         c++;     q.push(node(A[n - 1], c));     calc();     cout << Sol.size() << endl;     for (int i = 0; i < Sol.size(); i++)       cout << Sol[i].X <<     << Sol[i].Y <<     << Sol[i].Z << endl;     return 0;   }


#include <bits/stdc++.h>   const long long N = 1e6 + 10;   const long long mod = 1e9 + 7;   const long long inf = 0x3f3f3f3f;   const double eps = 1e-8;   const double pi = acos(-1);   using namespace std;   namespace geo {   long long sgn(double x) {     if (fabs(x) < eps) return 0;     if (x < 0)       return -1;     else       return 1;   }   struct point {     double x, y;     point() {}     point(double xx, double yy) {       x = xx;       y = yy;     }     point operator+(point b) { return point(x + b.x, y + b.y); }     point operator-(point b) { return point(x - b.x, y - b.y); }     double operator^(point b) { return x * b.y - y * b.x; }     double operator*(point b) { return x * b.x + y * b.y; }     point operator*(double b) { return point(x * b, y * b); }     double gettan() { return atan2(y, x); }     void read() { scanf( %lf%lf , &x, &y); }   };   struct line {     point s, e, l;     line() {}     line(point ss, point ee) {       s = ss;       e = ee;       l = e - s;     }     void read() {       s.read(), e.read();       l = e - s;     }     double gettan() { return atan2(e.y - s.y, e.x - s.x); }   };   struct circle {     point o;     double r;     circle() {}     circle(point oo, double rr) {       o = oo;       r = rr;     }   };   double dis2(point a, point b) { return (b - a) * (b - a); }   double dis(point a, point b) { return sqrt(dis2(a, b)); }   bool onseg(line l, point p) {     bool x1 = sgn((l.s - p) ^ (l.e - p)) == 0;     bool x2 = sgn((l.s - p) * (l.e - p)) <= 0;     return x1 && x2;   }   point spin(point p, double a) {     return point(p.x * cos(a) - p.y * sin(a), p.y * cos(a) + p.x * sin(a));   }   double len(point a) { return sqrt(a * a); }   point projection(line l, point p) {     return l.s + l.l * ((l.l * (p - l.s)) / ((l.l) * (l.l)));   }   bool judge(line l1, line l2) {     point a = l1.s, b = l1.e, c = l2.s, d = l2.e;     bool x1 = sgn((c - a) ^ l1.l) * sgn((d - a) ^ l1.l) <= 0;     bool x2 = sgn((a - c) ^ l2.l) * sgn((b - c) ^ l2.l) <= 0;     return x1 && x2 && max(l1.s.x, l1.e.x) >= min(l2.s.x, l2.e.x) &&            max(l2.s.x, l2.e.x) >= min(l1.s.x, l1.e.x) &&            max(l1.s.y, l1.e.y) >= min(l2.s.y, l2.e.y) &&            max(l2.s.y, l2.e.y) >= min(l1.s.y, l1.e.y);   }   point getcross(line l1, line l2) {     double s1 = ((l2.s - l1.s) ^ (l2.e - l1.s));     double s2 = ((l2.e - l1.e) ^ (l2.s - l1.e));     if (s1 + s2 == 0) return point{inf, inf};     return l1.s + l1.l * (s1 / (s1 + s2));   }   double dis_pl(point p, line l) {     point v = p - l.s;     double ans = (v ^ l.l) / sqrt(l.l * l.l);     return fabs(ans);   }   double askarea(point d[], long long n) {     d[n + 1] = d[1];     double area = 0;     for (long long i = 1; i <= n; i++) area += (d[i] ^ d[i + 1]);     area /= 2;     return fabs(area);   }   long long cmp(line a, line b) {     double t1 = a.gettan(), t2 = b.gettan();     if (sgn(t1 - t2) == 0) return (a.l ^ (b.e - a.s)) > 0;     return t1 < t2;   }   long long onright(line a, line b, line c) {     point p = getcross(b, c);     return (a.l ^ (p - a.s)) < 0;   }   void hpi(line li[], long long n) {     line que[N];     sort(li + 1, li + n + 1, cmp);     long long l = 1, r = 1, cnt = 0, i;     for (i = 1; i < n; i++)       if (sgn(li[i].gettan() - li[i + 1].gettan())) li[++cnt] = li[i];     li[++cnt] = li[n];     for (i = 1; i <= cnt; i++) {       while (r - l > 1 && onright(li[i], que[r - 1], que[r - 2])) r--;       while (r - l > 1 && onright(li[i], que[l], que[l + 1])) l++;       que[r++] = li[i];     }     while (r - l > 1 && onright(que[l], que[r - 1], que[r - 2])) r--;     while (r - l > 1 && onright(que[r - 1], que[l], que[l + 1])) l++;   }   }  // namespace geo   long long a[N], b[40];   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long n, i, j, ans = 0;       cin >> n;       memset(b, 0, sizeof(b));       for (i = 1; i <= n; i++) {         cin >> a[i];         for (j = 1; j < 33; j++)           if ((a[i] >> j) == 0) {             ans += b[j];             b[j]++;             break;           }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = int(2e6) + 12, mod = int(1e9) + 7;   int n, z[N];   char second[N];   int Z(string x) {     int m = int(x.size());     string t = x;     reverse((t).begin(), (t).end());     string second = x +  #  + t;     int res = 0;     for (int i = 1, l = 0, r = 0; i < second.size(); i++) {       z[i] = 0;       if (i <= r) z[i] = min(r - i + 1, z[i - l]);       while (i + z[i] < second.size() && second[z[i]] == second[i + z[i]]) z[i]++;       if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;       if (i > m && i + z[i] == int(second.size())) {         res = max(res, z[i]);       }     }     return res;   }   void solve() {     scanf(  n%s , second + 1);     n = strlen(second + 1);     int l = 1, r = n;     while (l <= r) {       if (second[l] == second[r]) {         l++;         r--;       } else         break;     }     string a =   ;     for (int i = l; i <= r; i++) {       a += second[i];     }     string b = a;     string ans =   ;     reverse((b).begin(), (b).end());     int z1 = Z(a);     int z2 = Z(b);     for (int i = 1; i < l; i++) ans += second[i];     if (z1 > z2) {       for (int i = 0; i < z1; i++) ans += a[i];     } else {       for (int i = 0; i < z2; i++) ans += b[i];     }     for (int i = max(r + 1, l); i <= n; i++) ans += second[i];     for (int i = 0; i < ans.size(); i++) {       putchar(ans[i]);     }     puts(  );   }   int main() {     int T = 1;     scanf( %d , &T);     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   constexpr int N = 5e5 + 5;   vector<int> elm[N];   struct SegTree {     struct Dat {       int l, r;       Dat *lc, *rc;       long long lmx, rmx, mx, sum;       int len() { return r - l + 1; }       void fset(long long kval) { lmx = rmx = mx = sum = kval; }       void pushup() {         lmx = max(lc->lmx, lc->sum + rc->lmx);         rmx = max(rc->rmx, rc->sum + lc->rmx);         mx = max({lc->mx, rc->mx, lc->rmx + rc->lmx});         sum = lc->sum + rc->sum;       }       void pushdown() {}     } dat[N << 2];     int siz = 0;     void init(int n) {       function<Dat *(int, int)> build = [&](int l, int r) {         Dat &nw = dat[siz++];         nw = {l, r};         if (l == r) {         } else {           int mid = (l + r) >> 1;           nw.lc = build(l, mid), nw.rc = build(mid + 1, r);           nw.pushup();         }         return &nw;       };       build(1, n);     }     template <typename Fn>     void travsal(int l, int r, Fn f) {       function<void(Dat &)> trav = [&](Dat &p) {         if (r < p.l || l > p.r) return;         if (p.l >= l && p.r <= r) {           return f(p);         } else {           p.pushdown();           int mid = (l + r) >> 1;           trav(*p.lc);           trav(*p.rc);           p.pushup();         }       };       trav(dat[0]);     }     void update(int x, long long val) {       travsal(x, x, [&](Dat &e) { e.fset(val); });     }     int query() { return dat[0].mx; }   } seg;   int a[N];   int main() {     ios::sync_with_stdio(false);     int n, c;     cin >> n >> c;     seg.init(n);     int base = 0;     for (int i = 1; i < n + 1; i++) {       cin >> a[i];       if (a[i] == c)         seg.update(i, -1), base++;       else         elm[a[i]].push_back(i);     }     int ans = base;     for (int i = 1; i < N; i++) {       if (elm[i].empty()) continue;       for (int pos : elm[i]) seg.update(pos, 1);       ans = max(ans, base + seg.query());       for (int pos : elm[i]) seg.update(pos, 0);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   using namespace std;   long long n, m;   long long a[((long long)(2e6 + 600))];   int main() {     cin >> n >> m;     long long l = 0;     long long pas = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (i && a[i] == a[i - 1]) l = i;       pas = max(pas, i - l + 1);     }     cout << pas;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:200000000 )   using namespace std;   const long long oo = 1LL << 60;   const long long kNumMoves = 4;   const long long kMoves[kNumMoves][2] = {{1, 0}, {-1, 0}, {0, -1}, {0, 1}};   int n, v, e;   vector<int> a, b;   vector<vector<int> > conn, edges;   vector<int> ansX, ansY, ansD;   vector<int> topSort;   vector<int> seen;   void DFS_Topological(int node) {     if (seen[node]) return;     seen[node] = 1;     for (int i = 0; i < int(n); ++i) {       if (edges[node][i] && !seen[i]) {         DFS_Topological(i);         conn[node].push_back(i);         conn[i].push_back(node);       }     }     topSort.push_back(node);   }   int AddTransfusionStep(int src, int dest, int delta) {     int mxMoveOut = min(a[src], delta);     int mxMoveIn = min(v - a[dest], mxMoveOut);     a[src] -= mxMoveIn;     a[dest] += mxMoveIn;     if (mxMoveIn)       ansX.push_back(src + 1), ansY.push_back(dest + 1), ansD.push_back(mxMoveIn);     return mxMoveIn;   }   int Transfuse_Out(int node, int dest, int delta) {     if (!delta || seen[node] || seen[dest]) return 0;     int step1 = AddTransfusionStep(node, dest, delta);     if (step1 == delta) return delta;     for (int i = 0; i < int(conn[dest].size()); ++i) {       int newDest = conn[dest][i];       if (newDest == node) continue;       if (seen[newDest]) continue;       AddTransfusionStep(dest, newDest, v);       Transfuse_Out(dest, newDest, v);       AddTransfusionStep(dest, newDest, v);     }     int step2 = AddTransfusionStep(node, dest, delta - step1);     return step1 + step2;   }   int Transfuse_In(int node, int dest, int delta) {     if (!delta || seen[node] || seen[dest]) return 0;     int step1 = AddTransfusionStep(dest, node, delta);     if (step1 == delta) return delta;     for (int i = 0; i < int(conn[dest].size()); ++i) {       int newDest = conn[dest][i];       if (newDest == node) continue;       if (seen[newDest]) continue;       AddTransfusionStep(newDest, dest, v);       Transfuse_In(dest, newDest, v);       AddTransfusionStep(newDest, dest, v);     }     int step2 = AddTransfusionStep(dest, node, delta - step1);     return step1 + step2;   }   bool Transfuse(int node) {     int delta = a[node] - b[node];     if (delta > 0) {       for (int i = 0; i < int(conn[node].size()); ++i) {         int dest = conn[node][i];         if (seen[dest]) continue;         delta -= Transfuse_Out(node, dest, delta);       }       return (delta == 0 && a[node] == b[node]);     } else if (delta < 0) {       delta = -delta;       for (int i = 0; i < int(conn[node].size()); ++i) {         int dest = conn[node][i];         if (seen[dest]) continue;         delta -= Transfuse_In(node, dest, delta);       }       return (delta == 0 && a[node] == b[node]);     }     return true;   }   bool FindTransfusions() {     seen.clear();     seen.resize(n, 0);     for (int i = 0; i < int(n); ++i) DFS_Topological(i);     seen.clear();     seen.resize(n, 0);     for (int i = 0; i < int(n); ++i) {       if (!Transfuse(topSort[i])) return false;       seen[topSort[i]] = 1;     }     return true;   }   int main() {     cin >> n >> v >> e;     a.resize(n), b.resize(n);     for (int i = 0; i < int(n); ++i) cin >> a[i];     for (int i = 0; i < int(n); ++i) cin >> b[i];     conn.resize(n);     edges.resize(n, vector<int>(n, 0));     for (int i = 0; i < int(e); ++i) {       int x, y;       cin >> x >> y;       --x, --y;       edges[x][y] = edges[y][x] = 1;     }     if (FindTransfusions()) {       cout << ansX.size() << endl;       for (int i = 0; i < int(ansX.size()); ++i)         cout << ansX[i] <<     << ansY[i] <<     << ansD[i] << endl;     } else {       cout <<  NO ;     }     int i;     cin >> i;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   inline int read() {     int x = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch -  0 , ch = getchar();     return x;   }   int A[maxn], B[maxn], N, MOD, fir, d, len;   int ksm(int x, int y) {     int res = 1;     for (; y; y >>= 1, x = (long long)x * x % MOD)       if (y & 1) res = (long long)res * x % MOD;     return res;   }   void Solve(int *P, int Len) {     int kd = P[1] - P[0], cnt = 0;     map<int, bool> vis;     for (int i = 0; i < N; ++i) vis[P[i]] = true;     for (int i = 0; i < N; ++i)       if (!vis.count((P[i] + kd) % MOD)) ++cnt;     d = (long long)kd * ksm(cnt, MOD - 2) % MOD;     fir = -1;     len = (MOD - d) % MOD;     for (int i = 0; i < N; ++i)       if (!vis.count((P[i] + d) % MOD))         if (~fir) {           fir = -1;           break;         } else           fir = P[i];   }   int main() {     MOD = read();     N = read();     for (int i = 0; i < N; ++i) A[i] = read();     if (N == 1 || N == MOD)       printf( %d 1 n , A[0]);     else {       sort(A, A + N);       if (2 * N < MOD)         Solve(A, N);       else {         map<int, bool> vis;         for (int i = 0; i < N; ++i) vis[A[i]] = true;         N = 0;         for (int i = 0; i < MOD; ++i)           if (!vis.count(i)) B[N++] = i;         Solve(B, N);         if (~fir) (fir += (long long)len * N % MOD) %= MOD;       }       if (~fir)         printf( %d %d n , fir, len);       else         puts( -1 );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int t, k;     long long int ans;     cin >> t;     while (t--) {       cin >> k;       ans = (k / 18) * 30;       k = k % 18;       if (k == 0) {         ans--;       }       while (k) {         ans++;         if (ans % 3 != 0 && ans % 10 != 3) {           k--;         }       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int64_t binexp(int64_t base, int64_t exponent) {     int64_t res = 1;     base = (base + 1000000007) % 1000000007;     while (exponent) {       if (exponent & 1) {         res = (res * base) % 1000000007;       }       exponent = exponent >> 1;       base = (base * base) % 1000000007;     }     return res;   }   void solve() {     double n;     cin >> n;     n = 2.0 * n;     double param, result;     param = (3.14159265 / n);     result = sin(param);     double ans1 = (1.0 / (result));     double res = cos(param / 2.0);     double ans2 = (1.0 * res);     double ans = (ans1 * ans2);     printf( %.10f n , ans);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int T = 1;     cin >> T;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   using namespace std;   const int N = 200100;   int a[N], t[N];   multiset<int> st1, st2;   multiset<int>::iterator it;   int sum = 0, nowt = 0, res = 0;   int n, m, k;   void ins(int x) {     sum += a[x];     if (st1.size() < m) {       st1.insert(t[x]);       nowt += (t[x] + 1) / 2;     } else {       it = st1.begin();       if ((*it) < t[x]) {         nowt += (t[x] + 1) / 2;         nowt -= ((*it) + 1) / 2;         nowt += (*it);         st1.insert(t[x]);         st2.insert((*it));         st1.erase(it);       } else {         nowt += t[x];         st2.insert(t[x]);       }     }   }   void del(int x) {     sum -= a[x];     if (st2.size() && st2.find(t[x]) != st2.end()) {       nowt -= t[x];       st2.erase(st2.find(t[x]));     } else {       nowt -= (t[x] + 1) / 2;       assert(st1.find(t[x]) != st1.end());       st1.erase(st1.find(t[x]));       if (st2.size()) {         it = st2.end();         it--;         nowt -= (*it);         nowt += ((*it) + 1) / 2;         st1.insert((*it));         st2.erase(it);       }     }   }   int main() {     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= n; i++) {       scanf( %d , &t[i]);     }     for (int i = 1, j = 1; i <= n; i++) {       while (j <= n) {         ins(j);         if (nowt > k) {           del(j);           break;         }         j++;       }       if (nowt <= k) res = max(res, sum);       if (i != j)         del(i);       else         j++;     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q, n, x;     char a, b;     vector<char> v;     cin >> q;     for (int i = 0; i < q; i++) {       x = 0;       cin >> n;       for (int j = 0; j < n; j++) {         cin >> a;         v.push_back(a);       }       if (v[0] < v[n - 1]) {         cout <<  YES  << endl;         cout <<  2  << endl;         for (int j = 0; j < n; j++) {           if (j == 0)             cout << v[j] <<    ;           else             cout << v[j];         }         cout << endl;       } else {         for (int j = 1; j < n - 1; j++) {           if (v[j] !=  0 ) {             x = 1;             break;           }         }         if (x == 0)           cout <<  NO  << endl;         else {           cout <<  YES  << endl;           cout <<  2  << endl;           for (int j = 0; j < n; j++) {             if (j == 0)               cout << v[j] <<    ;             else               cout << v[j];           }           cout << endl;         }       }       v.clear();     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)1e5 + 100;   const int mod = (int)1e9 + 7;   const int maxlog = (int)20;   const int P = mod;   int n, m, q, id[maxn], sq, res, cnt[maxn][500];   long long toadd[505], a[maxn];   long long ans[505];   vector<int> g[maxn];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cin >> n >> m >> q;     sq = 320;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= m; i++) {       int k;       cin >> k;       if (k >= sq) {         id[i] = ++res;       }       for (; k--;) {         int x;         cin >> x;         g[i].push_back(x);       }     }     for (int i = 1; i <= m; i++) {       if (id[i]) {         static bool used[maxn + 5];         memset(used, 0, sizeof used);         for (int x : g[i]) ans[id[i]] += a[x], used[x]++;         for (int j = 1; j <= m; j++) {           for (int x : g[j]) {             cnt[j][id[i]] += used[x];           }         }       }     }     for (; q--;) {       char s;       cin >> s;       if (s ==  ? ) {         int k;         cin >> k;         if (id[k]) {           cout << ans[id[k]] << endl;         } else {           long long Res = 0;           for (int x : g[k]) Res += a[x];           for (int i = 1; i <= res; i++) Res += toadd[i] * cnt[k][i];           cout << Res << endl;         }       } else {         int k, val;         cin >> k >> val;         if (!id[k])           for (int x : g[k]) a[x] += val;         else           toadd[id[k]] += val;         for (int i = 1; i <= res; i++) {           ans[i] += val * 1ll * cnt[k][i];         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int rlen = 1 << 18 | 1;   inline char gc() {     static char buf[rlen], *ib, *ob;     (ib == ob) && (ob = (ib = buf) + fread(buf, 1, rlen, stdin));     return ib == ob ? -1 : *ib++;   }   inline int read() {     int ans = 0;     char ch = gc();     while (!isdigit(ch)) ch = gc();     while (isdigit(ch)) ans = ((ans << 2) + ans << 1) + (ch ^ 48), ch = gc();     return ans;   }   const int N = 1e5 + 5;   vector<pair<int, int> > e[N];   int n, m, dis[N];   bool vis[N];   namespace xxj {   int a[31];   inline void insert(int x) {     if (!x) return;     for (register int i = 30; ~i; --i)       if ((x >> i) & 1)         if (!a[i]) {           a[i] = x;           break;         } else           x ^= a[i];   }   inline int query(int x) {     for (register int i = 30; ~i; --i) x = min(x, x ^ a[i]);     return x;   }   }  // namespace xxj   void dfs(int p, int fa) {     vis[p] = 1;     for (register int i = 0, v; i < e[p].size(); ++i) {       if ((v = e[p][i].first) == fa) continue;       if (!vis[v])         dis[v] = dis[p] ^ e[p][i].second, dfs(v, p);       else         xxj::insert(dis[v] ^ dis[p] ^ e[p][i].second);     }   }   int main() {     n = read(), m = read();     for (register int i = 1, u, v, w; i <= m; ++i)       u = read(), v = read(), w = read(), e[u].push_back(pair<int, int>(v, w)),       e[v].push_back(pair<int, int>(u, w));     dfs(1, 0), cout << xxj::query(dis[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct segtree {     using T = long long;     int n;     vector<T> node;     T e() { return (long long)1e18; }     T op(T x, T y) { return min(x, y); }     segtree() : segtree(0) {}     segtree(int _n) {       if (_n <= 1) {         n = _n;       } else {         n = 1 << (32 - __builtin_clz(_n - 1));       }       node.resize(2 * n, e());     }     segtree(vector<T> v) {       if ((int)v.size() <= 1) {         n = (int)v.size();       } else {         n = 1 << (32 - __builtin_clz((int)v.size() - 1));       }       node.resize(2 * n, e());       for (int i = 0; i < (int)v.size(); i++) {         node[i + n] = v[i];       }       for (int i = n - 1; i > 0; i--) {         node[i] = op(node[2 * i], node[2 * i + 1]);       }     }     void update(int k, T v) {       k += n;       node[k] = v;       while (k > 1) {         k /= 2;         node[k] = op(node[2 * k], node[2 * k + 1]);       }     }     T get(int x, int y, int k, int l, int r) {       if (r <= x || y <= l) {         return e();       }       if (x <= l && r <= y) {         return node[k];       }       T vl = get(x, y, 2 * k, l, (l + r) / 2);       T vr = get(x, y, 2 * k + 1, (l + r) / 2, r);       return op(vl, vr);     }     T get(int x, int y) { return get(x, y, 1, 0, n); }     T get(int x) { return node[x + n]; }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) {       int n;       cin >> n;       int k;       cin >> k;       vector<int> a, b;       for (int i = 0; i < n; i++) {         int x;         cin >> x;         if (x > 0) {           a.emplace_back(x);         } else if (x < 0) {           b.emplace_back(-x);         }       }       sort(a.begin(), a.end());       sort(b.begin(), b.end());       long long ans = 0;       for (int loop = 0; loop < 2; loop++) {         segtree seg((int)a.size() + 1);         seg.update(0, 0);         for (int i = 0; i < (int)a.size(); i++) {           long long t = a[i] * 2 + seg.get(max(0, i - k + 1), i + 1);           seg.update(i + 1, t);         }         ans += seg.get((int)a.size());         swap(a, b);       }       if (a.empty()) {         a.emplace_back(0);       }       if (b.empty()) {         b.emplace_back(0);       }       ans -= max(a.back(), b.back());       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int d[101][51][201][2] = {0};   bool used[101][51][201][2] = {false};   int n;   int sz;   string commands;   int rec(int cur, int left, int pos, int dir) {     if (cur == sz) {       d[cur][left][100 + pos][(dir + 1) % 2] = abs(pos);       used[cur][left][100 + pos][(dir + 1) % 2] = true;       return pos;     }     if (used[cur][left][100 + pos][(dir + 1) % 2]) {       return d[cur][left][100 + pos][(dir + 1) % 2];     }     used[cur][left][100 + pos][(dir + 1) % 2] = true;     int res = 0;     for (int i = 0; i <= left; ++i) {       if (cur == sz - 1 && left != 0) {         i = left;       }       int next_pos = pos;       int next_dir = dir;       if (i % 2 == 0) {         if (commands[cur] ==  T ) {           next_dir = -dir;         } else {           next_pos = pos + dir;         }       } else {         if (commands[cur] ==  T ) {           next_pos = pos + dir;         } else {           next_dir = -dir;         }       }       res = max(res, abs(rec(cur + 1, left - i, next_pos, next_dir)));     }     d[cur][left][100 + pos][(dir + 1) % 2] = res;     return res;   }   int main() {     int res;     cin >> commands;     cin >> n;     sz = commands.size();     res = rec(0, n, 0, 1);     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long LLINF = 1e18;   const int INF = 1e9;   const int MOD = 20101009;   const int HMOD = 999959;   const int VMOD = 5000000;   const int MAXN = 2e3 + 10;   const int MAXM = 5e5 + 10;   const int INV = 10050505;   const long long LLINV = 1e18;   const double eps = 1e-3;   int dirx[4] = {-1, 1, 0, 0}, diry[4] = {0, 0, -1, 1};   int n, m;   int r, c;   int limx, limy;   char G[MAXN][MAXN];   int dl[MAXN][MAXN];   int dr[MAXN][MAXN];   void bfs() {     memset(dl, 0x3f3f3f3f, sizeof(dl));     memset(dr, 0x3f3f3f3f, sizeof(dr));     deque<pair<int, int> > que;     que.push_front(make_pair(r, c));     dl[r][c] = dr[r][c] = 0;     while (!que.empty()) {       int x = que.front().first;       int y = que.front().second;       que.pop_front();       for (int i = 0; i < 4; ++i) {         int tx = x + dirx[i];         int ty = y + diry[i];         if (tx < 1 || tx > n || ty < 1 || ty > m) continue;         if (G[tx][ty] ==  * ) continue;         int cl = dl[x][y] + (diry[i] == -1);         int cr = dr[x][y] + (diry[i] == 1);         if (cl < dl[tx][ty] || cr < dr[tx][ty]) {           dl[tx][ty] = cl;           dr[tx][ty] = cr;           if (dirx[i] == 0)             que.push_back(make_pair(tx, ty));           else             que.push_front(make_pair(tx, ty));         }       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     scanf( %d%d , &n, &m);     scanf( %d%d , &r, &c);     scanf( %d%d , &limx, &limy);     for (int i = 1; i <= n; ++i) scanf( %s , G[i] + 1);     bfs();     int ans = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         if (G[i][j] ==  * ) continue;         if (dl[i][j] <= limx && dr[i][j] <= limy) ++ans;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 105000;   const int mod = 1e9 + 7;   vector<int> xloc[maxn], po[maxn];   vector<int> side[maxn], blk;   long long ans = 1;   long long c[maxn][2];   int vis[maxn], vis_cnt;   int d[maxn];   long long g[maxn][2][2];   long long f[maxn][2];   void dfs(int u, int id) {     if (vis[u]) return;     vis[u] = id;     blk.push_back(u);     for (int i = (0), iend = ((int)side[u].size() - 1); i <= iend; i++) {       int v = side[u][i];       if (vis[v]) continue;       dfs(v, id);     }   }   void dp(int id, int l1, int r1, int l2, int r2) {     for (int i = (0), iend = (blk.size() + 10); i <= iend; i++)       for (int j = (0), jend = (1); j <= jend; j++)         for (int k = (0), kend = (1); k <= kend; k++) g[i][j][k] = 0;     for (int i = (l1), iend = (r1); i <= iend; i++) g[0][0][i] = 1;     if ((!po[blk[0]][1]) || (abs(po[blk[0]][0]) == abs(po[blk[1]][0]) ||                              abs(po[blk[0]][0]) == abs(po[blk[1]][1])))       swap(po[blk[0]][0], po[blk[0]][1]);     for (int i = (1), iend = ((int)blk.size() - 1); i <= iend; i++)       if (abs(po[blk[i]][1]) == abs(po[blk[i - 1]][1]))         swap(po[blk[i]][0], po[blk[i]][1]);     for (int i = (1), iend = (blk.size()); i <= iend; i++) {       int x = blk[i - 1];       for (int j = (0), jend = (1); j <= jend; j++) {         for (int p = (0), pend = (1); p <= pend; p++) {           for (int q = (0), qend = (1); q <= qend; q++) {             g[i][((((po[x][0]) < 0) ^ p) | (((po[x][1]) < 0) ^ q)) ^ j][q] +=                 g[i - 1][j][p];             g[i][((((po[x][0]) < 0) ^ p) | (((po[x][1]) < 0) ^ q)) ^ j][q] %= mod;           }         }       }     }     for (int j = (0), jend = (1); j <= jend; j++) {       for (int k = (l2), kend = (r2); k <= kend; k++) {         c[id][j] += g[blk.size()][j][k];         c[id][j] %= mod;       }     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = (1), iend = (n); i <= iend; i++) {       int k, loc;       scanf( %d , &k);       while (k--) {         scanf( %d , &loc);         po[i].push_back(loc);         xloc[abs(loc)].push_back(i);       }     }     for (int i = (1), iend = (m); i <= iend; i++) {       if (xloc[i].size() == 2) {         side[xloc[i][0]].push_back(xloc[i][1]);         side[xloc[i][1]].push_back(xloc[i][0]);         d[xloc[i][0]]++;         d[xloc[i][1]]++;       } else if (!xloc[i].size())         ans *= 2, ans %= mod;     }     for (int i = (1), iend = (n); i <= iend; i++) {       if (vis[i]) continue;       blk.clear();       vis_cnt++;       dfs(i, vis_cnt);       if (blk.size() == 1) {         if (po[blk[0]].size() == 1)           c[vis_cnt][0] = 1, c[vis_cnt][1] = 1;         else if (abs(po[blk[0]][0]) != abs(po[blk[0]][1]))           c[vis_cnt][0] = 1, c[vis_cnt][1] = 3;         else if (po[blk[0]][0] == po[blk[0]][1])           c[vis_cnt][0] = 1, c[vis_cnt][1] = 1;         else           c[vis_cnt][0] = 0, c[vis_cnt][1] = 2;         continue;       }       int rt = 0;       for (int j = (0), jend = ((int)blk.size() - 1); j <= jend; j++) {         if (d[blk[j]] == 1) {           rt = blk[j];           break;         }       }       if (rt) {         for (int j = (0), jend = ((int)blk.size() - 1); j <= jend; j++)           vis[blk[j]] = 0;         blk.clear();         dfs(rt, vis_cnt);         int x = blk[0];         int l1 = 0, r1 = 1, l2 = 0, r2 = 1;         if (po[x].size() == 1) po[x].push_back(0), r1 = 0;         x = blk.back();         if (po[x].size() == 1) po[x].push_back(0), r2 = 0;         dp(vis_cnt, l1, r1, l2, r2);         continue;       }       dp(vis_cnt, 0, 0, 0, 0);       dp(vis_cnt, 1, 1, 1, 1);     }     f[0][0] = 1;     for (int i = (0), iend = (vis_cnt - 1); i <= iend; i++) {       for (int l = (0), lend = (1); l <= lend; l++) {         for (int x = (0), xend = (1); x <= xend; x++) {           f[i + 1][l ^ x] += f[i][l] * c[i + 1][x] % mod;           f[i + 1][l ^ x] %= mod;         }       }     }     printf( %lld , f[vis_cnt][1] * ans % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     getline(cin, s);     int x = s.length();     x = (x + 1) * 26 - x;     printf( %d , x);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> adj[200005];   vector<int> visited(200005, 0);   vector<long long int> ans;   void topo(long long int s) {     visited[s] = 1;     long long int sz = adj[s].size();     for (long long int i = 0; i < sz; i++) {       if (visited[adj[s][i]] == 0) topo(adj[s][i]);     }     ans.push_back(s);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int w;     cin >> w;     while (w--) {       long long int t, x, y, n, m;       cin >> n >> m;       vector<pair<long long int, long long int> > anso;       vector<pair<long long int, long long int> > edg;       for (long long int i = 1; i <= n; i++) {         visited[i] = 0;         adj[i].clear();       }       ans.clear();       for (long long int i = 0; i <= m - 1; i++) {         cin >> t >> x >> y;         if (t == 1) {           adj[x].push_back(y);           anso.push_back({x, y});         } else {           edg.push_back({x, y});         }       }       long long int fou = 0;       for (long long int i = 1; i <= n; i++) {         if (!visited[i]) topo(i);       }       reverse((ans).begin(), (ans).end());       vector<long long int> pre(n + 1, 0);       for (long long int i = 0; i < n; i++) {         pre[ans[i]] = i + 1;       }       for (long long int i = 0; i < anso.size(); i++) {         if (pre[anso[i].first] > pre[anso[i].second]) {           fou = 1;           break;         }       }       if (fou) {         cout <<  NO  <<   n ;         continue;       } else {         cout <<  YES  <<   n ;       }       long long int sz = edg.size();       for (long long int i = 0; i < sz; i++) {         if (pre[edg[i].first] < pre[edg[i].second]) {           anso.push_back({edg[i].first, edg[i].second});         } else {           anso.push_back({edg[i].second, edg[i].first});         }       }       for (auto i : anso) {         cout << i.first <<     << i.second <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> mp;   std ::map<int, int>::iterator x, l, s;   int main() {     int n, p;     cin >> n;     mp[0] = 0;     mp[1 << 30] = 0;     for (int i = 0; i < n; i++) {       cin >> p;       x = mp.lower_bound(p);       l = x--;       s = x->second > l->second ? x : l;       if (i) cout << s->first <<    ;       mp[p] = s->second + 1;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n, N;     cin >> m >> n;     N = floor((m * n) / 2);     cout << N;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     for (int a = 0; a < t; a++) {       int n;       scanf( %d , &n);       string attack, prepend;       cin >> attack;       while (!attack.empty() and attack.back() == attack.front()) {         prepend += attack.back();         attack.pop_back();       }       if (attack.empty()) {         printf( %d n , (n + 2) / 3);         continue;       }       attack = prepend + attack;       int answer = 0, streak = 1;       for (int b = 1; b < n; b++) {         if (attack[b] == attack[b - 1]) {           streak++;         } else {           streak = 1;         }         if (streak % 3 == 0) {           answer++;         }       }       printf( %d n , answer);     }   }


#include <bits/stdc++.h>   using namespace std;   inline void read(int& x) {     char c = getchar();     x = 0;     while (c <  0  || c >  9 ) c = getchar();     while (c <=  9  && c >=  0 ) x = x * 10 + c - 48, c = getchar();     return;   }   inline void write(int x) {     if (!x) {       putchar( 0 );       putchar(  n );       return;     }     int num = 0;     char c[15];     while (x) c[++num] = (x % 10) + 48, x /= 10;     while (num) putchar(c[num--]);     putchar(  n );     return;   }   inline int min(int a, int b) {     if (a < b) return a;     return b;   }   const int maxn = int(3e5) + 10;   const int K = 31;   const int INF = int(1e9) + 10;   struct tri {     int a, b, c;   } q[maxn];   int top = 0;   inline bool cmp(const tri& A, const tri& B) { return A.b < B.b; }   int n, qnum;   int b[maxn];   int ans[maxn];   struct Node {     int* a;     int ans;   } node[maxn * 4];   int* getnew(int siz) { return new int[siz]; }   void build(int k, int l, int r) {     node[k].a = getnew(r - l + 1);     if (l == r) {       node[k].a[0] = b[l];       node[k].ans = INF;       return;     }     int mid = (l + r) >> 1, siz = r - l + 1;     build((k << 1), l, mid);     build(((k << 1) ^ 1), mid + 1, r);     std::merge(node[(k << 1)].a, node[(k << 1)].a + mid - l + 1,                node[((k << 1) ^ 1)].a, node[((k << 1) ^ 1)].a + r - mid,                node[k].a);     int res = INF;     for (int i = 1; i < siz; i++) res = min(res, node[k].a[i] - node[k].a[i - 1]);     node[k].ans = res;     return;   }   int query(int, int, int, int, int);   void update(int k, int l, int r, int to, int x, int& d) {     if (l == r) {       node[k].ans = min(node[k].ans, abs(x - node[k].a[0]));       d = min(d, node[k].ans);       return;     }     int mid = (l + r) >> 1, siz = r - l + 1;     int* it = std::lower_bound(node[k].a, node[k].a + siz, x);     if ((it == node[k].a + siz || *it >= x + d) &&         (it == node[k].a || *(it - 1) <= x - d)) {       d = min(d, query(k, l, r, l, to));       return;     }     if (to > mid) {       update(((k << 1) ^ 1), mid + 1, r, to, x, d),           update((k << 1), l, mid, mid, x, d);     } else       update((k << 1), l, mid, to, x, d);     node[k].ans =         min(node[k].ans, min(node[(k << 1)].ans, node[((k << 1) ^ 1)].ans));     return;   }   int query(int k, int l, int r, int x, int y) {     if (l == x && r == y) return node[k].ans;     int mid = (l + r) >> 1;     if (y <= mid)       return query((k << 1), l, mid, x, y);     else if (x > mid)       return query(((k << 1) ^ 1), mid + 1, r, x, y);     else       return min(query((k << 1), l, mid, x, mid),                  query(((k << 1) ^ 1), mid + 1, r, mid + 1, y));   }   int main() {     read(n);     for (int i = 0; i < n; i++) read(b[i]);     read(qnum);     for (int i = 0; i < qnum; i++) {       int l, r;       read(l), read(r);       l--, r--;       const int K = 31;       if (r - l <= K) {         int cur[K + 1], siz = r - l + 1;         for (int j = l; j <= r; j++) cur[j - l] = b[j];         sort(cur, cur + siz);         int res = INF;         for (int j = 1; j < siz; j++) res = min(res, cur[j] - cur[j - 1]);         ans[i] = res;       } else         q[top++] = {l, r, i};     }     sort(q, q + top, cmp);     int curr = 0;     build(1, 0, n - 1);     for (int k = 0; k < top; k++) {       int l = q[k].a, r = q[k].b, index = q[k].c;       while (curr < r) {         ++curr;         int d = INF;         update(1, 0, n - 1, curr - 1, b[curr], d);       }       ans[index] = query(1, 0, n - 1, l, r);     }     for (int i = 0; i < qnum; i++) write(ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxN = 3e2 + 2, N = 1e5 + 7, MOD = 1e9 + 7, Mod = 1e9 + 6,                   INF = 1LL << 56;   long long n, m, k, x, y, z, dp[maxN][maxN], ans[maxN][maxN];   int main() {     cin.tie(0);     cout.tie(0);     ios::sync_with_stdio(false);     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) dp[i][j] = INF, ans[i][j] = INF;     }     for (int i = 1; i <= m; i++) cin >> x >> y >> z, dp[x][y] = min(dp[x][y], z);     for (long long i = n; i >= 1; i--) {       for (long long j = n; j >= 1; j--)         dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]),                dp[i][j - 1] = min(dp[i][j], dp[i][j - 1]);     }     for (int len = 1; len <= n - 1; len++) {       for (int i = 1; i <= n - len; i++) {         long long j = len - i;         for (int u = i; u <= j; u++)           dp[i][j] = min(dp[i][u] + dp[u + 1][j], dp[i][j]);       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= i; j++) {         if (i != 1) ans[i][j] = min(ans[i][j], ans[i - 1][j]);         for (int u = 1; u <= j; u++)           ans[i][j] = min(ans[i - u][j - u] + dp[i - u + 1][i], ans[i][j]);       }     }     if (ans[n][k] == INF) return cout <<  -1 n , 0;     return cout << ans[n][k] <<   n , 0;   }


#include <bits/stdc++.h>   using namespace std;   void RD(int &x) { scanf( %d , &x); }   void RD(long long &x) { scanf( %I64d , &x); }   void RD(double &x) { scanf( %lf , &x); }   void RD(int &x, int &y) { scanf( %d%d , &x, &y); }   void RD(long long &x, long long &y) { scanf( %I64d%I64d , &x, &y); }   void RD(double &x, double &y) { scanf( %lf%lf , &x, &y); }   void RD(char *s) { scanf( %s , s); }   void RD(char &s) { scanf( %c , &s); }   void RD(string &s) { cin >> s; }   void PR(int x) { printf( %d n , x); }   void PR(int x, int y) { printf( %d %d n , x, y); }   void PR(long long x) { printf( %I64d n , x); }   void PR(char x) { printf( %c n , x); }   void PR(char *x) { printf( %s n , x); }   void PR(string x) { cout << x << endl; }   const int inf = 1e9;   const long long mod = 1LL;   int dp[1010][1010];   char s1[1010], s2[1010];   int len1, len2;   int solve(int n, int m) {     if (n == len1) return dp[n][m] = len2 - m;     if (m == len2) return dp[n][m] = len1 - n;     int &ret = dp[n][m];     if (ret != inf) return ret;     if (s1[n] == s2[m])       ret = solve(n + 1, m + 1);     else       ret = min(min(1 + solve(n + 1, m + 1), 1 + solve(n, m + 1)),                 1 + solve(n + 1, m));     return ret;   }   void path(int n, int m, int p, int q) {     if (n == len1) {       int i, j;       for (i = m, j = q; i < len2; i++, j++)         printf( INSERT %d %c n , j + 1, s2[i]);       return;     }     if (m == len2) {       int i;       for (i = n; i < len1; i++) printf( DELETE %d n , p + 1);       return;     }     if (s1[n] == s2[m]) return path(n + 1, m + 1, p + 1, q + 1);     if (dp[n][m] == 1 + dp[n + 1][m + 1]) {       printf( REPLACE %d %c n , p + 1, s2[m]);       return path(n + 1, m + 1, p + 1, q + 1);     } else if (dp[n][m] == 1 + dp[n][m + 1]) {       printf( INSERT %d %c n , p + 1, s2[m]);       return path(n, m + 1, p + 1, q + 1);     } else {       printf( DELETE %d n , p + 1);       return path(n + 1, m, p, q);     }   }   int main() {     int i, j;     while (scanf( %s %s , s1, s2) == 2) {       len1 = strlen(s1);       len2 = strlen(s2);       for ((i) = 0; (i) < (int)(len1 + 1); (i)++)         for ((j) = 0; (j) < (int)(len2 + 1); (j)++) dp[i][j] = inf;       PR(solve(0, 0));       path(0, 0, 0, 0);     }     return 0;   }


#include <algorithm>   #include <iostream>   #include <climits>   #include <iomanip>   #include <cstring>   #include <string>   #include <vector>   #include <queue>   #include <cmath>   #include <set>   #include <map>      using namespace std;      template <typename T> istream &operator>>   (istream &is, vector<T> &vec)    {   for (auto &v : vec) is >> v; return is; }      #define all(x) (x).begin(),(x).end()   #define rall(x) (x).rbegin(),(x).rend()   #define ll long long   #define mod 1000000007   #define nod 1000000007   #define vi vector<int>   #define vll vector<ll>   #define pb push_back         // D R U L   int dx[] = {1, 0, -1, 0};   int dy[] = {0, 1, 0, -1};      const int mx = 1e6 + 5;   const int INF = mod;      ll power(ll x, ll y){       ll res = 1;       while(y > 0){           if(y & 1) res = (res * x) % nod;           y >>= 1;           x = (x * x) % nod;       }       return (res % nod);   }         // Check for number of Cases!!   void solve() {       ll n; cin >> n;       string str; cin >> str;       str +=  $ ;              vector<int> freq(26, -1);              for(int i = 1; i < str.length(); i++) {           if(str[i] != str[i - 1]) {               if(freq[str[i - 1] -  A ] == -1) {                   freq[str[i - 1] -  A ] = i;               }else {                   cout <<  NO n ;                   return;               }           }       }              cout <<  YES n ;   }      int main(){          #ifndef ONLINE_JUDGE       freopen( /ATOMCODES/input.txt ,  r , stdin);       freopen( /ATOMCODES/output.txt ,  w , stdout);       freopen( /ATOMCODES/err_output.txt ,  w , stderr);       #endif          ios_base::sync_with_stdio(false);       cin.tie(NULL);              int t = 1;       cin >> t;       while(t--) {         solve();       }   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 5;   void solve() {     long long v, c, vv, cc;     cin >> v >> c >> vv >> cc;     long long f = 0;     if (cc > min(v, c)) {       cout <<  NO n ;       return;     }     v += c;     vv += cc;     if (vv > v) {       cout <<  NO n ;       return;     }     cout <<  YES n ;     if (f == 1) {     } else {     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int n, c = 0, p = 0;       cin >> n;       long long int s = (n / 2);       for (int i = 1; i <= s; i++) {         p += 8;         c += (p * i);       }       cout << c << endl;     }   }


#include <bits/stdc++.h>   namespace imzzy {   class fastin {    private:     int _ch, _f;       public:     inline fastin &operator>>(char &c) {       c = getchar();       return *this;     }     template <typename _Tp>     inline fastin &operator>>(_Tp &_x) {       _x = 0;       while (!isdigit(_ch)) _f |= (_ch == 45), _ch = getchar();       while (isdigit(_ch))         _x = (_x << 1) + (_x << 3) + (_ch ^ 48), _ch = getchar();       _f && (_x = -_x, _f = 0);       return *this;     }     fastin() { _ch = _f = 0; }   } fin;   }  // namespace imzzy   using namespace imzzy;   const int maxn = 1004, maxm = 500004;   int nxt[maxn], pre[maxn], p[5];   bool g1[maxn][maxn], g2[maxn][maxn];   std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > > ans1, ans2;   inline std::pair<std::pair<int, int>, std::pair<int, int> > rev(       int u, int v, int n, bool g[maxn][maxn]) {     int indx = 0;     for (register int i = 1; i <= n; ++i)       if (g[u][i] && g[v][i]) p[++indx] = i;     g[u][v] = g[v][u] = 0, g[p[1]][p[2]] = g[p[2]][p[1]] = 1;     return std::make_pair(std::make_pair(u, v), std::make_pair(p[1], p[2]));   }   inline void work(       int n, bool g[maxn][maxn],       std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > > &res) {     for (register int i = 2; i <= n; ++i) {       for (register int j = n; j > 1; --j) {         if (j == i || j == pre[i] || j == nxt[i]) continue;         if (g[i][j]) res.push_back(rev(i, j, n, g));       }     }   }   signed main() {     int n, u, v;     fin >> n;     for (register int i = 1; i <= n; ++i) pre[i] = i - 1, nxt[i] = i + 1;     pre[1] = n, nxt[n] = 1;     for (register int i = 1; i <= n; ++i)       g1[i][pre[i]] = g1[i][nxt[i]] = g2[i][pre[i]] = g2[i][nxt[i]] = 1;     for (register int i = 1; i <= n - 3; ++i)       fin >> u >> v, g1[u][v] = g1[v][u] = 1;     for (register int i = 1; i <= n - 3; ++i)       fin >> u >> v, g2[u][v] = g2[v][u] = 1;     work(n, g1, ans1), work(n, g2, ans2);     std::cout << ans1.size() + ans2.size() <<   n ;     for (register int i = 0; i < ans1.size(); ++i)       std::cout << ans1[i].first.first <<     << ans1[i].first.second <<   n ;     for (register int i = ans2.size() - 1; i >= 0; --i)       std::cout << ans2[i].second.first <<     << ans2[i].second.second <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     cin >> a >> b >> c >> d;     if (a <= b)       cout <<  Second ;     else if (a > b)       cout <<  First ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, f;   char x;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> x;         if (x !=  B  && x !=  W  && x !=  G ) f = 1;       }     if (f == 0)       cout <<  #Black&White ;     else       cout <<  #Color ;   }


#include <bits/stdc++.h>   using namespace std;   struct Edge {     int u, v, w;     Edge() {}     Edge(int tu, int tv, int tw) : u(tu), v(tv), w(tw) {}     int operator<(const Edge e1) const { return w > e1.w; }   } p[100007];   int n, m;   struct uset {     int p[100007], sz[100007];     uset() {}     uset(int n) {       for (int i = 1; i <= n; i++) p[i] = i, sz[i] = 1;     }     int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); }   } us;   double kruskal() {     us = uset(n);     sort(p, p + m);     long long ans = 0;     for (int i = 0; i < m; i++) {       int u = p[i].u, v = p[i].v;       int fx = us.find(u), fy = us.find(v);       long long s1 = us.sz[fx], s2 = us.sz[fy];       if (fx != fy) {         long long cur = (s1 + s2) * (s1 + s2 - 1) - s1 * (s1 - 1) - s2 * (s2 - 1);         ans += cur * (long long)p[i].w;         us.p[fx] = fy;         us.sz[fy] += us.sz[fx];       }     }     return double(ans) / n / (n - 1);   }   int main() {     int c[100007], u, v;     for (; cin >> n >> m;) {       for (int i = 1; i <= n; i++) scanf( %d , c + i);       for (int i = 0; i < m; i++) {         scanf( %d%d , &u, &v);         p[i] = Edge(u, v, min(c[u], c[v]));       }       printf( %.9lf n , kruskal());     }     return 0;   }


#include <bits/stdc++.h>   const int MOD = 1e9 + 7;   using namespace std;   signed main() {     long long t, n;     cin >> t >> n;     long long a[n];     set<long long> s;     long long c = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n - 1; i++) {       c += t - a[i];     }     cout << c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200100;   const int M = 1000100;   const long long mod = 998244353;   int main() {     ios::sync_with_stdio(false);     int q;     cin >> q;     while (q--) {       string s;       cin >> s;       int l = 0, r = 0, u = 0, d = 0;       for (int i = 0; i < s.length(); i++) {         if (s[i] ==  L ) l++;         if (s[i] ==  R ) r++;         if (s[i] ==  U ) u++;         if (s[i] ==  D ) d++;       }       int ss = 0;       int minl = min(l, r);       int okl = 0, oku = 0;       if (minl != 0) {         okl = 1;       }       ss += minl;       int minu = min(u, d);       if (minu != 0) {         oku = 1;       }       ss += minu;       if (okl && oku) {         cout << ss * 2 << endl;         for (int i = 1; i <= minl; i++) {           cout <<  L ;         }         for (int i = 1; i <= minu; i++) {           cout <<  U ;         }         for (int i = 1; i <= minl; i++) {           cout <<  R ;         }         for (int i = 1; i <= minu; i++) {           cout <<  D ;         }         cout << endl;       } else if (okl && !oku) {         cout << 2 << endl;         cout <<  LR  << endl;       } else if (!okl && oku) {         cout << 2 << endl;         cout <<  UD  << endl;       } else {         cout << 0 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t = 1;     while (t--) {       long long n, min, cnt = 0, x;       cin >> n;       vector<long long> v(n);       for (int i = 0; i < n; ++i) cin >> v[i];       min = *min_element(v.begin(), v.end());       for (int i = 0; i < n; ++i) {         if (min == v[i]) {           cnt++;           x = i;         }       }       if (cnt > 1)         cout <<  Still Rozdil  << endl;       else         cout << x + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       string a, b, c;       cin >> a >> b >> c;       bool ok = true;       for (int i = 0; i < a.size(); i++) {         ok &= a[i] == c[i] || b[i] == c[i];       }       cout << (ok ?  YES n  :  NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 4e5 + 5;   int fa[maxn];   int m, n, q, i, x, y;   int getfa(int x) {     if (x == fa[x]) return x;     return fa[x] = getfa(fa[x]);   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (i = 1; i <= m + n; i++) fa[i] = i;     for (i = 1; i <= q; i++) {       scanf( %d%d , &x, &y);       fa[getfa(x)] = getfa(y + n);     }     int num = 0;     for (i = 1; i <= m + n; i++) {       if (fa[i] == i) num++;     }     cout << num - 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int arr[300001];   bool check(int val) {     if (val < 0) return false;     if (val >= m - 1) return true;     int prev = 0;     for (int i = int(1); i <= int(n); i++) {       if (arr[i] + val < prev) return false;       int r = (arr[i] + val) % m;       if (r < arr[i]) {         if (r >= prev)           continue;         else           prev = (prev > arr[i] ? prev : arr[i]);       } else {         prev = (prev > arr[i] ? prev : arr[i]);       }     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = int(1); i <= int(n); i++) cin >> arr[i];     int l = 0, r = m - 1;     while (l <= r) {       int mid = (l + r) / 2;       if (check(mid) && (!check(mid - 1))) {         cout << mid;         return 0;       } else if (!check(mid))         l = mid + 1;       else         r = mid - 1;     }   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 100100;   const int INF = 0x7f7f7f7f;   const double eps = 1e-8;   const double pi = 3.1415926535897932384626433832795;   int main() {     int n;     ios::sync_with_stdio(0);     cin >> n;     cout << n * n / 4 << endl;     for (int i = 1; i <= n / 2; i++)       for (int j = n / 2 + 1; j <= n; j++) cout << i <<     << j << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) { cerr << endl; }   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<   ,  ;     err(++it, args...);   }   namespace fastIO {   bool IOerror = 0;   inline char nc() {     static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;     if (p1 == pend) {       p1 = buf;       pend = buf + fread(buf, 1, 100000, stdin);       if (pend == p1) {         IOerror = 1;         return -1;       }     }     return *p1++;   }   inline bool blank(char ch) {     return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ;   }   inline void read(int &x) {     char ch;     while (blank(ch = nc()))       ;     if (IOerror) return;     for (x = ch -  0 ; (ch = nc()) >=  0  && ch <=  9 ; x = x * 10 + ch -  0 )       ;   }   }  // namespace fastIO   using namespace fastIO;   const double PI = acos(-1.0);   const double eps = 1e-8;   const int maxn = 2e6 + 7;   const long long mod = 1e9 + 7;   long long fac[maxn], finv[maxn];   long long qp(long long b, long long n) {     long long r = 1;     if (n <= 0) n += mod - 1;     b %= mod;     for (; n; n >>= 1, b = b * b % mod)       if (n & 1) r = r * b % mod;     return r;   }   long long pw[maxn];   void init() {     fac[1] = fac[0] = finv[0] = 1;     for (int i = 2; i < maxn; ++i) fac[i] = fac[i - 1] * i % mod;     finv[maxn - 1] = qp(fac[maxn - 1], mod - 2);     for (int i = maxn - 2; i >= 1; --i) finv[i] = finv[i + 1] * (i + 1) % mod;   }   long long C(int n, int m) {     return n >= m ? fac[n] * finv[n - m] % mod * finv[m] % mod : 0;   }   long long A(int n, int m) { return n >= m ? fac[n] * finv[n - m] % mod : 0; }   int main() {     int n, m, a, b;     cin >> n >> m >> a >> b;     init();     long long res = 0;     pw[0] = 1;     for (int i = 1; i < maxn; ++i) pw[i] = pw[i - 1] * m % mod;     for (int i = 0; i <= n - 2; ++i) {       long long tmp = A(n - 2, i) * C(m - 1, i) % mod * pw[n - 2 - i] % mod *                       (i + 2) % mod * qp(n, n - i - 3) % mod;       res = (res + tmp) % mod;     }     cout << res << endl;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:60000000 )   using namespace std;   const long double eps = 1e-9;   const int inf = (1 << 30) - 1;   const long long inf64 = ((long long)1 << 62) - 1;   const long double pi = 3.1415926535897932384626433832795;   template <class T>   T sqr(T x) {     return x * x;   }   int n, m, k;   vector<pair<int, int> > a;   vector<int> g[300500];   int u[300500];   vector<int> q;   void go(int v) {     u[v] = 1;     for (int i = 0; i < (int)(g[v].size()); i++)       if (u[g[v][i]] == 0)         go(g[v][i]);       else if (u[g[v][i]] == 1) {         cout << -1 << endl;         exit(0);       }     u[v] = 2;     q.push_back(v);   }   int main() {     cin >> n >> m;     k = m;     for (int i = 0; i < (int)(n); i++) {       a.clear();       for (int j = 0; j < (int)(m); j++) {         int x;         scanf( %d , &x);         if (x != -1) a.push_back(make_pair(x, j));       }       sort(a.begin(), a.end());       if (a.size() == 0) continue;       int l = 0;       int r = l;       while (r + 1 < (int)a.size() && a[r + 1].first == a[l].first) r++;       while (r + 1 < (int)a.size()) {         int l2 = r + 1;         int r2 = l2;         while (r2 + 1 < (int)a.size() && a[r2 + 1].first == a[l2].first) r2++;         for (int j = l; j <= r; j++) g[a[j].second].push_back(k);         for (int j = l2; j <= r2; j++) g[k].push_back(a[j].second);         k++;         l = l2;         r = r2;       }     }     memset(u, 0, sizeof(u));     q.clear();     for (int i = 0; i < (int)(m); i++)       if (!u[i]) go(i);     for (int i = (int)(q.size()) - 1; i >= 0; i--)       if (q[i] < m) printf( %d  , q[i] + 1);     cout << endl;     return 0;   }


#include <bits/stdc++.h>   inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   inline void sub(long long &a, long long b) {     a -= b;     if (a < 0) a += 1000000007;   }   inline void add(long long &a, long long b) {     a += b;     if (a >= 1000000007) a -= 1000000007;   }   template <typename T>   inline T const &MAX(T const &a, T const &b) {     return a > b ? a : b;   }   template <typename T>   inline T const &MIN(T const &a, T const &b) {     return a < b ? a : b;   }   inline long long qp(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % 1000000007;       a = a * a % 1000000007, b >>= 1;     }     return ans;   }   inline long long qp(long long a, long long b, long long c) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % c;       a = a * a % c, b >>= 1;     }     return ans;   }   using namespace std;   const unsigned long long ba = 233;   const double eps = 1e-5;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const int N = 1000 + 10, maxn = 1000000 + 10, inf = 0x3f3f3f3f;   vector<long long> v;   int main() {     long long n;     scanf( %lld , &n);     if (n % 3 != 0) return 0 * puts( 0 );     n /= 3;     for (long long i = 1; i * i <= n; i++) {       if (n % i == 0) {         v.push_back(i);         if (i * i != n) v.push_back(n / i);       }     }     sort(v.begin(), v.end());     int ans = 0;     for (int i = 0; i < v.size() && v[i] * v[i] * v[i] <= n; i++) {       for (int j = i; j < v.size() && v[i] * v[j] * v[j] <= n; j++) {         long long x = v[i], y = v[j], z = n / v[i] / v[j], a, b, c;         if (z < y || x * y * z != n) continue;         if ((x - y + z) % 2 != 0) continue;         b = (x - y + z) / 2;         a = x - b;         c = z - b;         if (a > b || a > c || b > c || a <= 0 || b <= 0 || c <= 0) continue;         set<int> s;         s.insert(a), s.insert(b), s.insert(c);         if (s.size() == 3)           ans += 6;         else if (s.size() == 2)           ans += 3;         else           ans += 1;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 10;   int mod = 1e9 + 7;   long long power(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % mod;       a = a * a % mod;       b >>= 1;     }     return res;   }   long long INV(long long a) { return power(a, mod - 2); }   mt19937 Rand(123456);   int Range(int l, int r) { return l + Rand() % (r - l + 1); }   map<long long, long long> mp;   void work(int l, int r, int k) {     if (k == 1 || l == r) {       ++mp[r - l + 1];       return;     }     int mid = (l + r) / 2;     work(l, mid, k - 1);     work(mid + 1, r, k - 1);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k >> mod;     vector<long long> inv(2 * n), inv_sum;     for (int i = 0; i <= 2 * n - 1; i++) inv[i] = INV(i);     inv_sum = inv;     for (int i = 1; i <= 2 * n - 1; i++) inv_sum[i] += inv_sum[i - 1];     for (auto& I : inv_sum) I %= mod;     auto merge = [&](int l, int r, const vector<long long>& inv_sum) {       long long res = (long long)l * r % mod * INV(2) % mod;       for (int i = 1; i <= l; i++) res -= inv_sum[i + r] - inv_sum[i];       res %= mod;       res += mod;       return res % mod;     };     work(1, n, k);     long long res = 0;     for (auto I : mp)       res += (I.first * (I.first - 1) % mod * INV(4) % mod) * I.second % mod,           res += I.second * (I.second - 1) % mod * INV(2) % mod *                  merge(I.first, I.first, inv_sum) % mod;     for (auto I : mp)       for (auto J : mp)         if (I.first < J.first)           res +=               merge(I.first, J.first, inv_sum) * I.second % mod * J.second % mod;     res %= mod;     res += mod;     res %= mod;     cout << res;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( inline ,  fast-math ,  unroll-loops ,                          no-stack-protector )   #pragma GCC target( popcnt,tune=native )   using namespace std;   namespace io {   const int SIZE = (1 << 21) + 1;   char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c,                                          qu[55];   int f, qr;   inline void flush() {     fwrite(obuf, 1, oS - obuf, stdout);     oS = obuf;   }   inline void putc(char x) {     *oS++ = x;     if (oS == oT) flush();   }   template <class T>   inline void getc(T &x) {     for (c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                          (iS == iT ? EOF : *iS++))                        : *iS++);          !((c >=  0  && c <=  9 ) || (c >=  a  && c <=  z ) ||            (c >=  A  && c <=  Z ));          c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                          (iS == iT ? EOF : *iS++))                        : *iS++))       ;     x = c;   }   template <class I>   inline void rd(I &x) {     for (f = 1, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                                 (iS == iT ? EOF : *iS++))                               : *iS++);          c <  0  || c >  9 ;          c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                          (iS == iT ? EOF : *iS++))                        : *iS++))       if (c ==  - ) f = -1;     for (x = 0; c <=  9  && c >=  0 ;          c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),                          (iS == iT ? EOF : *iS++))                        : *iS++))       x = x * 10 + (c & 15);     x *= f;   }   template <class I>   inline void print(I x) {     if (!x) putc( 0 );     if (x < 0) putc( - ), x = -x;     while (x) qu[++qr] = x % 10 +  0 , x /= 10;     while (qr) putc(qu[qr--]);   }   struct Flusher_ {     ~Flusher_() { flush(); }   } io_flusher_;   }  // namespace io   using io ::getc;   using io ::print;   using io ::putc;   using io ::rd;   const int MAXN = 100 + 5;   const int MOD = 1e9 + 7;   int mo(int x, int y) { return (x + y) >= MOD ? (x + y - MOD) : (x + y); }   int sub(int x, int y) { return x < y ? (x - y + MOD) : (x - y); }   int ksm(int x, int y) {     int res = 1;     for (; y; y >>= 1, x = 1ll * x * x % MOD)       if (y & 1) res = 1ll * res * x % MOD;     return res;   }   void fix(int &x, const int &v) { x = (x + v) >= MOD ? (x + v - MOD) : (x + v); }   int n, m;   bool vis[MAXN][MAXN];   vector<int> e[MAXN][MAXN];   void add(int x, int y, vector<int> t) {     vis[x][y] = 1;     e[x][y] = t;   }   struct Node {     vector<int> g[MAXN][MAXN];     vector<int> solvemid() {       vector<int> nxt, res, now;       for (int x = 1; x <= n; x++)         for (int y = 1; y <= n; y++)           for (int i = 0; i + 1 < e[x][y].size(); i++)             if (e[x][y][i] == x && e[x][y][i + 1] == y) {               now.clear();               nxt = e[x][y];               bool flag = 1;               do {                 now = nxt;                 nxt.clear();                 flag = (now.size() <= (2 * n + 1));                 for (int i = 0; i + 1 < now.size() && flag; i++) {                   if (!vis[now[i]][now[i + 1]]) {                     flag = 0;                     break;                   }                   nxt.insert(nxt.end(), e[now[i]][now[i + 1]].begin(),                              e[now[i]][now[i + 1]].end());                 }               } while (flag && now != nxt);               if (flag) {                 if (!res.size()) res = nxt;                 g[nxt[0]][nxt.back()].push_back(nxt.size() - 1);               }               break;             }       return res;     }     void solvefront() {       vector<int> nxt, res, now, Cnt;       for (int x = 1; x <= n; x++)         for (int y = 1; y <= n; y++)           if (e[x][y].size() && e[x][y].back() == x) {             now.clear();             nxt.clear();             nxt.push_back(x);             bool flag = 1;             do {               now = nxt;               nxt.clear();               flag = (now.size() <= (2 * n + 1));               nxt = e[now[0]][y];               reverse(nxt.begin(), nxt.end());               for (int i = 0; i + 1 < now.size() && flag; i++) {                 if (!vis[now[i + 1]][now[i]]) {                   flag = 0;                   break;                 }                 nxt.insert(nxt.end(), e[now[i + 1]][now[i]].rbegin(),                            e[now[i + 1]][now[i]].rend());               }             } while (flag && now != nxt);             if (flag) g[nxt.back()][y].push_back(nxt.size());           }     }     void solveend() {       vector<int> nxt, res, now, Cnt;       for (int x = 1; x <= n; x++)         for (int y = 1; y <= n; y++)           if (e[x][y].size() && e[x][y][0] == y) {             now.clear();             nxt.clear();             nxt.push_back(y);             bool flag = 1;             do {               now = nxt;               nxt.clear();               flag = (now.size() <= (2 * n + 1));               nxt = e[x][now[0]];               for (int i = 0; i + 1 < now.size() && flag; i++) {                 if (!vis[now[i]][now[i + 1]]) {                   flag = 0;                   break;                 }                 nxt.insert(nxt.end(), e[now[i]][now[i + 1]].begin(),                            e[now[i]][now[i + 1]].end());               }             } while (flag && now != nxt);             if (flag) g[x][nxt.back()].push_back(nxt.size());           }     }     int dp[MAXN][MAXN][MAXN];     void solveA() {       for (int i = 1; i <= n; i++) dp[i][i][0] = 1;       for (int i = 0; i <= n * 2; i++)         for (int s = 1; s <= n; s++)           for (int l = 1; l <= n; l++)             for (int r = 1; r <= n; r++)               for (auto &len : g[l][r])                 if (i + len <= 2 * n + 1) fix(dp[s][r][i + len], dp[s][l][i]);     }   } A, B, C;   int dp[MAXN][MAXN][MAXN], dp0[MAXN][MAXN][MAXN], ans[MAXN][MAXN];   int main() {     rd(n);     rd(m);     for (int i = 1, a, b, K; i <= m; i++) {       rd(a);       rd(b);       rd(K);       vector<int> v;       v.resize(K);       for (int i = 0; i < K; i++) rd(v[i]);       add(a, b, v);     }     A.solvefront();     vector<int> res = B.solvemid();     C.solveend();     A.solveA();     for (int i = 0; i <= n * 2; i++)       for (int s = 1; s <= n; s++)         for (int l = 1; l <= n; l++)           for (int r = 1; r <= n; r++)             for (auto &len : B.g[l][r])               if (i + len <= 2 * n) fix(dp[s][r][i + len], A.dp[s][l][i]);     for (int i = 0; i <= n * 2; i++)       for (int s = 1; s <= n; s++)         for (int l = 1; l <= n; l++)           for (int r = 1; r <= n; r++)             for (auto &len : C.g[l][r])               if (i + len <= 2 * n) fix(dp[s][r][i + len], dp[s][l][i]);     for (int l = 1; l <= n; l++)       for (int mid = 1; mid <= n; mid++)         if (vis[l][mid] && e[l][mid].empty())           for (int r = 1; r <= n; r++)             for (int i = 0; i + 1 <= 2 * n; i++)               fix(dp0[l][r][i + 1], dp[mid][r][i]);     for (int l = 1; l <= n; l++)       for (int r = 1; r <= n; r++)         for (int len = 1; len <= 2 * n; len++) fix(ans[r][len], dp[l][r][len]);     for (int i = 1; i <= 2 * n; i++)       for (int l = 1; l <= n; l++)         for (int r = 1; r <= n; r++)           for (int len = 1; len + i <= 2 * n; len++)             fix(ans[r][len + i], 1ll * ans[l][i] * dp0[l][r][len] % MOD);     for (int i = 1; i <= 2 * n; i++) {       int aa = 0;       for (int s = 1; s <= n; s++) fix(aa, ans[s][i]);       print(aa);       putc(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double t, y, j, n;     cin >> t;     while (t--) {       cin >> n;       j = n * n;       j = j - 4 * n;       if (j >= 0) {         double x = sqrt(j);         if ((-n - x) > 0)           cout <<  N ;         else {           x = (n - x) / 2;           if (x != 0)             y = n / x;           else             y = 0;           std::cout << std::fixed <<  Y                      <<     << std::setprecision(9) << x <<     << y;         }       } else         cout <<  N ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   constexpr long long INF = 2e18;   constexpr long long MOD = 1e9 + 7;   constexpr long long MAXN = 2e5 + 3;   void solve() {     long long n;     cin >> n;     map<long long, long long> m;     long long ans = 0;     for (long long i = 1; i <= n; ++i) {       long long x;       cin >> x;       m[x - i] += x;       ans = max(ans, m[x - i]);     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   float S, a, b, c;   int main() {     ios ::sync_with_stdio(false);     cin >> S >> a >> b >> c;     float sum = a + b + c;     if (sum == 0)       cout <<  0 0 0 ;     else       printf( %.12f %.12f %.12f , a * S / sum, b * S / sum, c * S / sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 20;   const long long mod = 1e9 + 7;   int w[(maxn * 4) << 2], n;   vector<pair<int, int> > col[(maxn * 4) << 2];   int query(int L, int R, int l, int r, int rt);   void pushup(int rt) { w[rt] = w[rt << 1] + w[rt << 1 | 1]; }   void pushdown(int rt) {     for (int i = 0; i < col[rt].size(); i++) {       int r = col[rt][i].second, l = col[rt][i].first;       int m = (l + r) >> 1;       col[rt << 1].push_back(make_pair(r + l - m, r));       col[rt << 1 | 1].push_back(make_pair(l, r + l - (m + 1)));       w[rt << 1] += query(r + l - m, r, 0, n, 1);       w[rt << 1 | 1] += query(l, r + l - (m + 1), 0, n, 1);     }     col[rt].clear();   }   void build(int l, int r, int rt) {     col[rt].clear();     w[rt] = 1;     if (l == r) return;     int m = (l + r) >> 1;     build(l, m, rt << 1);     build(m + 1, r, rt << 1 | 1);     pushup(rt);   }   void update(int L0, int R0, int L, int R, int l, int r, int rt) {     if (L <= l && r <= R) {       int R1 = R0 - (l - L), L1 = L0 + R - r;       col[rt].push_back(make_pair(L1, R1));       w[rt] += query(L1, R1, 0, n, 1);       return;     }     pushdown(rt);     int m = (l + r) >> 1;     if (L <= m) update(L0, R0, L, R, l, m, rt << 1);     if (m < R) update(L0, R0, L, R, m + 1, r, rt << 1 | 1);     pushup(rt);   }   int query(int L, int R, int l, int r, int rt) {     if (L <= l && r <= R) {       return w[rt];     }     pushdown(rt);     int m = (l + r) >> 1;     int ret = 0;     if (L <= m) ret += query(L, R, l, m, rt << 1);     if (m < R) ret += query(L, R, m + 1, r, rt << 1 | 1);     return ret;   }   int main() {     int q;     while (~scanf( %d%d , &n, &q)) {       int curl = 0, curr = n - 1;       build(0, n, 1);       int ra = 1;       for (int i = 0; i < q; i++) {         int x;         scanf( %d , &x);         if (ra) {           if (x == 1) {             int p;             scanf( %d , &p);             if (curl + 2 * p - 1 <= curr) {               update(curl, curl + p - 1, curl + p, curl + 2 * p - 1, 0, n, 1);               curl += p;             } else {               p = curr - curl + 1 - p;               if (p)                 update(curr - p + 1, curr, curr - 2 * p + 1, curr - p, 0, n, 1);               curr -= p;               ra = 0;             }           }           if (x == 2) {             int l, r;             scanf( %d%d , &l, &r);             int ans = query(curl + l, curl + r - 1, 0, n, 1);             printf( %d n , ans);           }         } else {           if (x == 1) {             int p;             scanf( %d , &p);             if (curr - 2 * p + 1 >= curl) {               update(curr - p + 1, curr, curr - 2 * p + 1, curr - p, 0, n, 1);               curr -= p;             } else {               p = curr - curl + 1 - p;               if (p)                 update(curl, curl + p - 1, curl + p, curl + 2 * p - 1, 0, n, 1);               curl += p;               ra = 1;             }           }           if (x == 2) {             int l, r;             scanf( %d%d , &l, &r);             int ans = query(curr - r + 1, curr - l, 0, n, 1);             printf( %d n , ans);           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MM = 120000;   vector<int> G[MM], T[MM];   int P[MM], L[MM];   void dfs(int u, int par) {     P[u] = par;     if (par != -1) L[u] = L[par] + 1;     for (auto v : G[u]) {       if (v != par) {         dfs(v, u);       }     }   }   int N, K;   bool rip = 0;   void dfs2(int u, int par, int lev) {     int kek = 0;     for (auto v : G[u]) {       if (v != par) {         kek++;         dfs2(v, u, lev + 1);       }     }     if (kek < 3 && kek != 0) {       rip = 1;     }     if (kek == 0 && lev != K) {       rip = 1;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> N >> K;     for (int i = 0; i < N - 1; i++) {       int u, v;       cin >> u >> v;       G[u - 1].push_back(v - 1);       G[v - 1].push_back(u - 1);     }     dfs(0, -1);     int mx = 0;     int el = -1;     for (int i = 0; i < N; i++) {       mx = max(mx, L[i]);       if (mx == L[i]) {         el = i;       }     }     if (mx >= K) {       mx = K;       while (mx--) el = P[el];       int rt = el;       dfs2(rt, -1, 0);       if (rip) {         cout <<  No ;       } else {         cout <<  Yes ;       }     } else {       cout <<  No ;       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int get(int x) {     int cnt = 0;     while (x >= 10) {       int sum = 0;       while (x) {         sum += x % 10;         x /= 10;       }       cnt++;       x = sum;     }     return cnt;   }   int main() {     string s;     cin >> s;     if (s.size() == 1)       cout << 0 << endl;     else {       int n = 0;       for (int i = 0; i < s.size(); i++) n += s[i] -  0 ;       cout << get(n) + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long ans = 1;     ans += (3 * n * (n + 1));     cout << ans;     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 n, k;     cin >> n >> k;     long long int ans = k / n;     long long int t1 = ans * n;     if (t1 < k) ans++;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<string> split(const string& s, char c) {     vector<string> v;     stringstream ss(s);     string x;     while (getline(ss, x, c)) v.push_back(move(x));     return move(v);   }   void err(vector<string>::iterator it) {}   template <typename T, typename... Args>   void err(vector<string>::iterator it, T a, Args... args) {     cerr << it->substr((*it)[0] ==    , it->length()) <<   =   << a <<   n ;     err(++it, args...);   }   int N, M;   int X[5013];   pair<long long, int> H[5013];   long long dp[5013][5013];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> N >> M;     for (int i = 0; i < N; i++) {       cin >> X[i];     }     long long housing = 0;     for (int i = 1; i <= M; i++) {       cin >> H[i].first >> H[i].second;       housing += H[i].second;     }     if (N > housing) {       cout << -1 << endl;       return 0;     }     sort(X, X + N);     sort(H + 1, H + M + 1);     for (int i = 0; i < N; i++) {       dp[0][i] = 1123456789123456789LL;     }     for (int i = 1; i <= M; i++) {       long long allin = 0;       deque<pair<long long, int> > mpq;       mpq.push_back({0, -1});       for (int j = 0; j < N; j++) {         allin += abs(X[j] - H[i].first);         long long diff = dp[i - 1][j] - allin;         while (mpq.size() && diff <= mpq.back().first) {           mpq.pop_back();         }         mpq.push_back({diff, j});         while (j - mpq.front().second > H[i].second) {           mpq.pop_front();         }         dp[i][j] = allin + mpq.front().first;       }     }     cout << dp[M][N - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000005], dp[1000005];   int main() {     int n, i, j;     while (~scanf( %d , &n)) {       memset(dp, 0, sizeof(dp));       for (i = 0; i < n; i++) {         scanf( %d , &a[i]);       }       for (i = 0; i < n; i++) {         dp[a[i]] = max(dp[a[i]], 1);         for (j = a[i] + a[i]; j <= a[n - 1]; j += a[i])           dp[j] = max(dp[j], dp[a[i]] + 1);       }       int ans = 1;       for (i = 0; i < n; i++) ans = max(ans, dp[a[i]]);       printf( %d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char **argv) {     int n;     long long m;     cin >> n >> m;     m -= 1;     vector<int> xs;     for (int i = 0; i < n; i++) {       xs.push_back(-1);     }     int i = 0;     int u = 0;     int v = n - 1;     while (u <= v) {       long long h = (1LL << (n - i - 2));       if (m >= h) {         xs[v] = i;         v -= 1;         m -= h;       } else {         xs[u] = i;         u += 1;       }       i += 1;     }     for (int i = 0; i < n; i++) printf( %d  , xs[i] + 1);     printf(  n );     return 0;   }