#include<bits/stdc++.h>   using namespace std;   #define mod        1000000007   #define pb         push_back   #define mp         make_pair   #define rep(n)     for(int i=0;i<n;i++)   #define repit(x)   for(auto it : x)   #define ll         long long   #define vi         vector<int>   #define vc         vector<char>   #define vs         vector<string>   #define mii        map<int ,int>   #define mci        map<char ,int>   /* bool prime[100001];    const int N=100000;    void sieve() {    int i,j;   for(i=2;i<=N;i++)   prime[i]=true;    prime[0]=prime[1]=false;   for(i=2;i*i<=N;i++){   if(prime[i]){   for(j=i*i;j<=N;j+=i)   prime[j]=false;   }   }   }*/   int gcd(int a,int b){   if(b==0)   return a;   else   return gcd(b,a%b);   }   void swap(int *x,int *y){   int temp=*x;   *x=*y;   *y=temp;   }   int main()   {          ios::sync_with_stdio(0);   cin.tie(0);   cout.tie(0);   int t;   cin>>t;   while(t--){   int i,n,c=0,j;   cin>>n;   string s,s2;   cin>>s;   map<string,int>m;   for(i=97;i<=122;i++){       string s1;       s1.push_back(i);       m.insert(make_pair(s1,0));   }   for(i=0;i<n;i++){       string s1;       s1.push_back(s[i]);       m[s1]++;   }   for(auto it=m.begin();it!=m.end();it++){       if(it->second==0){           c=1;           s2=it->first;           break;       }   }   if(c){       cout<<s2<<  n ;   }   else{       m.clear();       for(i=97;i<=122;i++){           for(j=97;j<=122;j++){               string s1;               s1.push_back(i);               s1.push_back(j);               m.insert(make_pair(s1,0));           }       }       for(i=0;i<n-1;i++){           string s1;           s1.push_back(s[i]);           s1.push_back(s[i+1]);           m[s1]++;       }       for(auto it=m.begin();it!=m.end();it++){           if(it->second==0){               c=1;               s2=it->first;               break;           }       }       if(c)       cout<<s2<<  n ;       else{           m.clear();           for(i=97;i<=122;i++){               for(j=97;j<=122;j++){                   for(int k=97;k<=122;k++){                       string s1;                       s1.push_back(i);                       s1.push_back(j);                       s1.push_back(k);                       m.insert(make_pair(s1,0));                   }               }           }           for(i=0;i<n-2;i++){               string s1;               s1.push_back(s[i]);               s1.push_back(s[i+1]);               s1.push_back(s[i+2]);               m[s1]++;                          }           for(auto it=m.begin();it!=m.end();it++){               if(it->second==0){                   c=1;                   s2=it->first;                   break;               }           }           cout<<s2<<  n ;       }   }   }   return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int table[1000][1000];   int main() {     int k = 0;     scanf( %d %d %d , &n, &m, &k);     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         scanf( %d , &table[i][j]);       }     }     while (k) {       char command;       int x, y;       scanf(  %c %d %d , &command, &x, &y);       if (command ==  g )         printf( %d n , table[x - 1][y - 1]);       else if (command ==  c )         for (int i = 0; i < n; ++i) swap(table[i][x - 1], table[i][y - 1]);       else         for (int i = 0; i < m; ++i) swap(table[x - 1][i], table[y - 1][i]);       k--;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   ifstream Cin( input.txt );   ofstream Cout( output.txt );   int main() {     long long i, n4 = 0, n7 = 0, n;     string a, b;     cin >> a >> b;     for (i = 0; i < a.length(); i++)       if (a[i] != b[i]) {         if (a[i] ==  4 )           n4++;         else           n7++;       }     cout << n4 + n7 - min(n4, n7);   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   ll min(ll a, ll b) {     if (a < b) return a;     return b;   }   void solve() {     ll testCases;     cin >> testCases;     while (testCases--) {       ll n;       cin >> n;       vector<ll> arr(n);       vector<ll> res(n, 1);       for (int i = 0; i < n; i++) cin >> arr[i];       int i = 0;       for (i = 0; i < n; i++) {         if (arr[i] != arr[(i + 1) % n]) break;       }       if (i == n) {         cout <<  1 n ;         for (i = 0; i < n; i++) cout << 1 <<    ;         cout <<   n ;         continue;       }       if (n % 2 == 0) {         cout <<  2 n ;         for (i = 0; i < n; i++) cout << (i % 2) + 1 <<    ;         cout <<   n ;         continue;       } else {         bool isTwo = 0;         for (i = 0; i < n; i++) {           if (arr[i] == arr[(i + 1) % n]) {             for (int j = 0, k = i + 1; k < n; k++, j ^= 1) res[k] = j + 1;             for (int j = 0, k = i; k >= 0; k--, j ^= 1) res[k] = j + 1;             cout <<  2 n ;             for (auto e : res) cout << e <<    ;             cout <<   n ;             isTwo = 1;             break;           }         }         if (!isTwo) {           cout <<  3 n ;           for (i = 0; i < n - 1; i++) cout << i % 2 + 1 <<    ;           cout <<  3 n ;         }       }     }   }   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(NULL);     };     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 3000 + 1;   pair<int, int> a[maxN];   pair<int, int> b[maxN];   int nx[maxN], pr[maxN], v[maxN];   int r, c, n;   inline int gg(int i) {     pair<int, int> x = {a[i].second, a[i].first};     return lower_bound(b, b + n + 2, x) - b;   }   inline int ff(int i) { return b[i].first; }   int nex(int i) {     if (v[nx[i]]) return nx[i];     return nx[i] = nex(nx[i]);   }   int prev(int i) {     if (v[pr[i]]) return pr[i];     return pr[i] = prev(pr[i]);   }   int L[11], R[11];   int main() {     cin >> r >> c >> n;     int k;     cin >> k;     for (int i = 0; i < n; i++) {       cin >> a[i].first >> a[i].second;       b[i] = {a[i].second, a[i].first};     }     b[n] = {0, 0}, b[n + 1] = {c + 1, 0};     sort(a, a + n);     sort(b, b + n + 2);     v[0] = v[n + 1] = 1;     pr[0] = 0, nx[n + 1] = n + 1;     long long ans = 0;     for (int i = 1; i <= r; i++) {       int ind = 0;       for (; ind < n && a[ind].first < i; ind++)         ;       if (ind == n) break;       for (int j = ind; j < n; j++) v[gg(j)] = 1;       for (int j = 1; j <= n; j++) {         nx[j] = j + 1;         pr[j] = j - 1;       }       int curr = 0;       for (int j = 1; j <= n; j++)         if (v[j]) {           int x = j;           for (int t = 1; t < k; t++, x = nex(x))             ;           curr += (ff(j) - ff(prev(j))) * (c + 1 - ff(x));         }       int ptr = n;       for (int i2 = r; i2 >= i; i2--) {         ans += curr;         for (; ptr > ind && a[ptr - 1].first >= i2; ptr--) {           L[0] = R[0] = gg(ptr - 1);           for (int t = 1; t < k; t++) {             L[t] = prev(L[t - 1]);             R[t] = nex(R[t - 1]);           }           for (int t = 0; t < k; t++) {             int left = L[t];             int right = R[k - t - 1];             curr -= (ff(left) - ff(prev(left))) * (ff(nex(right)) - ff(right));           }           v[L[0]] = 0;         }       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int arr[500005], brr[500005];   pair<int, int> tree[500005 * 4];   vector<int> vv[500005];   vector<pair<int, int> > qr[500005];   int ans[500005];   void build(int node, int b, int e) {     if (b == e) {       tree[node] = make_pair(500000000, 500000000);       return;     }     int left = 2 * node, right = left + 1, mid = (b + e) / 2;     build(left, b, mid);     build(right, mid + 1, e);     tree[node] = tree[left];   }   void update(int node, int b, int e, int i, int v) {     if (e < i || b > i) return;     if (b == e && b == i) {       tree[node] = make_pair(v, arr[b]);       return;     }     int left = 2 * node, right = left + 1, mid = (b + e) / 2;     update(left, b, mid, i, v);     update(right, mid + 1, e, i, v);     if (tree[left].first <= tree[right].first) {       tree[node] = tree[left];     } else       tree[node] = tree[right];   }   pair<int, int> query(int node, int b, int e, int l, int r) {     if (b > r || e < l) return make_pair(500000000, 500000000);     if (b >= l && e <= r) return tree[node];     int left = 2 * node, right = left + 1, mid = (b + e) / 2;     pair<int, int> p = query(left, b, mid, l, r);     pair<int, int> q = query(right, mid + 1, e, l, r);     if (p.first <= q.first) return p;     return q;   }   int main() {     int n;     scanf( %d , &n);     int mx = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &arr[i]);       vv[arr[i]].push_back(i);       mx = max(mx, arr[i]);     }     int q;     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       int l, r;       scanf( %d %d , &l, &r);       qr[r].push_back(make_pair(l, i));     }     build(1, 1, n);     for (int i = 1; i <= n; i++) {       int id = lower_bound(vv[arr[i]].begin(), vv[arr[i]].end(), i) -                vv[arr[i]].begin();       int v;       if (id == 0) {         v = 1;         brr[arr[i]] = i;       } else {         v = vv[arr[i]][id - 1] + 1;         update(1, 1, n, brr[arr[i]], 500000000);         brr[arr[i]] = i;       }       update(1, 1, n, i, v);       for (int j = 0; j < qr[i].size(); j++) {         pair<int, int> ret = query(1, 1, n, qr[i][j].first, i);         if (qr[i][j].first >= ret.first) ans[qr[i][j].second] = ret.second;       }     }     for (int i = 1; i <= q; i++) printf( %d n , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   const int MAXN = 200000;   int n, tot;   bool bz[N];   vector<int> g[N], edge[N];   int e[N * 2][2], gg[N];   int sz;   long long ans[N];   void add(int x, int y) {     e[++tot][0] = y;     e[tot][1] = gg[x];     gg[x] = tot;   }   void dfs(int x) {     bz[x] = 0;     sz++;     for (int i = gg[x]; i; i = e[i][1])       if (bz[e[i][0]]) dfs(e[i][0]);     gg[x] = 0;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       for (int j = 1; 1ll * j * j <= x; j++)         if ((x % j) == 0) {           g[j].push_back(i);           if (j * j != x) g[x / j].push_back(i);         }     }     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d %d , &x, &y);       edge[x].push_back(y);       edge[y].push_back(x);     }     for (int i = 1; i <= MAXN; i++)       if (g[i].size()) {         tot = 0;         for (auto u : g[i]) bz[u] = 1;         for (auto u : g[i])           for (auto v : edge[u])             if (bz[v]) add(u, v);         for (auto u : g[i])           if (bz[u]) {             sz = 0;             dfs(u);             ans[i] += 1ll * sz * (sz - 1) / 2 + sz;           }       }     for (int i = MAXN; i; i--)       for (int j = 2; 1ll * j * i <= MAXN; j++) ans[i] -= ans[i * j];     for (int i = 1; i <= MAXN; i++)       if (ans[i]) printf( %d %lld n , i, ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k, n;     scanf( %d%d , &n, &k);     vector<int> a(n), b(n), distributed(n), p(n);     vector<vector<int> > cart(k);     for (int i = 0; i < n; ++i) {       scanf( %d%d , &a[i], &b[i]);       distributed[i] = 0;       p[i] = i;     }     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         if (a[p[i]] < a[p[j]]) {           swap(p[i], p[j]);         }       }     }     int cart_ptr = 0;     for (int i = 0; i < n && cart_ptr < k; ++i) {       if (b[p[i]] == 1) {         distributed[p[i]] = 1;         cart[cart_ptr].push_back(p[i]);         ++cart_ptr;       }     }     deque<int> available;     for (int i = 0; i < n; ++i) {       if (!distributed[p[i]]) {         available.push_back(p[i]);       }     }     while (cart_ptr < k) {       cart[cart_ptr].push_back(available.front());       available.pop_front();       ++cart_ptr;     }     while (!available.empty()) {       cart[k - 1].push_back(available.front());       available.pop_front();     }     long long ans = 0;     for (int i = 0; i < k; ++i) {       int min_cost = 2000000000;       for (int j = 0; j < (int)cart[i].size(); ++j) {         ans += a[cart[i][j]] * 2;         min_cost = min(min_cost, a[cart[i][j]]);       }       if (b[cart[i][0]] == 1) {         ans -= min_cost;       }     }     cout << ans / 2;     if (ans % 2 == 0) {       cout <<  .0  << endl;     } else {       cout <<  .5  << endl;     }     for (int i = 0; i < k; ++i) {       cout << cart[i].size();       for (int j = 0; j < (int)cart[i].size(); ++j) {         cout <<     << cart[i][j] + 1;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9;   const int mod = (int)1e9 + 7;   const double pi = acos(-1.0);   const double eps = 1e-9;   const int maxn = (int)2e6 + 11;   long long n;   long long a[maxn];   long long sum[maxn];   int main() {     cin >> n;     a[1] = 2;     sum[1] = 2;     for (int i = 2; i <= 2000000; i++) {       a[i] = a[i - 1] + 3;       sum[i] = sum[i - 1] + a[i];     }     int ans = 0;     for (int i = 1; sum[i] <= n; i++) {       if ((n - sum[i]) % 3 == 0) ans++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, long long> mp[12];   long long a[200005], dig[200005];   long long state[200005][12];   int main() {     long long n, k;     scanf( %lld %lld , &n, &k);     for (int i = 0; i < n; i++) scanf( %lld , &a[i]);     for (int i = 0; i < n; i++) {       dig[i] = log10(a[i]) + 1;     }     for (int i = 0; i < n; i++) {       long long x = a[i];       long long tencnt = 1;       while (tencnt < 11) {         x = (x * 10LL) % k;         mp[tencnt][x]++;         state[i][tencnt] = x;         tencnt++;       }     }     long long ans = 0;     for (int i = 0; i < n; i++) {       long long len = dig[i];       long long m = (k - (a[i] % k)) % k;       if (mp[len].count(m) == 0) continue;       ans += mp[len][m];     }     for (int i = 0; i < n; i++) {       long long len = dig[i];       long long x = state[i][len];       if ((x + a[i]) % k == 0) {         ans--;       }     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const long long LINF = ~0ULL >> 1;   const int N = 1e3 + 7;   const int INF = 2e8 + 7;   const int MOD = 1e9 + 7;   const double PI = acos(-1.0);   const double EPS = 1e-8;   int n;   long long calc(long long A, long long B, long long C) {     return (A + 1) * (B + 2) * (C + 2);   }   void solve() {     long long mn = LINF, mx = -LINF, tmp;     for (int i = 1; 1ll * i * i * i <= n; ++i) {       if (n % i) continue;       for (int j = i, J = n / i; 1ll * j * j <= J; ++j) {         if (J % j) continue;         int k = n / i / j;         tmp = calc(i, j, k);         mn = min(mn, tmp), mx = max(mx, tmp);         tmp = calc(j, i, k);         mn = min(mn, tmp), mx = max(mx, tmp);         tmp = calc(k, i, j);         mn = min(mn, tmp), mx = max(mx, tmp);       }     }     cout << mn - n <<     << mx - n << endl;   }   int main() {     std::ios_base::sync_with_stdio(false);     cin >> n;     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x, r[100000], pos[100000], flag = 1, flag2;   pair<int, int> a[100000];   vector<int> ans, ans2;   int l(int n) {     if (!n) return 1;     if (n % 10 == 4 || n % 10 == 7) return l(n / 10);     return 0;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &x);       a[i] = pair<int, int>(x, i);     }     sort(a, a + n);     for (int i = 0; i < n; i++) {       r[a[i].second] = i;       pos[i] = a[i].second;       if (a[i].second != i) flag = 0;       if (!flag2 && l(a[i].first)) x = i, flag2 = 1;     }     if (flag) {       cout << 0 << endl;       return 0;     }     if (!flag2) {       cout << -1 << endl;       return 0;     }     for (int i = 0; i < n; i++)       if (i != x) {         if (pos[i] == i) continue;         if (pos[x] != i) {           ans.push_back(pos[x]), ans2.push_back(i);           int temp = pos[x];           swap(pos[x], pos[r[i]]);           swap(r[temp], r[i]);         }         ans.push_back(pos[x]), ans2.push_back(pos[i]);         swap(pos[x], pos[i]);         swap(r[pos[x]], r[pos[i]]);       }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++)       cout << ans[i] + 1 <<     << ans2[i] + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e3 + 10;   const int MOD = 998244353;   const int INF = 10;   int fact[MAXN], invfact[MAXN];   int add(int a, int b) {     int sum = a + b;     return (sum >= MOD ? sum -= MOD : (sum < 0 ? sum += MOD : sum));   }   int mul(int a, int b) { return 1LL * a * b % MOD; }   int pwr(int a, int b) {     return (!b ? 1                : (b & 1 ? 1LL * a * pwr(1LL * a * a % MOD, b >> 1) % MOD                         : pwr(1LL * a * a % MOD, b >> 1) % MOD));   }   int inv(int x) { return pwr(x, MOD - 2); }   void first() {     fact[0] = 1;     for (int i = 1; i < MAXN; i++) fact[i] = mul(fact[i - 1], i);     for (int i = 0; i < MAXN; i++) invfact[i] = inv(fact[i]);   }   int C(int n, int k) { return mul(mul(fact[n], invfact[k]), invfact[n - k]); }   int P(int n, int k) { return mul(fact[n], invfact[n - k]); }   int n, a[MAXN], dp[MAXN];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     first();     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     dp[n] = 1;     for (int i = n - 1; i >= 0; i--) {       if (a[i] <= 0 || a[i] + i - 1 > n - 1) {         continue;       }       for (int j = n - 1; j >= a[i] + i; j--) {         dp[i] = add(dp[i], mul(dp[j + 1], C(j - i, a[i])));       }     }     int ans = 0;     for (int i = 0; i < n; i++) {       ans = add(ans, dp[i]);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int* m = new int[n];     int* r = new int[n];     for (int i = 0; i < n; i++) {       cin >> m[i];     }     for (int i = 0; i < n; i++) {       cin >> r[i];     }     double total = 0;     for (int i = 0; i < 1000000; i++) {       for (int j = 0; j < n; j++) {         if (i % m[j] == r[j]) {           total++;           break;         }       }     }     double percentage = total / 1000000;     cout << fixed << setprecision(6) << percentage << endl;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {1, 1, -1, -1};   int dy[] = {1, -1, -1, 1};   long long int n, k, d1, d2, rem;   bool _solve(long long int w1, long long int w2, long long int w3) {     long long int tar = n / 3;     if (w1 < 0 || w2 < 0 || w3 < 0) return false;     if (tar >= w1 && tar >= w2 && tar >= w3 && abs(w1 - w2) == d1 &&         abs(w2 - w3) == d2)       return true;     return false;   }   bool solve() {     long long int _d1, w1, w2, w3, _d2;     for (int i = 0; i < 4; i++) {       _d1 = d1 * dx[i];       _d2 = d2 * dy[i];       w1 = (k + 2 * _d1 + _d2) / 3;       w2 = w1 - _d1;       w3 = w2 - _d2;       if (w1 + w2 + w3 != k) continue;       if (_solve(w1, w2, w3)) return true;     }     return false;   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       cin >> n >> k >> d1 >> d2;       if (n % 3 == 0) {         if (solve())           cout <<  yes  << endl;         else           cout <<  no  << endl;       } else         cout <<  no  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1.01e9;   const double eps = 1e-9;   const int N = 1010;   char s[N][N];   char res[N * N];   int resc = 0;   char ch[4] = { D ,  L ,  R ,  U };   int dx[4] = {1, 0, 0, -1};   int dy[4] = {0, -1, 1, 0};   pair<int, int> q[N * N];   int st = 0, en = 0;   int d[N][N];   int n, m;   void bfs(int x, int y) {     for (int i = 0; (i) < (n); ++i)       for (int j = 0; (j) < (m); ++j) d[i][j] = inf;     d[x][y] = 0;     q[en++] = {x, y};     while (st < en) {       x = q[st].first;       y = q[st].second;       st++;       for (int i = 0; (i) < (4); ++i) {         int xx = x + dx[i];         int yy = y + dy[i];         if (0 <= xx && xx < n && 0 <= yy && yy < m && s[xx][yy] ==  .  &&             d[xx][yy] == inf) {           d[xx][yy] = d[x][y] + 1;           q[en++] = {xx, yy};         }       }     }   }   int main() {     int k;     scanf( %d%d%d , &n, &m, &k);     if (k & 1) {       printf( IMPOSSIBLE n );       return 0;     }     for (int i = 0; (i) < (n); ++i) scanf( %s , s[i]);     int px = -1, py = -1;     for (int i = 0; (i) < (n); ++i)       for (int j = 0; (j) < (m); ++j)         if (s[i][j] ==  X ) {           px = i;           py = j;           s[i][j] =  . ;         }     bfs(px, py);     int x = px, y = py;     for (int it = 0; (it) < (k); ++it) {       int ok = 0;       for (int i = 0; (i) < (4); ++i) {         int xx = x + dx[i];         int yy = y + dy[i];         if (0 <= xx && xx < n && 0 <= yy && yy < m && d[xx][yy] <= k - it - 1) {           res[resc++] = ch[i];           x = xx;           y = yy;           ok = 1;           break;         }       }       if (!ok) {         printf( IMPOSSIBLE n );         return 0;       }     }     printf( %s n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[100010], a[110], b[110];   int pa[110], pb[110];   int main() {     scanf( %s%s%s , s, a, b);     int i, j;     j = -1;     pa[0] = -1;     int lena = strlen(a);     for (i = 1; i < lena; i++) {       while (j > -1 && a[j + 1] != a[i]) j = pa[j];       if (a[j + 1] == a[i]) j++;       pa[i] = j;     }     j = -1;     pb[0] = -1;     int lenb = strlen(b);     for (i = 1; i < lenb; i++) {       while (j > -1 && b[j + 1] != b[i]) j = pb[j];       if (b[j + 1] == b[i]) j++;       pb[i] = j;     }     int len = strlen(s);     int minn = len + 1;     j = -1;     for (i = 0; i < len; i++) {       while (j > -1 && a[j + 1] != s[i]) j = pa[j];       if (a[j + 1] == s[i]) j++;       if (j == lena - 1) {         minn = i;         break;       }     }     bool flag1 = false, flag2 = false;     j = -1;     for (i = minn + 1; i < len; i++) {       while (j > -1 && b[j + 1] != s[i]) j = pb[j];       if (b[j + 1] == s[i]) j++;       if (j == lenb - 1) {         flag1 = true;         break;       }     }     for (i = 0; i < len / 2; i++) swap(s[i], s[len - i - 1]);     j = -1;     minn = len;     for (i = 0; i < len; i++) {       while (j > -1 && a[j + 1] != s[i]) j = pa[j];       if (a[j + 1] == s[i]) j++;       if (j == lena - 1) {         minn = i;         break;       }     }     j = -1;     for (i = minn + 1; i < len; i++) {       while (j > -1 && b[j + 1] != s[i]) j = pb[j];       if (b[j + 1] == s[i]) j++;       if (j == lenb - 1) {         flag2 = true;         break;       }     }     if (flag1 && flag2)       printf( both n );     else if (flag1)       printf( forward n );     else if (flag2)       printf( backward n );     else       printf( fantasy n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long N, a[100010], s[100100], cnt[100010];   void update(long long *t, long long pos, long long val) {     for (; pos <= N; pos += pos & (-pos)) t[pos] += val;   }   long long query(long long *t, long long r) {     long long res = 0;     for (; r > 0; r -= r & (-r)) res += t[r];     return res;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> N;     int i;     long long nr, sum;     long double res = 0;     for (i = 1; i <= N; i++) {       cin >> a[i];       update(cnt, a[i], 1);       update(s, a[i], i);     }     for (i = 1; i <= N; i++) {       nr = query(cnt, a[i] - 1);       sum = query(s, a[i] - 1);       res += nr - (1.0 * i * (nr * (N + 1) - sum)) / (N * (N + 1));       nr = N - i - nr;       sum = query(s, N) - sum - i;       res += (1.0 * i * (nr * (N + 1) - sum)) / (N * (N + 1));       update(cnt, a[i], -1);       update(s, a[i], -i);     }     cout << fixed << setprecision(15) << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 1e6 + 10;   const long long INF = 1e18;   const long double EPS = 1e-12;   int a[300005];   map<int, int> mi;   int l_, r_;   long long pre[300005];   int b[300005];   int main() {     int n;     scanf( %d , &n);     for (int i = (int)1; i < (int)n + 1; i++) {       scanf( %d , &a[i]);     }     for (int i = (int)1; i < (int)n + 1; i++) {       if (mi[a[i]] == 0) mi[a[i]] = i;     }     for (int i = (int)1; i < (int)n + 1; i++) {       pre[i] = pre[i - 1];       if (a[i] >= 0) pre[i] += (long long)(a[i]);     }     long long ans = -(long long)(1e12);     l_ = 0;     r_ = 0;     for (int i = n; i >= 1; i--) {       int x = a[i];       int l = mi[x];       if (i == mi[x]) continue;       long long net = pre[i - 1] - pre[l];       net += 2LL * (long long)(x);       if (net > ans) {         ans = net;         l_ = l;         r_ = i;       }     }     int cnt = 0;     for (int i = 0; i < (int)n + 1; i++) b[i] = 0;     for (int i = (int)1; i < (int)n + 1; i++) {       if (i == l_ || i == r_) {         b[i] = 1;         continue;       }       if (l_ < i && i < r_ && a[i] > 0) {         b[i] = 1;       } else {         b[i] = 0;         cnt++;       }     }     cout << ans <<     << cnt << endl;     for (int i = (int)1; i < (int)n + 1; i++) {       if (b[i] == 0) {         printf( %d  , i);       }     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int Read() {     int x = 0, f = 1, c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     return x * f;   }   const int MAXN = 300005;   int n, m, a[MAXN], f[MAXN], g[MAXN];   inline bool Chk(int d) {     f[0] = g[0] = 1;     for (int i = 1, j = 1; i <= n; i++) {       while (a[i] - a[j] > d) j++;       if (i >= m && g[i - m] - (j == 1 ? 0 : g[j - 2]) > 0)         f[i] = 1;       else         f[i] = 0;       g[i] = g[i - 1] + f[i];     }     return f[n];   }   int main() {     n = Read(), m = Read();     for (int i = 1; i <= n; i++) a[i] = Read();     sort(a + 1, a + n + 1);     int l = 0, r = a[n], ret = 0;     while (l <= r) {       int mid = l + r >> 1;       if (Chk(mid))         ret = mid, r = mid - 1;       else         l = mid + 1;     }     return printf( %d n , ret), 0;   }


