malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, tot;   long long ans, sum;   char s[100010], t[100010];   void print(int x, int opt) {     tot++;     printf( %d %d n , x, opt);     if (tot == 100000) exit(0);   }   bool check(int i, int opt) {     if (i == n) return 0;     if (opt == -1) {       if (s[i + 1] >  0 ) return s[i]--, s[i + 1]--, print(i, -1), 1;       if (check(i + 1, 1)) return s[i]--, s[i + 1]--, print(i, -1), 1;       return 0;     }     if (opt == 1) {       if (s[i + 1] <  9 ) return s[i]++, s[i + 1]++, print(i, 1), 1;       if (check(i + 1, -1)) return s[i]++, s[i + 1]++, print(i, 1), 1;       return 0;     }   }   int main() {     scanf( %d%s%s , &n, s + 1, t + 1);     for (int i = 1; i < n; i++) {       int S = sum + s[i] -  a , T = t[i] -  a ;       ans += abs(S - T), sum = T - S;     }     if (sum + s[n] -  a  != t[n] -  a ) return puts( -1 ), 0;     printf( %lld n , ans);     for (int i = 1; i < n; i++) {       while (s[i] > t[i])         if (!check(i, -1)) return puts( -1 ), 0;       while (s[i] < t[i])         if (!check(i, 1)) return puts( -1 ), 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[100005];   int c[100005], N, full;   int LG;   void read() {     scanf( %d n , &N);     for (int line = 1; line <= N; ++line) {       scanf( %s , s + 1);       s[0] =  # ;       int len = strlen(s) - 1;       LG = len;       for (int i = 1; i <= len; ++i) {         if (s[i] ==  ? ) continue;         if (c[i] == 0) {           c[i] = s[i] -  a  + 1;           continue;         }         if (c[i] == s[i] -  a  + 1)           continue;         else {           if (c[i] != -1) {             c[i] = -1;             full++;           }           if (full == len) return;         }       }     }   }   int main() {     read();     for (int i = 1; i <= LG; ++i)       if (c[i] == -1)         printf( ? );       else if (c[i] == 0)         printf( x );       else         printf( %c , c[i] +  a  - 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = (int)2e9;   const double EPS = 1e-6;   const double PI = 3.1415926535;   const int MOD = 1000003;   int last[100000];   int main() {     int a, b, m, now, i = 2;     cin >> a >> b >> m >> now;     last[now] = 1;     while (1) {       now = (a * now + b) % m;       if (last[now]) {         cout << i - last[now];         return 0;       } else         last[now] = i++;     }   }
#include <bits/stdc++.h>   using namespace std;   struct Expr {     char a[1010], b[1010];     int v;     int op;   };   Expr exps[5010];   char ansMin[1010], ansMax[1010];   char buf[10010];   map<string, int> varIndex;   int calc(int a, int b, int op) {     if (op == 1)       return a & b;     else if (op == 2)       return a | b;     else if (op == 3)       return a ^ b;   }   int work(int bit, int n, int v) {     int ans = 0;     for (int i = 0; i < n; i++) {       if (exps[i].op) {         int a, b;         if (isdigit(exps[i].a[0]))           a = exps[i].a[bit] -  0 ;         else if (exps[i].a[0] ==  ? )           a = v;         else {           string _var;           _var.assign(exps[i].a);           a = varIndex[_var];           a = exps[a].v;         }         if (isdigit(exps[i].b[0]))           b = exps[i].b[bit] -  0 ;         else if (exps[i].b[0] ==  ? )           b = v;         else {           string _var;           _var.assign(exps[i].b);           b = varIndex[_var];           b = exps[b].v;         }         exps[i].v = calc(a, b, exps[i].op);         ans += exps[i].v;       } else {         exps[i].v = exps[i].a[bit] -  0 ;         ans += exps[i].v;       }     }     return ans;   }   int main() {     int n, m;     char op[16], var[16];     scanf( %d%d , &n, &m);     getchar();     for (int i = 0; i < n; i++) {       gets(buf);       if (sscanf(buf,  %s := %s %s %s , var, exps[i].a, op, exps[i].b) == 4) {         if (op[0] ==  A )           exps[i].op = 1;         else if (op[0] ==  O )           exps[i].op = 2;         else if (op[0] ==  X )           exps[i].op = 3;       } else {         sscanf(buf,  %s := %s , var, exps[i].a);         exps[i].op = 0;       }       string _var;       _var.assign(var);       varIndex[var] = i;     }     for (int i = 0; i < m; i++) {       int a = work(i, n, 0);       int b = work(i, n, 1);       if (a > b)         ansMin[i] =  1 , ansMax[i] =  0 ;       else if (a < b)         ansMin[i] =  0 , ansMax[i] =  1 ;       else         ansMin[i] =  0 , ansMax[i] =  0 ;     }     puts(ansMin);     puts(ansMax);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     map<int, vector<int>> mappu;     cin >> n >> m;     for (long long i = (0); i < (m); i++) {       int a, b;       cin >> a >> b;       mappu[a].push_back(b);       mappu[b].push_back(a);     }     for (long long i = (1); i < (n + 1); i++) {       mappu[i].push_back(i);       sort(mappu[i].begin(), mappu[i].end());     }     for (long long i = (1); i < (n + 1); i++) {       for (long long j = (0); j < (mappu[i].size()); j++) {         if (mappu[i] != mappu[mappu[i][j]]) {           cout <<  NO ;           return 0;         }       }     }     cout <<  YES ;   }
#include <bits/stdc++.h>   using namespace std;   int a[105];   struct Fenwick_Tree {     int sz, c[305];     void init(int n) {       sz = n;       for (int i = 1; i <= n; i++) c[i] = 0;     }     int lowbit(int x) { return x & (-x); }     void update(int p, int v) {       for (int i = p; i <= sz; i += lowbit(i)) c[i] = max(c[i], v);     }     int query(int p) {       int res = 0;       for (int i = p; i > 0; i -= lowbit(i)) res = max(res, c[i]);       return res;     }   } BIT;   int b[200005], cnt[305];   int pre[305], suf[305];   int main() {     int n, T;     scanf( %d%d , &n, &T);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     if (T <= 2000) {       for (int i = 0; i < T; i++)         for (int j = 1; j <= n; j++) b[i * n + j] = a[j];       int ans = 0;       BIT.init(300);       for (int i = 1; i <= n * T; i++) {         int len = BIT.query(b[i]) + 1;         BIT.update(b[i], len);         ans = max(ans, len);       }       printf( %d n , ans);     } else {       for (int i = 1; i <= n; i++) cnt[a[i]]++;       for (int i = 0; i < 2000; i++)         for (int j = 1; j <= n; j++) b[i * n + j] = a[j];       BIT.init(300);       for (int i = 1; i <= 1000 * n; i++) {         pre[b[i]] = BIT.query(b[i]) + 1;         BIT.update(b[i], pre[b[i]]);       }       BIT.init(300);       for (int i = 2000 * n; i > 1000 * n; i--) {         suf[b[i]] = BIT.query(301 - b[i]) + 1;         BIT.update(301 - b[i], suf[b[i]]);       }       int ans = 0;       for (int i = 1; i <= 300; i++)         ans = max(ans, pre[i] + suf[i] + cnt[i] * (T - 2000));       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1000011;   const long long INF = (1 << 29) + 123;   const long long MOD = 1000000007;   const long double PI = 4 * atan((long double)1);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, w;     cin >> n >> w;     int l[n];     int x;     long long ans[w], pf[w + 1];     for (int i = 0; i < w + 1; i++) ans[i] = pf[i] = 0;     for (int i = 0; i < n; i++) {       cin >> l[i];       deque<pair<long long, int>> store;       int window = w - l[i] + 1;       int best = -INF;       for (int j = 0; j < w; j++) {         if (j < l[i]) {           cin >> x;           while (!store.empty() && x >= store.back().first) store.pop_back();           store.push_back(make_pair(x, j));           best = max(best, x);         } else if (j == l[i] && j < window) {           j = window;           if (best >= 0) {             pf[l[i]] += best;             pf[window] -= best;           } else {             if (window - 1 < w - window + 1) {               pf[window - 1] += best;               pf[w - window + 1] -= best;             }           }         }         if (j == w) break;         while (store.front().second <= j - window) store.pop_front();         if (store.front().first > 0 || (j >= window - 1 && j <= w - window)) {           ans[j] += 1LL * store.front().first;         }       }     }     long long total = 0;     for (int i = 0; i < w; i++) {       total += pf[i];       cout << ans[i] + total <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse4 )   using namespace std;   constexpr long long mod = 1000000007;   const long long INF = mod * mod;   const double eps = 1e-12;   const double pi = acosl(-1.0);   long long mod_pow(long long x, long long n, long long m = mod) {     long long res = 1;     while (n) {       if (n & 1) res = res * x % m;       x = x * x % m;       n >>= 1;     }     return res;   }   struct modint {     long long n;     modint() : n(0) { ; }     modint(long long m) : n(m) {       if (n >= mod)         n %= mod;       else if (n < 0)         n = (n % mod + mod) % mod;     }     operator int() { return n; }   };   bool operator==(modint a, modint b) { return a.n == b.n; }   modint operator+=(modint& a, modint b) {     a.n += b.n;     if (a.n >= mod) a.n -= mod;     return a;   }   modint operator-=(modint& a, modint b) {     a.n -= b.n;     if (a.n < 0) a.n += mod;     return a;   }   modint operator*=(modint& a, modint b) {     a.n = ((long long)a.n * b.n) % mod;     return a;   }   modint operator+(modint a, modint b) { return a += b; }   modint operator-(modint a, modint b) { return a -= b; }   modint operator*(modint a, modint b) { return a *= b; }   modint operator^(modint a, long long n) {     if (n == 0) return modint(1);     modint res = (a * a) ^ (n / 2);     if (n % 2) res = res * a;     return res;   }   long long inv(long long a, long long p) {     return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);   }   modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }   const int max_n = 1 << 10;   modint fact[max_n], factinv[max_n];   void init_f() {     fact[0] = modint(1);     for (int i = 0; i < max_n - 1; i++) {       fact[i + 1] = fact[i] * modint(i + 1);     }     factinv[max_n - 1] = modint(1) / fact[max_n - 1];     for (int i = max_n - 2; i >= 0; i--) {       factinv[i] = factinv[i + 1] * modint(i + 1);     }   }   modint comb(int a, int b) {     if (a < 0 || b < 0 || a < b) return 0;     return fact[a] * factinv[b] * factinv[a - b];   }   long long gcd(long long a, long long b) {     if (a < b) swap(a, b);     while (b) {       long long r = a % b;       a = b;       b = r;     }     return a;   }   void solve() {     long long a, b;     cin >> a >> b;     modint ans = 0;     for (long long i = 1; i < b; i++) {       long long num = a;       ans += num * i;       modint cr = num * (num + 1) / 2;       cr *= i;       ans += cr * (modint)b;     }     cout << ans <<   n ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[10005], cnt[305], dp[10005], inf = 1e8;   int main() {     int n, t;     scanf( %d %d , &n, &t);     int max_num = 0, len = n * min(n / 2, t);     if (len <= 0) len = n;     for (int i = 1; i <= n; ++i) {       scanf( %d , a + i);       max_num = max(max_num, ++cnt[a[i]]);     }     for (int i = n + 1; i <= len; ++i) {       a[i] = a[i - n];     }     int ans = 0;     for (int i = 1; i <= len; ++i) {       dp[i] = 1;       for (int j = i - 1; j >= max(i - n, 1); --j) {         if (a[i] >= a[j]) {           dp[i] = max(dp[i], dp[j] + 1);         }       }       ans = max(ans, dp[i]);     }     if (n / 2 == 0) n++;     if (t <= (n / 2)) {       printf( %d n , ans);     } else {       printf( %d n , ans + max_num * (t - (n / 2)));     }     return 0;   }
#include <bits/stdc++.h>   const int MAXN = 1e5 * 5;   const int INF = 1e9 + 7;   const int N = 5000;   using namespace std;   int n, m, h[N], c[N], cnt;   char a[N][N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) {         cin >> a[i][j];         if (a[i][j] ==  * ) ++h[i], ++c[j], ++cnt;       }     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         if (h[i] + c[j] - (a[i][j] ==  * ) >= cnt) {           cout <<  YES  <<   n ;           cout << i <<     << j;           return 0;         }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N_MAX = 1e9, MAX = 4000001, MOD = 1000000007;   int t, n, k, ans[200001];   vector<int> cnt[200001];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       cin >> n >> k;       int sum = 0;       fill(ans, ans + n + 1, 0);       for (int i = 0; i < n + 1; i++) cnt[i].clear();       for (int i = 0; i < n; i++) {         int a;         cin >> a;         if (cnt[a].size() < k) cnt[a].push_back(i);       }       int curr = 1, aa = 0;       for (int i = 1; i <= n; i++) {         aa += cnt[i].size();       }       aa -= aa % k;       for (int i = 1; i <= n; i++) {         int s = min(k, (int)cnt[i].size());         for (int j = 0; j < s; j++) {           ans[cnt[i][j]] = curr;           curr = curr % k + 1;           aa--;           if (aa == 0) break;         }         if (aa == 0) break;       }       for (int i = 0; i < n; i++) {         cout << ans[i] <<    ;       }       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       string aba;       cin >> aba;       int ab = 0;       int ba = 0;       if (aba[0] != aba[aba.size() - 1]) {         aba[0] = aba[aba.size() - 1];         for (int i = 0; i < aba.size() - 1; i++) {           if (aba[i] ==  a  && aba[i + 1] ==  b ) {             ab += 1;           } else if (aba[i] ==  b  && aba[i + 1] ==  a ) {             ba += 1;           }         }         if (ab == ba) {           for (char c : aba) {             cout << c;           }         } else {           aba[aba.size() - 1] = aba[0];           for (char c : aba) {             cout << c;           }         }       } else {         for (char c : aba) {           cout << c;         }       }       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, T;   vector<int> intp;   vector<int> t;   vector<double> p;   vector<vector<long double> > dp;   vector<vector<long double> > pows;   long double ans;   void addAns(const vector<long double>& prob, int index) {     for (int j = 1; j <= T; j++) {       if (index == n - 1) {         ans += prob[j] * n;         continue;       }       if (j + t[index + 1] > T) {         ans += prob[j] * (index + 1) * pows[100 - intp[index + 1]][T - j];       }     }   }   int main() {     cin >> n >> T;     intp = vector<int>(n);     p = vector<double>(n);     t = vector<int>(n);     for (int i = 0; i < (int)(n); i++) {       cin >> intp[i] >> t[i];       p[i] = intp[i] / 100.0;     }     pows = vector<vector<long double> >(101, vector<long double>(T + 1));     for (int i = 0; i <= 100; i++) {       pows[i][0] = 1;       for (int j = 1; j <= T; j++) {         pows[i][j] = pows[i][j - 1] * i / 100.0;         if (pows[i][j] < 1e-100) pows[i][j] = 0;       }     }     dp = vector<vector<long double> >(2, vector<long double>(T + 1));     long double curp = 1;     for (int j = 1; j < t[0]; j++) {       dp[0][j] = curp * p[0];       curp *= (1 - p[0]);     }     dp[0][t[0]] = curp;     addAns(dp[0], 0);     for (int i = 1; i < n; i++) {       int ci = i & 1;       int pi = ci ^ 1;       long double sum = 0;       for (int j = 1; j <= T; j++) {         sum = sum * (1 - p[i]) + dp[pi][j - 1];         if (j >= t[i]) {           sum -= dp[pi][j - t[i]] * pows[100 - intp[i]][t[i] - 1];         }         dp[ci][j] = sum * p[i];         if (j >= t[i]) {           dp[ci][j] += dp[pi][j - t[i]] * pows[100 - intp[i]][t[i] - 1];         }       }       addAns(dp[ci], i);     }     cout.precision(16);     cout << fixed << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   ostream &operator<<(ostream &out, string str) {     for (char c : str) out << c;     return out;   }   template <class L, class R>   ostream &operator<<(ostream &out, pair<L, R> p) {     return out <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {     out <<  { ;     for (auto it = a.begin(); it != a.end(); it = next(it))       out << (it != a.begin() ?  ,   :   ) << *it;     return out <<  } ;   }   void dump() { cerr <<   n ; }   template <class T, class... Ts>   void dump(T a, Ts... x) {     cerr << a <<  ,  ;     dump(x...);   }   template <class T>   int size(T &&a) {     return a.size();   }   using LL = long long;   using PII = pair<int, int>;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     auto ask = [&](int len) {       cout <<  ? 1   << len << endl;       int k = len * (len + 1) / 2;       vector<vector<string>> ret(len + 1);       for (int i = 0; i < k; i++) {         string str;         cin >> str;         ret[size(str)].emplace_back(str);       }       return ret;     };     if (n <= 2) {       auto x = ask(1);       if (n == 1) cout <<  !   << x[1][0];       if (n == 2) {         auto y = ask(2);         cout <<  !   << x[1][0] << (y[1][0] == x[1][0] ? y[1][1] : y[1][0]);       }       cout << endl;       return 0;     }     const int A = 26;     auto count = [&](vector<string> vec) {       vector<int> ret(A);       for (auto &str : vec)         for (char c : str) ret[c -  a ]++;       return ret;     };     auto process = [&](int len, vector<vector<string>> all) {       vector<vector<int>> ret(len + 1);       auto ref = count(all[1]);       auto used = ref;       for (int i = 1; i <= (len - 1) / 2; i++) {         auto a = count(all[i + 1]);         auto b = ref;         for (int &x : b) x *= (i + 1);         for (int j = 1; j <= i - 1; j++) {           for (int &x : ret[j]) a[x] += 1 + i - j;         }         for (int j = 0; j < A; j++)           for (int k = 0; k < b[j] - a[j]; k++) {             ret[i].emplace_back(j);             used[j]--;           }       }       for (int j = 0; j < A; j++)         for (int k = 0; k < used[j]; k++) ret[(len + 1) / 2].emplace_back(j);       return ret;     };     int l = (n + 1) / 2;     auto h1 = ask(l);     auto h2 = ask(l - 1);     auto e1 = process(l, h1);     auto e2 = process(l - 1, h2);     false;     false;     vector<int> ans(n + 1);     auto c1 = count(h1[1]);     auto c2 = count(h2[1]);     for (int j = 0; j < A; j++)       if (c1[j] != c2[j]) ans[l] = j;     false;     auto find = [&](vector<int> a, int b) { return (a[0] == b ? a[1] : a[0]); };     for (int i = 1; i <= l / 2; i++) {       ans[i] = find(e1[i], ans[l + 1 - i]);       if (size(e2[i]) == 2) ans[l - i] = find(e2[i], ans[i]);     }     false;     auto h = ask(n);     auto e = process(n, h);     false;     for (int i = 1; i <= n / 2; i++) {       ans[n + 1 - i] = find(e[i], ans[i]);       false;     }     cout <<  !  ;     for (int i = 1; i <= n; i++) cout << char(ans[i] +  a );     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   char getc() {     char c = getchar();     while ((c <  A  || c >  Z ) && (c <  a  || c >  z ) && (c <  0  || c >  9 ))       c = getchar();     return c;   }   long long gcd(long long n, long long m) { return m == 0 ? n : gcd(m, n % m); }   long long read() {     long long x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 )       x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     return x * f;   }   int n, m;   long long a[300010], b[300010];   signed main() {     n = read(), m = read();     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i <= m; i++) b[i] = read();     sort(a + 1, a + n + 1);     long long u = 0;     for (int i = 2; i <= n; i++) u = gcd(u, a[i] - a[i - 1]);     for (int i = 1; i <= m; i++)       if (u % b[i] == 0) {         cout <<  YES  << endl;         cout << a[1] <<     << i;         return 0;       }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   int main() {     long long a, b, k = 0;     bool flag = true;     std::stack<long long> st;     std::cin >> a >> b;     st.push(b);     while (b > a && flag) {       if (b % 10 == 1) {         b = b / 10;         st.push(b);         k++;       } else if (b % 2 == 0) {         b = b / 2;         st.push(b);         k++;       } else {         flag = false;       }     }     if (!flag || b != a) {       std::cout <<  NO ;     } else {       std::cout <<  YES  << std::endl << k + 1 << std::endl;       while (!st.empty()) {         std::cout << st.top() <<    ;         st.pop();       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int fin[100005];   int main() {     int n;     while (cin >> n) {       int l, r;       int flag = 1;       int temp;       for (int i = 0; i < n; i++) {         cin >> l >> r;         if (i == 0)           fin[0] = l > r ? l : r;         else {           temp = l > r ? l : r;           if (temp <= fin[i - 1])             fin[i] = temp;           else             fin[i] = l < r ? l : r;           if (fin[i] > fin[i - 1]) flag = 0;         }       }       if (!flag) cout <<  NO  << endl;       if (flag) cout <<  YES  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3005;   int n, m, k, p[N];   bool vis[N];   inline void mk(int v) {     for (int i = v; !vis[i]; i = p[i]) vis[i] = 1;   }   int main() {     while (~scanf( %d , &n)) {       for (int i = 0; i < n; ++i) scanf( %d , &p[i]), --p[i];       scanf( %d , &m);       m = n - m;       for (int i = 0; i < n; ++i)         if (!vis[i]) k++, mk(i);       for (int i = 0; i < n; ++i) vis[i] = false;       printf( %d n , (int)abs(k - m));       if (k > m) {         mk(0);         for (int i = 1; i < n && k > m; ++i) {           if (!vis[i]) {             printf( %d %d  , 1, i + 1);             k--;             mk(i);           }         }       } else if (k < m) {         for (int i = 0; i < n && k < m; ++i) {           vector<int> pos(n, -1);           int cur = 0;           for (int j = p[i]; j != i; j = p[j]) pos[j] = ++cur;           pos[i] = cur;           cur = 0;           for (int j = i + 1; j < n && k < m; ++j)             if (pos[j] > cur) {               printf( %d %d  , i + 1, j + 1);               k++;               cur = pos[j];               swap(p[i], p[j]);             }         }       }       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct crew {     string name;     string pos;   };   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<crew> a(n);     for (int i = 0; i < n; i++) cin >> a[i].name >> a[i].pos;     for (int i = 0; i < n; i++) {       if (a[i].pos ==  rat ) cout << a[i].name <<   n ;     }     for (int i = 0; i < n; i++) {       if (a[i].pos ==  child  || a[i].pos ==  woman ) cout << a[i].name <<   n ;     }     for (int i = 0; i < n; i++) {       if (a[i].pos ==  man ) cout << a[i].name <<   n ;     }     for (int i = 0; i < n; i++) {       if (a[i].pos ==  captain ) cout << a[i].name <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int m, n, t, k;   long long a[10];   long long x[10];   int cnt;   bool ok(int n) {     for (int i = 2; i <= n; i++)       if (a[i] == i) return 0;     for (int i = 2; i <= n; i++) {       int t = a[i];       int cnt = 0;       while (t != 1) {         cnt++;         t = a[t];         if (cnt > n) return 0;       }     }     return 1;   }   void fun(int n, int cur) {     if (cur == n + 1) {       if (ok(n)) cnt++;       return;     }     for (int i = 1; i <= n; ++i) {       a[cur] = i;       fun(n, cur + 1);     }   }   int main() {     for (int i = 1; i <= 8; i++) {       cnt = 0;       fun(i, 2);       x[i] = cnt;     }     scanf( %d%d , &n, &k);     long long s = n - k;     long long ans = (x[k] * k) % 1000000007;     for (int i = 0; i < s; ++i) ans = (ans * s) % 1000000007;     printf( %I64d n , ans);     return 0;   }