#include <bits/stdc++.h>   using namespace std;   const long long base = 1E9 + 7;   const int N = 200100;   const double ep = 0.0000001;   int n;   long long x[N], y[N];   long long cx = 0, cy = 0;   void fail() {     cout <<  NO ;     exit(0);   }   bool symmetric(int i, int j) {     long long x1 = cx - x[i] * n;     long long y1 = cy - y[i] * n;     long long x2 = cx - x[j] * n;     long long y2 = cy - y[j] * n;     return (x1 == -x2) && (y1 == -y2);   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i];       cx += x[i];       cy += y[i];     }     if (n % 2 == 1) fail();     int j = 0;     for (j = 1; j < n; j++)       if (symmetric(0, j)) break;     for (int i = 0; i < n; i++, j++) {       if (j == n) j = 0;       if (!symmetric(i, j)) fail();     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   int compare(char *s, char *t, int l) {     int i;     for (i = 0; i < l; i++) {       char a = toupper(s[i]), b = toupper(t[i]);       if (a != b) return a - b;     }     return 0;   }   int main() {     static char ss[100][100 + 1], cc[100 + 1], lucky[100];     static int ll[100];     int n, m, i, j;     char c, c_, a, a_;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %s , ss[i]);       ll[i] = strlen(ss[i]);     }     scanf( %s n%c , cc, &c), m = strlen(cc);     c_ = toupper(c);     a = c ==  a  ?  b  :  a ;     a_ = toupper(a);     for (j = 0; j < m; j++)       for (i = 0; i < n; i++)         if (m - j >= ll[i] && compare(cc + j, ss[i], ll[i]) == 0)           memset(lucky + j, 1, ll[i]);     for (j = 0; j < m; j++)       if (lucky[j]) {         if (tolower(cc[j]) == c)           cc[j] = isupper(cc[j]) ? a_ : a;         else           cc[j] = isupper(cc[j]) ? c_ : c;       }     printf( %s n , cc);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[1100];   int main() {     scanf( %s , s);     for (int i = 0; s[i]; i++) printf( %c , s[i]);     for (int i = strlen(s) - 1; i >= 0; i--) printf( %c , s[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string p[105] = {  };   int cts[105] = {0};   string pass;   int main(int argc, char const *argv[]) {     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> p[i];       int xx = p[i].length();       cts[xx]++;     }     for (int i = 1; i <= 100; i++) {       cts[i] += cts[i - 1];     }     cin >> pass;     int plen = pass.length();     int mans = cts[plen - 1];     mans += 5 * (mans / k);     mans++;     cout << mans <<    ;     int maxans = cts[plen] - 1;     maxans += 5 * (maxans / k);     maxans++;     cout << maxans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       int sum = 0;       for (int i = 0; i < n; i++) {         int a;         cin >> a;         sum += a;       }       if (sum == m) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N_ = 100500;   int N, M;   vector<int> gph[N_], rev[N_], bth[N_];   int outdg[N_], indg[N_];   bool visited[N_];   vector<int> ord;   void dfs(int u) {     visited[u] = true;     for (int i = 0; i < gph[u].size(); i++) {       int v = gph[u][i];       if (!visited[v]) dfs(v);     }     ord.push_back(u);   }   queue<int> que;   int grp[N_], gn;   int c1[N_], c2[N_];   void dfs2(int u) {     visited[u] = true;     ++c1[gn];     grp[u] = gn;     for (int i = 0; i < bth[u].size(); i++) {       int v = bth[u][i];       if (!visited[v]) dfs2(v);     }   }   int cnt3;   void dfs3(int u) {     visited[u] = true;     ++cnt3;     for (int i = 0; i < rev[u].size(); i++) {       int v = rev[u][i];       if (!visited[v]) dfs3(v);     }   }   int main() {     scanf( %d%d , &N, &M);     for (int e = 1; e <= M; e++) {       int u, v;       scanf( %d%d , &u, &v);       gph[u].push_back(v);       rev[v].push_back(u);       bth[u].push_back(v);       bth[v].push_back(u);       ++outdg[u];       ++indg[v];     }     memset(visited, 0, sizeof visited);     for (int i = 1; i <= N; i++)       if (!visited[i]) dfs(i);     memset(visited, 0, sizeof visited);     for (int i = 1; i <= N; i++)       if (!visited[i]) {         ++gn;         dfs2(i);       }     memset(visited, 0, sizeof visited);     for (int i = ord.size(); i--;) {       int u = ord[i];       if (!visited[u]) {         cnt3 = 0;         dfs3(u);         if (cnt3 >= 2) c2[grp[u]] += 1;       }     }     int ans = 0;     for (int g = 1; g <= gn; g++) {       c2[g] += c1[g] - 1;       ans += min(c1[g], c2[g]);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long n, t;     cin >> n >> t;     string s1, s2;     getline(cin, s1);     getline(cin, s1,  . );     getline(cin, s2);     long a = -1, count = 0;     for (int i = 0; i < s2.length(); i++)       if (s2[i] >=  5 ) {         a = i;         break;       }     if (a == -1) {       cout << s1 <<  .  << s2;       return 0;     }     if (a == 0) {       int c = s1.length() - 1;       while (s1[c] ==  9  && c >= 0) c--;       if (c == -1) {         cout <<  1 ;         for (int i = 0; i < s1.length(); i++) cout <<  0 ;         return 0;       }       s1[c]++;       for (c++; c < s1.length(); c++) s1[c] =  0 ;       cout << s1;       return 0;     }     long b = a - 1;     while (s2[b] ==  4  && b >= 0 && b >= a - t + 1) {       b--;     }     if (b == -1) {       int c = s1.length() - 1;       while (s1[c] ==  9  && c >= 0) c--;       if (c == -1) {         cout <<  1 ;         for (int i = 0; i < s1.length(); i++) cout <<  0 ;         return 0;       }       s1[c]++;       for (c++; c < s1.length(); c++) s1[c] =  0 ;       cout << s1;       return 0;     } else {       s2[b]++;       cout << s1 <<  . ;       for (int i = 0; i <= b; i++) cout << s2[i];       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 400000;   const double EPS = 1e-9;   int mods(int a, int b) { return (b + (a % b)) % b; }   int n, m, k, x, ans, p[105], s[105], strongest[105];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     for (int i = 0; i < n; i++) cin >> p[i];     for (int i = 0; i < n; i++) {       cin >> s[i];       strongest[s[i]] = max(strongest[s[i]], p[i]);     }     for (int i = 0; i < k; i++) {       cin >> x;       if (strongest[s[x - 1]] != p[x - 1]) ans++;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   istream& operator>>(istream& in, pair<T1, T2>& a) {     in >> a.first >> a.second;     return in;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2> a) {     out << a.first <<     << a.second;     return out;   }   template <typename T, typename T1>   T amax(T& a, T1 b) {     if (b > a) a = b;     return a;   }   template <typename T, typename T1>   T amin(T& a, T1 b) {     if (b < a) a = b;     return a;   }   const long long INF = 1e18;   const int32_t M = 1e9 + 7;   const int32_t MM = 998244353;   const int N = 3e5 + 5;   struct node {     node* next[2] = {0};   } ns[19 * N];   int cnt = 1;   node* create() {     if (cnt < 19 * N)       return ns + cnt++;     else       return new node();   }   void insert(int x) {     node* tmp = ns;     for (int i = 19; i >= 0; i--) {       int k = x >> i & 1;       if (!tmp->next[k]) tmp->next[k] = create();       tmp = tmp->next[k];     }   }   int query(int x) {     node* tmp = ns;     int ans = 0;     for (int i = 19; i >= 0; i--) {       int k = x >> i & 1;       if (tmp->next[k]) {         tmp = tmp->next[k];       } else {         ans += (1 << i);         tmp = tmp->next[!k];       }     }     return ans;   }   void solve() {     set<int> s;     for (int i = 0; i < 1 << 19; i++) {       s.insert(i);     }     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       s.erase(x);     }     for (int x : s) {       insert(x);     }     int prev = 0;     for (int i = 0; i < m; i++) {       int q;       cin >> q;       prev ^= q;       cout << query(prev) <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using bigint = long long int;   using vi = vector<int>;   using vll = vector<long long int>;   int cnt[200001];   int main() {     int N, A;     cin >> N >> A;     for (int i = 0; i < N; i++) {       int x;       cin >> x;       cnt[x]++;     }     int ans = 0;     if (cnt[A] == 0) {       ans++;       cnt[A] = 1;     }     int left = 0, right = 0;     for (int i = 1; i < A; i++) left += cnt[i];     for (int i = A + 1; i < 100001; i++) right += cnt[i];     if (left == right) {       cout << ans <<   n ;       return 0;     }     if (left > right) {       if (right + cnt[A] - 1 >= left)         cout << ans <<   n ;       else         cout << ans + left - (right + cnt[A] - 1) <<   n ;     } else if (right > left) {       if (left + cnt[A] - 1 >= right - 1)         cout << ans <<   n ;       else         cout << ans + (right - 1) - (left + cnt[A] - 1) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int H, W, K;     cin >> H >> W >> K;     vector<string> photo(H);     for (int h = 0; h < int(H); ++h) cin >> photo[h];     vector<vector<char> > star(H, vector<char>(W, 0));     for (int r = 1; r < int(H - 1); ++r)       for (int c = 1; c < int(W - 1); ++c) {         if (photo[r][c] ==  1  && photo[r - 1][c] ==  1  &&             photo[r][c - 1] ==  1  && photo[r + 1][c] ==  1  &&             photo[r][c + 1] ==  1 ) {           star[r][c] = 1;         }       }     long long res = 0;     for (int c1 = 0; c1 < int(W); ++c1) {       vector<int> row_stars(H, 0);       for (int c2 = c1 + 3; c2 <= int(W); ++c2) {         for (int r = 0; r < int(H); ++r) row_stars[r] += star[r][c2 - 2];         int r1 = 0, stars = 0;         for (int r2 = r1 + 3; r2 <= int(H); ++r2) {           stars += row_stars[r2 - 2];           while (stars - row_stars[r1 + 1] >= K) {             stars -= row_stars[r1 + 1];             ++r1;           }           if (stars >= K) res += r1 + 1;         }       }     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a, b, ans[400];   string s[400];   long long calc(int pos, int res) {     for (int i = res + 1; i <= 10; i++) {       for (int j = 0; j < 1 << i; j++) {         string t =   ;         for (int k = 0; k < i; k++) t = t + (char)(((j >> k) & 1) +  0 );         if (s[pos].find(t) == -1) {           ans[pos] = i - 1;           return i - 1;         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) cin >> s[i];     cin >> m;     for (int i = 1; i <= m; i++) {       cin >> a >> b;       s[n + i] = s[a] + s[b];       if (s[n + i].length() > 1000)         s[n + i] = s[n + i].substr(0, 500) +                    s[n + i].substr(s[n + i].length() - 500, 500);       cout << calc(n + i, max(ans[a], ans[b])) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   long long dp[5010][5010];   char s[5010], z[5010];   long long solve() {     int M = strlen(s), N = strlen(z);     for (int i = 0; i <= M; i++) dp[i][0] = 0;     for (int i = 0; i <= N; i++) dp[0][i] = 0;     for (int i = 1; i <= M; i++)       for (int j = 1; j <= N; j++) {         dp[i][j] = dp[i][j - 1];         if (s[i - 1] == z[j - 1])           dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + 1) % mod;       }     long long ans = 0;     for (int i = 0; i <= M; i++) ans = (ans + dp[i][N]) % mod;     return ans;   }   int main() {     scanf( %s %s , s, z);     int ans = solve();     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Max_n = 2e5 + 10;   const int Max_m = 4e5 + 10;   int f[Max_n];   struct A {     long long val;     int pos;     bool operator<(const A &a) const { return val < a.val; }   } a[Max_n];   struct Edge {     int u, v;     long long cost;     bool operator<(const Edge &edge) const { return cost < edge.cost; }   } edge[Max_m * 2];   int Find(int v) {     if (f[v] == v) return v;     return f[v] = Find(f[v]);   }   bool Merge(int m, int n) {     int t1 = Find(m);     int t2 = Find(n);     if (t1 != t2) {       f[t1] = t2;       return true;     }     return false;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     int cnt = 0;     for (int i = 1; i <= n; i++) f[i] = i;     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i].val);       a[i].pos = i;     }     sort(a + 1, a + n + 1);     for (int i = 2; i <= n; i++) {       edge[cnt].u = a[1].pos;       edge[cnt].v = a[i].pos;       edge[cnt++].cost = a[1].val + a[i].val;       edge[cnt].u = a[i].pos;       edge[cnt].v = a[1].pos;       edge[cnt++].cost = a[1].val + a[i].val;     }     for (int i = 1; i <= m; i++) {       int u, v;       long long cost;       scanf( %d%d%lld , &u, &v, &cost);       edge[cnt].u = u;       edge[cnt].v = v;       edge[cnt++].cost = cost;       edge[cnt].u = v;       edge[cnt].v = u;       edge[cnt++].cost = cost;     }     sort(edge, edge + cnt);     long long ans = 0;     int edgeCnt = 0;     for (int i = 0; i < cnt; i++) {       if (Merge(edge[i].u, edge[i].v)) {         ans += edge[i].cost;         edgeCnt++;       }       if (edgeCnt == n - 1) break;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int defence[4];   int atack[4];   int main() {     for (int i = 0; i < 4; i++) cin >> defence[i] >> atack[i];     int maximum = max(defence[0], defence[1]);     maximum = max(maximum, atack[0]);     maximum = max(maximum, atack[1]);     if (defence[0] > atack[2] && defence[0] > atack[3] && atack[1] > defence[2] &&         atack[1] > defence[3]) {       cout <<  Team 1 ;       return 0;     }     if (defence[1] > atack[2] && defence[1] > atack[3] && atack[0] > defence[2] &&         atack[0] > defence[3]) {       cout <<  Team 1 ;       return 0;     }     if ((defence[0] + atack[1]) < (defence[1] + atack[0])) {       if (defence[1] < atack[3] && atack[0] < defence[2]) {         cout <<  Team 2 ;         return 0;       } else if (defence[1] < atack[2] && atack[0] < defence[3]) {         cout <<  Team 2 ;         return 0;       }     } else {       if (defence[0] < atack[3] && atack[1] < defence[2]) {         cout <<  Team 2 ;         return 0;       } else if (defence[0] < atack[2] && atack[1] < defence[3]) {         cout <<  Team 2 ;         return 0;       }     }     cout <<  Draw ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, q;   int x[411111], y[411111], a[411111], b[411111], aa[411111], bb[411111];   int ans[411111];   int mi[2000222];   void init(int pos, int l, int r) {     mi[pos] = -1;     if (l == r) return;     init(pos + pos, l, (l + r) / 2);     init(pos + pos + 1, (l + r) / 2 + 1, r);   }   void mod(int pos, int l, int r, int x, int v) {     if (x < l || x > r) return;     if (l == r) {       mi[pos] = v;       return;     }     mod(pos + pos, l, (l + r) / 2, x, v);     mod(pos + pos + 1, (l + r) / 2 + 1, r, x, v);     mi[pos] = min(mi[pos + pos], mi[pos + pos + 1]);   }   int fin(int pos, int l, int r, int ll, int rr) {     ll = max(ll, l);     rr = min(rr, r);     if (ll > rr) return 1e9;     if (l == ll && r == rr) return mi[pos];     return min(fin(pos + pos, l, (l + r) / 2, ll, rr),                fin(pos + pos + 1, (l + r) / 2 + 1, r, ll, rr));   }   void solve() {     vector<pair<int, int> > ev;     for (int i = 0; i < k; i++) {       ev.push_back(make_pair(y[i], -(i + 1)));     }     for (int i = 0; i < q; i++) {       ev.push_back(make_pair(bb[i], i + 1));     }     sort(ev.begin(), ev.end());     init(1, 0, n - 1);     for (int i = 0; i < ev.size(); i++) {       int id = ev[i].second;       if (id < 0) {         id = (-id) - 1;         mod(1, 0, n - 1, x[id], y[id]);       } else {         id = id - 1;         if (fin(1, 0, n - 1, a[id], aa[id]) >= b[id]) ans[id] = 1;       }     }   }   int main() {     cin >> n >> m >> k >> q;     for (int i = 0; i < k; i++) {       scanf( %d%d , &x[i], &y[i]);       x[i]--;       y[i]--;     }     for (int i = 0; i < q; i++) {       scanf( %d%d%d%d , &a[i], &b[i], &aa[i], &bb[i]);       a[i]--;       b[i]--;       aa[i]--;       bb[i]--;       ans[i] = 0;     }     solve();     for (int i = 0; i < k; i++) swap(x[i], y[i]);     for (int i = 0; i < q; i++) {       swap(a[i], b[i]);       swap(aa[i], bb[i]);     }     swap(n, m);     solve();     for (int i = 0; i < q; i++)       if (ans[i])         puts( YES );       else         puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0;     bool t = false;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) t = true, ch = getchar();     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch - 48, ch = getchar();     return t ? -x : x;   }   int n, Q, lans;   struct Line {     int v, next, w;   } e[100100 << 1];   int h[100100], cnt = 1;   inline void Add(int u, int v, int w) {     e[cnt] = (Line){v, h[u], w};     h[u] = cnt++;   }   struct Tree {     int rt, p[19][100100], dfn[100100], low[100100], ln[100100], md[100100],         dep[100100], tim;     void dfs(int u, int ff) {       p[0][u] = ff;       ln[dfn[u] = ++tim] = u;       md[u] = dep[u];       for (int i = 1; i < 19; ++i) p[i][u] = p[i - 1][p[i - 1][u]];       for (int i = h[u]; i; i = e[i].next) {         int v = e[i].v;         if (v == ff) continue;         dep[v] = dep[u] + e[i].w;         dfs(v, u);         md[u] = max(md[u], md[v]);       }       low[u] = tim;     }     pair<int, int> mx[100100 << 2];     int tag[100100 << 2];     void pushup(int now) { mx[now] = max(mx[(now << 1)], mx[(now << 1 | 1)]); }     void Build(int now, int l, int r) {       if (l == r) {         mx[now] = make_pair(dep[ln[l]], ln[l]);         return;       }       int mid = (l + r) >> 1;       Build((now << 1), l, mid);       Build((now << 1 | 1), mid + 1, r);       pushup(now);     }     void Modify(int now, int l, int r, int L, int R, int w) {       if (L <= l && r <= R) {         mx[now].first += w;         tag[now] += w;         return;       }       int mid = (l + r) >> 1;       if (L <= mid) Modify((now << 1), l, mid, L, R, w);       if (R > mid) Modify((now << 1 | 1), mid + 1, r, L, R, w);       pushup(now);       mx[now].first += tag[now];     }     int ans[100100], vis[100100];     void pre(int _rt) {       rt = _rt;       dfs(rt, 0);       Build(1, 1, n);       for (int i = 2; i <= n; ++i) {         ans[i] = ans[i - 1] + mx[1].first;         for (int j = mx[1].second; j && !vis[j]; j = p[0][j])           vis[j] = i, Modify(1, 1, n, dfn[j], low[j], dep[p[0][j]] - dep[j]);       }     }     int Solve(int x, int y) {       y = min(y, n);       if (vis[x] <= y) return ans[y];       int u = x;       for (int i = 18; ~i; --i)         if (vis[p[i][x]] > y) x = p[i][x];       x = p[0][x];       return ans[y] + md[u] - dep[x] -              min(dep[x], min(ans[y] - ans[y - 1], md[x] - dep[x]));     }   } T1, T2;   int mx, rt;   void dfs(int u, int ff, int dep) {     if (dep > mx) mx = dep, rt = u;     for (int i = h[u]; i; i = e[i].next)       if (e[i].v != ff) dfs(e[i].v, u, dep + e[i].w);   }   int main() {     n = read();     Q = read();     for (int i = 1, u, v, w; i < n; ++i)       u = read(), v = read(), w = read(), Add(u, v, w), Add(v, u, w);     mx = 0;     dfs(1, 0, 0);     T1.pre(rt);     while (Q--) {       int u = (read() + lans - 1) % n + 1, v = (read() + lans - 1) % n + 1;       printf( %d n , lans = T1.Solve(u, v << 1));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int inf = 1e9 + 7;   const long long int inf2 = inf * inf;   priority_queue<long long int, vector<long long int>, greater<long long int>>       mnheap;   priority_queue<long long int> mxheap;   long long int gcd(long long int x, long long int y) {     if (x == 0) return y;     return gcd(y % x, x);   }   int is_prime(long long int x) {     if (x < 2) return 0;     for (long long int i = 2; i * i <= x; i++) {       if (x % i == 0) return 0;     }     return 1;   }   inline long long int modpw(long long int x, long long int y, long long int z) {     long long int res = 1;     x = x % z;     while (y) {       if (y & 1) res = (res * x) % z;       x = (x * x) % z;       y /= 2;     }     return res;   }   inline long long int modinv(long long int x, long long int z) {     return modpw(x, z - 2, z);   }   long long int lcm(long long int x, long long int y) {     return (x * y) / gcd(x, y);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       int dp[n][m];       string st[n];       for (int i = 0; i < n; i++) cin >> st[i];       int cnt = 0;       for (int i = 0; i < n - 1; i++) {         if (st[i][m - 1] ==  R ) cnt++;       }       for (int i = 0; i < m - 1; i++) {         if (st[n - 1][i] ==  D ) cnt++;       }       cout << cnt << endl;     }   }