#include <bits/stdc++.h>   using namespace std;   int t;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> t;     while (t--) {       int m;       int n;       cin >> m >> n;       vector<int> a[500];       vector<int> b[500];       for (int i = 0; i < m; i++) {         for (int j = 0; j < n; j++) {           int temp;           cin >> temp;           a[i].push_back(temp);         }       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           int temp;           cin >> temp;           b[i].push_back(temp);         }       }       pair<int, int> place;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (a[0][0] == b[i][j]) {             place = make_pair(i, j);           }         }       }       map<int, int> rows;       for (int i = 0; i < m; i++) {         rows.insert({a[i][0], i});       }       for (int i = 0; i < m; i++) {         for (int j = 0; j < n; j++) {           cout << a[rows[b[place.first][i]]][j] <<    ;         }         cout <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     auto solve = []() {       int n;       cin >> n;       vector<pair<int, int>> a(n);       for (int i = 0; i < n; i++) {         cin >> a[i].first;         a[i].first--;       }       vector<int> ans(n + n);       vector<int> used(n + n);       for (int i = 0; i < n; i++) {         ans[i * 2] = a[i].first;         a[i].second = i * 2;         used[a[i].first] = 1;       }       for (int i = 1; i < n + n; i += 2) {         int x = ans[i - 1];         int j;         for (j = x + 1; j < n + n && used[j]; j++)           ;         if (j == n + n) {           cout << -1 <<   n ;           return 0;         }         used[j] = 1;         ans[i] = j;       }       for (int i = 0; i < n + n; i++) {         if (i > 0) cout <<    ;         cout << ans[i] + 1;       }       cout <<   n ;     };     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int res(long long int x) {     long long int ans = 0;     if (x > 0) ans = (x * (x - 1)) / 2;     return ans;   }   int main() {     long int n;     long long int d;     cin >> n >> d;     vector<long long int> vect;     long long int x;     for (long int i = 0; i < n; i++) {       cin >> x;       vect.push_back(x);     }     vector<long long int>::iterator it, it2;     long long int ans = 0;     for (long int i = 2; i < n; i++) {       it = lower_bound(vect.begin(), vect.end(), vect[i] - d);       if (it != vect.end()) {         ans = ans + res(i - (it - vect.begin()));       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool Check(int N, int pos) { return (bool)(N & (1 << pos)); }   int Set(int N, int pos) { return (N | (1 << pos)); }   long long BigMod(long long B, long long P, long long M) {     long long R = 1;     while (P > 0) {       if (P % 2 == 1) {         R = (R * B) % M;       }       P /= 2;       B = (B * B) % M;     }     return R;   }   int n, m;   vector<pair<double, int> > v;   int dp[5005][5005][2];   inline int call(int pos, int got, int stat) {     if (got > m) return 10000;     if (pos == n) {       if (got == m)         return 0;       else         return 10000;     }     if (dp[pos][got][stat] != -1) return dp[pos][got][stat];     int ret = 0;     int g = 0;     if (v[pos].second != got and stat == 0) g = 1;     ret = min(call(pos + 1, got, 0), call(pos, got + 1, 1));     return dp[pos][got][stat] = ret + g;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     memset(dp, -1, sizeof(dp));     cin >> n >> m;     v.resize(n);     for (int i = 0; i < n; i++) {       cin >> v[i].second >> v[i].first;     }     sort(v.begin(), v.end());     int mx = 10000;     for (int i = 0; i < m; i++) {       mx = min(mx, call(0, i + 1, 0));     }     cout << mx;   }


