malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   int n;   int sum = 0;   int a[16];   int mat[4][4];   int rows[4], cols[4];   int gotx[4], goty[4], gotd[2];   int x[16], y[16];   int diag[2];   bool dfs(int state, int mask) {     for (int i = 0; i < 2; i++) {       if (gotd[i] == n && diag[i] != sum) {         return false;       }     }     if (state == n * n) return true;     int row = x[state];     int col = y[state];     bool d1 = row == col;     bool d2 = row + col == n - 1;     for (int i = 0; i < n * n; i++) {       if ((mask & (1 << i)) != 0 && rows[row] + a[i] <= sum &&           cols[col] + a[i] <= sum && (!d1 || diag[0] + a[i] <= sum) &&           (!d2 || diag[1] + a[i] <= sum)) {         if (gotx[row] + 1 == n && rows[row] + a[i] < sum) {           continue;         }         if (goty[col] + 1 == n && cols[col] + a[i] < sum) {           continue;         }         gotx[row]++;         goty[col]++;         rows[row] += a[i];         cols[col] += a[i];         if (d1) {           gotd[0]++;           diag[0] += a[i];         }         if (d2) {           gotd[1]++;           diag[1] += a[i];         }         if (dfs(state + 1, mask ^ (1 << i))) {           mat[row][col] = a[i];           return true;         }         gotx[row]--;         goty[col]--;         if (d1) {           gotd[0]--;           diag[0] -= a[i];         }         if (d2) {           gotd[1]--;           diag[1] -= a[i];         }         rows[row] -= a[i];         cols[col] -= a[i];       }     }     return false;   }   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(NULL);     std::cin >> n;     int mn = 1e9;     long long ans = 0;     for (int i = 0; i < n * n; i++) {       std::cin >> a[i];       mn = std::min(mn, a[i]);       ans += a[i];     }     std::cout << ans / n << std::endl;     if (n == 1) {       std::cout << a[0] << std::endl;       return 0;     } else if (n == 2) {       x[0] = 0;       x[1] = 1;       x[2] = 0;       x[3] = 1;       y[0] = 0;       y[1] = 1;       y[2] = 1;       y[3] = 0;     } else if (n == 3) {       x[0] = 0;       x[1] = 1;       x[2] = 2;       x[3] = 0;       x[4] = 2;       x[5] = 0;       x[6] = 1;       x[7] = 1;       x[8] = 2;       y[0] = 0;       y[1] = 1;       y[2] = 2;       y[3] = 2;       y[4] = 0;       y[5] = 1;       y[6] = 0;       y[7] = 2;       y[8] = 1;     } else if (n == 4) {       int wtfx[] = {0, 1, 2, 3, 0, 1, 2, 3, 0, 0, 1, 1, 2, 2, 3, 3};       int wtfy[] = {0, 1, 2, 3, 3, 2, 1, 0, 1, 2, 0, 3, 0, 3, 1, 2};       for (int i = 0; i < 16; i++) {         x[i] = wtfx[i];         y[i] = wtfy[i];       }     }     long long cur = 0;     for (int i = 0; i < n * n; i++) {       a[i] -= mn;       cur += a[i];     }     srand(time(0));     std::random_shuffle(a, a + n * n);     sum = cur / n;     dfs(0, (1 << (n * n)) - 1);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         std::cout << mat[i][j] + mn << (j + 1 == n ?   n  :    );       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     int c = 0;     for (int i = 0; i < n; i++) {       if (i == 0 && a[0] > 0) {         c++;       }       if (i > 0 && a[i] != 0 && a[i] != a[i - 1]) {         c++;       }     }     cout << c << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long l;     cin >> l;     int div = 0;     for (int i = 5; i < 1 + pow(l, 0.5); i++) {       if (l % i == 0) {         div = i;         break;       }     }     if (div == 0 || (l / div) < 5) {       cout << -1 << endl;     } else {       char a[div][int(l / div)];       a[0][0] =  a ;       a[0][1] =  e ;       a[0][2] =  i ;       a[0][3] =  o ;       a[0][4] =  u ;       a[1][0] =  e ;       a[1][1] =  i ;       a[1][2] =  o ;       a[1][3] =  u ;       a[1][4] =  a ;       a[2][0] =  i ;       a[2][1] =  o ;       a[2][2] =  u ;       a[2][3] =  a ;       a[2][4] =  e ;       a[3][0] =  o ;       a[3][1] =  u ;       a[3][2] =  a ;       a[3][3] =  e ;       a[3][4] =  i ;       a[4][0] =  u ;       a[4][1] =  a ;       a[4][2] =  e ;       a[4][3] =  i ;       a[4][4] =  o ;       for (int i = 0; i < 5; i++) {         for (int j = 5; j < (l / div); j++) {           a[i][j] = a[i][j - 5];         }       }       for (int i = 5; i < div; i++) {         for (int j = 0; j < (l / div); j++) {           a[i][j] = a[i - 5][j];         }       }       for (int i = 0; i < div; i++) {         for (int j = 0; j < (l / div); j++) {           cout << a[i][j];         }       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int arr[98];   int main() {     string s;     vector<long long> v(4);     for (int i = 0; i < 4; i++) cin >> v[i];     sort(v.begin(), v.end());     char c1, c2, c3;     cin >> c1 >> c2 >> c3;     if (c1 ==  *  && c2 ==  *  && c3 ==  * )       cout << v[0] * v[1] * v[2] * v[3] << endl;     else if (c1 ==  +  && c2 ==  +  && c3 ==  + )       cout << v[0] + v[1] + v[2] + v[3] << endl;     else if (c1 ==  *  && c2 ==  +  && c3 ==  + ) {       if (c1 == 0) cout << (v[0] * v[3]) + v[1] + v[2] << endl;       cout << (v[0] * v[1]) + v[2] + v[3] << endl;     } else if (c1 ==  *  && c2 ==  *  && c3 ==  + )       cout << min(min((v[0] * v[1] * v[2]) + v[3], (v[0] * v[1]) + (v[2] * v[3])),                   (v[0] * v[3]) + (v[1] * v[2]))            << endl;     else if (c1 ==  +  && c2 ==  *  && c3 ==  * )       cout << (v[2] + v[3]) * v[0] * v[1] << endl;     else if (c1 ==  +  && c2 ==  +  && c3 ==  * )       cout << (v[1] + v[2] + v[3]) * v[0] << endl;     else if (c1 ==  +  && c2 ==  *  && c3 ==  + )       cout << (v[0] * v[1]) + v[2] + v[3] << endl;     else if (c1 ==  *  && c2 ==  +  && c3 ==  * )       cout << (((v[1] * v[2]) + v[3]) * v[0]) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     vector<long long> a(n), b(n);     for (long long i = 0; i < n; ++i) cin >> a[i];     for (long long i = 0; i < n; ++i) cin >> b[i];     map<long long, vector<long long> > mp;     long long m;     cin >> m;     for (long long i = 0; i < n; ++i) {       mp[a[i]].push_back(i + 1);       mp[b[i]].push_back(i + 1);     }     long long ans = 1;     for (auto it = mp.begin(); it != mp.end(); ++it) {       long long den = 0;       long long num = it->second.size();       sort(it->second.begin(), it->second.end());       for (long long i = 1; i < (it->second.size()); ++i) {         if ((it->second[i]) == (it->second[i - 1])) den++;       }       long long nn = 1;       for (long long i = num; i > 0; --i) {         if (i & 1 || den == 0)           nn *= i;         else {           nn *= (i / 2);           den--;         }         if (nn > m) nn %= m;       }       ans *= nn;       if (ans > m) ans %= m;     }     cout << ans % m;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t, n, doc[100010], doc1[100010], p[100010];   vector<vector<int> > g;   vector<pair<int, pair<int, int> > > q;   vector<int> tin, tout;   int par(int u) {     if (p[u] == u) return u;     return p[u] = par(p[u]);   }   void dfs(int u) {     tin[u] = t;     for (int i = 0; i < g[u].size(); i++)       if (tin[g[u][i]] == -1) {         t++;         dfs(g[u][i]);       }     tout[u] = ++t;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int m, d = 0;     cin >> n >> m;     g.resize(n);     tin.resize(n, -1);     tout.resize(n);     for (int i = 0; i < n; i++) p[i] = i;     for (int i = 0; i < m; i++) {       int type, x, y;       cin >> type;       if (type == 1) {         cin >> x >> y;         x--;         y--;         p[x] = y;         g[y].push_back(x);       } else if (type == 2) {         cin >> x;         x--;         doc1[d] = par(x);         doc[d++] = x;       } else {         cin >> x >> y;         x--;         y--;         int a = 0;         if (par(x) == par(doc[y])) a = 1;         q.push_back(make_pair(a, make_pair(x, y)));       }     }     t = 0;     for (int i = 0; i < n; i++)       if (p[i] == i) dfs(i);     for (int i = 0; i < q.size(); i++) {       if (q[i].first == 0) {         cout <<  NO n ;         continue;       }       int u = q[i].second.first, v = doc[q[i].second.second],           x = doc1[q[i].second.second];       if (tin[u] <= tin[v] && tout[u] >= tout[v] && tin[x] <= tin[u] &&           tout[x] >= tout[u])         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     unsigned long long int counter = 0, a, b, t;     cin >> a >> b;     while (true) {       if (b > a) {         t = a;         a = b;         b = t;       }       counter = counter + (a / b);       a = (a % b);       if (a == 0) break;     }     cout << counter;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000;   int ans[N], l[N], r[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> l[i];     }     for (int i = 0; i < n; ++i) {       cin >> r[i];     }     for (int k = n; k > 0; --k) {       for (int i = 0; i < n; ++i) {         if (l[i] == 0 && r[i] == 0 && ans[i] == 0) {           ans[i] = k;         }       }       int prefix = 0;       for (int i = 0; i < n; ++i) {         if (ans[i] == k) {           ++prefix;         } else if (ans[i] == 0) {           l[i] -= prefix;         }       }       int suffix = 0;       for (int i = n - 1; i >= 0; --i) {         if (ans[i] == k) {           ++suffix;         } else if (ans[i] == 0) {           r[i] -= suffix;         }       }     }     if (count(ans, ans + n, 0) == 0) {       cout <<  YES n ;       for (int i = 0; i < n; ++i) {         cout << ans[i] <<    ;       }       cout <<   n ;     } else {       cout <<  NO n ;     }   }
#include <bits/stdc++.h>   using namespace std;   bool boy[1000], girl[1000];   int n, m, b, g, x, y, q[1000][2], h, t;   int main() {     memset(boy, false, sizeof(boy));     scanf( %d%d%d , &n, &m, &b);     for (int i = 1; i <= b; i++) {       scanf( %d , &x);       boy[x] = true;     }     memset(girl, false, sizeof(girl));     scanf( %d , &g);     for (int i = 1; i <= g; i++) {       scanf( %d , &y);       girl[y] = true;     }     h = t = 0;     for (int i = 0; i < n; i++)       if (boy[i]) {         t++;         q[t][1] = 0;         q[t][2] = i;       }     for (int i = 0; i < m; i++)       if (girl[i]) {         t++;         q[t][1] = 1;         q[t][2] = i;       }     while (h < t) {       h++;       if (q[h][1]) {         int u = q[h][2] % n;         for (int i = 1; i <= n; i++) {           if (!boy[u]) {             boy[u] = true;             t++;             q[t][1] = 0;             q[t][2] = u;           }           u = (u + m) % n;         }       } else {         int u = q[h][2] % m;         for (int i = 1; i <= m; i++) {           if (!girl[u]) {             girl[u] = true;             t++;             q[t][1] = 1;             q[t][2] = u;           }           u = (u + n) % m;         }       }     }     if (t == n + m)       puts( Yes );     else       puts( No );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[1000];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (!(a[i] & 1)) --a[i];     }     for (int i = 0; i < n; i++) {       cout << a[i] <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string a;   constexpr char t[4] = { A ,  C ,  T ,  G };   int best = INT_MAX;   int main() {     cin >> n;     cin >> a;     for (int i = 0; i < n - 3; ++i) {       int cur = 0;       for (int j = 0; j < 4; ++j) {         int temp = min(abs(t[j] - a[i + j]), abs(t[j] + 26 - a[i + j]));         temp = min(temp, abs(t[j] - a[i + j] - 26));         cur += temp;       }       best = min(best, cur);     }     cout << best;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void prn(T first) {     cout << first <<   n ;   }   int main() {     int a[4];     cin >> a[0] >> a[1] >> a[2] >> a[3];     sort(a, a + 4);     if (a[0] + a[3] == a[1] + a[2] || a[3] == a[0] + a[1] + a[2]) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, h, v[1100];     multiset<long long> s;     cin >> n >> h;     for (int i = 0; i < n; i++) cin >> v[i];     long long k, ht;     for (int i = 0; i < n; i++) {       s.insert(v[i]);       k = 0;       ht = 0;       for (multiset<long long>::reverse_iterator rit = s.rbegin();            rit != s.rend(); ++rit) {         if (k % 2 == 0) ht += *rit;         k++;       }       if (ht > h) {         cout << i <<   n ;         return 0;       }     }     cout << n <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   pair<int, int> st[3000002];   void build(int v, int l, int r) {     if (l == r) {       st[v] = make_pair(s[l] ==  ( , s[l] ==  ) );       return;     }     int lv, rv, mid;     lv = 2 * v;     rv = 2 * v + 1;     mid = (l + r) / 2;     build(lv, l, mid);     build(rv, mid + 1, r);     st[v].first = st[rv].first + max(0, st[lv].first - st[rv].second);     st[v].second = st[lv].second + max(0, st[rv].second - st[lv].first);   }   pair<int, int> query(int v, int l, int r, int L, int R) {     if (r < L || R < l) return make_pair(0, 0);     if (L <= l && r <= R) return st[v];     pair<int, int> L1 = query(2 * v, l, (l + r) / 2, L, R);     pair<int, int> R1 = query(2 * v + 1, (l + r) / 2 + 1, r, L, R);     return make_pair(R1.first + max(0, L1.first - R1.second),                      L1.second + max(0, R1.second - L1.first));   }   int main() {     cin >> s;     int n = s.length();     build(1, 0, n - 1);     int m;     cin >> m;     for (int i = 0; i < m; ++i) {       int l, r;       cin >> l >> r;       l--;       r--;       pair<int, int> q = query(1, 0, n - 1, l, r);       cout << r - l + 1 - (q.first + q.second) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long double k, d, t, g, c, p, ilec, ilep, cp, zos;   long long dzielup(long long x, long long y) {     if (x % y == 0) return x / y;     return x / y + 1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     cin >> k >> d >> t;     cout.precision(10);     g = dzielup(k, d);     c = g * d;     p = k + (c - k) / 2;     ilep = floor(t / p);     cp = ilep * p;     zos = t - cp;     if (zos <= k) {       cout << fixed << ilep * c + zos <<   n ;     } else {       zos -= k;       cout << fixed << ilep * c + k + 2 * zos <<   n ;     }     return 0;   }
#include <iostream>   using namespace std;      const int MOD = 1e9+7, N = 1e5+5;      long long inv(long long a) {       long long b = 1;       int k = MOD-2;       while(k) {           if(k%2) b = b * a % MOD;           a = a * a % MOD;           k /= 2;       }       return b;   }      long long fact[N], ifact[N];      long long binom(long long x, long long y) {       if(x < 0 || y < 0 || x < y) return 0;       return fact[x] * ifact[x-y] % MOD * ifact[y] % MOD;   }      int t, n, k;      int main() {       ios_base::sync_with_stdio(false); cin.tie(0);       fact[0] = ifact[0] = 1;       for (int i = 1; i < N; i++) fact[i] = fact[i-1] * i % MOD;       ifact[N-1] = inv(fact[N-1]);       for (int i = N-2; 0 < i; i--) ifact[i] = ifact[i+1] * (i+1) % MOD;       cin >> t;       while(t--) {           cin >> n >> k;           long long sol = 0;           for (long long l = 1; l <= n; l++) sol = (sol + binom(n-(l-1)*(k-1), l) * fact[l] % MOD * fact[n-l]) % MOD;           sol = (sol + fact[n]) * ifact[n] % MOD;           cout << sol <<   n ;       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   void debug_out() { cerr << endl; }   template <class T>   ostream& prnt(ostream& out, T v) {     out << v.size() <<   n ;     for (auto e : v) out << e <<    ;     return out;   }   template <class T>   ostream& operator<<(ostream& out, vector<T> v) {     return prnt(out, v);   }   template <class T>   ostream& operator<<(ostream& out, set<T> v) {     return prnt(out, v);   }   template <class T1, class T2>   ostream& operator<<(ostream& out, map<T1, T2> v) {     return prnt(out, v);   }   template <class T1, class T2>   ostream& operator<<(ostream& out, pair<T1, T2> p) {     return out <<  (  << p.first <<     << p.second <<  ) ;   }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << H;     debug_out(T...);   }   const int N = 1001;   const int MOD = 998244353;   int n, dp[2][N], a[N], k, f[100100], r[N];   int solve(int x) {     for (int i = 1; i <= n; i++) {       int j = upper_bound(a + 1, a + n + 1, a[i] - x) - a;       j--;       r[i] = j;     }     for (int j = 1; j <= k; j++) {       for (int i = 1; i <= n; i++)         if (j == 1)           dp[1][i] = 1;         else           dp[j % 2][i] = dp[1 - j % 2][r[i]];       for (int i = 2; i <= n; i++)         dp[j % 2][i] += dp[j % 2][i - 1], dp[j % 2][i] %= MOD;     }     return dp[k % 2][n];   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + n + 1);     int mx = a[n] / (k - 1) + 1;     for (int x = 0; x <= mx; x++) f[x] = solve(x);     long long ans = 0;     for (int x = 0; x < mx; x++) {       f[x] -= f[x + 1];       if (f[x] < 0) f[x] += MOD;       ans += (1LL * x * f[x]) % MOD;       ans %= MOD;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int Set(int N, int pos) { return N = N | (1 << pos); }   int reset(int N, int pos) { return N = N & ~(1 << pos); }   bool check(int N, int pos) { return (bool)(N & (1 << pos)); }   inline int addmod(int x, int y) {     return (x % 1000000007 + y % 1000000007) % 1000000007;   }   inline int submod(int x, int y) {     return (x % 1000000007 - y % 1000000007 + 1000000007) % 1000000007;   }   inline int mulmod(int x, int y) {     return (x % 1000000007 * 1LL * y % 1000000007) % 1000000007;   }   inline int nextSubMask(int i, int mask) { return (i - 1) & mask; }   template <typename T>   void we_r_done(T mssg) {     cout << mssg;     exit(0);   }   vector<char> chick;   string s[102];   int n, m, c;   int row, col;   bool vis[111][111];   void fixrc(int i, int j) {     row = i;     col = j;   }   char who;   void fun(int i, int j, int baki) {     if (s[i][j] ==  R  && baki == 0) {       fixrc(i, j);       return;     }     baki -= (s[i][j] ==  R );     s[i][j] = who;     vis[i][j] = true;     if (j && vis[i][j - 1] == false) {       fun(i, j - 1, baki);     } else if ((j + 1) < m && vis[i][j + 1] == false) {       fun(i, j + 1, baki);     } else if (i)       fun(i - 1, j, baki);   }   int main() {     for (char i =  0 ; i <=  9 ; i++) chick.push_back(i);     for (char i =  A ; i <=  Z ; i++) chick.push_back(i);     for (char i =  a ; i <=  z ; i++) chick.push_back(i);     int t;     cin >> t;     while (t--) {       cin >> n >> m >> c;       int tot = 0;       for (int i = 0; i < n; i++) {         cin >> s[i];         for (int j = 0; j < m; j++) {           tot += (s[i][j] ==  R );           vis[i][j] = false;         }       }       row = n - 1;       col = m - 1;       char last;       for (int i = 0; i < c; i++) {         who = chick[i];         int cc = c - i;         cc = tot / cc + (tot % cc != 0);         tot -= cc;         fun(row, col, cc);       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           cout << s[i][j];         }         cout << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t, zero, cur;   long long ans;   string s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       cin >> s;       ans = zero = 0;       for (int i = 0; i < s.size(); i++) {         if (s[i] ==  0 ) {           if (i == 0 || s[i - 1] ==  1 ) {             zero = 1;           } else {             zero++;           }         } else {           cur = 0;           if (i == 0 || s[i - 1] ==  1 ) {             zero = 0;           }           int b = min(i + 18, (int)s.size());           for (int j = i; j < b; j++) {             cur = cur * 2 + (s[j] -  0 );             if ((j - i + 1) + min(zero, cur - (j - i + 1)) == cur) {               ans++;             }           }         }       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios::sync_with_stdio(false);     int n;     cin >> n;     string sign[n];     long long x[n];     char ans[n];     long long low = -2e9, up = 2e9;     for (int i = 0; i < n; i++) {       cin >> sign[i] >> x[i] >> ans[i];       if (sign[i] ==  >= ) {         if (ans[i] ==  Y )           low = max(low, x[i]);         else           up = min(x[i] - 1, up);       } else if (sign[i] ==  > ) {         if (ans[i] ==  Y )           low = max(low, x[i] + 1);         else           up = min(x[i], up);       } else if (sign[i] ==  <= ) {         if (ans[i] ==  Y )           up = min(x[i], up);         else           low = max(low, x[i] + 1);       } else {         if (ans[i] ==  Y )           up = min(x[i] - 1, up);         else           low = max(low, x[i]);       }     }     if (low > up)       cout <<  Impossible ;     else       cout << low;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, l, r;   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d%d , &l, &r);     }     for (int i = 0; i < n; i++) {       if (i & 1)         printf( 0 );       else         printf( 1 );     }     puts(  );   }
#include <bits/stdc++.h>   using namespace std;   int fir[200010], to[200010 << 1], nxt[200010 << 1], cnt;   long long f[200010], fac[200010];   void add(int u, int v) {     nxt[++cnt] = fir[u];     fir[u] = cnt;     to[cnt] = v;   }   void dfs(int x, int fa) {     f[x] = 1;     int i, s = (x != 1);     for (i = fir[x]; i; i = nxt[i])       if (to[i] != fa) {         dfs(to[i], x);         f[x] *= f[to[i]];         f[x] %= 998244353;         s++;       }     f[x] *= fac[s];     f[x] %= 998244353;   }   int main() {     int n, i, u, v;     cin >> n;     fac[0] = 1;     for (i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % 998244353;     for (i = 1; i < n; i++) scanf( %d%d , &u, &v), add(u, v), add(v, u);     dfs(1, 0);     cout << f[1] * n % 998244353;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[1000];     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     int res = 0;     int sum = 10;     int ress = 0;     for (int i = 0; i < n; i++) {       sum += a[i];       if (sum <= 720) {         res++;         if (sum > 360) {           ress += sum - 360;         }       }     }     cout << res <<     << ress;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = (119 << 23) + 1;   int add(int a, int b) { return (a += b) < M ? a : a - M; }   int sub(int a, int b) { return (a -= b) < 0 ? a + M : a; }   int mul(int a, int b) { return 1LL * a * b % M; }   int mod_pow(int a, int b) {     int res = 1;     while (b) {       if (b % 2) {         res = mul(res, a);       }       a = mul(a, a);       b /= 2;     }     return res;   }   int mod_inv(int a) { return mod_pow(a, M - 2); }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<int> a(n);     for (auto& i : a) {       cin >> i;     }     sort(a.rbegin(), a.rend());     for (int i = 1; i < n; ++i) {       a[i] = add(a[i], a[i - 1]);     }     for (int k = 1; k <= n; ++k) {       int ans = 0;       for (int i = 0; i < n; i += k) {         int sum = a[min(i + k - 1, n - 1)];         sum = sub(sum, i ? a[i - 1] : 0);         ans = add(ans, mul(i / k, sum));       }       ans = mul(ans, mod_inv(n));       cout << ans <<    ;     }     cout <<   n ;   }