#include <bits/stdc++.h>   int main() {     char s[150];     int o = 1, z = 0, a[150];     scanf( %s , &s);     for (int i = 0; i < strlen(s); i++) {       a[i] = s[i] -  0 ;     }     for (int i = 0; i < strlen(s) - 1; i++) {       if (a[i] == a[i + 1]) {         o++;         if (o == 7) {           printf( YES n );           return 0;         }       } else         o = 1;     }     printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mxn = 1e5 + 5;   int n, a[mxn], c[mxn];   bool vis[mxn];   int main() {     scanf( %d , &n);     for (int(i) = (int)(1); (i) <= (int)(n); ++(i)) scanf( %d , a + i);     int cnt = 0;     for (int(i) = (int)(n); (i) >= (int)(1); --(i)) {       c[i] = c[i + 1] + (vis[a[i]] == 0);       vis[a[i]] = 1;     }     long long ans = 0;     memset(vis, 0, sizeof(vis));     for (int(i) = (int)(1); (i) <= (int)(n); ++(i))       if (!vis[a[i]]) {         vis[a[i]] = 1;         ans += c[i + 1];       }     return 0 * printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   int a[N], n, q;   long long sum[N << 2][11], mul[11] = {1};   long long SUM[11], LA[11];   int lazy[N << 2][11];   void pushup(int rt) {     for (int i = 0; i < 10; ++i) {       sum[rt][i] = sum[rt << 1][i] + sum[rt << 1 | 1][i];     }   }   void pushdown(int rt) {     for (int i = 0; i < 10; ++i)       SUM[i] = sum[rt << 1][i], LA[i] = lazy[rt << 1][i];     for (int i = 0; i < 10; ++i) {       int u = i, v = lazy[rt][i];       if (u == v) continue;       for (int j = 0; j < 10; ++j) {         if (lazy[rt << 1][j] == u) {           LA[j] = lazy[rt][i];         }       }       SUM[lazy[rt][i]] += sum[rt << 1][i];       SUM[i] -= sum[rt << 1][i];     }     for (int i = 0; i < 10; ++i)       sum[rt << 1][i] = SUM[i], lazy[rt << 1][i] = LA[i];     for (int i = 0; i < 10; ++i)       SUM[i] = sum[rt << 1 | 1][i], LA[i] = lazy[rt << 1 | 1][i];     for (int i = 0; i < 10; ++i) {       int u = i, v = lazy[rt][i];       if (u == v) continue;       for (int j = 0; j < 10; ++j) {         if (lazy[rt << 1 | 1][j] == u) {           LA[j] = lazy[rt][i];         }       }       SUM[lazy[rt][i]] += sum[rt << 1 | 1][i];       SUM[i] -= sum[rt << 1 | 1][i];     }     for (int i = 0; i < 10; ++i)       sum[rt << 1 | 1][i] = SUM[i], lazy[rt << 1 | 1][i] = LA[i];     for (int i = 0; i < 10; ++i) lazy[rt][i] = i;   }   void build(int l, int r, int rt) {     for (int i = 0; i < 10; ++i) lazy[rt][i] = i;     if (l == r) {       int x = a[l], index = 0;       while (x) {         int y = x % 10;         x /= 10;         sum[rt][y] += mul[index];         index++;       }       return;     }     int mid = (l + r) >> 1;     build(l, mid, rt << 1);     build(mid + 1, r, rt << 1 | 1);     pushup(rt);   }   void update(int l, int r, int rt, int L, int R, int x, int y) {     if (L <= l && r <= R) {       for (int j = 0; j < 10; ++j) {         if (lazy[rt][j] == x) {           lazy[rt][j] = y;           sum[rt][y] += sum[rt][x];           sum[rt][x] = 0;         }       }       return;     }     pushdown(rt);     int mid = (l + r) >> 1;     if (L <= mid) update(l, mid, rt << 1, L, R, x, y);     if (R > mid) update(mid + 1, r, rt << 1 | 1, L, R, x, y);     pushup(rt);   }   long long query(int l, int r, int rt, int L, int R) {     if (L <= l && r <= R) {       long long ret = 0;       for (int i = 0; i < 10; ++i) ret += sum[rt][i] * i;       return ret;     }     pushdown(rt);     int mid = (l + r) >> 1;     long long ret = 0;     if (L <= mid) ret += query(l, mid, rt << 1, L, R);     if (R > mid) ret += query(mid + 1, r, rt << 1 | 1, L, R);     return ret;   }   int main() {     for (int i = 1; i < 11; ++i) mul[i] = mul[i - 1] * 10;     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);     }     build(1, n, 1);     while (q--) {       int op, L, R, x, y;       scanf( %d , &op);       if (op == 1) {         scanf( %d%d%d%d , &L, &R, &x, &y);         if (x == y) continue;         update(1, n, 1, L, R, x, y);       } else {         scanf( %d%d , &L, &R);         printf( %lld n , query(1, n, 1, L, R));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1ll << 32;   const int mod = 1e9 + 7;   inline int add(int x, int y) {     x += y;     if (x >= mod) return x - mod;     return x;   }   inline int sub(int x, int y) {     x -= y;     if (x < 0) return x + mod;     return x;   }   inline int mul(int x, int y) { return (x * 1ll * y) % mod; }   inline int power(int x, int y) {     int ans = 1;     while (y) {       if (y & 1) ans = mul(ans, x);       x = mul(x, x);       y >>= 1;     }     return ans;   }   inline int inv(int x) { return power(x, mod - 2); }   const long long FACTORIAL_SIZE = 1.1e6;   long long fact[FACTORIAL_SIZE], ifact[FACTORIAL_SIZE];   void gen_factorial(long long n) {     fact[0] = fact[1] = ifact[0] = ifact[1] = 1;     for (long long i = 2; i <= n; i++) {       fact[i] = (i * fact[i - 1]) % mod;     }     ifact[n] = inv(fact[n]);     for (long long i = n - 1; i >= 2; i--) {       ifact[i] = ((i + 1) * ifact[i + 1]) % mod;     }   }   long long nck(long long n, long long k) {     long long den = (ifact[k] * ifact[n - k]) % mod;     return (den * fact[n]) % mod;   }   const int N = 300000;   long long f(string s) {     if (s ==  Tetrahedron ) return 4;     if (s ==  Cube ) return 6;     if (s ==  Octahedron ) return 8;     if (s ==  Dodecahedron ) return 12;     if (s ==  Icosahedron ) return 20;   }   void solve() {     long long n;     cin >> n;     long long ans = 0;     for (long long i = 0; i < n; i++) {       string s;       cin >> s;       ans += f(s);     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long tc = 1;     int i = 1;     while (tc--) {       solve();       i++;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   bool isvalid(long long x) {     if (x >= 0 && x <= n - 1)       return true;     else       return false;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     vector<long long> a(n);     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     sort(a.begin(), a.end());     vector<long long> b(n);     b[0] = a[n - 1];     long long i = n - 2;     long long j = n - 3;     long long right = 1;     long long left = n - 1;     while (true) {       if (isvalid(i)) {         b[right] = a[i];         right++;         i -= 2;       }       if (isvalid(j)) {         b[left] = a[j];         left--;         j -= 2;       }       if (isvalid(i) == false && isvalid(j) == false) break;     }     bool done = true;     if (b[0] >= b[1] + b[n - 1]) {       done = false;     }     if (b[n - 1] >= b[n - 2] + b[0]) {       done = false;     }     for (long long i = 1; i <= n - 2; i++) {       if (b[i] >= b[i - 1] + b[i + 1]) {         done = false;         break;       }     }     if (!done) {       cout <<  NO             <<   n ;     } else {       cout <<  YES             <<   n ;       for (long long i = 0; i < n; i++) {         cout << b[i] <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ans;   int main() {     int d, n, u, i, prev;     cin >> d >> n;     for (i = 0; i < n; i++) {       cin >> u;       if (i and prev != 1) ans += d - prev + 1;       prev = u + 1;       if (prev > d) prev -= d;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int ans = 1e9;       for (int i = 1; i * i <= n; i++) {         ans = min(ans, i - 1 + (n - i + i - 1) / i);       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   const int n = 7;   const int msiz = 1 << n;   const int mod = 1000000007;   int a[n];   int ans[msiz];   long long int tans[msiz];   struct matrix {     long long int cont[msiz][msiz];     matrix operator*(const matrix& r) const {       matrix p;       int i, j, k;       for (i = 0; i < msiz; i++) {         for (j = 0; j <= i; j++) {           p.cont[i][j] = 0;           for (k = 0; k < msiz; k++) {             p.cont[i][j] += cont[i][k] * r.cont[k][j];             p.cont[i][j] %= mod;           }         }       }       for (i = 0; i < msiz; i++) {         for (j = i + 1; j < msiz; j++) {           p.cont[i][j] = p.cont[j][i];         }       }       return p;     }   };   matrix q[4];   matrix pwr(int x) {     matrix res;     if (x == 0) {       int i, j;       for (i = 0; i < msiz; i++) {         for (j = 0; j < msiz; j++) {           if (i == j)             res.cont[i][j] = 1;           else             res.cont[i][j] = 0;         }       }       return res;     }     res = pwr(x / 4);     res = res * res;     res = res * res;     if (x % 4 != 0) res = res * q[x % 4];     return res;   }   int main() {     int i, j, k, l;     matrix p;     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     for (i = 0; i < msiz; i++) {       ans[i] = 0;     }     ans[0] = 1;     for (i = n; i > 0; i--) {       for (j = 0; j < msiz; j++) {         for (k = 0; k < msiz; k++) {           p.cont[j][k] = 0;         }       }       for (j = 0; j < (1 << i); j++) {         for (k = 0; k < (1 << i); k++) {           for (l = 0; l < (1 << (i - 1)); l++) {             if ((j | k | l | (l << 1)) == (1 << i) - 1) p.cont[j][k]++;           }         }       }       q[1] = p;       q[2] = p * p;       q[3] = q[2] * p;       p = pwr(a[i - 1]);       for (j = 0; j < msiz; j++) {         tans[j] = 0;         for (k = 0; k < msiz; k++) {           tans[j] += ans[k] * p.cont[j][k];           tans[j] %= mod;         }       }       for (j = 0; j < msiz; j++) ans[j] = tans[j];     }     printf( %d , ans[0]);   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int max_n = 1e5 + 5;   string q[max_n];   int dig[10][2];   int main() {     string s;     cin >> s;     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) cin >> q[i];     for (int i = 0; i <= 9; i++) {       dig[i][0] = i;       dig[i][1] = 10;     }     for (int i = n; i >= 1; i--) {       int d = q[i][0] -  0 ;       int len = q[i].length();       int sum = 0, pw = 1;       for (int j = 3; j < len; j++) {         int k = q[i][j] -  0 ;         sum = (1LL * sum * dig[k][1] % mod + dig[k][0]) % mod;         pw = 1LL * pw * dig[k][1] % mod;       }       dig[d][0] = sum;       dig[d][1] = pw;     }     int len = s.length();     int ans = 0;     for (int i = 0; i < len; i++) {       int d = s[i] -  0 ;       ans = (1LL * ans * dig[d][1] % mod + dig[d][0]) % mod;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 101000;   int n, z[N], a[N], b[N];   set<pair<int, int> > Set;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     for (int i = 0; i < n; i++) {       scanf( %d , &b[i]);     }     vector<int> ans;     for (int i = 0; i < n; i++) {       z[i] = a[i] - b[i];       if (i) z[i] += z[i - 1];       Set.insert(make_pair(z[i], i));     }     int line = 0;     for (int i = 0; i < n; i++) {       if (Set.begin()->first >= line) {         ans.push_back(i + 1);       }       line = z[i];     }     line = 0;     Set.clear();     for (int i = n - 1; i >= 0; i--) {       z[i] = a[i] - b[(i + n - 1) % n];       if (i != n - 1) z[i] += z[i + 1];       Set.insert(make_pair(z[i], i));     }     for (int i = n - 1; i >= 0; i--) {       if (Set.begin()->first >= line) {         ans.push_back(i + 1);       }       line = z[i];     }     sort(ans.begin(), ans.end());     ans.erase(unique(ans.begin(), ans.end()), ans.end());     printf( %d n , (int)ans.size());     for (__typeof((ans).begin()) it = (ans).begin(); it != (ans).end(); it++) {       printf( %d  , *it);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, r, m;   vector<int> h;   vector<long long> pref;   long long cost(long long goal) {     long long indexl = distance(h.begin(), lower_bound(h.begin(), h.end(), goal));     long long cost_a = 0;     if (indexl > 0) {       cost_a = goal * (indexl)-pref[indexl - 1];     }     long long indexh = distance(h.begin(), upper_bound(h.begin(), h.end(), goal));     long long cost_r =         pref[n - 1] - pref[indexh - 1] - (n - 1 - indexh + 1) * goal;     long long res = 0;     if (cost_a > cost_r) {       res = m * cost_r + (cost_a - cost_r) * a;     } else {       res = m * cost_a + (cost_r - cost_a) * r;     };     ;     ;     return res;   }   void solve() {     cin >> n >> a >> r >> m;     m = min(m, a + r);     h = vector<int>(n);     pref = vector<long long>(n);     for (int i = 0; i < n; ++i) {       cin >> h[i];     }     sort(h.begin(), h.end());     ;     for (int i = 0; i < n; ++i) {       if (i > 0) {         pref[i] = pref[i - 1] + h[i];       } else {         pref[i] = h[i];       }     }     long long answer = LLONG_MAX;     for (int i = 0; i < n; ++i) {       if (i > 0 && h[i] == h[i - 1]) {         continue;       }       answer = min(answer, cost((long long)h[i]));     }     answer = min(answer, cost((long long)(pref[n - 1] / n)));     answer = min(answer, cost((long long)(1 + pref[n - 1] / n)));     cout << answer << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     for (int i = 1; i <= t; ++i) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   typedef struct {     double x, y;   } point_t;   typedef struct {     double x, y, r;   } circle_t;   typedef struct {     double A, B, C;   } Line;   Line zhong_chui_xian(circle_t circle1, circle_t circle2) {     Line L1;     point_t p;     double k;     p.x = (circle1.x + circle2.x) / 2;     p.y = (circle1.y + circle2.y) / 2;     if (fabs(circle1.y - circle2.y) < 1E-8) {       L1.A = 1;       L1.B = 0;       L1.C = -p.x;     } else if (fabs(circle1.x - circle2.x) < 1E-8) {       L1.A = 0;       L1.B = 1;       L1.C = -p.y;     } else {       k = -1 / ((circle1.y - circle2.y) / (circle1.x - circle2.x));       L1.A = k;       L1.B = -1;       L1.C = p.y - k * p.x;     }     return L1;   }   int line_intersect(Line L1, Line L2, point_t& p) {     double d, d1, d2, d3;     d = L1.A * L2.B - L2.A * L1.B;     if (fabs(d) < 1E-8) {       d1 = L1.A / L2.A;       d2 = L1.B / L2.B;       d3 = L1.C / L2.C;       if (fabs(d1 - d2) < 1E-8 && fabs(d2 - d3) < 1E-8)         return 2;       else         return 0;     }     p.x = (L2.C * L1.B - L1.C * L2.B) / d;     p.y = (L2.A * L1.C - L1.A * L2.C) / d;     return 1;   }   circle_t yuan_guiji(circle_t circle1, circle_t circle2) {     circle_t circle3;     double keep1, keep2, keep3;     keep1 =         (circle2.r * circle2.r * circle1.x - circle1.r * circle1.r * circle2.x) /         (circle1.r * circle1.r - circle2.r * circle2.r);     keep2 =         (circle2.r * circle2.r * circle1.y - circle1.r * circle1.r * circle2.y) /         (circle1.r * circle1.r - circle2.r * circle2.r);     keep3 = (circle2.r * circle2.r * circle1.x * circle1.x -              circle1.r * circle1.r * circle2.x * circle2.x -              circle1.r * circle1.r * circle2.y * circle2.y +              circle2.r * circle2.r * circle1.y * circle1.y) /             (circle1.r * circle1.r - circle2.r * circle2.r);     circle3.x = -keep1;     circle3.y = -keep2;     circle3.r = sqrt(keep3 + keep1 * keep1 + keep2 * keep2);     return circle3;   }   int equa(double A, double B, double C, double& x1, double& x2) {     double f = B * B - 4 * A * C;     if (f < 0) return -1;     x1 = (-B + sqrt(f)) / (2 * A);     x2 = (-B - sqrt(f)) / (2 * A);     return 1;   }   double point_line_dis(point_t a, Line ln) {     return (fabs(ln.A * a.x + ln.B * a.y + ln.C) /             sqrt(ln.A * ln.A + ln.B * ln.B));   }   int line_circle_intersect(Line ln, circle_t Y, point_t& p1, point_t& p2) {     double t1, t2, len;     point_t p3;     p3.x = Y.x;     p3.y = Y.y;     len = point_line_dis(p3, ln);     if (len > Y.r) return 0;     int zz = -1;     if (fabs(ln.B) < 1e-8) {       p1.x = p2.x = -1.0 * ln.C / ln.A;       zz = equa(1.0, -2.0 * Y.y,                 Y.y * Y.y + (p1.x - Y.x) * (p1.x - Y.x) - Y.r * Y.r, t1, t2);       p1.y = t1;       p2.y = t2;     } else if (fabs(ln.A) < 1e-8) {       p1.y = p2.y = -1.0 * ln.C / ln.B;       zz = equa(1.0, -2.0 * Y.x,                 Y.x * Y.x + (p1.y - Y.y) * (p1.y - Y.y) - Y.r * Y.r, t1, t2);       p1.x = t1;       p2.x = t2;     } else {       zz = equa(           ln.A * ln.A + ln.B * ln.B,           2.0 * ln.A * ln.C + 2.0 * ln.A * ln.B * Y.y - 2.0 * ln.B * ln.B * Y.x,           ln.B * ln.B * Y.x * Y.x + ln.C * ln.C + 2 * ln.B * ln.C * Y.y +               ln.B * ln.B * Y.y * Y.y - ln.B * ln.B * Y.r * Y.r,           t1, t2);       p1.x = t1, p1.y = -1 * (ln.A / ln.B * t1 + ln.C / ln.B);       p2.x = t2, p2.y = -1 * (ln.A / ln.B * t2 + ln.C / ln.B);     }     if (p1.x - p2.x < 1E-8 && p1.y - p2.y < 1E-8)       return 1;     else       return 2;   }   double dist(double xa, double ya, double xb, double yb) {     return sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb));   }   double max(double a, double b) { return a > b ? a : b; }   double min(double a, double b) { return a < b ? a : b; }   int circle_intersect(circle_t A, circle_t B, point_t& ia, point_t& ib) {     if (A.x == B.x && A.y == B.y) return 5;     double dd = dist(A.x, A.y, B.x, B.y);     if (A.r + B.r + 1E-8 < dd) return 1;     double k, a, b, d, aa, bb, cc, c, drt;     k = A.r;     a = B.x - A.x;     b = B.y - A.y;     c = B.r;     d = (c * c) - (k * k) - (a * a) - (b * b);     aa = 4 * (a * a) + 4 * (b * b);     bb = 4 * b * d;     cc = (d * d) - 4 * (a * a) * (k * k);     drt = (bb * bb) - 4 * aa * cc;     if (drt < 0) return 5;     drt = sqrt(drt);     ia.y = (-bb + drt) / 2 / aa;     ib.y = (-bb - drt) / 2 / aa;     if (fabs(a) < 1E-8) {       ia.x = sqrt((k * k) - (ia.y * ia.y));       ib.x = -ia.x;     } else {       ia.x = (2 * b * ia.y + d) / -2 / a;       ib.x = (2 * b * ib.y + d) / -2 / a;     }     ia.x += A.x;     ia.y += A.y;     ib.x += A.x;     ib.y += A.y;     if (fabs(ia.y - ib.y) < 1E-8) {       if (fabs(A.r + B.r - dd) < 1E-8) return 2;       if (fabs(dd - (max(A.r, B.r) - min(A.r, B.r))) < 1E-8) return 3;     }     return 4;   }   int main() {     circle_t circle[3];     int i, count;     Line L1, L2;     point_t p, p1, p2;     circle_t circle1, circle2;     for (i = 0; i < 3; i++)       scanf( %lf%lf%lf , &circle[i].x, &circle[i].y, &circle[i].r);     if (fabs(circle[0].r - circle[1].r) < 1E-8) {       L1 = zhong_chui_xian(circle[0], circle[1]);       if (fabs(circle[1].r - circle[2].r) < 1E-8) {         L2 = zhong_chui_xian(circle[1], circle[2]);         line_intersect(L1, L2, p);         printf( %0.5lf %0.5lf n , p.x, p.y);       } else {         circle2 = yuan_guiji(circle[1], circle[2]);         count = line_circle_intersect(L1, circle2, p1, p2);         if (count == 1) {           printf( %0.5lf %0.5lf n , p1.x, p1.y);         } else if (count == 2) {           if ((circle[0].r / dist(circle[0].x, circle[0].y, p1.x, p1.y)) >               (circle[0].r / dist(circle[0].x, circle[0].y, p2.x, p2.y)))             printf( %0.5lf %0.5lf n , p1.x, p1.y);           else             printf( %0.5lf %0.5lf n , p2.x, p2.y);         }       }     } else {       circle1 = yuan_guiji(circle[0], circle[1]);       if (fabs(circle[1].r - circle[2].r) < 1E-8) {         L2 = zhong_chui_xian(circle[1], circle[2]);         count = line_circle_intersect(L2, circle1, p1, p2);         if (count == 1) {           printf( %0.5lf %0.5lf n , p1.x, p1.y);         } else if (count == 2) {           if ((circle[0].r / dist(circle[0].x, circle[0].y, p1.x, p1.y)) >               (circle[0].r / dist(circle[0].x, circle[0].y, p2.x, p2.y)))             printf( %0.5lf %0.5lf n , p1.x, p1.y);           else             printf( %0.5lf %0.5lf n , p2.x, p2.y);         }       } else {         circle2 = yuan_guiji(circle[1], circle[2]);         count = circle_intersect(circle1, circle2, p1, p2);         if (count == 2 || count == 3) {           printf( %0.5lf %0.5lf n , p1.x, p1.y);         } else if (count == 4) {           if ((circle[0].r / dist(circle[0].x, circle[0].y, p1.x, p1.y)) >               (circle[0].r / dist(circle[0].x, circle[0].y, p2.x, p2.y)))             printf( %0.5lf %0.5lf n , p1.x, p1.y);           else             printf( %0.5lf %0.5lf n , p2.x, p2.y);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   string to_string(pair<A, B> p);   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p);   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p);   string to_string(const string& s) { return     + s +    ; }   string to_string(const char* s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   string to_string(vector<bool> v) {     bool first = true;     string res =  { ;     for (int i = 0; i < static_cast<int>(v.size()); i++) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(v[i]);     }     res +=  } ;     return res;   }   template <size_t N>   string to_string(bitset<N> v) {     string res =   ;     for (size_t i = 0; i < N; i++) {       res += static_cast<char>( 0  + v[i]);     }     return res;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto& x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ) ;   }   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   const int mod = 1e9 + 7;   const int maxn = 200005;   const int inf = 1e9;   int tiempo[maxn], x[maxn], y[maxn], pref[maxn], dp[maxn];   void solve() {     int r, n;     cin >> r >> n;     for (int i = 1; i <= n; i++) {       cin >> tiempo[i] >> x[i] >> y[i];       dp[i] = -inf;     }     x[0] = y[0] = 1;     int ans = -inf;     for (int i = 1; i <= n; i++) {       for (int j = i - 1; j >= 0; j--) {         if (tiempo[i] - tiempo[j] > 2 * r) {           dp[i] = max(dp[i], pref[j] + 1);           break;         }         int dist = abs(x[i] - x[j]) + abs(y[i] - y[j]);         if (dist <= (tiempo[i] - tiempo[j])) {           dp[i] = max(dp[i], dp[j] + 1);         }       }       pref[i] = pref[i - 1];       pref[i] = max(pref[i], dp[i]);       ans = max(ans, pref[i]);     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   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;   const string task =   ;   template <class T>   T sqr(T x) {     return x * x;   }   const int nmax = 2100;   int a[nmax][nmax];   char s[nmax][nmax];   int n, res;   int x[nmax], y[nmax];   int main() {     int n;     cin >> n;     gets(s[0]);     for (int i = 0; i < (int)(n); i++) gets(s[i]);     for (int i = 0; i < (int)(n); i++)       for (int j = 0; j < (int)(n); j++) a[i][j] = s[i][j] -  0 ;     int res = 0;     memset(x, 0, sizeof x);     memset(y, 0, sizeof y);     for (int i = n - 1; i > 0; i--) {       for (int j = 0; i + j < n; j++) {         int now = a[i + j][j] + x[i + j] + y[j];         now = now & 1;         if (now) {           res++;           x[i + j]++;           y[j]++;         }       }     }     for (int i = 0; i < (int)(n); i++) a[i][i] = (a[i][i] + x[i] + y[i]) & 1;     memset(x, 0, sizeof x);     memset(y, 0, sizeof y);     for (int i = n - 1; i > 0; i--) {       for (int j = 0; i + j < n; j++) {         int now = a[j][i + j] + x[j] + y[i + j];         now = now & 1;         if (now) {           res++;           y[i + j]++;           x[j]++;         }       }     }     for (int i = 0; i < (int)(n); i++) a[i][i] = (a[i][i] + x[i] + y[i]) & 1;     for (int i = 0; i < (int)(n); i++)       if (a[i][i] == 1) res++;     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = (1ll << 60);   const int maxn = 10010;   long long dp[2][maxn], c;   int p[maxn], s[maxn];   int n, id;   int main() {     scanf( %d%I64d , &n, &c);     for (int i = 0; i < n; i++) scanf( %d , p + i);     for (int i = 0; i < n; i++) scanf( %d , s + i);     for (int i = 1; i <= n; i++) dp[0][i] = inf;     for (int i = 0; i < n; i++) {       for (int j = 0; j <= i + 1; j++) dp[id ^ 1][j] = inf;       for (int j = 0; j <= i; j++) {         dp[id ^ 1][j] = min(dp[id ^ 1][j], dp[id][j] + p[i] + c * j);         dp[id ^ 1][j + 1] = min(dp[id ^ 1][j + 1], dp[id][j] + s[i]);       }       id ^= 1;     }     long long res = inf;     for (int i = 0; i <= n; i++) res = min(res, dp[id][i]);     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void in(long long int &number) {     bool negative = false;     register int c;     number = 0;     c = getchar();     if (c ==  - ) {       negative = true;       c = getchar();     }     for (; (c > 47 && c < 58); c = getchar()) number = number * 10 + c - 48;     if (negative) number *= -1;   }   void in(int &number) {     bool negative = false;     register int c;     number = 0;     c = getchar();     if (c ==  - ) {       negative = true;       c = getchar();     }     for (; (c > 47 && c < 58); c = getchar()) number = number * 10 + c - 48;     if (negative) number *= -1;   }   int k[100005];   int main() {     int n, m;     in(n);     in(m);     memset(k, 0, sizeof(k));     vector<long long int> a(n);     for (int i = 0; i <= n - 1; i++) in(a[i]);     vector<int> dp(n);     dp[n - 1] = 1;     k[a[n - 1]] = 1;     for (int i = n - 2; i >= 0; i--) {       if (k[a[i]] == 0) {         dp[i] = dp[i + 1] + 1;         k[a[i]] = 1;       } else         dp[i] = dp[i + 1];     }     while (m--) {       int l;       in(l);       l--;       cout << dp[l] <<   n ;     }     return 0;   }


