malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long n;   long long m;   long long t;   void solve() {}   struct point {     long long x, y;   };   bool isSquare(point a, point b, point c, point d) {     long long dist1 =         (long long)(b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y);     long long dist2 =         (long long)(b.x - c.x) * (b.x - c.x) + (b.y - c.y) * (b.y - c.y);     long long dist3 =         (long long)(c.x - d.x) * (c.x - d.x) + (c.y - d.y) * (c.y - d.y);     long long dist4 =         (long long)(a.x - d.x) * (a.x - d.x) + (a.y - d.y) * (a.y - d.y);     return dist1 == dist2 && dist1 == dist3 && dist1 == dist4;   }   bool noZeroArea(point a, point b, point c, point d) {     long long dist1 =         (long long)(b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y);     long long dist2 =         (long long)(b.x - c.x) * (b.x - c.x) + (b.y - c.y) * (b.y - c.y);     long long dist3 =         (long long)(c.x - d.x) * (c.x - d.x) + (c.y - d.y) * (c.y - d.y);     long long dist4 =         (long long)(a.x - d.x) * (a.x - d.x) + (a.y - d.y) * (a.y - d.y);     if (dist1 > 0 && dist2 > 0 && dist3 > 0 && dist4 > 0) return true;     return false;   }   long long IsOrthogonal(point a, point b, point c) {     return (b.x - a.x) * (b.x - c.x) + (b.y - a.y) * (b.y - c.y) == 0;   }   long long IsRectangle(point a, point b, point c, point d) {     return IsOrthogonal(a, b, c) && IsOrthogonal(b, c, d) &&            IsOrthogonal(c, d, a) && noZeroArea(a, b, c, d);   }   long long IsRectangleAnyOrder(point a, point b, point c, point d) {     return IsRectangle(a, b, c, d) || IsRectangle(b, c, a, d) ||            IsRectangle(c, a, b, d);   }   long long IsSquareAnyOrder(point a, point b, point c, point d) {     return (IsRectangle(a, b, c, d) && isSquare(a, b, c, d)) ||            (IsRectangle(b, c, a, d) && isSquare(b, c, a, d)) ||            (IsRectangle(c, a, b, d) && isSquare(c, a, b, d));   }   int main() {     ios_base::sync_with_stdio(false);     point pt[10];     for (int i = 1; i <= 8; i++) {       long long x, y;       cin >> x >> y;       pt[i].x = x;       pt[i].y = y;     }     int mtints[] = {1, 2, 3, 4, 5, 6, 7, 8};     sort(mtints, mtints + 8);     do {       if (IsSquareAnyOrder(pt[mtints[0]], pt[mtints[1]], pt[mtints[2]],                            pt[mtints[3]]) &&           IsRectangleAnyOrder(pt[mtints[4]], pt[mtints[5]], pt[mtints[6]],                               pt[mtints[7]])) {         cout <<  YES  << endl;         cout << mtints[0] <<     << mtints[1] <<     << mtints[2] <<                  << mtints[3] << endl;         cout << mtints[4] <<     << mtints[5] <<     << mtints[6] <<                  << mtints[7] << endl;         return 0;       }     } while (next_permutation(mtints, mtints + 8));     cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Edge {     int to, w, type;     Edge() {}     Edge(int _to, int _w, int _type) : to(_to), w(_w), type(_type) {}     bool operator<(const Edge other) { return type < other.type; }   };   const long long N = 1e5 + 5, oo = 1e18;   long long n, m, k, dist[N], res;   int deg[N];   vector<Edge> adj[N];   bool mark[N];   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(0);     cin.tie(0);     clock_t tStart = clock();     cin >> n >> m >> k;     for (long long huy = 0, _n = (m); huy < _n; huy++) {       long long u, v, w;       cin >> u >> v >> w;       adj[u].push_back(Edge(v, w, 0));       adj[v].push_back(Edge(u, w, 0));     }     for (long long nene = 0, _n = (k); nene < _n; nene++) {       long long v, t;       cin >> v >> t;       adj[1].push_back(Edge(v, t, 1));       adj[v].push_back(Edge(1, t, 1));     }     set<pair<long long, long long> > pq;     pq.clear();     pq.insert(pair<long long, long long>(0, 1));     for (long long i = (2), _b = (n); i <= _b; i++) dist[i] = oo;     while (!pq.empty()) {       pair<long long, long long> front = *(pq.begin());       long long d = front.first, u = front.second;       pq.erase(pq.begin());       if (d > dist[u]) continue;       for (Edge e : adj[u])         if (dist[u] + e.w < dist[e.to]) {           dist[e.to] = dist[u] + e.w;           pq.insert(pair<long long, long long>(dist[e.to], e.to));         }     }     for (long long u = (1), _b = (n); u <= _b; u++)       for (Edge e : adj[u]) {         if (dist[u] + e.w == dist[e.to]) {           deg[e.to]++;         }       }     res = k;     for (long long u = (1), _b = (n); u <= _b; u++)       for (Edge e : adj[u]) {         if (e.type == 1 && dist[u] + e.w == dist[e.to]) {           if (deg[e.to] == 1) res--;           deg[e.to]--;         }       }     cout << res <<   n ;     fprintf(stderr,  Time taken: %.2fs n ,             (double)(clock() - tStart) / CLOCKS_PER_SEC);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, d;   bool b;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       cin >> n >> d;       b = false;       if (d <= n) {         cout <<  YES n ;         continue;       }       for (long long x = 1; x * x <= d; x++) {         long long X = x + 1;         long long D = 0;         D = d / X;         if (d % X != 0) {           D++;         }         long long sol = x + (D);         if (sol <= n) {           cout <<  YES n ;           b = true;           break;         }       }       if (b == false) {         cout <<  NO n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   std::vector<long long> digit(long long num) {     string str, s;     std::vector<long long> v;     str = to_string(num);     for (int i = 0; i < str.size(); ++i) {       s = str[i];       v.push_back(stoi(s));     }     return v;   }   void solve() {     long long num, best;     cin >> num;     std::vector<long long> arr(num + 11);     std::vector<long long> d;     arr[0] = 0;     for (int i = 1; i < 10; ++i) {       arr[i] = 1;     }     for (int i = 10; i <= num; ++i) {       best = 2000000000000000000;       d = digit(i);       for (auto y : d) {         if (y != 0) {           best = min(best, arr[i - y] + 1);         }       }       arr[i] = best;     }     cout << arr[num] << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int tt = 1;     while (tt--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int T;     cin >> T;     while (T--) {       string s[9];       for (long long int i = 0; i < 9; i++) {         cin >> s[i];       }       for (long long int i = 0; i < 9; i++) {         for (long long int j = 0; j < 9; j++) {           if (s[i][j] ==  3 ) s[i][j] =  1 ;         }       }       for (long long int i = 0; i < 9; i++) {         cout << s[i] <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long l = 1, k = n, cnt = 0, h = n, ans = 0;     while (l <= h) {       long long mid = l + (h - l) / 2;       k = n;       cnt = 0;       while (k > 0) {         if (k >= mid) {           k = k - mid;           cnt += mid;           k = k - (k / 10);         } else {           cnt += k;           break;         }       }       if (cnt >= (n + 1) / 2) {         ans = mid;         h = mid - 1;       } else {         l = mid + 1;       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long l1, l2, r1, r2, k;   int main() {     cin >> l1 >> r1 >> l2 >> r2 >> k;     if (l2 > r1 || r2 < l1) {       cout << 0 <<   n ;       return 0;     }     long long l, r;     if (r1 < r2) {       r = r1;     } else {       r = r2;     }     if (l1 > l2) {       l = l1;     } else {       l = l2;     }     long long flag = 0;     if (k >= l && k <= r) {       flag = 1;     }     cout << r - l - flag + 1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int n, c[30], a[N], s[N], st[N], t, w, k, m;   char b[N];   void sol() {     scanf( %s , b + 1);     n = strlen(b + 1);     for (int i = 0; i < 26; i++) c[i] = 0;     t = m = w = k = 0;     for (int i = 1; i <= n; i++) {       s[i] = b[i] -  a ;       if (i > 1 && s[i] == s[i - 1]) k++, c[s[i]]++;     }     for (int i = 0; i < 26; i++) m = max(m, c[i]);     printf( %d n , max((k + 1) / 2, m) + 1);     for (int i = 1; i <= n; i++) {       a[++w] = s[i];       if (w <= 1 || a[w] != a[w - 1]) continue;       if (a[w] == a[st[t]] || !t) {         st[++t] = w;         continue;       }       m = 0;       for (int j = 0; j < 26; j++)         if (c[j] > c[m]) m = j;       if (c[m] * 2 < k || m == a[w] || m == a[st[t]]) {         k -= 2;         c[a[w]]--;         c[a[st[t]]]--;         printf( %d %d n , st[t], w - 1);         a[st[t]] = a[w];         w = st[t];         t--;       } else         st[++t] = w;     }     for (int l = w, i = w; i >= 1; i--) {       if (i == 1 || a[i - 1] == a[i]) {         printf( %d %d n , i, l);         l = i - 1;       }     }   }   int main() {     int t;     scanf( %d , &t);     while (t--) sol();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, w1[555][555], w2[555][555], w3[555][555], gl, Pre[300011], anslen;   char ch;   struct AnsNode {     int x, y, z;     void init(int _x, int _y, int _z) { x = _x, y = _y, z = _z; }   } Ans[1000111];   struct Node {     int x, y;     void init(int _x, int _y) { x = _x, y = _y; }   } gg[300011];   void Read(int &res) {     for (ch = getchar(); ch !=  .  && ch !=  # ; ch = getchar())       ;     res = (ch ==  . );   }   void Work(int nowx, int nowy) {     int i, dx, dy;     gg[gl = 1].init(nowx, nowy);     w2[nowx][nowy] = 1;     for (i = 1; i <= gl; ++i) {       dx = gg[i].x, dy = gg[i].y;       if (dx > 1 && w1[dx - 1][dy] && w2[dx - 1][dy] == 0) {         w2[dx - 1][dy] = 1;         gg[++gl].init(dx - 1, dy);         Pre[gl] = i;       }       if (dx < n && w1[dx + 1][dy] && w2[dx + 1][dy] == 0) {         w2[dx + 1][dy] = 1;         gg[++gl].init(dx + 1, dy);         Pre[gl] = i;       }       if (dy > 1 && w1[dx][dy - 1] && w2[dx][dy - 1] == 0) {         w2[dx][dy - 1] = 1;         gg[++gl].init(dx, dy - 1);         Pre[gl] = i;       }       if (dy < m && w1[dx][dy + 1] && w2[dx][dy + 1] == 0) {         w2[dx][dy + 1] = 1;         gg[++gl].init(dx, dy + 1);         Pre[gl] = i;       }     }     for (i = gl; i > 1; --i) {       dx = gg[Pre[i]].x, dy = gg[Pre[i]].y;       if (w3[dx][dy] == 0) {         Ans[++anslen].init(1, dx, dy);         w3[dx][dy] = 1;       }       if (w3[gg[i].x][gg[i].y] == 1) Ans[++anslen].init(0, gg[i].x, gg[i].y);       if (w3[gg[i].x][gg[i].y] < 2) Ans[++anslen].init(2, gg[i].x, gg[i].y);       w3[gg[i].x][gg[i].y] = 2;     }     if (w3[dx][dy] == 0) {       Ans[++anslen].init(1, nowx, nowy);       w3[nowx][nowy] = 1;     }   }   int main() {     int i, j;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; ++i)       for (j = 1; j <= m; ++j) Read(w1[i][j]);     memset(w2, 0, sizeof(w2));     memset(w3, 0, sizeof(w3));     anslen = 0;     for (i = 1; i <= n; ++i)       for (j = 1; j <= m; ++j)         if (w2[i][j] == 0 && w1[i][j] != 0) Work(i, j);     cout << anslen << endl;     for (i = 1; i <= anslen; ++i) {       if (Ans[i].x == 0)         printf( D %d %d n , Ans[i].y, Ans[i].z);       else if (Ans[i].x == 1)         printf( B %d %d n , Ans[i].y, Ans[i].z);       else         printf( R %d %d n , Ans[i].y, Ans[i].z);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char c = getchar();     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) f = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) x = x * 10 + c -  0 ;     return x * f;   }   int n;   char a[1000010], b[1000010];   int fail[1000010];   int main() {     n = read();     scanf( %s , b + 1);     scanf( %s , a + 1);     n--;     for (int i = (1); i <= (n); i++)       if (a[i] ==  N )         a[i] =  S ;       else if (a[i] ==  S )         a[i] =  N ;       else if (a[i] ==  E )         a[i] =  W ;       else if (a[i] ==  W )         a[i] =  E ;     reverse(a + 1, a + n + 1);     int j = 0;     for (int i = (2); i <= (n); i++) {       for (; j && a[j + 1] != a[i]; j = fail[j])         ;       fail[i] = (a[j + 1] == a[i]) ? ++j : j;     }     j = 0;     for (int i = (1); i <= (n); i++) {       for (; j && a[j + 1] != b[i]; j = fail[j])         ;       if (a[j + 1] == b[i]) j++;     }     if (j)       printf( NO n );     else       printf( YES n );   }
#include <bits/stdc++.h>   using namespace std;   int A[10000][2];   int main() {     int N, M, K;     cin >> N >> M >> K;     int cur = 0;     for (int i = 0; i < M; i++)       for (int j = (i + 1); j < M; j++) {         A[cur][K] = i + 1;         A[cur][1 - K] = j + 1;         cur++;       }     cout << cur << endl;     for (int i = 0; i < cur; i++) cout << A[i][0] <<     << A[i][1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MAXN = 1e6 + 5;   long long a[MAXN], b[MAXN];   int main() {     int x;     cin >> x;     for (int i = 1; i <= x; i++)       for (int j = 1; j <= x; j++) {         if (i * j > x && (i / j) < x && (i % j == 0)) {           cout << i <<     << j << endl;           return 0;         }       }     cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxN = 1e5 + 10;   const long long MOD = 1e9 + 17;   long long s, t, n, m;   long long d[2][maxN];   vector<pair<long long, long long> > g[maxN], h[maxN];   vector<pair<pair<long long, long long>, long long> > edge;   long long dp[2][maxN];   void dij0(long long source) {     fill(d[0], d[0] + maxN, 1e18 + 10);     d[0][source] = 0;     dp[0][source] = 1;     set<pair<long long, long long> > s;     s.insert(make_pair(d[0][source], source));     while (!s.empty()) {       long long v = s.begin()->second;       s.erase(s.begin());       for (long long i = 0; i < g[v].size(); i++) {         long long u = g[v][i].first, w = g[v][i].second;         if (d[0][u] > d[0][v] + w) {           dp[0][u] = dp[0][v] % MOD;           s.erase(make_pair(d[0][u], u));           d[0][u] = d[0][v] + w;           s.insert(make_pair(d[0][u], u));         } else if (d[0][u] == d[0][v] + w)           dp[0][u] += dp[0][v], dp[0][u] %= MOD;       }     }   }   void dij1(long long source) {     fill(d[1], d[1] + maxN, 1e18 + 10);     d[1][source] = 0;     dp[1][source] = 1;     set<pair<long long, long long> > s;     s.insert(make_pair(d[1][source], source));     while (!s.empty()) {       long long v = s.begin()->second;       s.erase(s.begin());       for (long long i = 0; i < h[v].size(); i++) {         long long u = h[v][i].first, w = h[v][i].second;         if (d[1][u] > d[1][v] + w) {           dp[1][u] = dp[1][v] % MOD;           s.erase(make_pair(d[1][u], u));           d[1][u] = d[1][v] + w;           s.insert(make_pair(d[1][u], u));         } else if (d[1][u] == d[1][v] + w)           dp[1][u] += dp[1][v], dp[1][u] %= MOD;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m >> s >> t;     s--;     t--;     for (long long i = 0; i < m; i++) {       long long v, u, w;       cin >> v >> u >> w;       v--, u--;       g[v].push_back(make_pair(u, w));       h[u].push_back(make_pair(v, w));       edge.push_back(make_pair(make_pair(v, u), w));     }     dij0(s);     dij1(t);     for (long long i = 0; i < m; i++) {       long long v = edge[i].first.first, u = edge[i].first.second;       long long w = edge[i].second;       if (d[0][v] + w + d[1][u] == d[0][t]) {         if ((dp[0][v] * dp[1][u]) % MOD == dp[0][t]) {           cout <<  YES  <<   n ;           continue;         }       }       if (d[0][v] + d[1][u] + 1 < d[0][t]) {         cout <<  CAN   << d[0][v] + w + d[1][u] - d[0][t] + 1 <<   n ;         continue;       }       cout <<  NO  <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b, c, d, i, j, k, l, arr[26], max = 1;     long long int dp[1005], len[1005];     for (i = 0; i < 1005; i++) dp[i] = 0;     cin >> a;     string s;     cin >> s;     for (i = 0; i < 26; i++) cin >> arr[i];     dp[0] = 1;     dp[1] = 1;     len[0] = 0;     for (i = 2; i <= a; i++) {       int t = 0;       l = 99999;       j = i + 1;       while (j > 1) {         j--;         t++;         if (l > arr[s[j - 1] - 97]) l = arr[s[j - 1] - 97];         if (l >= t) {           dp[i] += dp[j - 1];         } else {           if (i - j > max) max = i - j;           len[i] = j;           break;         }         if (j == 1) {           if (max < i) max = i;         }         len[i] = 0;       }       dp[i] = dp[i] % 1000000007;     }     int ss = 1;     i = a;     while (len[i] != 0) {       i = len[i];       ss++;     }     cout << dp[a] << endl;     cout << max << endl;     cout << ss << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef struct {     long long v;     long long c;   } double_pair;   struct line {     long long k, b;     line() {}     line(long long _k, long long _b) : k(_k), b(_b) {}     long long Solve(long long val) {       long long _a = val - b, _b = k;       if (_a % _b == 0)         return _a / _b;       else         return _a / _b + 1;     }     long long f(long long x) { return k * x + b; }   };   double_pair D[300000];   int n;   line St[300000];   int top;   long long X[300000], s;   long long intersection(line a, line b) {     long long _a = a.b - b.b, _b = b.k - a.k;     if (_a % _b == 0)       return _a / _b;     else       return _a / _b + 1;   }   bool slope_compare(double_pair d1, double_pair d2) {     return ((d1.c < d2.c) || (d1.c == d2.c && d1.v > d2.v));   }   bool check(long long x, long long _s) {     if (x > X[top - 1]) return x >= St[top].Solve(_s);     int pos = lower_bound(X + 1, X + top, x) - X;     if (X[pos] == x) pos++;     return x >= St[pos].Solve(_s);   }   long long chat(long long _s) {     long long l = 0, r = _s, mid;     while (l + 1 < r) {       mid = (l + r) >> 1;       if (check(mid, _s))         r = mid;       else         l = mid;     }     return r;   }   void find_hull() {     St[++top] = line(D[0].v, -D[0].c);     long long i1, i2;     for (int i = 1; i < n; ++i) {       long long x0 = chat(D[i].c);       long long p = lower_bound(X + 1, X + top, x0) - X;       long long y0 =           St[p + (X[p] == x0)].k * x0 + St[p + (X[p] == x0)].b - D[i].c;       line tmp(D[i].v, y0 - x0 * D[i].v);       while (top >= 2 && (((i1 = intersection(tmp, St[top])) <=                                (i2 = intersection(St[top], St[top - 1])) ||                            (i1 == i2 && tmp.f(i1) >= St[top].f(i1)))))         --top;       St[++top] = tmp;       X[top - 1] = intersection(St[top], St[top - 1]);     }   }   int main() {     cin >> n >> s;     for (int i = 1; i <= n; i++) cin >> D[i].v >> D[i].c;     sort(D + 1, D + n + 1, slope_compare);     int tmp_n = n, maxv = 0;     n = 0;     for (int i = 1; i <= tmp_n; i++) {       if (maxv >= D[i].v) continue;       maxv = D[i].v;       D[n++] = D[i];     }     find_hull();     cout << chat(s);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 123457;   int n, m, S, A, D, R, h[N];   vector<int> adj[N];   bool is[N];   bool dfs(int v, int par = 0) {     h[v] = h[par] + 1;     bool c = is[v];     if (c && h[v] >= D) D = h[v], R = v;     if (c && h[v] == D && v < S) S = v;     for (int i = 0; i < adj[v].size(); ++i)       if (adj[v][i] != par) c |= dfs(adj[v][i], v);     if (c) ++A;     return c;   }   int main() {     cin >> n >> m;     int a, b;     for (int i = 0; i < n - 1; ++i) {       cin >> a >> b;       adj[a].push_back(b), adj[b].push_back(a);     }     h[0] = -1;     memset(is, false, sizeof(is));     S = 0, A = 0, D = 0;     for (int i = 0; i < m; ++i) {       cin >> R;       is[R] = true;     }     dfs(R);     dfs(R);     S = N;     dfs(R), dfs(R);     cout << S << endl << (A - 4) / 2 - D << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MD = 1000000007;   long long A[100000 + 1], dp[100000 + 1];   long long exp(long long a, long long b) {     long long r = 1;     while (b > 0) {       if (b & 1) r = r * a;       b /= 2;       a = a * a;     }     return r;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t, n, i, s, j, p, m, x, y, k, q;     string s1;     map<long long, long long> mp;     for (i = 0; i <= 32; i++) mp.insert({exp(2, i), i});     cin >> n >> m;     for (long long i = 1; i <= n; i++) {       cin >> x;       A[mp[x]]++;     }     while (m--) {       cin >> x;       p = 0;       for (i = 32; i >= 0; --i) {         k = min(x / exp(2, i), A[i]);         p += k;         x -= k * exp(2, i);       }       if (x != 0)         cout <<  -1 n ;       else         cout << p <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int server, temp;     int a, b;     a = 0;     b = 0;     int sum1, sum2;     sum1 = 0;     sum2 = 0;     for (int i = 0; i < n; i++) {       cin >> server;       if (server == 1) {         cin >> temp;         a++;         sum1 += temp;       } else {         cin >> temp;         b++;         sum2 += temp;       }       cin >> temp;     }     if (sum1 / a >= 5)       cout <<  LIVE  << endl;     else       cout <<  DEAD  << endl;     if (sum2 / b >= 5)       cout <<  LIVE  << endl;     else       cout <<  DEAD  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1 << 30;   const long long linf = 1LL << 60;   const int maxn = 100 + 5;   int A[maxn];   bool used[maxn];   vector<int> Q;   vector<vector<int> > B;   vector<int> C;   int n, k, m, q;   long double anal() {     long double res = 0;     for (int i = 0; i < m; ++i) {       res += (long double)A[B.back()[i] - 1];       used[B.back()[i] - 1] = 1;     }     res /= (long double)m;     return res;   }   int main() {     long double _min = inf;     long double _max = -1;     cin >> n >> k;     for (int i = 0; i < n; ++i) cin >> A[i];     m = n / k;     Q.reserve(m);     cin >> q;     for (int i = 0; i < q; ++i) {       Q.clear();       for (int j = 0; j < m; ++j) {         int x;         cin >> x;         Q.push_back(x);       }       sort((Q).begin(), (Q).end());       bool _new = 1;       for (int j = 0; j < B.size(); ++j) {         if (B[j][0] == Q[0]) {           _new = 0;           break;         }       }       if (_new) {         B.push_back(Q);         long double _res = anal();         if (_min > _res) _min = _res;         if (_max < _res) _max = _res;       }     }     if ((int)(B).size() < k) {       C.reserve(n);       for (int i = 0; i < n; ++i) {         if (!used[i]) C.push_back(A[i]);       }       sort((C).begin(), (C).end());       long double res = 0;       for (int i = 0; i < m; ++i) {         res += (long double)C[i];       }       res /= (long double)m;       if (_min > res) _min = res;       if (_max < res) _max = res;       res = 0;       for (int i = (int)(C).size() - 1; i >= (int)(C).size() - m; --i) {         res += (long double)C[i];       }       res /= (long double)m;       if (_min > res) _min = res;       if (_max < res) _max = res;     }     cout.setf(ios::fixed);     cout.precision(8);     cout << _min <<     << _max <<   n ;     return 0;   }