malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int k25 = 0, k50 = 0, n;     cin >> n;     bool f = 1;     for (int i = 0; i < n; i++) {       int q;       cin >> q;       if (q == 25)         k25++;       else if (q == 50) {         if (k25) {           k25--;           k50++;         } else           f = 0;       } else {         if (k50 && k25) {           k25--;           k50--;         } else if (k25 >= 3)           k25 -= 3;         else           f = 0;       }     }     if (f)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, a, b = 0;     cin >> x;     for (int i = 1; i <= x; i++) {       int k = 1;       while (i * k <= x) {         if (i * i * k > x && k < x) {           a = i * k;           b = i;           break;         } else           k = k + 1;       }     }     if (b == 0)       cout << -1;     else       cout << a <<     << b;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200000 + 10;   int a[maxn];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       a[x] = i;     }     int x = 0;     for (int i = 0; i < n; i++) {       int m;       scanf( %d , &m);       int t = a[m] - x;       if (t < 0) {         printf( 0  );       } else {         printf( %d  , t);         x = a[m];       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long a[n + 2];       map<long long, long long> m;       for (long long i = 1; i <= 1000; i++) {         m[i] = 0;       }       for (long long i = 0; i < n; i++) {         cin >> a[i];         m[a[i]]++;       }       vector<pair<long long, long long>> v;       for (auto i : m) {         v.push_back({i.first, i.second});       }       long long d = 0;       sort(v.rbegin(), v.rend());       for (long long i = 0; i < v.size(); i++) {         d += v[i].second;         if (d >= v[i].first) {           cout << v[i].first << endl;           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, x, frq, ans[25][25];   map<int, int> mp;   priority_queue<pair<int, int> > pq;   priority_queue<pair<int, set<pair<int, int> > > > mat;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n * n; ++i) cin >> x, ++mp[x];     for (auto it : mp) pq.push({it.second, it.first});     for (int i = 0; i < (n + 1) / 2; ++i) {       for (int j = 0; j < (n + 1) / 2; ++j) {         set<pair<int, int> > temp;         temp.insert({i, j});         temp.insert({n - i - 1, j});         temp.insert({i, n - j - 1});         temp.insert({n - i - 1, n - j - 1});         mat.push({temp.size(), temp});       }     }     while (mat.size()) {       set<pair<int, int> > temp = mat.top().second;       x = pq.top().second, frq = pq.top().first, mat.pop(), pq.pop();       if (frq < temp.size()) return cout <<  NO , 0;       for (auto it : temp) ans[it.first][it.second] = x, --frq;       pq.push({frq, x});     }     cout <<  YES n ;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) cout << ans[i][j] <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXI = numeric_limits<int>::max() / 2;   const int MINI = numeric_limits<int>::min() / 2;   const long long MAXL = numeric_limits<long long>::max() / 2;   const long long MINL = numeric_limits<long long>::min() / 2;   int cnt[2][2];   long long pro(long long s, int &s1, int &s2) {     while (s % 2 == 0) {       ++s1;       s /= 2;     }     while (s % 3 == 0) {       ++s2;       s /= 3;     }     return s;   }   int solve(int &s1, int &s2, int t, long long &a, long long &b) {     int ans = 0;     while (s1 > t) {       --s1;       ++s2;       ++ans;       if (a % 3 == 0)         a = a * 2 / 3;       else         b = b * 2 / 3;     }     return ans;   }   int solve(int &s1, int &s2, long long &a, long long &b) {     int ans = 0;     while (s1 > s2) {       --s1;       ++ans;       if (a % 2 == 0)         a /= 2;       else         b /= 2;     }     return ans;   }   int main(int argc, char *argv[]) {     long long a, b, c, d, s, t;     cin >> a >> b >> c >> d;     s = a * b;     t = c * d;     if (pro(s, cnt[0][0], cnt[0][1]) != pro(t, cnt[1][0], cnt[1][1]))       cout << -1 << endl;     else {       int ans = cnt[0][1] > cnt[1][1]                     ? solve(cnt[0][1], cnt[0][0], cnt[1][1], a, b)                     : solve(cnt[1][1], cnt[1][0], cnt[0][1], c, d);       ans += cnt[0][0] > cnt[1][0] ? solve(cnt[0][0], cnt[1][0], a, b)                                    : solve(cnt[1][0], cnt[0][0], c, d);       cout << ans << endl;       cout << a <<     << b << endl;       cout << c <<     << d << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007LL;   long long powmod(long long b, long long e, long long m) {     if (!e) return 1;     long long r = powmod(b, e / 2, m);     return ((r * r) % m * ((e & 1) ? b : 1)) % m;   }   string s;   long long k;   int main() {     cin >> s >> k;     long long cum = 0;     for (int i = s.size() - 1; i >= 0; i--) {       if (s[i] ==  5  || s[i] ==  0 ) cum += powmod(2, i, mod);       if (cum >= mod) cum -= mod;     }     long long len = s.size();     long long num = powmod(2, len * k, mod);     num = (num - 1 + mod) % mod;     long long den = (powmod(2, s.size(), mod) - 1 + mod) % mod;     long long show = (num * powmod(den, mod - 2, mod)) % mod;     long long opa = (cum * show) % mod;     cout << opa << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int mode, t;   const int INF = 1e9 + 7;   void solve() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     int rot = 0;     if (s[0] == s[n - 1]) {       int start = -1;       for (int i = 0; i < n - 1; i++) {         if (s[i] != s[i + 1]) {           start = i + 1;           break;         }       }       if (start < 0) {         cout << s << endl;         return;       }       rotate(s.begin(), s.begin() + start, s.end());       rot = start;     }     vector<int> sizes;     char prev = s[0];     int size = 0;     for (char c : s) {       if (c == prev) {         size++;       } else {         sizes.push_back(size);         prev = c;         size = 1;       }     }     sizes.push_back(size);     int groups = sizes.size();     vector<int> dist(groups, INF);     for (int i = 0; i < 2 * groups; i++) {       if (sizes[i % groups] > 1) {         dist[i % groups] = 0;       } else {         dist[i % groups] =             min(dist[i % groups], 1 + dist[(i - 1 + groups) % groups]);       }     }     for (int i = 2 * groups - 1; i >= 0; i--) {       dist[i % groups] =           min(dist[i % groups], 1 + dist[(i + 1 + groups) % groups]);     }     vector<char> answer(n);     int i = 0;     char curr = s[0];     for (int group_no = 0; group_no < groups; group_no++) {       if (sizes[group_no] > 1) {         for (int rep = 0; rep < sizes[group_no]; rep++) {           answer[i] = curr;           i++;         }       } else {         if (k <= dist[group_no]) {           if (k % 2) {             answer[i] =  B  +  W  - curr;           } else {             answer[i] = curr;           }         } else {           if (dist[group_no] % 2) {             answer[i] =  B  +  W  - curr;           } else {             answer[i] = curr;           }         }         i++;       }       curr =  B  +  W  - curr;     }     rotate(answer.begin(), answer.begin() + n - rot, answer.end());     for (char c : answer) {       cout << c;     }     cout << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     mode = 0;     if (mode == 0) {       solve();     } else {       cin >> t;       while (t--) {         solve();       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, l, v1, v2, k;   int main() {     cin >> n >> l >> v1 >> v2 >> k;     long double T = 0;     long double S = l, t1, t2, d;     int m = ((n + k - 1) / k);     S = S / ((long double)(m) - ((long double)(m - 1) * (v2 - v1)) / (v2 + v1));     t1 = S / v2;     t2 = (S * (v2 - v1)) / (v2 + v1) / v2;     T = t1 * m + t2 * (m - 1);     cout << fixed << setprecision(15) << T;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x7fffffff;   int main() {     int n;     cin >> n;     int sum = 0;     int zero = 0;     for (int i = 0; i < 2 * n; i++) {       int x;       scanf( %*d.%d , &x);       sum += x;       if (x == 0) zero++;     }     int ans = INF;     for (int k = 0; k <= n; k++) {       if (k + zero < n) continue;       ans = min(ans, abs(k * 1000 - sum));     }     printf( %d.%03d n , ans / 1000, ans % 1000);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 998244353;   long long pwr(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % MOD;       b >>= 1, a = a * a % MOD;     }     return ans;   }   long long inv(long long a) { return pwr(a, MOD - 2); }   template <class T, int SZ>   struct BIT {     T bit[SZ + 1];     BIT() { memset(bit, 0, sizeof bit); }     void upd(int k, T val) {       for (; k <= SZ; k += (k & -k)) bit[k] += val;     }     T query(int k) {       T temp = 0;       for (; k > 0; k -= (k & -k)) temp += bit[k];       return temp;     }     T query(int l, int r) { return query(r) - query(l - 1); }   };   BIT<long long, 1 << 18> b1;   BIT<long long, 1 << 18> b2;   map<int, bool> m;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, cnt = 0, ans = 0, k;     cin >> n;     long long a[n];     for (int i = 0; i < n; ++i) {       cin >> a[i];       if (a[i] == -1)         ++cnt;       else {         m[a[i]] = 1;       }     }     ans += ((cnt * (cnt - 1)) % MOD * inv((long long)4)) % MOD;     for (int i = 0; i < n; ++i) {       if (a[i] != -1) {         b1.upd(a[i], 1LL);         ans += b1.query(a[i] + 1, n);         ans %= MOD;       }     }     for (int i = 1; i <= n; ++i) {       if (!m[i]) b2.upd(i, 1LL);     }     long long left[n], right[n], t = 0;     for (int i = 0; i < n; ++i) {       left[i] = t;       t += (a[i] == -1);     }     t = 0;     for (int i = n - 1; i >= 0; --i) {       right[i] = t;       t += (a[i] == -1);     }     for (int i = 0; i < n; ++i) {       if (a[i] != -1) {         k = (left[i] * b2.query(a[i], n)) % MOD;         k = (k * inv(cnt)) % MOD;         ans += k;         k = (right[i] * b2.query(1, a[i])) % MOD;         k = (k * inv(cnt)) % MOD;         ans += k;         ans %= MOD;       }     }     cout << ans % MOD <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int const INF = 100000;   int p[INF + 1];   int M[INF + 1];   int main() {     memset(p, -1, sizeof(p));     memset(M, -1, sizeof(M));     set<pair<int, int> > S;     int n, x, k;     cin >> n;     while (n--) {       cin >> x >> k;       if (p[k] < x) {         p[k] = x;         M[k] = max(M[k], x);         S.insert(pair<int, int>(x, k));       } else {         if (S.find(pair<int, int>(x, k)) != S.end())           continue;         else {           cout <<  NO ;           return 0;         }       }     }     long long cmp = 0;     for (int i = 0; i <= INF; i++) cmp += (M[i] + 1);     if (cmp == S.size())       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   #define LOG(FMT...) fprintf(stderr, FMT);   #define rep(i, j, k) for(int i = j; i <= k; ++ i)   #define per(i, j, k) for(int i = j; i >= k; -- i)   using namespace std;   #define fs first   #define sc second   #define pb push_back   #define mp make_pair   typedef pair<int, int> pii;   typedef double db;   typedef long long ll;   typedef long double ldb;   typedef unsigned int uint;   typedef unsigned long long ull;   mt19937 mt(std::chrono::system_clock::now().time_since_epoch().count());   uniform_int_distribution<ll> ran(0, 1ll << 62);   void ucin() { ios::sync_with_stdio(0); cin.tie(0); }   // uniform_real_distribution<double> dbran;   template<class T> inline void chkmax(T &x, const T &y) { if(x < y) x = y; }   template<class T> inline void chkmin(T &x, const T &y) { if(x > y) x = y; }   inline ll sqr(ll x) { return x * x; }   inline ll cub(ll x) { return x * x * x; }      const int N = 4e5 + 10;   const int mod = 1e9 + 7;   int n, k;   int qpow(int a, int b) {     int ans = 1;     for(; b >= 1; b >>= 1, a = (ll)a * a % mod)       if(b & 1) ans = (ll)ans * a % mod;     return ans;   }   int fac[N], fav[N];    int C(int n, int m) {     return n < 0 || n < m ? 0 : (ll)fac[n] * fav[m] % mod * fav[n - m] % mod;   }   int iC(int n, int m) {     return n < m ? 0 : (ll)fav[n] * fac[m] % mod * fac[n - m] % mod;   }   void binom(int n) {     fac[0] = 1;     rep(i, 1, n) fac[i] = (ll)fac[i - 1] * i % mod;     fav[n] = qpow(fac[n], mod - 2);     per(i, n, 1) fav[i - 1] = (ll)fav[i] * i % mod;   }   int main() {     binom(2e5);     int test;     scanf( %d , &test);     while(test --) {       scanf( %d%d , &n, &k);       int ans = 1;       rep(i, 1, n - 1) {         if(n - 1 - (i - 1) * k < 0) break ;         ans = (ans + 1ll * C(n - 1 - (i - 1) * k + i + 1 - 1, i + 1 - 1) * iC(n, i)) % mod;       }       printf( %d n , ans);     }     return 0;   }   //choose i[0,n-1], x_{1,...,i}, 1111 (i+1空), x_1 >= 0, x_{2,..i} >= k,x_{i+1} >= 0,  sum = n-1
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<long long> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     set<pair<long long, int>> all;     for (int i = 0; i < n; i++) {       all.insert({a[i], i});     }     vector<pair<long long, int>> res;     while (!all.empty()) {       pair<long long, int> prev = *all.begin();       all.erase(all.begin());       if (all.empty()) {         res.push_back(prev);         break;       }       pair<long long, int> next = *all.begin();       all.erase(all.begin());       if (next.first != prev.first) {         res.push_back(prev);         all.insert(next);       } else {         all.insert({prev.first * 2LL, next.second});       }     }     sort(res.begin(), res.end(),          [&](pair<long long, int> a, pair<long long, int> b) {            return a.second < b.second;          });     cout << res.size() <<   n ;     for (auto p : res) {       cout << p.first <<    ;     }     cout <<   n ;     return;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, m, min, max;     scanf( %d %d %d %d , &n, &m, &min, &max);     int arr[m];     for (int i = 0; i < m; i++) {       scanf( %d , &arr[i]);     }     int chmin = 0, chmax = 0, wrong = 0;     for (int i = 0; i < m; i++) {       if (arr[i] == min) chmin = 1;       if (arr[i] == max) chmax = 1;       if (arr[i] > max || arr[i] < min) wrong = 1;     }     if (wrong == 1)       printf( Incorrect n );     else if (chmin == 1 && chmax == 1)       printf( Correct n );     else if (chmin == 1 || chmax == 1) {       if (n - m >= 1)         printf( Correct n );       else         printf( Incorrect n );     } else {       if (n - m >= 2)         printf( Correct n );       else if (n - m >= 1 && min == max)         printf( Correct n );       else         printf( Incorrect n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     map<string, string> map1;     for (int i = 0; i < n; ++i) {       string t1, t2;       cin >> t1 >> t2;       map1[t2] = t1;     }     for (int j = 0; j < m; ++j) {       string t1, t2, t3;       cin >> t1 >> t2;       for (int i = 0; i < t2.size() - 1; ++i) {         t3 += t2[i];       }       cout << t1 <<     << t2 <<   #  << map1[t3] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   long long a[100000], i, n, m, k;   set<int> s;   int main() {     cin >> n >> k;     for (i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     s.insert(a[0]);     for (i = 1; i < n; i++) {       m = s.size();       if (a[i] % k != 0) {         s.insert(a[i]);       } else {         s.insert(a[i] / k);         if (m != s.size()) {           s.erase(a[i] / k);           s.insert(a[i]);         }       }     }     cout << s.size();   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   long long a[3][N];   int p[3][N];   int n;   map<long long, int> mp;   map<pair<int, int>, int> f;   int solve(int x, int y) {     if (p[0][x] == -1 && p[1][y] == -1 && p[2][min(x, y)] == -1) return 0;     pair<int, int> cnt(x, y);     if (f.count(cnt)) return f[cnt];     int ret = 0;     if (p[0][x] != -1 && p[0][x] >= p[1][y])       ret = max(ret, solve(p[0][x], y) + 1);     else if (p[1][y] != -1)       ret = max(ret, solve(x, p[1][y]) + 1);     int z = min(x, y);     if (p[2][z] != -1) ret = max(ret, solve(p[2][z], p[2][z]) + 1);     return f[cnt] = ret;   }   int main() {     scanf( %d , &n);     for (int i(1); i <= (n); ++i) scanf( %lld , &a[0][i]);     for (int i(1); i <= (n); ++i) scanf( %lld , &a[1][i]);     for (int i(1); i <= (n); ++i) a[2][i] = a[0][i] + a[1][i];     for (int i(0); i <= (2); ++i)       for (int j(1); j <= (n); ++j) a[i][j] += a[i][j - 1];     for (int i(0); i <= (2); ++i) {       mp.clear();       mp[0] = 0;       p[i][0] = -1;       for (int j(1); j <= (n); ++j) {         p[i][j] = mp.count(a[i][j]) ? mp[a[i][j]] : -1;         p[i][j] = max(p[i][j], p[i][j - 1]);         mp[a[i][j]] = j;       }     }     return 0 * printf( %d n , solve(n, n));   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const int maxm = 100005;   int x[maxm], xr[maxm];   int main() {     int n, i, j, k, sum, m, cnt = 0, ans, t;     int x1, x2, y;     scanf( %d%d , &n, &m);     for (i = 0; i < n; i++) scanf( %d , &x[i]);     ans = t = 0;     sort(x, x + n);     for (i = 1; i <= m; i++) {       scanf( %d%d%d , &x1, &x2, &y);       if (x1 == 1) {         xr[t++] = x2;         if (x2 == INF) ans++;       }     }     sort(xr, xr + t);     ans += n;     i = 0, j = 0;     cnt = t;     while (i < n) {       while (j < t && xr[j] < x[i]) {         --cnt;         ++j;       }       ans = min(ans, cnt + i);       if (ans == 0) break;       ++i;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const int N = 1e3 + 10;   int len[N];   int h[N];   int cost[N];   int main() {     memset((cost), (0x3f), sizeof(cost));     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int a, b;       cin >> a >> b >> h[i];       len[i] = (a + b) * 2;     }     int m;     cin >> m;     while (m--) {       int we, hi, p;       cin >> hi >> we >> p;       for (int i = 1; i <= n; i++) {         if (hi >= h[i]) {           int o = hi / h[i] * we;           cost[i] = min(cost[i], (len[i] + o - 1) / o * p);         }       }     }     long long ans = 0;     for (int i = 1; i <= n; i++) ans += cost[i];     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   #define pb push_back   using namespace std;   const int N = 3e5 + 5;   vector<int> G[N], G0[N];   long long day;   int cur, n, pv, pt, a[N], fa[N], dep[N];   int prv[N], pst[N], np[N], bp[N], ep[N];   void Build(int u) {    for(int v : G0[u]) {     if(v == fa[u]) continue;     fa[v] = u;     dep[v] = dep[u] + 1;     Build(v);     G[u].pb(v);     }    sort(G[u].begin(), G[u].end(), [](int x, int y){ return a[x] < a[y]; });   }   void Dfs1(int u) {    for(int v : G[u]) Dfs1(v);    pst[u] = ++pt;    ep[pt] = u;   }   bool Find(int u, int v) {    if(u == v) return true;    if(u == 1) return false;     return Find(fa[u], v);   }   void Back(int u) {    if(u == 1) return;    swap(a[u], a[fa[u]]);    day++;    Back(fa[u]);    }   void Dfs2(int u) {    if(a[u] < cur) return;    prv[u] = pv;    bp[pv++] = u;    for(int v : G[u]) Dfs2(v);   }   void Dfs3(int u) {    prv[u] = ++pv;    for(int v : G[u]) Dfs3(v);   }   int main() {    ios::sync_with_stdio(false);    cin >> n;    for(int i = 1; i <= n; i++) {     cin >> a[i];     np[a[i]] = i;     }    for(int i = 1; i < n; i++) {     int u, v;     cin >> u >> v;     G0[u].pb(v);     G0[v].pb(u);    }    Build(1);    Dfs1(1);    if(a[1] == 1) {     Dfs3(1);     for(int i = 1; i <= n; i++) {      if(prv[i] != a[i]) {       cout <<  NO n ;       return 0;      }     }     cout <<  YES n0 n ;     for(int i = 1; i <= n; i++) cout << prv[i] <<    ;     return 0;     }    cur = a[1] - 1;    if(!Find(ep[cur], np[cur])) {     cout <<  NO n ;     return 0;    }    Back(np[cur]);    for(int i = 1; i <= n; i++) np[a[i]] = i;    for(int i = 1; i < cur; i++) {     if(np[i] != ep[i]) {      cout <<  NO n ;      return 0;     }    }    pv = cur;    Dfs2(1);    for(int i = cur; i <= n; i++) {     if(np[i] != bp[i]) {      cout <<  NO n ;      return 0;     }    }    cout <<  YES n ;    for(int i = 1; i < cur; i++) day += dep[np[i]];    cout << day << endl;    pv = 0;    Dfs3(1);    for(int i = 1; i <= n; i++) cout << prv[i] <<    ;    return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, w;     cin >> n >> w;     vector<int> a(n), b(n);     for (int& v : a) cin >> v;     for (int& v : b) cin >> v;     double l = 0, r = 2e9;     for (int t = 0; t < 500; t++) {       double m = (l + r) / 2;       double now = m;       for (int i = 0; i < n && now >= 0; i++) {         now -= (w + now) / a[i];         if (now < 0) break;         now -= (w + now) / b[(i + 1) % n];       }       if (now >= 0)         r = m;       else         l = m;     }     if (r == 2e9)       cout << -1 <<   n ;     else       cout << fixed << setprecision(10) << r <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int a, b, c;   double dp[102][102][102];   int main() {     scanf( %d%d%d , &a, &b, &c);     int n = max(max(a, b), c);     dp[1][0][0] = 1;     dp[1][1][0] = 1;     for (int i = 1; i <= n; i++) dp[i][0][0] = 1;     for (int i = 1; i <= n; i++)       for (int j = 0; j <= n; j++)         for (int k = 0; k <= n; k++) {           if (j && k) {             double p = i * j + j * k + k * i;             dp[i][j][k] = (dp[i][j - 1][k] * i * j + dp[i][j][k - 1] * j * k +                            dp[i - 1][j][k] * k * i) /                           p;           }           if (j && !k) dp[i][j][k] = 1;           if (!j && k) dp[i][j][k] = 0;           if (!j && !k) dp[i][j][k] = 1;         }     printf( %.12f %.12f %.12f , dp[a][b][c], dp[b][c][a], dp[c][a][b]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char tmp[100001];   string v[100001][2];   long long dp[100001][2];   long long c[100001];   int n;   long long f(int i, int j) {     if (i == n - 1) return 0;     if (dp[i][j] == -1) {       dp[i][j] = 1000000000000000LL;       if (v[i][j] <= v[i + 1][0]) dp[i][j] = min(dp[i][j], f(i + 1, 0));       if (v[i][j] <= v[i + 1][1])         dp[i][j] = min(dp[i][j], f(i + 1, 1) + c[i + 1]);     }     return dp[i][j];   }   int main() {     ios_base::sync_with_stdio(false);     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %I64d , &c[i]);     for (int i = 0; i < n; i++) {       scanf(  %s , tmp);       v[i][0] = v[i][1] = tmp;       reverse(v[i][1].begin(), v[i][1].end());     }     memset(dp, -1, sizeof(dp));     long long res = min(f(0, 0), f(0, 1) + c[0]);     if (res == 1000000000000000LL) res = -1;     printf( %I64d n , res);   }