#include<bits/stdc++.h>   #define mx                          100005   #define lli                         long long int   #define ulli                        unsigned long long int   #define mset(a,b)                   memset(a, b, sizeof(a))   #define infile                      freopen( in.txt ,  r , stdin);   #define outfile                     freopen ( out.txt , w ,stdout);   #define fileclose                   fclose (stdin); fclose (stdout);   #define test_case                   lli T; cin>>T;for(lli t=1;t<=T;t++)   #define scani(x)                    scanf( %d ,&x);   #define printi(x)                   printf( %d n ,x);   #define scanli(x)                   scanf( %lld ,&x);   #define printli(x)                  printf( %lld n ,x);   #define frep(i,from,to)             for(lli i=from;i<=to;i++)   #define frev(i,from,to)             for(lli i=from;i>=to;i--)      using namespace std;      int main()   {          //infile       //outfile       test_case       {           lli n;           lli x,mini=2000000000,mi;           scanli(n);              frep(i,1,n)           {               cin>>x;               if(x<mini)               {                   mi=i;                   mini=x;               }           }           cout<<n-1<<  n ;           frep(j,1,n)           {               if(mi!=j)                  cout<<mi<<   <<j<<   <<mini<<   <<abs(mi-j)+mini<<  n ;           }             }       fileclose   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma )   #pragma GCC optimize( unroll-loops )   using namespace std;   long long int MOD = 998244353;   double eps = 1e-12;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int k, n, w, product = 0;     cin >> k >> n >> w;     for (int i = 1; i <= w; i++) {       product += (i * k);     }     long long int res = product - n;     if (res <= 0)       cout <<  0  << endl;     else       cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 32005;   int n, m, i, j, f;   int a[N];   long long ans;   int main() {     scanf( %d%d , &n, &m);     for (i = m + 1; i <= (n + 1) / 2; i++) {       for (j = m + 1; j < 2 * i; j++) {         f = (i * (2 * i - j) + (n + 1) * (2 * j - i)) / (i + j);         f = max(f, m);         if (f > n - m) continue;         a[i] += n - m - f;       }     }     for (i = m + 1; i <= (n + 1) / 2; i++) ans += 2 * a[i];     if (n % 2) ans -= a[i - 1];     printf( %I64d n , 3 * ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Mod = 1e9 + 7;   const double pi = 2 * acos(0.0);   const int N = 3e5 + 5;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, t;     cin >> t;     while (t--) {       cin >> n;       int x, z = 0, tot = 0;       for (int i = 0; i < n; i++) {         cin >> x;         if (!x) z++;         tot += x;       }       cout << z + ((tot + z) == 0) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x;   int a[105];   long double dp[2][105][10005];   const long double threshold = 1e-12;   int main() {     scanf( %d%d , &n, &x);     long double s = 0.0;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       s += a[i];     }     dp[0][0][0] = 1.0;     for (int i = 0; i < n; i++) {       int now = i & 1, nxt = now ^ 1;       memset(dp[nxt], 0, sizeof(dp[nxt]));       for (int j = 0; j <= i; j++) {         for (int k = 0; k <= 10000; k++) {           dp[nxt][j][k] += dp[now][j][k];           dp[nxt][j + 1][k + a[i + 1]] += dp[now][j][k] * (j + 1) / (n - j);         }       }     }     long double ans = 0.0;     for (int i = 0; i <= n - 1; i++)       for (int j = 0; j <= s; j++)         ans += dp[n & 1][i][j] *                (min((s - j) / (n - i), ((long double)n / (n - i) + 1) * x / 2.0));     printf( %.10Lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int MOD = 1000000007;   const long double PI = 3.14159265;   long long int powerWithMod(long long int base, long long int exponent,                              long long int MODulus = LLONG_MAX) {     long long int ansult = 1;     base %= MODulus;     while (exponent > 0) {       if (exponent % 2 == 1) ansult = (ansult * base) % MODulus;       exponent >>= 1;       base = (base * base) % MODulus;     }     return ansult;   }   long long int gcdExtended(long long int a, long long int b, long long int *x,                             long long int *y) {     cout << a <<     << b <<     << *x <<     << *y <<   n ;     if (a == 0) {       *x = 0, *y = 1;       return b;     }     long long int x1, y1;     long long int gcd = gcdExtended(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     cout <<  AFTER   << a <<     << b <<     << *x <<     << *y <<   n ;     return gcd;   }   long long int MODInverse(long long int a, long long int m) {     long long int x, y;     long long int g = gcdExtended(a, m, &x, &y);     cout << g <<     << x <<     << y <<   n ;     long long int ans = (x % m + m) % m;     return ans;   }   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long int n, a = 0, x, m = 0;     cin >> n;     for (int i = 1; i <= n; i++) cin >> x, a += x, m = max(x, m);     cout << max(m, (a + n - 2) / (n - 1)) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 100005;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     {       long long int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;       cin >> n;       vector<long long int> v;       long long int a[n];       j = 0;       ans = 0;       for (i = 0; i < n; i++) {         cin >> a[i];         if (a[i] < 0) {           j++;           if (j == 3) {             v.push_back(i - ans);             cnt++;             ans = i;             j = 1;           }         }         if (i == n - 1) {           v.push_back(i - ans + 1);           cnt++;         }       }       cout << max((long long int)1, cnt) << endl;       for (auto x : v) {         cout << x <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e7;   const long long MOD = 998244353;   vector<vector<int> > occur;   vector<vector<long long> > minC, dp;   long long gV(int l, int r) {     if (l == r + 1) {       return 1;     }     return dp[l][r];   }   void calc(int l, int r) {     int cMinC = minC[l][r];     vector<int> &cOccur = occur[cMinC];     int fI = cOccur[0];     int lI = cOccur[cOccur.size() - 1];     if (fI < l || r < lI) {       dp[l][r] = 0;       return;     }     long long sumR = 0;     for (int nR = lI; nR <= r; nR++) {       sumR = (sumR + gV(lI + 1, nR) * gV(nR + 1, r)) % MOD;     }     long long sumL = 0;     for (int nL = fI; nL >= l; nL--) {       sumL = (sumL + gV(l, nL - 1) * gV(nL, fI - 1)) % MOD;     }     long long inProd = 1;     for (int i = 0; i + 1 < cOccur.size(); i++) {       inProd = inProd * gV(cOccur[i] + 1, cOccur[i + 1] - 1) % MOD;     }     dp[l][r] = (sumL * sumR % MOD) * inProd % MOD;   }   int main() {     int N, M;     cin >> M >> N;     vector<int> a;     for (int i = 0; i < N; i++) {       int x;       cin >> x;       x--;       if (a.empty() || a[a.size() - 1] != x) {         a.push_back(x);       }     }     N = a.size();     if (N > 2 * M) {       cout << 0 << endl;       return 0;     }     minC.resize(N);     for (int i = 0; i < N; i++) {       minC[i].resize(N);       int cMin = a[i];       for (int j = i; j < N; j++) {         cMin = min(cMin, a[j]);         minC[i][j] = cMin;       }     }     occur.resize(M);     for (int i = 0; i < N; i++) {       occur[a[i]].push_back(i);     }     dp.resize(N);     for (int i = 0; i < N; i++) {       dp[i].resize(N);       fill(dp[i].begin(), dp[i].end(), 0);     }     for (int len = 1; len <= N; len++) {       for (int l = 0; l < N; l++) {         int r = l + len - 1;         if (r >= N) {           continue;         }         calc(l, r);       }     }     cout << dp[0][N - 1] << endl;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK: 2000000 )   using namespace std;   int main(void) {     srand(time(0));     cout << fixed << setprecision(7);     cerr << fixed << setprecision(7);     int n;     ios_base ::sync_with_stdio(0);     cin.tie(0);     cin >> n;     function<int(int)> ok = [&](int k) {       return !k ? 0 : ok(k / 10) | ((k % 10 != 4) && (k % 10 != 7));     };     static int f[1 << 20];     for (int i = 1; i <= n; ++i) f[i] = i;     function<int(int)> get = [&](int k) {       return k == f[k] ? k : f[k] = get(f[k]);     };     for (int i = 1; i < n; ++i) {       int a, b, c;       cin >> a >> b >> c;       if (ok(c)) f[get(a)] = get(b);     }     static int S[1 << 20];     for (int i = 1; i <= n; ++i) ++S[get(i)];     long long ans = 0;     for (int i = 1; i <= n; ++i)       ans += 1ll * (n - S[get(i)]) * (n - S[get(i)] - 1);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   vector<long long> v[100009], vv[100009];   long long vis[100009], dis[101][100001], ar[100001];   void bfs(long long k) {     queue<long long> q;     memset(vis, 0, sizeof(vis));     for (long long x : vv[k]) {       q.push(x);       vis[x] = 1;       dis[k][x] = 0;     }     while (!q.empty()) {       long long x = q.front();       q.pop();       for (long long y : v[x]) {         if (!vis[y]) {           vis[y] = 1;           q.push(y);           dis[k][y] = dis[k][x] + 1;         }       }     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m, k, s, ans = 1e15;     cin >> n >> m >> k >> s;     for (long long i = 1; i <= n; i++) {       cin >> ar[i];       vv[ar[i]].push_back(i);     }     for (long long i = 0; i < m; i++) {       long long x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     for (long long i = 1; i <= k; i++) bfs(i);     for (long long i = 1; i <= n; i++) {       vector<long long> hh;       long long as = 0;       for (long long j = 1; j <= k; j++) hh.push_back(dis[j][i]);       sort(hh.begin(), hh.end());       for (long long j = 0; j < s; j++) as += hh[j];       cout << as <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 4e5 + 5;   const int MAXM = 2e5 + 5;   const int MOD = 998244353;   const int INF = 0x3f3f3f3f;   int a[MAXN], sum[MAXN];   vector<int> v;   map<int, int> mp;   int main() {     int n, I;     scanf( %d%d , &n, &I);     mp.clear();     memset(sum, 0, sizeof(sum));     int B = I * 8;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       if (mp.find(a[i]) == mp.end()) {         mp[a[i]] = 1;       } else {         ++mp[a[i]];       }       v.emplace_back(a[i]);     }     sort(a + 1, a + n + 1);     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());     int sz = v.size(), K;     for (int i = sz; i >= 1; --i) {       if (n * int(ceil(log2(i))) <= B) {         K = i;         break;       }     }     for (int i = 0; i < sz; ++i) {       if (i == 0)         sum[i] = mp[v[i]];       else         sum[i] = sum[i - 1] + mp[v[i]];     }     int ans = n, tmp = 0;     for (int i = 0; i <= max(sz - K, 0); ++i) {       tmp = 0;       if (i != 0) tmp += sum[i - 1];       tmp += sum[sz - 1] - sum[min(i + K - 1, sz - 1)];       ans = min(tmp, ans);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, i, high, low, mid, nstr, ninte;   int main() {     scanf( %lld , &a);     long long ans[a], str[a], inte[a], exp[a];     for (i = 0; i < a; i++) {       scanf( %lld %lld %lld , &str[i], &inte[i], &exp[i]);     }     for (i = 0; i < a; i++) {       high = exp[i];       low = 0;       ans[i] = 0;       while (low <= high) {         mid = (high + low) / 2;         nstr = str[i] + mid;         ninte = inte[i] + (exp[i] - mid);         if (nstr > ninte) {           ans[i] = (exp[i] + 1) - mid;           high = mid - 1;         } else {           low = mid + 1;         }       }     }     for (i = 0; i < a; i++) {       printf( %lld n , ans[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a1, a2, b1, b2, k = 1, f = 0, ans = 0;     scanf( %d , &n);     while (k <= 4) {       scanf( %d%d%d%d , &a1, &a2, &b1, &b2);       if (n >= a1 + b1 || n >= a1 + b2)         ans = a1;       else if (n >= a2 + b1 || n >= a2 + b2)         ans = a2;       if (ans > 0) {         f = 1;         printf( %d %d %d , k, ans, n - ans);         break;       }       k++;     }     if (f == 0) printf( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<int> s;   vector<vector<int> > v;   bool ch[100005];   void go(int i) {     ch[i] = true;     int z = 0;     for (auto it : v[i]) {       if (ch[it] == false) {         z++;         go(it);       }     }     if (z == 0) {       s.insert(i);     }   }   void dynamic() {     int n;     cin >> n;     long double sum = 0;     cin >> sum;     v.resize(n + 1);     memset(ch, 0, sizeof(ch));     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     go(1);     int z = s.size();     if (v[1].size() == 1) {       z++;     }     sum = sum / z;     sum *= 2;     cout << setprecision(12) << sum <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     t = 1;     while (t--) {       dynamic();     }   }