#include <bits/stdc++.h>   using namespace std;   char bd[1100][1100];   int n, m;   int rt[1100][1100];   int down[1100][1100];   int cnt[1100][1100];   int check(int width, int height, int x, int y) {     int filled = 0;     bool first = true;     while (true) {       int godown = down[x][y] - height;       if (godown < 0) break;       if (cnt[x][y] - cnt[x][y + width] - cnt[x + down[x][y]][y] +               cnt[x + down[x][y]][y + width] ==           width * down[x][y]) {         if (first) {           filled += width * down[x][y];           first = false;         } else {           filled += height + width * godown;         }       } else         break;       if ((y + 1) + width <= m) {         y++;         x += godown;       } else         break;     }     return filled;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) scanf( %s , bd[i]);     for (int i = n - 1; i >= 0; i--) {       for (int j = m - 1; j >= 0; j--) {         if (bd[i][j] ==  . ) {           rt[i][j] = down[i][j] = 0;         } else {           rt[i][j] = 1 + rt[i][j + 1];           down[i][j] = 1 + down[i + 1][j];         }       }     }     int tlx = -1;     int tly = -1;     int tot = 0;     for (int i = n - 1; i >= 0; i--) {       for (int j = m - 1; j >= 0; j--) {         if (bd[i][j] ==  X ) {           tlx = i;           tly = j;           tot++;         }         cnt[i][j] =             (bd[i][j] ==  X ) + cnt[i + 1][j] + cnt[i][j + 1] - cnt[i + 1][j + 1];       }     }     int best = 1000000000;     for (int height = 1; height <= down[tlx][tly]; height++) {       int width = rt[tlx][tly];       int filled = check(width, height, tlx, tly);       if (filled == tot) best = min(best, width * height);     }     for (int width = 1; width <= rt[tlx][tly]; width++) {       int height = down[tlx][tly];       int filled = check(width, height, tlx, tly);       if (filled == tot) best = min(best, width * height);     }     printf( %d n , best == 1000000000 ? -1 : best);   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1 << 30;   const int N = 100100;   char a[N], b[N];   int n, m, k, p[27];   int Par(int i) { return p[i] = (i == p[i]) ? i : Par(p[i]); }   bool same(int i, int j) { return Par(i) == Par(j); }   int comp[27];   void mrg(int i, int j) {     if (same(i, j)) return;     i = Par(i);     j = Par(j);     p[i] = p[j];     comp[i] += comp[j];   }   vector<pair<char, char> > v;   int main() {     scanf( %d , &n);     scanf( %s , a);     scanf( %s , b);     for (int i = 0; i < 26; i++) {       p[i] = i;       comp[i] = 1;     }     for (int i = 0; i < n; i++) {       if (same(b[i] -  a , a[i] -  a )) continue;       mrg(b[i] -  a , a[i] -  a );       v.push_back({a[i], b[i]});     }     printf( %d n , v.size());     for (auto x : v) printf( %c %c n , x.first, x.second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double pi = acos(-1);   struct point {     int x, y;   } p[2005];   vector<double> v;   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d%d , &p[i].x, &p[i].y);     long long ans = 0;     for (int i = 1; i <= n; i++) {       v.clear();       for (int j = 1; j <= n; j++)         if (j != i) v.push_back(atan2(p[j].y - p[i].y, p[j].x - p[i].x));       sort(v.begin(), v.end());       int k = 0;       int now = 0;       for (int j = 0; j < v.size(); j++) {         while (v[k] + now * pi < v[j] + pi) {           k++;           if (k >= v.size()) k = 0, now += 2;         }         int w = (j - k >= 0 ? j - k : k - j - 1);         ans += 1ll * w * (w - 1) / 2 * (n - w - 2) * (n - w - 3) / 2;       }     }     printf( %lld n , ans / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 6, MAX = 2e5 + 5, OO = 1000000009;   long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }   long long lcm(long long x, long long y) { return (x * y / gcd(x, y)); }   long long fact(long long z) { return (z <= 1) ? 1 : z * fact(z - 1); }   int a, b, aa, bb, ans;   void Check(int p) {     while (a % p == 0) {       a /= p;       aa++;     }     while (b % p == 0) {       b /= p;       bb++;     }     ans += abs(aa - bb);     aa = bb = 0;   }   int main() {     scanf( %d %d , &a, &b);     Check(2);     Check(3);     Check(5);     return printf( %d , a == b ? ans : -1), 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000 * 1000 * 1000 + 7;   const int INF = 2000 * 1000 * 1000;   const double EPS = 1e-9;   const double pi = acos(-1.0);   const int maxn = 100010;   inline long long sqr(int n) { return n * 1ll * n; }   struct Point {     int x, y;     Point() {}     inline bool operator<(const Point& p) const { return y < p.y; }     inline long long dist_to(const Point& p) const {       return sqr(x - p.x) + sqr(y - p.y);     }   };   Point a[maxn];   int n, x, sum;   long long minans = INF * 1ll * INF;   inline void update(const Point& p1, const Point& p2) {     minans = min(minans, p1.dist_to(p2));   }   inline void go(int l, int r) {     if (r - l <= 3) {       for (int i = l; i <= r; i++)         for (int j = i + 1; j <= r; j++) update(a[i], a[j]);       sort(a + l, a + r + 1);       return;     }     int mid = (l + r) >> 1;     int midx = a[mid].x;     int buf_size = 0;     go(l, mid - 1);     go(mid, r);     static Point buf[maxn];     merge(a + l, a + mid, a + mid, a + r + 1, buf);     copy(buf, buf + (r - l + 1), a + l);     for (int i = l; i <= r; i++) {       if (sqr(abs(a[i].x - midx)) < minans) {         for (int j = buf_size - 1; j >= 0 && sqr(a[i].y - buf[j].y) < minans; j--)           update(a[i], buf[j]);         buf[buf_size++] = a[i];       }     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &x);       sum += x;       a[i].x = i + 1;       a[i].y = sum;     }     go(0, n - 1);     printf( %I64d , minans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, m;     cin >> n >> m;     vector<long long> col(m);     for (long long i = 0; i < m; i++) {       cin >> col[i];     }     vector<long long> suf(m, 0);     suf[m - 1] = 0;     for (long long i = m - 2; i >= 0; i--) {       suf[i] = suf[i + 1] + col[i + 1];     }     vector<long long> ans;     for (long long i = 0, cur = 0, r = 0; i < m; i++) {       ans.push_back(cur);       r = cur + col[i];       if (r > n) {         cout <<  -1  << endl;         return 0;       }       cur++;       if (suf[i] < n - r) {         cout <<  -1  << endl;         return 0;       } else if (suf[i] < n - cur) {         long long pos = n - suf[i];         for (long long j = i + 1; j < m; j++) {           ans.push_back(pos);           pos += col[j];         }         break;       }     }     for (long long i = 0; i < m; i++) {       cout << ans[i] + 1 <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int iinf = 1 << 29;   const long long llinf = 1ll << 60;   const double PI = 3.14159265;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   long long mrand(long long B) { return (unsigned long long)rng() % B; }   long long cross(pair<long long, long long> p1, pair<long long, long long> p2) {     return p1.first * p2.second - p2.first * p1.second;   }   bool online(pair<long long, long long> a, pair<long long, long long> b,               pair<long long, long long> c) {     pair<long long, long long> p1{b.first - a.first, b.second - a.second};     pair<long long, long long> p2{c.first - a.first, c.second - a.second};     return cross(p1, p2) == 0;   }   void z_func(vector<int> &z, vector<int> &s, int n) {     int L = 0, R = 0;     for (int i = 1; i < n; i++) {       if (i > R) {         L = R = i;         while (R < n && s[R - L] == s[R]) R++;         z[i] = R - L;         R--;       } else {         int k = i - L;         if (z[k] < R - i + 1)           z[i] = z[k];         else {           L = i;           while (R < n && s[R - L] == s[R]) R++;           z[i] = R - L;           R--;         }       }     }   }   const int MXN = 400;   long long ans;   int n, m;   int v[MXN][MXN], up[MXN][MXN], down[MXN][MXN], leftt[MXN][MXN],       rightt[MXN][MXN], ul[MXN][MXN], ur[MXN][MXN], lol[MXN][MXN], lr[MXN][MXN];   void populate() {     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (!v[i][j]) continue;         if (i && v[i - 1][j]) up[i][j] = 1 + up[i - 1][j];         if (j && v[i][j - 1]) leftt[i][j] = 1 + leftt[i][j - 1];         if (i && j && v[i - 1][j - 1]) ul[i][j] = 1 + ul[i - 1][j - 1];         if (i && j != m - 1 && v[i - 1][j + 1]) ur[i][j] = 1 + ur[i - 1][j + 1];       }     }     for (int i = n - 1; i >= 0; --i) {       for (int j = m - 1; j >= 0; --j) {         if (!v[i][j]) continue;         if (i != n - 1 && v[i + 1][j]) down[i][j] = 1 + down[i + 1][j];         if (j != m - 1 && v[i][j + 1]) rightt[i][j] = 1 + rightt[i][j + 1];         if (i != n - 1 && j != m - 1 && v[i + 1][j + 1])           lr[i][j] = 1 + lr[i + 1][j + 1];         if (i != n - 1 && j && v[i + 1][j - 1]) lol[i][j] = 1 + lol[i + 1][j - 1];       }     }   }   void do_lower_leftt(int x, int y) {     for (int i = x + 1, j = y - 1; i < n && j >= 0 && v[i][j]; ++i, --j) {       ans += down[x][y] >= 2 * (i - x) && lr[i][j] >= i - x;       ans += down[x][y] >= i - x && rightt[i][j] >= y - j;       ans += lr[x][y] >= i - x && rightt[i][j] >= 2 * (y - j);     }   }   void do_down(int x, int y) {     for (int i = x + 1; i < n && v[i][y]; ++i) {       ans += lr[x][y] >= i - x && rightt[i][y] >= i - x;       ans += rightt[x][y] >= i - x && ur[i][y] >= i - x;       ans +=           (i - x) % 2 == 0 && lr[x][y] >= (i - x) / 2 && ur[i][y] >= (i - x) / 2;     }   }   void do_lower_rightt(int x, int y) {     for (int i = x + 1, j = y + 1; i < n && j < m && v[i][j]; ++i, ++j) {       ans += rightt[x][y] >= j - y && up[i][j] >= i - x;       ans += rightt[x][y] >= 2 * (j - y) && ur[i][j] >= i - x;     }   }   void work() {     cin >> n >> m;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         char c;         cin >> c;         while (c !=  0  && c !=  1 ) cin >> c;         v[i][j] = c ==  0  ? 1 : 0;       }     populate();     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (!v[i][j]) continue;         do_lower_leftt(i, j);         do_down(i, j);         do_lower_rightt(i, j);       }     }     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i, x, sum = 0;     long long int c[100009];     scanf( %lld %lld , &n, &x);     for (i = 0; i < n; i++) {       scanf( %lld , &c[i]);     }     sort(c, c + n);     for (i = 0; i < n; i++) {       sum = sum + c[i] * x;       x--;       if (x == 0) x++;     }     printf( %lld n , sum);   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 2147383647;   const double pi = 2 * acos(0.0);   const double eps = 1e-9;   struct debugger {     template <typename T>     debugger& operator,(const T& v) {       cerr << v <<    ;       return *this;     }   } dbg;   inline long long gcd(long long a, long long b) {     a = ((a) < 0 ? -(a) : (a));     b = ((b) < 0 ? -(b) : (b));     while (b) {       a = a % b;       swap(a, b);     }     return a;   }   int ext_gcd(int a, int b, int& x, int& y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     int x1, y1;     int d = ext_gcd(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return d;   }   inline long long modInv(int a, int m) {     int x, y;     ext_gcd(a, m, x, y);     if (x < 0) x += m;     return x;   }   inline long long power(long long a, long long p) {     long long res = 1, x = a;     while (p) {       if (p & 1) res = (res * x);       x = (x * x);       p >>= 1;     }     return res;   }   inline long long bigmod(long long a, long long p, long long m) {     long long res = 1, x = a % m;     while (p) {       if (p & 1) res = (res * x) % m;       x = (x * x) % m;       p >>= 1;     }     return res;   }   bool ispalin(string s) {     string s2 = s;     reverse(s2.begin(), s2.end());     if (s == s2)       return true;     else       return false;   }   int main() {     string s, t, x;     cin >> s;     int len = s.size();     for (int i = (0); i <= (len); ++i) {       for (int j = ( a ); j <= ( z ); ++j) {         t = s;         x = j;         t.insert(i, x);         if (ispalin(t)) {           cout << t << endl;           return 0;         }       }     }     cout <<  NA  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long fmm(long long a, long long b, long long m = 1000000007) {     long long r = 0;     a %= m;     b %= m;     while (b > 0) {       if (b & 1) {         r += a;         r %= m;       }       a += a;       a %= m;       b >>= 1;     }     return r % m;   }   inline long long fme(long long a, long long b, long long m = 1000000007) {     long long r = 1;     a %= m;     while (b > 0) {       if (b & 1) {         r *= a;         r %= m;       }       a *= a;       a %= m;       b >>= 1;     }     return r % m;   }   inline long long sfme(long long a, long long b, long long m = 1000000007) {     long long r = 1;     a %= m;     while (b > 0) {       if (b & 1) r = fmm(r, a, m);       a = fmm(a, a, m);       b >>= 1;     }     return r % m;   }   std::vector<long long> primes;   long long primsiz;   std::vector<long long> fact;   std::vector<long long> invfact;   inline void sieve(long long n) {     long long i, j;     std::vector<bool> a(n);     a[0] = true;     a[1] = true;     for (i = 2; i * i < n; ++i) {       if (!a[i]) {         for (j = i * i; j < n; j += i) {           a[j] = true;         }       }     }     for (i = 2; i < n; ++i)       if (!a[i]) primes.push_back(i);     primsiz = primes.size();   }   inline void sieve() {     long long n = 1010000, i, j, k = 0;     std::vector<bool> a(n);     primes.resize(79252);     a[0] = a[1] = true;     for (i = 2; (j = (i << 1)) < n; ++i) a[j] = true;     for (i = 3; i * i < n; i += 2) {       if (!a[i]) {         k = (i << 1);         for (j = i * i; j < n; j += k) a[j] = true;       }     }     k = 0;     for (i = 2; i < n; ++i)       if (!a[i]) primes[k++] = i;     primsiz = k;   }   inline bool isPrimeSmall(unsigned long long n) {     if (((!(n & 1)) && n != 2) || (n < 2) || (n % 3 == 0 && n != 3)) return false;     for (unsigned long long k = 1; 36 * k * k - 12 * k < n; ++k)       if ((n % (6 * k + 1) == 0) || (n % (6 * k - 1) == 0)) return false;     return true;   }   bool _p(unsigned long long a, unsigned long long n) {     unsigned long long t, u, i, p, c = 0;     u = n / 2, t = 1;     while (!(u & 1)) {       u /= 2;       ++t;     }     p = fme(a, u, n);     for (i = 1; i <= t; ++i) {       c = (p * p) % n;       if ((c == 1) && (p != 1) && (p != n - 1)) return 1;       p = c;     }     if (c != 1) return 1;     return 0;   }   inline bool isPrime(unsigned long long n) {     if (((!(n & 1)) && n != 2) || (n < 2) || (n % 3 == 0 && n != 3)) return 0;     if (n < 1373653) {       for (unsigned long long k = 1; (((36 * k * k) - (12 * k)) < n); ++k)         if ((n % (6 * k + 1) == 0) || (n % (6 * k - 1) == 0)) return 0;       return 1;     }     if (n < 9080191) {       if (_p(31, n) || _p(73, n)) return 0;       return 1;     }     if (_p(2, n) || _p(7, n) || _p(61, n)) return 0;     return 1;   }   unsigned long long nCk(long long n, long long k,                          unsigned long long m = 1000000007) {     if (k < 0 || k > n || n < 0) return 0;     if (k == 0 || k == n) return 1;     if (fact.size() >= (unsigned long long)n && isPrime(m)) {       return (((fact[n] * invfact[k]) % m) * invfact[n - k]) % m;     }     unsigned long long i = 0, j = 0, a = 1;     k = ((k) < (n - k) ? (k) : (n - k));     for (; i < (unsigned long long)k; ++i) {       a = (a * (n - i)) % m;       while (j < (unsigned long long)k && (a % (j + 1) == 0)) {         a = a / (j + 1);         ++j;       }     }     while (j < (unsigned long long)k) {       a = a / (j + 1);       ++j;     }     return a % m;   }   void nCkInit(unsigned long long m = 1000000007) {     long long i, mx = 1010000;     fact.resize(mx + 1);     invfact.resize(mx + 1);     fact[0] = 1;     for (i = 1; i <= mx; ++i) {       fact[i] = (i * fact[i - 1]) % m;     }     invfact[mx] = fme(fact[mx], m - 2, m);     for (i = mx - 1; i >= 0; --i) {       invfact[i] = (invfact[i + 1] * (i + 1)) % m;     }   }   template <class T>   T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   void extGCD(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1, y = 0;       return;     }     long long x1, y1;     extGCD(b, a % b, x1, y1);     x = y1;     y = x1 - (a / b) * y1;   }   inline void get(long long &x) {     int n = 0;     x = 0;     char c = getchar_unlocked();     if (c ==  - ) n = 1;     while (c <  0  || c >  9 ) {       c = getchar_unlocked();       if (c ==  - ) n = 1;     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + c -  0 ;       c = getchar_unlocked();     }     if (n) x = -x;   }   inline int get(char *p) {     char c = getchar_unlocked();     int i = 0;     while (c !=   n  && c !=   0  && c !=     && c !=   r  && c != EOF) {       p[i++] = c;       c = getchar_unlocked();     }     p[i] =   0 ;     return i;   }   inline void put(long long a) {     int n = (a < 0 ? 1 : 0);     if (n) a = -a;     char b[20];     int i = 0;     do {       b[i++] = a % 10 +  0 ;       a /= 10;     } while (a);     if (n) putchar_unlocked( - );     i--;     while (i >= 0) putchar_unlocked(b[i--]);     putchar_unlocked(   );   }   inline void putln(long long a) {     int n = (a < 0 ? 1 : 0);     if (n) a = -a;     char b[20];     int i = 0;     do {       b[i++] = a % 10 +  0 ;       a /= 10;     } while (a);     if (n) putchar_unlocked( - );     i--;     while (i >= 0) putchar_unlocked(b[i--]);     putchar_unlocked(  n );   }   const int K = 3;   std::vector<std::vector<long long> > mul(std::vector<std::vector<long long> > a,                                            std::vector<std::vector<long long> > b,                                            unsigned long long m = 1000000007) {     std::vector<std::vector<long long> > c(K, std::vector<long long>(K));     for (int ii = 0; ii < (K); ++ii)       for (int jj = 0; jj < (K); ++jj)         for (int kk = 0; kk < (K); ++kk)           c[ii][jj] = (c[ii][jj] + a[ii][kk] * b[kk][jj]) % m;     return c;   }   std::vector<std::vector<long long> > fme(std::vector<std::vector<long long> > a,                                            unsigned long long n,                                            unsigned long long m = 1000000007) {     if (n == 1) return a;     if (n & 1) return mul(a, fme(a, n - 1, m), m);     std::vector<std::vector<long long> > x = fme(a, n / 2, m);     return mul(x, x, m);   }   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(NULL);     std::cout.tie(NULL);     long long t = 0, n = 0, m = 0, maxx = 0, minn = 0, curr = 0, k = 0, num = 0,               siz = 0, n1 = 0, n2 = 0, n3 = 0, n4 = 0, ind = 0;     long long root = 0, sum = 0, diff = 0, q = 0, choice = 0, d = 0, len = 0,               begg = 0, endd = 0, pos = 0, cnt = 0, lo = 0, hi = 0, mid = 0,               ans = 0;     bool flag = false;     std::string s1, s2, s3, str;     char ch, ch1, ch2, ch3, *ptr;     double dub = 0;     cin >> n1 >> n2;     root = 1;     while (1) {       if (pos == 0) {         if (n1 < root) break;         n1 -= root;       } else {         if (n2 < root) break;         n2 -= root;       }       ++root;       pos = 1 - pos;     }     if (pos == 0)       cout <<  Vladik ;     else       cout <<  Valera ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t = 1;   void solve() {     long long n, x, y, cnt = 0, p = 1;     cin >> n;     vector<long long> arr(n + 1), vis(n + 1, 0);     vector<vector<long long> > v(n + 1);     for (long long i = 0; i < n - 1; i += 1) {       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     queue<long long> q1, q;     for (long long i = 0; i < n; i += 1) {       cin >> x;       arr[i] = x;       q1.push(x);     }     q.push(1);     q1.pop();     while (!q.empty()) {       x = q.front();       vector<long long> vv;       set<long long> s;       cnt = 0;       for (long long i = 0; i < int((v[x]).size()); i += 1) {         if (vis[v[x][i]] == 0) {           cnt++;           vv.push_back(v[x][i]);         }       }       vis[q.front()] = 1;       q.pop();       for (long long i = p; i < p + cnt; i += 1) {         s.insert(arr[i]);         q.push(arr[i]);         vis[arr[i]] = 1;       }       for (long long i = 0; i < int((vv).size()); i += 1) {         if (((s).find(vv[i]) != (s).end())) {           s.erase(vv[i]);         } else {           cout <<  No ;           return;         }       }       p = p + cnt;     }     cout <<  Yes ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> point[100];   double ang[100];   double dp[10000000];   int i, j, k, N, M, K, l, r;   void clear() {}   void init() {     scanf( %d%d%d , &N, &l, &r);     for (i = 0; i <= N - 1; i++) {       int first;       scanf( %d%d%d , &point[i].first, &point[i].second, &first);       ang[i] = (first * 1.0) * 3.1415926535 / 180.0;     }   }   double func(int a, int h, double ang, double st) {     double alpha = atan(fabs(a - st) / h);     if (a > st) {       double beta = alpha - ang;       if (beta > 0) {         double q = h * tan(beta);         return min(1.0 * r, a - q);       } else {         beta *= -1;         return min(1.0 * r, a + h * tan(beta));       }     } else {       if (alpha + ang > 3.1415926535 / 2) {         return 1.0 * r;       } else {         double beta = alpha + ang;         return min(1.0 * r, h * tan(beta) + a);       }     }   }   void calc() {     for (i = 0; i <= (1 << N) - 1; i++) {       dp[i] = l * 1.0;     }     for (i = 0; i <= (1 << N) - 1; i++) {       for (j = 0; j <= N - 1; j++) {         if (!(i & (1 << j)))           dp[i | (1 << j)] =               max(dp[i | (1 << j)],                   func(point[j].first, point[j].second, ang[j], dp[i]));       }     }     printf( %.8f n , dp[(1 << N) - 1] - l);   }   int main() {     clear();     init();     calc();   }


#include <bits/stdc++.h>   using namespace std;   int vis[100005], n, m, x, y, mi, eg, re;   char t;   vector<vector<pair<int, int> > > adj;   vector<vector<int> > re1;   vector<int> t0, t1;   void dfs(int u, int ty) {     if (vis[u] == -1) {       vis[u] = ty;       if (ty == 0)         t0.push_back(u);       else         t1.push_back(u);       for (int j = 0; j < adj[u].size(); j++) {         pair<int, int> te = adj[u][j];         if (te.second == eg)           dfs(te.first, ty);         else           dfs(te.first, 1 - ty);       }     } else if (vis[u] != ty) {       mi = -1;       return;     }   }   int main() {     cin >> n >> m;     adj.assign(n + 1, vector<pair<int, int> >(0));     re1.assign(2, vector<int>(0));     for (int i = 0; i < m; i++) {       cin >> x >> y >> t;       adj[x].push_back(pair<int, int>(y, t ==  B ));       adj[y].push_back(pair<int, int>(x, t ==  B ));     }     memset(vis, -1, sizeof(vis));     mi = 0;     eg = 1;     for (int i = 1; i <= n; i++) {       t0.clear();       t1.clear();       if (vis[i] == -1) dfs(i, 0);       if (mi == -1) break;       if (t0.size() < t1.size()) {         mi += t0.size();         for (int j = 0; j < t0.size(); j++) re1[0].push_back(t0[j]);       } else {         mi += t1.size();         for (int j = 0; j < t1.size(); j++) re1[0].push_back(t1[j]);       }     }     re = mi;     memset(vis, -1, sizeof(vis));     mi = 0;     eg = 0;     for (int i = 1; i <= n; i++) {       t0.clear();       t1.clear();       if (vis[i] == -1) dfs(i, 0);       if (mi == -1) break;       if (t0.size() < t1.size()) {         mi += t0.size();         for (int j = 0; j < t0.size(); j++) re1[1].push_back(t0[j]);       } else {         mi += t1.size();         for (int j = 0; j < t1.size(); j++) re1[1].push_back(t1[j]);       }     }     if (mi == -1) {       if (re == -1)         cout << -1 << endl;       else {         cout << re << endl;         for (int i = 0; i < re1[0].size(); i++) cout << re1[0][i] <<    ;         cout << endl;       }     } else if (re == -1) {       cout << mi << endl;       for (int i = 0; i < re1[1].size(); i++) cout << re1[1][i] <<    ;       cout << endl;     } else {       if (mi < re) {         cout << mi << endl;         for (int i = 0; i < re1[1].size(); i++) cout << re1[1][i] <<    ;         cout << endl;       } else {         cout << re << endl;         for (int i = 0; i < re1[0].size(); i++) cout << re1[0][i] <<    ;         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int hashCh = 31;   struct HashCh {     string code;     int number;   };   long long getHash(string text) {     long long hash = 0;     int size = text.size();     for (int i = 0; i < size; i++) {       int ch = static_cast<int>(text[i]);       hash += pow(hashCh, i) * ch;     }     return hash;   }   int main() {     vector<string> password;     map<long long, HashCh> numbers;     char buf[80];     string oneNumber;     for (int i = 0; i < 80; i++) {       char ch;       cin >> ch;       oneNumber += ch;       if ((i % 10) == 9) {         password.push_back(oneNumber);         oneNumber =   ;       }     }     for (int i = 0; i < 10; i++) {       string number;       cin >> number;       HashCh ch = HashCh();       ch.code = number;       ch.number = i;       long long hash = getHash(number);       numbers[hash] = ch;     }     vector<int> result;     for (int i = 0; i < 8; i++) {       auto it = numbers.find(getHash(password[i]));       if (it != numbers.end() && it->second.code == password[i]) {         result.push_back(it->second.number);       }     }     for (auto i = result.begin(); i != result.end(); i++) {       cout << *i;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct fastIO {     fastIO() { ios_base::sync_with_stdio(0); }   };   const int MAXN = 1e6 * 2;   long long n, a[MAXN], x, ans = MAXN, b;   int main() {     fastIO();     cin >> n;     for (long long i = 0; i < n; i++) cin >> a[i];     for (x = 0; x < n; x++) {       b = 0;       for (long long i = 0; i < n; i++) {         b += (abs(x - i) + i + x) * a[i] * 2;       }       if (0) cerr << ans << endl;       ans = min(ans, b);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, k, x;       cin >> n >> k;       char s;       string str;       int p = n / k, q = n % k;       for (int i = 0; i < k; ++i) {         x = i + 97;         s = x;         if (i == k - 1) p = p + q;         for (int j = 0; j < p; ++j) str += s;       }       cout << str << endl;     }   }