#include <bits/stdc++.h>   using namespace std;   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b);   long long int gcd(long long int a, long long int b);   int prime(int n);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1;     while (t--) {       long long int n, m, sum;       cin >> n >> m;       long long int a[n];       for (int i = 0; i < n; i++) cin >> a[i];       sort(a, a + n, greater<int>());       for (int k = 1; k <= n; k++) {         sum = 0;         for (int i = 0; i < n; i++) {           sum += max(0LL, a[i] - (i / k));         }         if (sum >= m) {           cout << k << endl;           break;         }       }       if (sum < m) cout << -1 << endl;     }   }   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int prime(int n) {     int flag = 1;     for (int i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         flag = 0;         break;       }     }     return flag;   }


#include <bits/stdc++.h>   using namespace std;   const int D[8][2] = {{1, 0},  {0, 1},  {-1, 0},  {0, -1},                        {1, -1}, {-1, 1}, {-1, -1}, {1, 1}};   int N, M, K, f[600005], F[3005][6005], b[600005], tot;   int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }   bool can(int& x, int& y) {     if (!y) y = 2 * M;     if (y > 2 * M) y = 1;     return 1 <= x && x <= N && F[x][y];   }   bool check(int x, int y) {     tot++;     int xx, yy;     for (int i = 0; i < 8; i++)       if (can(xx = x + D[i][0], yy = y + D[i][1])) b[find(F[xx][yy])] = tot;     for (int i = 0; i < 8; i++)       if (can(xx = x + D[i][0], yy = y + M + D[i][1]) &&           b[find(F[xx][yy])] == tot)         return 0;     return 1;   }   void add(int x, int y, int z) {     F[x][y] = z;     for (int i = 0; i < 8; i++) {       int xx = x + D[i][0], yy = y + D[i][1];       if (can(xx, yy)) f[find(F[xx][yy])] = find(z);     }   }   void doit() {     int ans = 0;     scanf( %d%d%d , &N, &M, &K);     if (M == 1) {       puts( 0 );       return;     }     for (int i = 1; i <= 2 * K; i++) f[i] = i;     for (int i = 1, x, y; i <= K; i++) {       scanf( %d%d , &x, &y);       if (check(x, y)) add(x, y, i), add(x, y + M, i + K), ans++;     }     printf( %d n , ans);   }   int main() {     doit();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[3] = {0, 0, 0}, s;   int main() {     string n;     getline(cin, n);     string x;     getline(cin, x);     s = x.size();     s = (s + 1) / 2;     for (int i = 0; i < 2 * s - 1; i += 2) {       if (x[i] ==  1 ) a[0]++;       if (x[i] ==  2 ) a[1]++;       if (x[i] ==  3 ) a[2]++;     }     cout << s - max(a[0], max(a[1], a[2]));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b, d, p, q, s, t, r;     cin >> a >> b >> d;     p = a + a + b + b;     q = a + d + b;     s = a + d + d + a;     t = b + d + d + b;     r = min(p, min(q, min(s, t)));     cout << r << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Print() { cout << endl; }   template <typename T1, typename... T>   void Print(const T1 &t1, const T &...t) {     cout << t1 <<    ;     Print(t...);   }   template <typename T1, typename T2>   ostream &operator<<(ostream &os, const pair<T1, T2> &p) {     os <<  (  << p.first <<  ,   << p.second <<  ) ;     return os;   }   long long gcd(long long a, long long b) {     if (b) {       long long r = a % b;       a = b, b = r;     }     return a;   }   tuple<long long, long long, long long> extend_gcd(long long a, long long b) {     if (b == 0)       return make_tuple(a, 1, 0);     else {       long long g, nx, ny;       std::tie(g, nx, ny) = extend_gcd(b, a % b);       return make_tuple(g, ny, nx - (a / b) * ny);     }   }   long long fastpow(long long a, long long e, long long mod) {     if (e == 0) return 1;     if (e == 1) return a % mod;     long long t = fastpow(a, e / 2, mod);     t = t * t % mod;     if (e & 1)       return t * a % mod;     else       return t % mod;   }   const double PI = 3.14159265358979323846;   const int MOD = (int)1e9 + 7;   char s[100007], t[100007];   int n, m;   long long dp[100007], psum[100007];   vector<int> process() {     vector<int> p(2);     int last = 0;     for (int i = 2; i <= m; i++) {       while (last > 0 && t[i] != t[last + 1]) last = p[last];       if (t[i] == t[last + 1])         p.push_back(++last);       else         p.push_back(last);     }     return p;   }   int main() {     scanf( %s %s , s + 1, t + 1);     n = strlen(s + 1);     m = strlen(t + 1);     auto pre = process();     unordered_set<int> pos;     int last = 0;     for (int i = 1; i <= n; i++) {       while (last > 0 && s[i] != t[last + 1]) last = pre[last];       if (s[i] == t[last + 1]) {         last++;         if (last == m) {           pos.insert(i);           last = pre[last];         }       }     }     long long ans = 0;     last = -1;     dp[0] = 1, psum[0] = 1;     for (int i = 1; i <= n; i++) {       if (!pos.count(i) && last == -1) {         dp[i] = 1;       } else if (pos.count(i)) {         dp[i] = (psum[i - m] + dp[i - 1]) % MOD;         last = i;       } else {         dp[i] = (psum[last - m] + dp[i - 1]) % MOD;       }       psum[i] = (dp[i] + psum[i - 1]) % MOD;     }     printf( %lld n , (dp[n] + MOD - 1) % MOD);   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10;   const int inf = 1000000009;   int i, j, k, m, n, l;   int ans;   int f(int n, int m) {     return n < m ? (n + (n % 2) * (m - 1)) / 2 : f(n - m, 2 * m);   }   int main() {     cin >> n;     cout << (n < 2 ? 0 : f(n - 2, 2)) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAX = 100005;   const long long mod = 1000000007;   const double PI = 2 * acos(0.0);   const double EPS = 0.00000000001;   int main() {     long long n;     cin >> n;     string a, b;     cin >> a >> b;     long long OO = 0, II = 0, IO = 0, OI = 0;     for (long long i = 0; i < n; i++) {       if (a[i] ==  1  and b[i] ==  1 )         II++;       else if (a[i] ==  0  and b[i] ==  0 )         OO++;       else if (a[i] ==  1  and b[i] ==  0 )         IO++;       else if (a[i] ==  0  and b[i] ==  1 )         OI++;     }     long long ans = (OO * II) + (OI * IO) + (OO * IO);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 5;   long long a[N];   long long p[N];   long long size[N];   long long n;   long long root(long long v) {     if (v != p[v]) {       return p[v] = root(p[v]);     }     return v;   }   void fix(long long v, long long x) {     if (v == n + 1) return;     p[v] = v + 1;     long long r = root(p[v]);     p[v] = r;     if (size[r] + x <= a[r]) {       size[r] += x;       return;     } else {       long long excess = size[r] + x - a[r];       size[r] = a[r];       fix(r, excess);     }     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       p[i] = i;       size[i] = 0;     }     p[n + 1] = n + 1;     long long q;     cin >> q;     while (q--) {       long long type, x, k;       cin >> type;       if (type == 1) {         cin >> k >> x;         if (size[k] + x <= a[k]) {           size[k] += x;         } else {           long long excess = size[k] + x - a[k];           size[k] = a[k];           if (k == n) continue;           fix(k, excess);         }       } else {         cin >> k;         cout << size[k] <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int v = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       v = v * 10 + c -  0 ;       c = getchar();     }     return v * f;   }   const int Maxn = 100005;   int bit[5005][10005];   int bt[10005];   void Add(int x) {     assert(x);     while (x < 10005) {       bt[x]++;       x += x & -x;     }   }   int Query(int x) {     int ans = 0;     while (x) {       ans += bt[x];       x -= x & -x;     }     return ans;   }   void add(int x, int y) {     assert(x && y);     for (int i = x; i < 5005; i += i & -i) {       for (int j = y; j < 10005; j += j & -j) {         bit[i][j]++;       }     }   }   int query(int x, int y) {     int ret = 0;     for (int i = x; i; i -= i & -i) {       for (int j = y; j; j -= j & -j) {         ret += bit[i][j];       }     }     return ret;   }   int dir[Maxn], x[Maxn], y[Maxn], len[Maxn];   int ans[Maxn];   int n, q;   void Rot() {     for (int i = 0; i < q; i++) {       swap(x[i], y[i]);       x[i] = -x[i];     }     int Minx = 1e9, Miny = 1e9;     for (int i = 0; i < q; i++) {       Minx = min(Minx, x[i]);       Miny = min(Miny, y[i]);     }     for (int i = 0; i < q; i++) {       x[i] = x[i] - Minx + 1;       y[i] = y[i] - Miny + 1;     }   }   void Solve(int D) {     int cnt = 0;     for (int i = 0; i < q; i++) {       if (dir[i] == D) {         cnt++;       } else if (dir[i] == -1) {         ans[i] += cnt;       }     }     memset(bt, 0, sizeof(bt));     for (int i = 0; i < q; i++) {       if (dir[i] == D) {         Add(5001 - (x[i] - 1));       } else if (dir[i] == -1) {         ans[i] -= Query(5001 - (x[i]));       }     }     memset(bt, 0, sizeof(bt));     for (int i = 0; i < q; i++) {       if (dir[i] == D) {         Add(5001 - (y[i] - 1));       } else if (dir[i] == -1) {         ans[i] -= Query(5001 - y[i]);       }     }     memset(bt, 0, sizeof(bt));     for (int i = 0; i < q; i++) {       if (dir[i] == D) {         Add(x[i] + y[i] + len[i] + 1);       } else if (dir[i] == -1) {         ans[i] -= Query(x[i] + y[i]);       }     }     memset(bit, 0, sizeof(bit));     for (int i = 0; i < q; i++) {       if (dir[i] == D) {         add(5001 - (x[i] - 1), 5001 - (y[i] - 1));       } else if (dir[i] == -1) {         ans[i] += query(5001 - x[i], 5001 - y[i]);       }     }     memset(bit, 0, sizeof(bit));     for (int i = 0; i < q; i++) {       if (dir[i] == D) {         add(5001 - (x[i] - 1), x[i] + y[i] + len[i] + 1);       } else if (dir[i] == -1) {         ans[i] += query(5001 - x[i], x[i] + y[i]);       }     }     memset(bit, 0, sizeof(bit));     for (int i = 0; i < q; i++) {       if (dir[i] == D) {         add(5001 - (y[i] - 1), x[i] + y[i] + len[i] + 1);       } else if (dir[i] == -1) {         ans[i] += query(5001 - y[i], x[i] + y[i]);       }     }   }   int main() {     scanf( %d %d , &n, &q);     for (int i = 0; i < q; i++) {       int tp;       scanf( %d , &tp);       if (tp == 1) {         scanf( %d %d %d %d , &dir[i], &x[i], &y[i], &len[i]);         if (dir[i] >= 3) dir[i] = 7 - dir[i];       } else {         scanf( %d %d , &x[i], &y[i]);         dir[i] = -1;       }     }     for (int i = 1; i <= 4; i++) {       Solve(i);       Rot();     }     for (int i = 0; i < q; i++) {       if (dir[i] == -1) {         printf( %d n , ans[i]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int s = 0;     char ch = getchar();     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) s = s * 10 + ch -  0 , ch = getchar();     return s;   }   inline char getch() {     char ch = getchar();     while (!islower(ch)) ch = getchar();     return ch;   }   const int N = 20005;   int n, m, u, v, x, y, c1, c2, ans;   int dfn[N], dep[N], fa[N], dfn_t, pos[N], ab[N];   int tag[N], len[N], type[N];   char s[N], t[N], fw[N];   vector<pair<int, char> > G[N];   void dfs(int u, int f) {     dep[u] = dep[f] + 1, fa[u] = f;     dfn[u] = ++dfn_t, pos[dfn_t] = u;     ab[dfn[u]] = dfn[f];     for (auto v : G[u]) {       if (v.first == f) continue;       fw[v.first] = v.second;       dfs(v.first, u);     }   }   int main() {     n = read(), m = read();     for (int i = 1; i < n; i++) {       u = read(), v = read();       char c = getch();       G[u].emplace_back(v, c);       G[v].emplace_back(u, c);     }     dfs(1, 0);     for (int T = 1; T <= m; T++) {       memset(s + 1, 0, n * sizeof(char));       u = x = read(), v = y = read();       c1 = c2 = 0;       while (u != v)         dep[u] > dep[v] ? (s[++c1] = fw[u], u = fa[u])                         : (t[++c2] = fw[v], v = fa[v]);       for (; c2;) s[++c1] = t[c2--];       type[dfn[x]] = len[dfn[x]] = 0, tag[dfn[x]] = T;       ans = 0;       for (int i = dfn[x]; ab[i];) {         tag[ab[i]] = T, len[ab[i]] = len[i] + 1;         type[ab[i]] =             (type[i]                  ? type[i]                  : ((fw[pos[i]] > s[len[ab[i]]]) - (fw[pos[i]] < s[len[ab[i]]])));         i = ab[i];         if (type[i] == -1 || (!type[i] && len[i] < c1)) ++ans;       }       for (int i = 2; i <= n; i++) {         if (tag[i] != T) {           len[i] = len[ab[i]] + 1;           type[i] = (type[ab[i]]                          ? type[ab[i]]                          : ((fw[pos[i]] > s[len[i]]) - (fw[pos[i]] < s[len[i]])));           if (type[i] == -1 || (!type[i] && len[i] < c1)) ++ans;         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   int a[maxn], cnt[maxn], tmp[maxn];   int main(void) {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);       if (a[i] <= m) cnt[a[i]]++;     }     for (int i = 1; i <= m; i++)       for (int k = 1; k * i <= m; k++) tmp[k * i] += cnt[i];     int M = -1, p;     for (int i = 1; i <= m; i++)       if (tmp[i] > M) M = tmp[i], p = i;     printf( %d %d n , p, M);     for (int i = 1; i <= n; i++)       if (p % a[i] == 0) printf( %d  , i);     return 0;   }


#include <bits/stdc++.h>   long long int const MOD = 1000000007;   long long int const N = 1000005;   long long int const LN = 20;   long long int const inf = 8e18;   using namespace std;   long long int n, m, a[N];   vector<pair<long long int, long long int> > v[N];   struct data {     long long int d, second, prev, idx;     data(long long int d, long long int second, long long int prev,          long long int idx) {       this->d = d;       this->second = second;       this->prev = prev;       this->idx = idx;     }     bool operator<(data other) const {       if (d != other.d) return d < other.d;       if (second != other.second) return second < other.second;       if (prev != other.prev) return prev < other.prev;       if (idx != other.idx) return idx < other.idx;       return 0;     }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     long long int n, m, k;     cin >> n >> m >> k;     for (long long int i = 1; i <= m; i++) {       long long int a, b, c;       cin >> a >> b >> c;       v[a].push_back({c, b});       v[b].push_back({c, a});     }     for (long long int i = 1; i <= n; i++) sort(v[i].begin(), v[i].end());     set<pair<long long int, long long int> > st;     set<data> q;     for (long long int i = 1; i <= n; i++) {       st.insert({i, i});       q.insert(data(v[i][0].first, i, i, 0));     }     k = 2 * k;     while (!q.empty()) {       data cur = *q.begin();       q.erase(cur);       long long int nxt = v[cur.prev][cur.idx].second;       if (st.find({cur.second, nxt}) == st.end()) {         st.insert({cur.second, nxt});         k--;         if (k == 0) {           cout << cur.d <<   n ;           return 0;         }         q.insert(data(cur.d + v[nxt][0].first, cur.second, nxt, 0));       }       if (cur.idx + 1 < v[cur.prev].size())         q.insert(data(             cur.d - v[cur.prev][cur.idx].first + v[cur.prev][cur.idx + 1].first,             cur.second, cur.prev, cur.idx + 1));     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int x;       cin >> x;       int divisor = 1;       int digits;       int ans = 0;       for (; divisor <= 9; divisor++) {         if (x / divisor == 1 && x % divisor == 0) {           digits = 1;           break;         } else if (x / divisor == 11 && x % divisor == 0) {           digits = 2;           break;         } else if (x / divisor == 111 && x % divisor == 0) {           digits = 3;           break;         } else if (x / divisor == 1111 && x % divisor == 0) {           digits = 4;           break;         }       }       ans = ans + 10 * (divisor - 1);       ans = ans + ((digits) * (digits + 1)) / 2;       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   set<long long> tp;   long long tmp[100002], x, y, z, t;   char ch;   int main() {     int n, k;     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %lld%c%lld%c%lld%c%lld , &x, &ch, &y, &ch, &z, &ch, &t);       tmp[i] = t + (1 << 8) * z + (1 << 16) * y + (1 << 24) * x;     }     long long sum = 0LL;     bool mn = false;     for (int i = 31; i >= 0; i--) {       sum += (1LL << i);       tp.clear();       for (int j = 1; j <= n; j++) {         tp.insert((tmp[j] & sum));       }       if (tp.size() == k) {         int ans = 0;         for (int i = 31; i > 23; i--) {           ans = ans * 2;           if ((1LL << i) & sum) ans++;         }         printf( %d. , ans);         ans = 0;         for (int i = 23; i > 15; i--) {           ans = ans * 2;           if ((1LL << i) & sum) ans++;         }         printf( %d. , ans);         ans = 0;         for (int i = 15; i > 7; i--) {           ans = ans * 2;           if ((1LL << i) & sum) ans++;         }         printf( %d. , ans);         ans = 0;         for (int i = 7; i >= 0; i--) {           ans = ans * 2;           if ((1LL << i) & sum) ans++;         }         printf( %d , ans);         ans = 0;         mn = true;         break;       }     }     if (mn == false) printf( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> child;     int n, k;     scanf( %d %d , &n, &k);     int *A = new int[k];     for (int i = 0; i < k; ++i) {       scanf( %d , &A[i]);     }     for (int i = 0; i < n; ++i) {       child.push_back(i + 1);     }     int count = 0;     for (int i = 0; i < k; ++i) {       count += A[i];       count = count % (n - i);       printf( %d  , child[count]);       child.erase(child.begin() + count);       if (count >= child.size()) count = 0;     }     return 0;   }