#include<bits/stdc++.h>   using namespace std;   typedef long long ll;   const int maxn=405;   const int P=998244353;   ll dp[2][maxn][maxn][3][3],sum[maxn][maxn];   int cur,las,n,c[26];   void add(ll &dpp,ll add) {    add%=P;    while(add<0) add+=P;    dpp+=add;    while(dpp>=P) dpp-=P;   }   int main() {    scanf( %d ,&n);    for(int i=0;i<26;++i)     scanf( %d ,&c[i]);    dp[0][0][0][0][0]=1;    las=1;cur=0;    for(int i=1;i<=n;++i) {     swap(las,cur);     for(int j=0;j<=i;++j)      for(int k=0;k<=i;++k)       for(int l=0;l<3;++l)        for(int m=0;m<3;++m)         dp[cur][j][k][l][m]=0;     for(int j=0;j<=i;++j)      for(int k=0;k<=i;++k)       for(int l=0;l<3;++l)        for(int m=0;m<3;++m) {         if(!dp[las][j][k][l][m])continue;         add(dp[cur][j][k][m][0],1LL*dp[las][j][k][l][m]*((l||(i<=2))?24:23)%P);         if(l!=1) add(dp[cur][j+1][k][m][1],dp[las][j][k][l][m]);         if(l!=2) add(dp[cur][j][k+1][m][2],dp[las][j][k][l][m]);        }    }     for(int i=0;i<=n;++i)     for(int j=0;j<=n;++j)      for(int k=0;k<3;++k)       for(int kk=0;kk<3;++kk)        add(sum[i][j],dp[cur][i][j][k][kk]);    for(int i=n;i>=0;--i)     for(int j=n;j>=0;--j)      add(sum[i][j],sum[i+1][j]+sum[i][j+1]-sum[i+1][j+1]);    ll res=1;    for(int i=1;i<=n;++i)     res=res*((i<=2)?26:25)%P;    for(int i=0;i<26;++i)     add(res,-sum[c[i]+1][0]);    for(int i=0;i<26;++i)     for(int j=i+1;j<26;++j)      add(res,sum[c[i]+1][c[j]+1]);    res+=P;    res%=P;    printf( %lld n ,res);   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     a = abs(a), b = abs(b);     if (a < b) swap(a, b);     return b ? gcd(b, a % b) : a;   }   vector<vector<int> > adj;   set<int> st;   const int dx[] = {0, 0, -1, 1};   const int dy[] = {-1, 1, 0, 0};   long long n, ary[300000 + 5] = {4, 8, 15, 16, 23, 42}, dp[300000 + 5];   int main(void) {     ios::sync_with_stdio(false), cin.tie(NULL);     cin >> n;     for (int i = 0, j, x; i < n; ++i) {       cin >> x;       j = lower_bound(ary, ary + 6, x) - ary;       if (j == 0)         dp[0] += 1;       else if (dp[j - 1]) {         dp[j - 1] -= 1;         dp[j] += 1;       }     }     cout << n - dp[5] * 6;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[100001];   int n, cost[100001];   int gr, nod, gr2;   void DFS(int x, int t, int val) {     for (int i = 1; i <= v[x][0]; i++) {       if (v[x][i] != t) {         if (val == 0) {           DFS(v[x][i], x, cost[v[x][i]]);         } else {           if (val != cost[v[x][i]]) {             gr++;             if (nod != x) gr2++;             nod = x;           }           DFS(v[x][i], x, cost[v[x][i]]);         }       }     }   }   int main() {     int a, b, i, j;     cin >> n;     for (i = 1; i <= n; i++) {       v[i].push_back(0);     }     for (i = 1; i < n; i++) {       cin >> a >> b;       v[a][0]++;       v[b][0]++;       v[a].push_back(b);       v[b].push_back(a);     }     for (i = 1; i <= n; i++) cin >> cost[i];     DFS(1, 0, 0);     if (gr2 <= 2) {       if (gr == 0) {         cout <<  YES               <<   n               << 1;       } else {         gr = 0;         DFS(nod, 0, 0);         if (gr != 0) {           cout <<  NO ;         } else {           cout <<  YES ;           cout <<   n  << nod;         }       }     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Ans[1001], A[1001], B[1001], C[1001], D[1001], E[1001];   int value(int Arr[], int i, int j, int k) {     return (Arr[j] - Arr[i]) * (Arr[k] - Arr[i]);   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> A[i] >> B[i] >> C[i] >> D[i] >> E[i];     }     int index = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (j != i) {           for (int k = 0; k < n; k++) {             if (k != i && k != j) {               if ((value(A, i, j, k) + value(B, i, j, k) + value(C, i, j, k) +                    value(D, i, j, k) + value(E, i, j, k)) > 0) {                 Ans[i] = -1;                 break;               }             }           }         }       }     }     int count = 0;     for (int i = 0; i < n; i++) {       if (Ans[i] != -1) {         count++;       }     }     cout << count << endl;     for (int i = 0; i < n; i++) {       if (Ans[i] != -1) {         cout << i + 1 << endl;         count++;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int T;     cin >> T;     while (T--) {       int N;       cin >> N;       vector<int> a(N);       ;       for (int& x : a) cin >> x;       int ans = (a[0] == 1);       for (int i = 1; i < N; ++i) {         if (a[i] == 0) continue;         int j = i;         while (j < N && a[j] == 1) ++j;         ans += (j - i) / 3;         i = j - 1;       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using Vi = vector<int>;   using Pii = pair<int, int>;   int uplg(int n) { return 32 - __builtin_clz(n); }   int uplg(ll n) { return 64 - __builtin_clzll(n); }   void run();   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cout << fixed << setprecision(12);     run();     cout << flush;     _Exit(0);   }   ll ch2(ll n) { return n * (n - 1) / 2; }   ll ch3(ll n) { return n * (n - 1) * (n - 2) / 6; }   void run() {     int n;     double p;     cin >> n >> p;     constexpr ll SCALE = 10000;     ll pScaled = llround(p * SCALE);     ll low = pScaled * ch3(n) * 2;     for (int a = (0); a < (n + 1); a++) {       ll cur = (ch3(a) * 2 + ch2(a) * (n - a) * 2 + a * ch2(n - a)) * SCALE;       if (cur >= low) {         cout << a <<   n ;         return;       }     }     assert(0);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string q[41];     long long n, p, i, count = 1, check = 1;     cin >> n >> p;     for (i = 0; i < n; i++) cin >> q[i];     for (i = n - 2; i >= 0; i--) {       if (q[i] ==  halfplus ) {         count = count * 2 + 1;         check++;       } else         count = count * 2;     }     cout << p * count - (p / 2) * check << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve();   const int N = 10000005;   long long i, j, n, s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }   void solve() {     cin >> n;     for (i = 1; i <= n; i = i * 10) {       s += n - i + 1;     }     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   int par[100005], val[100005];   int lefm[100005], rim[100005];   int root = 0;   vector<vector<int> > adjl;   int n;   void pre(int node) {     if (adjl[node].size() == 0) {       lefm[node] = val[node];       rim[node] = val[node];       return;     }     for (int i = (0); i < (adjl[node].size()); ++i) {       pre(adjl[node][i]);       if (val[adjl[node][i]] < val[node])         lefm[node] = lefm[adjl[node][i]];       else         rim[node] = rim[adjl[node][i]];     }   }   double res[100005];   pair<int, int> qu[100005];   void query(int node, int left, int right, long long cost, int dep) {     if (adjl[node].size() == 0) {       for (int i = (left); i < (right); ++i) res[qu[i].second] += cost * 1. / dep;       return;     }     int ind = lower_bound(qu + left, qu + right, make_pair(val[node], 0)) - qu;     if (ind > left && adjl[node].size() == 2)       query(adjl[node][0], left, ind, cost + lefm[adjl[node][1]], dep + 1);     if (ind < right && adjl[node].size() == 2)       query(adjl[node][1], ind, right, cost + rim[adjl[node][0]], dep + 1);   }   int main() {     int x, y, k;     scanf( %d , &n);     adjl.clear();     adjl.resize(n);     for (int i = (0); i < (n); ++i) {       scanf( %d %d , &x, &y);       x--;       val[i] = y;       par[i] = x;       if (x >= 0) adjl[x].push_back(i);       if (x < 0) root = i;     }     for (int i = (0); i < (adjl.size()); ++i) {       if (adjl[i].size() == 2)         if (val[adjl[i][0]] > val[adjl[i][1]]) swap(adjl[i][0], adjl[i][1]);       if (adjl[i].size() == 1) throw 2;     }     pre(root);     scanf( %d , &k);     for (int i = (0); i < (k); ++i) scanf( %d , &qu[i].first), qu[i].second = i;     sort(qu, qu + k);     query(root, 0, k, 0, 0);     for (int i = (0); i < (k); ++i) printf( %.12lf n , res[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long double judge1(long long k, long long d, long long t) {     long double ans;     long double unit = k + (d - k) * 1.0 / 2;     ans = floor(t / unit) * d;     long double res = t * 1.0 - floor(t / unit) * unit;     if (res <= k) {       ans += res;       return ans;     } else {       ans += k;       res -= k;     }     ans += (res * 2);     return ans;   }   long double judge2(long long k, long long d, long long t) {     long double ans;     ans = t;     return ans;   }   long double judge3(long long k, long long d, long long t) {     long double ans;     long double unitt = (k / d + 1) * d * 1.0;     long double unitw = k + (unitt - k) / 2.0;     ans += floor(t / unitw) * unitt;     long double res = t - floor(t / unitw) * unitw;     if (fabs(res - k) <= 1e-9 || res < k) {       ans += res;       return ans;     } else {       ans += k;       res -= k;     }     ans += (res * 2.0);     return ans;   }   int main() {     ios::sync_with_stdio(false);     long long k, d, t;     while (cin >> k >> d >> t) {       long double ans;       if (k < d)         ans = judge1(k, d, t);       else if (k % d == 0)         ans = judge2(k, d, t);       else         ans = judge3(k, d, t);       cout << fixed << setprecision(1) << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 310;   int n, a[maxn];   int main() {     scanf( %d , &n);     for (int i = (1); i <= (n); ++i) scanf( %d , &a[i]);     for (int i = (1); i <= (n - 1); ++i) {       for (int j = (1); j <= (a[i]); ++j) printf( PRL );       printf( R );     }     for (int j = (1); j <= (a[n]); ++j) printf( LRP );   }


#include <bits/stdc++.h>   using namespace std;   long long n, h, ok;   long long cal(long long dep, long long pos, int tag) {     if (ok) return 0;     if (dep == 0) {       ok = 1;       return 0;     }     long long tmp;     if (!tag) {       if (pos > (1LL << (dep - 1)))         tmp = (1LL << dep) + cal(dep - 1, pos - (1LL << (dep - 1)), 0);       else         tmp = 1LL + cal(dep - 1, pos, 1);     } else {       if (pos > (1LL << (dep - 1)))         tmp = 1LL + cal(dep - 1, pos - (1LL << (dep - 1)), 0);       else         tmp = (1LL << dep) + cal(dep - 1, pos, 1);     }     return tmp;   }   int main() {     while (cin >> h >> n) {       ok = 0;       cout << cal(h, n, 0) << endl;     }   }


#include <bits/stdc++.h>   long long a[100][100];   using namespace std;   struct DynamicDisjointSetDS {     std::unordered_map<int, int> parent, degree;     int N;     DynamicDisjointSetDS(int n) { N = n; }     int getParent(int vertex) {       if (parent.find(vertex) != parent.end()) {         if (parent[vertex] != vertex) {           parent[vertex] = getParent(parent[vertex]);           return parent[vertex];         }       } else {         parent.insert(make_pair(vertex, vertex));         degree.insert(make_pair(vertex, 1));       }       return vertex;     }     void Union(int vertexA, int vertexB) {       int x = getParent(vertexA);       int y = getParent(vertexB);       if (x == y) return;       if (degree[x] > degree[y]) {         parent[y] = x;         degree[x] = degree[x] + degree[y];       } else {         parent[x] = y;         degree[y] = degree[y] + degree[x];       }     }     int GetTotalComponent() {       unordered_set<int> total;       for (auto itr = parent.begin(); itr != parent.end(); itr++) {         total.insert(getParent(itr->first));       }       return N - parent.size() + total.size();     }   };   int main() {     using namespace std;     long long n, m, q;     cin >> n >> m >> q;     unordered_set<long long> s, s2;     for (long long i = 1; i <= n; i++) {       s.insert(i);     }     for (long long i = 1; i <= m; i++) {       s2.insert(i);     }     DynamicDisjointSetDS ds(m + 1);     vector<vector<long long>> v(m + 1);     while (q--) {       long long r, c;       cin >> r >> c;       v[c].push_back(r);       s.erase(r);       s2.erase(c);     }     for (vector<long long> v2 : v) {       for (long long i = 1; i < v2.size(); i++) {         ds.Union(v2[i], v2[i - 1]);       }     }     unordered_set<long long> sc;     for (long long i = 1; i <= n; i++) {       sc.insert(ds.getParent(i));     }     cout << (s2.size() + sc.size() - 1) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int f = 1, x = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -f;       c = getchar();     }     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return f * x;   }   inline int lowbit(int x) { return x & (-x); }   inline int modadd(int x, int y) {     return (x + y >= 1000000007 ? x + y - 1000000007 : x + y);   }   inline int sgn(int x) { return (x < 0 ? -1 : (x > 0 ? 1 : 0)); }   template <typename T>   T gcd(T a, T b) {     return (!b) ? a : gcd(b, a % b);   }   int poww(int a, int b) {     int res = 1;     while (b > 0) {       if (b & 1) res = 1ll * res * a % 1000000007;       a = 1ll * a * a % 1000000007, b >>= 1;     }     return res;   }   const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};   const int ddx[] = {-1, -1, -1, 0, 0, 1, 1, 1},             ddy[] = {-1, 0, 1, -1, 1, -1, 0, 1};   int n, a[100005];   void init() {     n = read();     for (int i = 1; i <= n; ++i) a[i] = read();   }   bool check1() {     long long tot = 0;     for (int i = n - 1; i >= 1; --i) {       if (a[i] < tot) return false;       if (a[i] > a[i + 1]) tot += a[i] - a[i + 1];     }     return true;   }   bool check2() {     long long tot = 0;     for (int i = 2; i <= n; ++i) {       if (a[i] < tot) return false;       if (a[i] > a[i - 1]) tot += a[i] - a[i - 1];     }     return true;   }   void solve() {     if (check1())       printf( YES n );     else if (check2())       printf( YES n );     else       printf( NO n );   }   int main() {     int T = read();     while (T--) {       init();       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct grp {     long long to, wt, edgeCode;     char type;   };   struct Node {     long long x, dis;   };   struct comp {     inline bool operator()(const Node& n1, const Node& n2) const {       if (n1.dis != n2.dis) return n1.dis < n2.dis;       return n1.x < n2.x;     }   };   void dijkstra(long long n, vector<vector<grp> >& edges, vector<long long>& dis,                 vector<bool>& visited, vector<pair<long long, long long> >& par) {     set<Node, comp> myset;     for (long long i = 1; i <= n; ++i) {       Node node;       node.x = i, node.dis = dis[i];       myset.insert(node);     }     while (myset.size()) {       set<Node>::iterator it = myset.begin();       Node node = *it;       myset.erase(it);       visited[node.x] = true;       for (long long i = 0; i < edges[node.x].size(); ++i) {         grp& edge = edges[node.x][i];         if (visited[edge.to]) {           continue;         }         long long newDis = dis[node.x] + edge.wt;         if (newDis < dis[edge.to] ||             (newDis == dis[edge.to] && edge.type ==  r )) {           Node prevNode, newNode;           prevNode.x = edge.to, prevNode.dis = dis[edge.to];           newNode.x = edge.to, newNode.dis = newDis;           dis[edge.to] = newDis;           par[edge.to] = {node.x, edge.edgeCode};           myset.erase(myset.find(prevNode));           myset.insert(newNode);         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, m, k;     cin >> n >> m >> k;     vector<vector<grp> > edges(n + 1);     long long edgeCode = 0;     for (long long i = 0; i < m; i++) {       long long x, y, w;       cin >> x >> y >> w;       grp g;       g.to = y, g.wt = w, g.type =  r , g.edgeCode = edgeCode++;       edges[x].push_back(g);       g.to = x, g.edgeCode = edgeCode++;       edges[y].push_back(g);     }     vector<pair<long long, long long> > trainPaths(k);     for (long long i = 0; i < k; ++i) {       long long y, w;       cin >> y >> w;       trainPaths[i] = {y, edgeCode};       grp g;       g.to = y, g.wt = w, g.type =  t , g.edgeCode = edgeCode++;       edges[1].push_back(g);     }     vector<long long> dis(n + 1, 100000000000000000);     vector<bool> visited(n + 1, false);     vector<pair<long long, long long> > par(n + 1, {-1, -1});     dis[1] = 0;     dijkstra(n, edges, dis, visited, par);     long long ans = 0;     for (long long i = 0; i < k; ++i) {       long long dest = trainPaths[i].first, edgeCode = trainPaths[i].second;       if (par[dest].first == 1 && par[dest].second == edgeCode) {         continue;       }       ++ans;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   long long int power(long long int x, long long int b) {     long long int p = 1;     while (b > 0) {       if (b & 1) {         p = p * x;         p %= 1000000007;       }       b >>= 1;       x *= x;       x %= 1000000007;     }     return p % 1000000007;   }   using namespace std;   struct lex_compare {     bool operator()(         const pair<long long int, pair<long long int, long long int> > p1,         const pair<long long int, pair<long long int, long long int> > p2) {       return (p1.first == p2.first) ? p1.second.first < p2.second.first                                     : p1.first > p2.first;     }   };   long long int n, m, b, mo;   long long int dp[2][500 + 1][500 + 1];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long int w, m;     cin >> w >> m;     bool f = 1;     map<long long int, long long int> coeff;     long long int term = 1;     while (m >= term && term <= 10000000000) {       long long int x = (term * (m / term) - (w * term) * (m / (w * term)));       x /= term;       if (x <= 1) {         term *= w;       } else {         if (x != (w - 1)) {           f = 0;           break;         } else {           m += (w * term - term);         }         term *= w;       }     }     if (f)       cout <<  YES             <<   n ;     else       cout <<  NO             <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> di[100003];   struct trie {     trie *zero, *one;     int val;     trie() {       zero = one = NULL;       val = 100003;     }   } * root[100003];   void add(trie *cur, int a) {     int i, ck;     for (i = 20; i >= 0; i--) {       ck = (1 << i & a);       if (ck == 0) {         cur->val = min(cur->val, a);         if (cur->zero == NULL) cur->zero = new trie();         cur = cur->zero;         cur->val = min(cur->val, a);       } else {         cur->val = min(cur->val, a);         if (cur->one == NULL) cur->one = new trie();         cur = cur->one;         cur->val = min(cur->val, a);       }     }   }   int query(trie *cur, int a, int lim) {     int i, ck, ans;     for (i = 20; i >= 0; i--) {       ck = (1 << i & a);       if (ck == 0) {         if (cur->one != NULL && cur->one->val + a <= lim)           cur = cur->one;         else if (cur->zero != NULL)           cur = cur->zero;         ans = cur->val;       } else {         if (cur->zero != NULL && cur->zero->val + a <= lim)           cur = cur->zero;         else if (cur->one != NULL)           cur = cur->one;         ans = cur->val;       }     }     return ans;   }   void pre() {     for (int i = 1; i < 100003; i++) {       for (int j = i; j < 100003; j += i) di[j].push_back(i);       root[i] = new trie();     }   }   int main() {     pre();     int q, a, k, s, v, ty;     scanf( %d , &q);     while (q--) {       scanf( %d , &ty);       if (ty == 1) {         scanf( %d , &a);         for (int x : di[a]) {           add(root[x], a);         }       } else {         scanf( %d %d %d , &v, &k, &s);         if (root[k]->val + v > s || root[k]->val == 0 || v % k)           printf( -1 n );         else           printf( %d n , query(root[k], v, s));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isPrime(int n) {     if (n <= 1) return false;     for (int i = 2; i < n; i++)       if (n % i == 0) return false;     return true;   }   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       vector<long long int> v;       for (long long int i = 0; i < n; i++) {         long long int x;         cin >> x;         v.push_back(x);       }       if (v[0] + v[1] <= v[n - 1]) {         cout << 1 <<     << 2 <<     << n <<   n ;       } else {         cout << -1 <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char bb[111][111];   int in[111][111];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) scanf( %s , bb[i]);     vector<pair<pair<int, int>, int>> stars;     for (int i = 1; i < n - 1; i++) {       for (int j = 1; j < m - 1; j++) {         if (bb[i][j] !=  * ) continue;         int l, r, u, d;         l = r = i;         u = d = j;         for (int k = i; k < n; k++)           if (bb[k][j] ==  * )             r = k;           else             break;         for (int k = i; k >= 0; k--)           if (bb[k][j] ==  * )             l = k;           else             break;         for (int k = j; k < m; k++)           if (bb[i][k] ==  * )             d = k;           else             break;         for (int k = j; k >= 0; k--)           if (bb[i][k] ==  * )             u = k;           else             break;         int starLevel = min(min(r - i, i - l), min(d - j, j - u));         if (starLevel) {           for (int k = i - starLevel; k <= i + starLevel; k++) in[k][j] = 1;           for (int k = j - starLevel; k <= j + starLevel; k++) in[i][k] = 1;           stars.push_back({{i + 1, j + 1}, starLevel});         }       }     }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if ((bb[i][j] ==  *  && in[i][j] == 0) ||             (in[i][j] == 1 && bb[i][j] ==  . ))           return puts( -1 );     cout << stars.size() << endl;     for (auto u : stars) {       printf( %d %d %d n , u.first.first, u.first.second, u.second);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 500;   const int LN = 21;   const long long mod = 1e9 + 7;   const long long INF = 1LL << 57;   long long n, m, u, v, k, t, q, a, x, d;   int tree[4 * N];   int sum[4 * N];   int lim = 1e6 + 2;   int arr[N], brr[N];   bool print = false;   void modify(int i, int l, int r, int index, int val) {     if (l == r) {       tree[i] += val;       sum[i] = tree[i];       return;     }     int mid = (l + r) / 2;     if (index <= mid)       modify(i + 1 + i, l, mid, index, val);     else       modify(i + 2 + i, mid + 1, r, index, val);     tree[i] = max(tree[i + 2 + i], tree[i + 1 + i] + sum[i + 2 + i]);     sum[i] = sum[i + 1 + i] + sum[i + 2 + i];   }   int find(int i, int l, int r, int sumx) {     if (l == r) return l;     int mid = (l + r) / 2;     if (tree[i + 2 + i] + sumx > 0) {       return find(i + 2 + i, mid + 1, r, sumx);     } else       return find(i + 1 + i, l, mid, sumx + sum[i + 2 + i]);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       cin >> arr[i];     }     for (int i = 1; i <= m; ++i) cin >> brr[i];     for (int i = 1; i <= n; ++i) {       modify(0, 0, lim, arr[i], 1);     }     for (int i = 1; i <= m; ++i) {       modify(0, 0, lim, brr[i], -1);     }     cin >> q;     while (q--) {       int type;       cin >> type;       if (type == 1) {         int i, x;         cin >> i >> x;         modify(0, 0, lim, arr[i], -1);         modify(0, 0, lim, x, 1);         arr[i] = x;         int price = find(0, 0, lim, 0);         if (price == 0)           cout << -1 <<   n ;         else           cout << price <<   n ;       } else {         int i, x;         cin >> i >> x;         modify(0, 0, lim, brr[i], 1);         modify(0, 0, lim, x, -1);         brr[i] = x;         int price = find(0, 0, lim, 0);         if (price == 0)           cout << -1 <<   n ;         else           cout << price <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &a) {     T 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();     }     a = x * f;   }   template <typename T, typename... Args>   void read(T &t, Args &...args) {     read(t);     read(args...);   }   long long n, k, a[100005];   struct node {     long long len, k;     bool operator<(const node &x) const {       long long tmp1 = (len / k) * (len / k) * (k - len % k) +                        (len / k + 1) * (len / k + 1) * (len % k);       long long tmp2 = (x.len / x.k) * (x.len / x.k) * (x.k - x.len % x.k) +                        (x.len / x.k + 1) * (x.len / x.k + 1) * (x.len % x.k);       long long kk = k + 1;       long long tmpp1 = (len / kk) * (len / kk) * (kk - len % kk) +                         (len / kk + 1) * (len / kk + 1) * (len % kk);       kk = x.k + 1;       long long tmpp2 = (x.len / kk) * (x.len / kk) * (kk - x.len % kk) +                         (x.len / kk + 1) * (x.len / kk + 1) * (x.len % kk);       tmp1 -= tmpp1;       tmp2 -= tmpp2;       if (k == len) tmp1 = 0;       if (x.k == x.len) tmp2 = 0;       return tmp1 < tmp2;     }   };   priority_queue<node> q;   void update(long long &ans, node &x) {     ans -= (x.len / x.k) * (x.len / x.k) * (x.k - x.len % x.k) +            (x.len / x.k + 1) * (x.len / x.k + 1) * (x.len % x.k);     x.k++;     ans += (x.len / x.k) * (x.len / x.k) * (x.k - x.len % x.k) +            (x.len / x.k + 1) * (x.len / x.k + 1) * (x.len % x.k);   }   signed main() {     read(n, k);     long long ans = 0;     for (long long i = 1; i <= n; i++) {       read(a[i]);       node tmp;       tmp.len = a[i];       tmp.k = 1;       q.push(tmp);     }     for (long long i = 1; i <= n; i++) ans += a[i] * a[i];     k -= n;     while (k) {       k += 19260817;       node x = q.top();       q.pop();       update(ans, x);       q.push(x);       k -= 19260818;     }     printf( %lld n , ans +  O  -  O );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, l, v1, v2, k;   long double dn, dl, dv1, dv2, dk;   long long times;   long double x;   double T;   int main() {     scanf( %lld%lld%lld%lld%lld , &n, &l, &v1, &v2, &k);     dn = n;     dl = l;     dv1 = v1;     dv2 = v2;     dk = k;     times = (n - 1) / k + 1;     x = l / (v2 * times - (dv2 - dv1) / (dv2 + dv1) * dv2 * (times - 1));     T = x * (times + (dv2 - dv1) / (dv2 + dv1) * (times - 1));     printf( %lf n , T);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const N = 3e5;   int n, p1[N], p2[N], p3[N], num1[N], num2[N], F[N][2], T[N * 4];   void buildT(int v, int tl, int tr) {     if (tl == tr) {       T[v] = 1;     } else {       int tm = (tl + tr) / 2;       buildT(v * 2, tl, tm);       buildT(v * 2 + 1, tm + 1, tr);       T[v] = T[v * 2] + T[v * 2 + 1];     }   }   void updT(int v, int tl, int tr, int p) {     if (tl == tr) {       T[v] = 0;     } else {       int tm = (tl + tr) / 2;       if (tm >= p)         updT(v * 2, tl, tm, p);       else         updT(v * 2 + 1, tm + 1, tr, p);       T[v] = T[v * 2] + T[v * 2 + 1];     }   }   int getT(int v, int tl, int tr, int k) {     if (tl == tr) {       return tl;     } else {       int tm = (tl + tr) / 2;       if (T[v * 2] >= k)         return getT(v * 2, tl, tm, k);       else         return getT(v * 2 + 1, tm + 1, tr, k - T[v * 2]);     }   }   void upd(int x, int t) {     while (x < n) {       ++F[x][t];       x |= (x + 1);     }   }   int get(int x, int t) {     int r = 0;     while (x >= 0) {       r += F[x][t];       x = (x & (x + 1)) - 1;     }     return r;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &p1[i]);     for (int i = 0; i < n; ++i) scanf( %d , &p2[i]);     for (int i = 0; i < n; ++i) {       num1[i] = p1[i] - get(p1[i], 0);       upd(p1[i] + 1, 0);       num2[i] = p2[i] - get(p2[i], 1);       upd(p2[i] + 1, 1);     }     for (int i = n - 1; i >= 0; --i) {       num1[i] += num2[i];       if (i) num1[i - 1] += num1[i] / (n - i);       num1[i] %= (n - i);     }     buildT(1, 0, n - 1);     for (int i = 0; i < n; ++i) {       int need = num1[i] + 1;       int val = getT(1, 0, n - 1, need);       p3[i] = val;       updT(1, 0, n - 1, val);     }     for (int i = 0; i < n; ++i) printf( %d  , p3[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v;   long long x, y, z, a, b, c, sum, ans, total, t, cnt, n, m, k, p, kase;   string s1, s2;   map<long long, long long> mp;   set<long long> s;   map<long long, long long>::iterator itr1, ptr1;   set<long long>::iterator itr, ptr;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> t;     while (t--) {       long long x1, x2, y1, y2;       cin >> x1 >> y1 >> x2 >> y2;       ans = abs(x1 - x2);       ans *= abs(y1 - y2);       cout << ans + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   long long n, sum, n1, pick, ans, t, a[N], b[N], f[N], f1[N], m, t1;   int main() {     scanf( %lld , &n);     for (int i = 1; i <= 8; i++) {       scanf( %lld , &a[i]);       sum = sum + a[i] * i;     }     if (sum <= n) return printf( %lld n , sum), 0;     n1 = std::max((long long)0, n - 840), n = n - n1;     for (int i = 1; i <= 8; i++) {       if (a[i] < n1 / i)         pick = a[i];       else         pick = n1 / i;       if (a[i] - pick < 10) pick = std::max((long long)0, a[i] - 10);       ans = ans + pick * i, n1 = n1 - pick * i, a[i] = a[i] - pick;     }     n += n1;     for (int i = 1; i <= 8; i++) {       t = 1;       while (a[i] > 0) {         t1 = std::min(t, a[i]);         a[i] = a[i] - t1;         f[++m] = t1 * i;         t <<= 1;       }     }     for (long long i = 1; i <= m; i++)       for (long long j = n; j >= f[i]; j--)         f1[j] = std::max(f1[j], f1[j - f[i]] + f[i]);     printf( %lld n , ans + f1[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string st[5050];   int fr[27];   int main() {     memset(fr, 0, sizeof(fr));     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> k >> n;     for (int i = 0; i < k; i++) {       cin >> st[i];     }     string res = st[0];     memset(fr, 0, sizeof(fr));     bool du = false;     for (int i = 0; i < n; i++) {       fr[res[i] -  a ]++;       if (fr[res[i] -  a ] > 1) {         du = true;       }     }     int ma = 0;     int mi = 0;     bool po = true;     for (int i = 1; i < k; i++) {       int df = 0;       int ct[27] = {0};       for (int j = 0; j < n; j++) {         ct[st[i][j] -  a ]++;         if (st[i][j] != res[j]) {           df++;         }       }       if (df > 4) {         po = false;         break;       }       for (int j = 0; j < 27; j++) {         if (ct[j] != fr[j]) {           po = false;           break;         }       }       if (df > ma) {         ma = df;         mi = i;       }     }     if (!po) {       cout << -1 <<   n ;       return 0;     }     if (ma == 0) {       swap(res[0], res[1]);       cout << res <<   n ;       return 0;     }     if (ma == 2) {       if (!du) {         cout << -1 <<   n ;         return 0;         cout << -1 <<   n ;         return 0;       }       cout << res <<   n ;       return 0;     }     int q[4];     int ctr = 0;     for (int i = 0; i < n; i++) {       if (res[i] != st[mi][i]) {         q[ctr++] = i;       }     }     po = false;     int tr[2] = {0, 0};     for (int id = 0; id < 3; id++) {       if (ma < 4) {         q[3] = q[id];       } else if (id > 0)         break;       for (int i = 0; i < 4; i++) {         for (int j = 0; j < 4; j++) {           if (po) break;           int md = 0;           swap(res[q[i]], res[q[j]]);           for (int c = 1; c < k; c++) {             int df = 0;             for (int l = 0; l < n; l++) {               if (res[l] != st[c][l]) {                 df++;               }             }             md = max(md, df);           }           swap(res[q[i]], res[q[j]]);           if (md == 2) {             po = true;             tr[0] = i;             tr[1] = j;           }         }       }     }     if (po) {       swap(res[q[tr[0]]], res[q[tr[1]]]);       cout << res <<   n ;     } else {       cout << -1 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   string multiply(string num1, string num2) {     int len1 = num1.size();     int len2 = num2.size();     if (len1 == 0 || len2 == 0) return  0 ;     vector<int> result(len1 + len2, 0);     int i_n1 = 0;     int i_n2 = 0;     for (int i = len1 - 1; i >= 0; i--) {       int carry = 0;       int n1 = num1[i] -  0 ;       i_n2 = 0;       for (int j = len2 - 1; j >= 0; j--) {         int n2 = num2[j] -  0 ;         int sum = n1 * n2 + result[i_n1 + i_n2] + carry;         carry = sum / 10;         result[i_n1 + i_n2] = sum % 10;         i_n2++;       }       if (carry > 0) result[i_n1 + i_n2] += carry;       i_n1++;     }     int i = result.size() - 1;     while (i >= 0 && result[i] == 0) i--;     if (i == -1) return  0 ;     string s =   ;     while (i >= 0) s += std::to_string(result[i--]);     return s;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int T;     cin >> T;     while (T--) {       long int n;       cin >> n;       n = n / 2;       string n1, n2, n3, ans1, ans;       int temp;       if (n % 3 == 0) {         temp = 4 * n / 3;         n1 = to_string(temp);         n2 = to_string(n + 1);         n3 = to_string(2 * n + 1);         ans1 = multiply(n1, n2);         ans = multiply(ans1, n3);       } else if (n % 3 == 2) {         temp = 4 * (n + 1) / 3;         n1 = to_string(temp);         n2 = to_string(n);         n3 = to_string(2 * n + 1);         ans1 = multiply(n1, n2);         ans = multiply(ans1, n3);       } else {         temp = 4 * (2 * n + 1) / 3;         n1 = to_string(temp);         n2 = to_string(n + 1);         n3 = to_string(n);         ans1 = multiply(n1, n2);         ans = multiply(ans1, n3);       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int n, x[N], y[N], xs[N], ys[N], cnt[2][2];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &x[i], &y[i]);       xs[i] = x[i], ys[i] = y[i];     }     sort(xs + 1, xs + n + 1);     sort(ys + 1, ys + n + 1);     int m = (n + 1) / 2;     int cx = xs[m], cy = ys[m];     int dx = xs[m + 1] - xs[m], dy = ys[m + 1] - ys[m];     if (n & 1) {       dx = min(dx, xs[m] - xs[m - 1]);       dy = min(dy, ys[m] - ys[m - 1]);     }     long long ans = 0;     bool flag = 0;     for (int i = 1; i <= n; i++) {       ans += abs(x[i] - cx) + abs(y[i] - cy);       ++cnt[x[i] <= cx][y[i] <= cy];       if (x[i] == cx && y[i] == cy) flag = 1;     }     if (cnt[0][0] && cnt[0][1] && cnt[1][1] && cnt[1][0]) {       if (n % 2 == 0 || flag) ans -= min(dx, dy);     }     printf( %lld n , ans * 2);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cout << fixed;     double d, L, v1, v2;     cin >> d >> L >> v1 >> v2;     cout << setprecision(8) << (L - d) / (v1 + v2) << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long scan_d() {     char t = getchar();     long long you = 0;     while (t >  9  || t <  0 ) t = getchar();     while (t <=  9  && t >=  0 ) {       you *= 10;       you += t -  0 ;       t = getchar();     }     return you;   }   long long dp[1050][1050];   long long op[1001];   int main() {     for (int i = 0; i <= 1010; i++) dp[1][i] = 1;     for (int i = 2; i <= 1010; i++)       for (int o = i - 1; o <= 1010; o++) {         dp[i][o] = dp[i - 1][o - 1] + dp[i][o - 1];         dp[i][o] %= 1000000007;       }     long long y;     y = scan_d();     long long sum = 0;     for (int i = 1; i <= y; i++) {       op[i] = scan_d();     }     long long ans = 1;     for (int i = 1; i <= y; i++) {       sum += op[i];       ans *= dp[op[i]][sum - 1];       ans %= 1000000007;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const long long mod = 1e9 + 7;   const long long N = 1e5 + 10;   inline long long add(long long x, long long y) {     x += y;     if (x >= mod) x -= mod;     return x;   }   inline long long mul(long long x, long long y) {     x = (1LL * x * y) % mod;     return x;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long n;     cin >> n;     n--;     cout <<  0 0  << endl;     fflush(stdout);     if (n == 0) {       cout <<  1 0 1 1 ;       fflush(stdout);       return 0;     }     string prev;     cin >> prev;     long long l = 0;     long long r = 1e9;     long long i = 1;     while (i <= n) {       long long m = (l + r) / 2;       cout << m <<                <<  0  << endl;       fflush(stdout);       string s;       cin >> s;       if (s == prev) {         l = m;       } else {         r = m;       }       i++;     }     if (r - l < 2) {       cout << r <<   1   << (r + 1) <<     << (2 * (r + 1) - 2 * l - 1);       fflush(stdout);       return 0;     }     long long m = (l + r) / 2;     cout << m <<   0   << m <<   1 ;     fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> c;   vector<bool> used;   void dfs(int u, vector<vector<int>>& v) {     used[u] = 1;     for (int i = 0; i < v[u].size(); i++) {       if (c[u] == c[v[u][i]] && !used[v[u][i]]) {         dfs(v[u][i], v);       }     }   }   int main() {     int n;     cin >> n;     vector<vector<int>> v(n);     c.resize(n);     used.resize(n, 0);     vector<int> cnt(110000);     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       v[a].push_back(b);       v[b].push_back(a);     }     for (int i = 0; i < n; i++) {       cin >> c[i];     }     for (int i = 0; i < n; i++) {       if (!used[i]) {         cnt[c[i]]++;         dfs(i, v);       }     }     multiset<int> data;     for (int i = 0; i < 100010; i++) {       for (int j = 0; j < cnt[i]; j++) {         data.insert(i);       }     }     for (int i = 0; i < n; i++) {       bool check = 0;       multiset<int> tmp;       for (int j = 0; j < v[i].size(); j++) {         if (c[v[i][j]] == c[i]) {           check = 1;         }         tmp.insert(c[v[i][j]]);       }       if (!check) {         tmp.insert(c[i]);       }       if (tmp == data) {         cout <<  YES  << endl;         cout << i + 1 << endl;         return 0;       }     }     cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   struct node {     double x, y;   } po[1010];   double dis(node a, node b) {     return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));   }   node mark;   double cha(node a, node b, node c) {     return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);   }   double get(node a, node b, node c) {     return abs(cha(a, b, c)) / dis(a, b) / 2.0;   }   int main() {     int n;     cin >> n;     double ans = 1e9;     for (int i = (0); i < (n); ++i) cin >> po[i].x >> po[i].y;     for (int i = (0); i < (n); ++i) {       ans = min(ans, get(po[(i - 1 + n) % n], po[(i + 1) % n], po[i]));     }     cout << fixed << setprecision(10) << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long n, x, c, cnt;   vector<long long> v1, v2;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     while (n--) {       cin >> x;       if (x > 0)         v1.push_back(x), c += x;       else         v2.push_back(abs(x)), cnt += abs(x);     }     if (c > cnt) {       cout <<  first n ;       return 0;     }     if (cnt > c) {       cout <<  second n ;       return 0;     }     bool a = 0;     for (int i = 0; i < min(v1.size(), v2.size()); i++) {       if (v1[i] > v2[i]) {         cout <<  first n ;         return 0;       } else if (v1[i] < v2[i]) {         cout <<  second n ;         return 0;       }     }     if (x < 0)       cout <<  second  << endl;     else       cout <<  first  << endl;     return 0;   }