#include <bits/stdc++.h>   char g[64][64];   int h[64][64];   void conv(long long x, long long y, long long a, long long b, long long *dx,             long long *dy) {     long long k, l;     k = x - y + b * 2000000000LL;     l = x + y + a * 2000000000LL;     *dx = k / (2 * b) - 1000000000LL;     *dy = l / (2 * a) - 1000000000LL;   }   void solve(int x1, int y1, int x2, int y2, int a, int b) {     long long c, d, e, f, g, h, i;     conv(x1, y1, a, b, &c, &d);     conv(x2, y2, a, b, &e, &f);     g = c - e;     if (g < 0) g = -g;     h = d - f;     if (h < 0) h = -h;     i = g > h ? g : h;     printf( %d n , i);   }   int main() {     int i, j, u, v;     int a, b, x1, y1, x2, y2;     long long A, B;     long long k, l;     memset(g, 0, sizeof(g));     scanf( %d %d %d %d %d %d , &a, &b, &x1, &y1, &x2, &y2);     solve(x1, y1, x2, y2, a, b);     return 0;   }


#include <bits/stdc++.h>   long long k, m = 9, l, c, lc, n, md, tr = 1, fl, res;   int main() {     scanf( %lld , &k);     while (1) {       l++;       lc += m * l;       if (k - lc <= 0) {         c = k - (lc - m * l);         break;       }       m *= 10;       tr *= 10;     }     n = (c + l - 1) / l;     tr = tr + n - 1;     md = c % l;     if (md == 0) md += l;     while (1) {       res = tr % 10;       tr /= 10;       if (l - fl == md) {         printf( %lld , res);         return 0;       }       fl++;     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();     return x * f;   }   inline void write(int x, char end =    ) {     char F[200];     int tmp = x > 0 ? x : -x, cnt = 0;     if (x == 0) putchar( 0 );     if (x < 0) putchar( - );     while (tmp > 0) F[cnt++] = tmp % 10 +  0 , tmp /= 10;     while (cnt > 0) putchar(F[--cnt]);     putchar(end);   }   void f(int a, int b) { write(a), write(b,   n ); }   int main() {     n = read();     if (n % 4 >= 2) return puts( NO ), 0;     puts( YES );     for (int i = 1; i < n; i += 2) {       for (int j = i + 2; j < n; j += 2)         f(i, j), f(i + 1, j + 1), f(i, j + 1), f(i + 1, j);       if (n % 4 == 1)         f(i, n), f(i, i + 1), f(i + 1, n);       else         f(i, i + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 100;   const int inf = 0x7ffffff;   int a[maxn];   long long dp[maxn];   int main(void) {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     dp[0] = 0;     for (int i = 1; i <= n; i++) {       dp[i] = dp[i - 1] + 20;       int pos1 = lower_bound(a + 1, a + n + 1, a[i] - 90 + 1) - a - 1;       int pos2 = lower_bound(a + 1, a + n + 1, a[i] - 1440 + 1) - a - 1;       long long t1 = (i - pos1 + 1) * 20;       long long t2 = (i - pos2 + 1) * 20;       dp[i] = min(dp[i], dp[pos1] + min(50LL, t1));       dp[i] = min(dp[i], dp[pos2] + min(120LL, t2));       printf( %I64d n , dp[i] - dp[i - 1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000005;   const int MAXN = 1e5 + 5;   const int LG = 22;   int dp[51][51][51][51];   int n;   int a[55][55];   int get(int tli, int tlj, int rbi, int rbj) {     int res = a[rbi][rbj];     if (tli > 0) res = res - a[tli - 1][rbj];     if (tlj > 0) res = res - a[rbi][tlj - 1];     if (tli > 0 && tlj > 0) res = res + a[tli - 1][tlj - 1];     return res;   }   int foo(int r1, int r2, int c1, int c2) {     if (r1 > r2 or c1 > c2) return 0;     if (dp[r1][r2][c1][c2] != -1) return dp[r1][r2][c1][c2];     int ans = (get(r1, c1, r2, c2) > 0) * max(r2 - r1 + 1, c2 - c1 + 1);     for (int i = r1; i < r2; i++) {       ans = min(ans, foo(r1, i, c1, c2) + foo(i + 1, r2, c1, c2));     }     for (int i = c1; i < c2; i++) {       ans = min(ans, foo(r1, r2, c1, i) + foo(r1, r2, i + 1, c2));     }     return dp[r1][r2][c1][c2] = ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     string s[n];     for (int i = 0; i < n; i++) cin >> s[i];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (s[i][j] ==  # ) {           a[i][j] = 1;         }       }     }     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         for (int ii = 0; ii < n; ii++)           for (int jj = 0; jj < n; jj++) dp[i][ii][j][jj] = -1;     for (int i = 0; i < n; i++) {       for (int j = 1; j < n; j++) {         a[i][j] += a[i][j - 1];       }     }     for (int i = 1; i < n; i++) {       for (int j = 0; j < n; j++) {         a[i][j] += a[i - 1][j];       }     }     int ans = foo(0, n - 1, 0, n - 1);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int kappa[100];   void incc(int jj) {     if (kappa[jj] > 9) {       kappa[jj + 1]++;       kappa[jj] %= 10;       incc(jj + 1);     }   }   void get_count(int a1, int a2, int a3) {     int i, j;     if (a2 - a3 == 2) {       j = 0;       for (i = a2; i >= a1; i--) {         if (!(s[i] ==  . )) {           kappa[j] += s[i] -  0 ;           if (kappa[j] > 9) {             kappa[j + 1]++;             kappa[j] %= 10;           }           j++;         }       }     } else {       j = 2;       for (i = a2; i >= a1; i--) {         if (!(s[i] ==  . )) {           kappa[j] += s[i] -  0 ;           if (kappa[j] > 9) {             kappa[j + 1]++;             kappa[j] %= 10;           }           j++;         }       }     }     incc(j);   }   int main(void) {     cout << setprecision(10);     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int i, i1, q, g, flag = 0, tt;     for (i = 0; i < 100; i++) {       kappa[i] = 0;     }     double k = 0;     cin >> s;     int leng;     leng = s.length();     i = 0;     while (i < leng) {       if (flag == 0) {         if (!(( z  >= s[i]) && (s[i] >=  a ))) {           flag = 1;           q = i;         }       } else {         if (( z  >= s[i]) && (s[i] >=  a )) {           flag = 0;           g = i - 1;           get_count(q, g, tt);         }         if (s[i] ==  . ) {           tt = i;         }       }       i++;     }     get_count(q, leng - 1, tt);     for (i = 99; i > -1; i--) {       if (kappa[i] > 0) {         break;       }     }     if ((kappa[0] == 0) && (kappa[1] == 0)) {       for (i1 = i; i1 > 1; i1--) {         cout << kappa[i1];         if ((i1 % 3 == 2) && (i1 > 2)) {           cout <<  . ;         }       }     } else {       if (i > 1) {         for (i1 = i; i1 > 1; i1--) {           cout << kappa[i1];           if ((i1 % 3 == 2) && (i1 > 2)) {             cout <<  . ;           }         }         cout <<  . ;         cout << kappa[1];         cout << kappa[0];       } else {         cout <<  0. ;         cout << kappa[1];         cout << kappa[0];       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   using bigint = long long int;   using vi = vector<int>;   using vll = vector<long long int>;   int spf[2005];   void smallestFactor() {     for (int i = 1; i <= 2000; i++) spf[i] = i;     for (int i = 2; i * i <= 2000; i++) {       if (spf[i] == i) {         for (int j = i * i; j <= 2000; j += i) {           if (spf[j] == j) spf[j] = i;         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     smallestFactor();     int T;     cin >> T;     while (T--) {       int N;       cin >> N;       int arr[N + 1];       for (int i = 0; i < N; i++) {         int x;         cin >> x;         arr[i] = spf[x];       }       map<int, int> m;       int j = 1;       vi ans;       for (int i = 0; i < N; i++) {         if (m.find(arr[i]) != m.end())           ans.push_back(m[arr[i]]);         else {           m[arr[i]] = j;           ans.push_back(j);           j++;         }       }       cout << j - 1 <<   n ;       for (int x : ans) cout << x <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int arr[123456];   map<long long int, bool> mp;   int main() {     int a = 0, b = 0, n, k, l, r, all, kall;     cin >> n >> k >> l >> r >> all >> kall;     int rest = all - kall;     for (int i = 0; i < k; i++) {       arr[i] = kall / k;       if (kall % k != 0) {         arr[i]++;         kall--;       }     }     int rem, man = n - k;     if (k != n) {       for (int i = k; i < n; i++) {         arr[i] = rest / man;         rem = rest % man;         if (rem != 0) {           arr[i]++;           rest--;         }       }     }     random_shuffle(arr, arr + n);     for (int i = 0; i < n - 1; i++) {       printf( %d  , arr[i]);     }     cout << arr[n - 1] << endl;   }


#include <bits/stdc++.h>   using namespace std;   void min_self(int& a, int b) { a = min(a, b); }   void max_self(int& a, int b) { a = max(a, b); }   const int NAX = (int)(2e5 + 5);   int v[NAX], visited[NAX];   int component_size;   void visit(int i) {     if (!visited[i]) {       ++component_size;       visited[i] = 1;       visit(v[i]);       visited[i] = component_size;       return;     }     return;   }   int main() {     int t, n;     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       for (int i = 1; i <= n; ++i) scanf( %d , &v[i]);       for (int i = 1; i <= n; ++i) {         component_size = 0;         visit(i);       }       for (int i = 1; i <= n; ++i) printf( %d  , visited[i]);       printf(  n );       for (int i = 1; i <= n; ++i) visited[i] = 0;     }     return 0;   }


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


#pragma GCC optimize( Ofast )      #include <iostream>   #include <fstream>   #include <algorithm>   #include <functional>   #include <array>   #include <chrono>   #include <random>   #include <vector>   #include <string>   #include <sstream>   #include <cmath>   #include <cstring>   #include <bitset>   #include <list>   #include <stack>   #include <queue>   #include <set>   #include <map>   #include <cassert>      #define sq(x) ((x) * (x))   #define err(x) cerr <<  [ #x ]    << (x) <<   n ;   #define errp(x) cerr <<  [ #x ]  {  << ((x).first) <<  ,   << ((x).second) <<  } n ;   #define errv(x) {cerr <<  [ #x ]  [ ;for(const auto& ___ : (x)) cerr << ___ <<  ,  ; cerr <<  ] n ;}   #define errvn(x, n) {cerr <<  [ #x ]  [ ;for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] <<  ,  ; cerr <<  ] n ;}   #define errf() cerr <<   n n ;      using namespace std;      using ll = long long;   using ull = unsigned long long;   using ld = long double;      mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   ll getrnd(ll l, ll r) {       return uniform_int_distribution<ll>(l, r)(rng);   }      template <typename T1, typename T2> inline bool relax(T1& a, const T2& b) {       return a > b ? a = b, true : false;   }      template <typename T1, typename T2> inline bool strain(T1& a, const T2& b) {       return a < b ? a = b, true : false;   }      // :::::::::::::::::::::::::::::::      void solve() {       int n;       cin >> n;              int x = 0;       vector<int> a(n);       for (int i = 0; i < n; ++i) {           cin >> a[i];           x ^= a[i];       }              int cur = 0;       for (int i = 0; i < n; ++i) {           cur ^= a[i];           if (cur == (x ^ cur)) {               cout <<  YES n ;               return;           }       }              cur = 0;       for (int i = 0; i < n; ++i) {           cur ^= a[i];           int sec = 0;           for (int j = i + 1; j < n - 1; ++j) {               sec ^= a[j];               if (cur == sec && sec == (cur ^ sec ^ x)) {                   cout <<  YES n ;                   return;               }           }       }       cout <<  NO n ;   }      int main() {       ios::sync_with_stdio(0);       cin.tie(nullptr); cout.tie(nullptr);              int t = 1;       cin >> t;       while (t--)           solve();              return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[120];   int n, m;   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + n + 1);     int s = 0;     int j;     for (j = 1; j < n; j++) {       s += a[j];       if (s > m) break;     }     if (j < n)       cout <<  NO ;     else       cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<long long int> a(n), b(n);       map<long long int, bool> mp;       bool ok = false;       for (int i = 0; i < n; i++) {         cin >> a[i];         b[i] = a[i];         if (mp[a[i]]) {           ok = true;         }         mp[a[i]] = true;       }       sort(b.rbegin(), b.rend());       if (a != b) {         ok = true;       }       if (ok) {         cout <<  YES  << endl;       } else {         cout <<  NO  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   uint64_t log4(uint64_t n) { return log2(n) / 2; }   uint64_t getA(uint64_t triple) {     if (triple == 0) {       return 1;     }     uint64_t doubleBits;     if (triple == 1) {       doubleBits = 1;     } else {       doubleBits = log4(triple * 3 + 1);     }     uint64_t tripleIndex = triple - (pow(4, doubleBits) - 1) / 3;     return pow(4, doubleBits) + tripleIndex;   }   uint64_t getB(uint64_t A) {     uint64_t res = 0;     uint64_t power = 1;     while (A > 0) {       if (A % 4 == 1) {         res += 2 * power;       }       if (A % 4 == 2) {         res += 3 * power;       }       if (A % 4 == 3) {         res += power;       }       power *= 4;       A /= 4;     }     return res;   }   uint64_t getC(uint64_t A) {     uint64_t res = 0;     uint64_t power = 1;     while (A > 0) {       if (A % 4 == 1) {         res += 3 * power;       }       if (A % 4 == 2) {         res += power;       }       if (A % 4 == 3) {         res += 2 * power;       }       power *= 4;       A /= 4;     }     return res;   }   uint64_t solve(uint64_t n) {     uint64_t triple = (n - 1) / 3;     uint64_t A = getA(triple);     if (n % 3 == 0) {       return getC(A);     }     if (n % 3 == 1) {       return A;     }     return getB(A);   }   int main() {     int T;     cin >> T;     for (int t = 0; t < T; t++) {       uint64_t n;       cin >> n;       uint64_t result;       result = solve(n);       cout << result << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   const int N = 1000010;   template <class T>   class BIT {     T bit[N + 1];     int n;       public:     BIT() {       n = N;       memset(bit, 0, sizeof(bit));     }     T sum(int i) {       T s = 0;       ++i;       while (i > 0) {         s += bit[i];         s %= MOD;         i -= i & -i;       }       return s;     }     void add(int i, T x) {       ++i;       while (i <= n) {         bit[i] += x;         bit[i] %= MOD;         i += i & -i;       }     }   };   BIT<long long> T;   int n, m, k;   vector<pair<int, int>> in[1000010];   vector<pair<int, int>> out[1000010];   set<int> alive;   set<pair<int, int>> itv;   int main() {     scanf( %d %d %d , &n, &m, &k);     alive.insert(1);     itv.insert(make_pair(0, 0));     for (int i = 0; i < (k); i++) {       int a, b, c, d;       scanf( %d %d %d %d , &a, &b, &c, &d);       in[b].push_back(make_pair(a, c));       out[d + 1].push_back(make_pair(a, c));     }     T.add(1, 1);     for (int i = 1; i <= m; ++i)       if (in[i].size() > 0 || out[i].size() > 0) {         sort((in[i]).begin(), (in[i]).end());         sort((out[i]).begin(), (out[i]).end());         vector<pair<int, long long>> vals;         for (int j = 0; j < (in[i].size()); j++) {           pair<int, int> p = in[i][j];           auto it = itv.upper_bound(make_pair(p.second + 1, n));           --it;           if (it->second < p.second + 1) {             long long num = T.sum(p.second) - T.sum(it->second);             num %= MOD;             if (num < 0) num += MOD;             vals.emplace_back(p.second + 1, i > 1 ? num : 0LL);             if (i > 1) alive.insert(p.second + 1);           }         }         for (pair<int, int> p : out[i]) {           itv.erase(p);         }         for (int j = 0; j < (vals.size()); j++) {           T.add(vals[j].first, vals[j].second);         }         for (int j = 0; j < (in[i].size()); j++) {           pair<int, int> p = in[i][j];           itv.insert(p);           auto it = alive.lower_bound(p.first);           while (it != alive.end() && *it <= p.second) {             int pos = *it;             long long k = T.sum(pos) - T.sum(pos - 1);             k %= MOD;             T.add(pos, MOD - k);             alive.erase(it++);           }         }       }     long long ret = T.sum(n);     auto it = itv.end();     --it;     ret = (ret - T.sum(it->second)) % MOD;     if (ret < 0) ret += MOD;     printf( %d n , (int)ret);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double PI = acos(-1.0);   const double E = exp(1);   const int N = 1e5 + 5;   int n;   map<long long, long long> m;   int main(void) {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) {       long long a;       cin >> a;       if (!m.count(a)) m[a] = 0;       m[a]++;     }     long long at = 0;     long long s;     long long f = 0;     for (map<long long, long long>::iterator it = m.begin(); it != m.end();          it++) {       s = it->first;       long long x = it->second;       at += s - f;       at = max(0LL, at - x);       f = s;     }     cout << s - at + 1 << endl;     return 0;   }