malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void abc() { cout << endl; }   template <typename T, typename... U>   void abc(T a, U... b) {     cout << a <<    , abc(b...);   }   template <typename T>   void printv(T l, T r) {     while (l != r) cout << *l <<    n [++l == r];   }   template <typename A, typename B>   istream& operator>>(istream& o, pair<A, B>& a) {     return o >> a.first >> a.second;   }   template <typename A, typename B>   ostream& operator<<(ostream& o, pair<A, B> a) {     return o <<  (  << a.first <<  ,   << a.second <<  ) ;   }   template <typename T>   ostream& operator<<(ostream& o, vector<T> a) {     bool is = false;     for (T i : a) {       o << (is ?     :  { ), is = true, o << i;     }     return o <<  } ;   }   template <typename T>   struct vv : vector<vector<T>> {     vv(int n, int m, T v) : vector<vector<T>>(n, vector<T>(m, v)) {}     vv() {}   };   template <typename T>   struct vvv : vector<vv<T>> {     vvv(int n, int m, int k, T v) : vector<vv<T>>(n, vv<T>(m, k, v)) {}     vvv() {}   };   const int mod = 1e9 + 7, N = 200001, logN = 20, K = 80000;   long long int modpow(long long int a, int b) {     long long int ans = 1;     for (; b; b >>= 1, a = a * a % mod) {       if (b & 1) ans = ans * a % mod;     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<int> a(n);     vv<long long int> inv(n, n, 0);     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j) {         inv[i][j] = modpow((a[i] + a[j]) % mod, mod - 2);       }     vv<long long int> pre(1 << n, n, 1);     vv<long long int> pw(n, n + 1, 1);     for (int i = 0; i < n; ++i) {       for (int j = 1; j <= n; ++j) {         pw[i][j] = pw[i][j - 1] * a[i] % mod;       }     }     for (int i = 0; i < n; ++i) {       for (int s = 0; s < 1 << n; ++s) {         for (int j = 0; j < n; ++j)           if (s >> j & 1) {             pre[s][i] = pre[s][i] * inv[i][j] % mod;           }       }     }     vector<long long int> dp(1 << n, 1);     for (int s = 0; s < 1 << n; ++s) {       for (int t = s ^ (s & (-s)); t > 0; t = (t - 1) & s) {         long long int res = dp[t];         for (int j = 0; j < n; ++j)           if (t >> j & 1) {             res = res * pre[t ^ s][j] % mod * pw[j][__builtin_popcount(t ^ s)] %                   mod;           }         dp[s] -= res;         if (dp[s] < 0) dp[s] += mod;       }     }     long long int ans = 0;     for (int s = 0; s < 1 << n; ++s) {       int k = __builtin_popcount(s);       long long int res = dp[s];       for (int i = 0; i < n; ++i)         if (s >> i & 1) {           for (int j = 0; j < n; ++j)             if (~s >> j & 1) {               res = res * a[i] % mod * inv[i][j] % mod;             }         }       ans += res * k % mod;       if (ans >= mod) ans -= mod;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   int main() {     int t, res = 0;     long x, y, n;     std::cin >> t;     for (int i = 0; i < t; i++) {       std::cin >> x >> y >> n;       if (n > 0) {         res = (n - y) % x;         std::cout << n - res <<   n ;       } else {         std::cout << 0 <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int N, i, j;   string S, R;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> N >> S;     for (i = N - 2; i >= 0; i -= 2) {       R = R + S[i];     }     if (N % 2 == 0)       i = 1;     else       i = 0;     for (i = i; i < N; i += 2) {       R = R + S[i];     }     cout << R << endl;   }
#include <bits/stdc++.h>   template <typename T>   inline void read(T &x) {     x = 0;     char c = getchar();     bool flag = false;     while (!isdigit(c)) {       if (c ==  - ) flag = true;       c = getchar();     }     while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();     if (flag) x = -x;   }   using namespace std;   int n, q, nn;   bitset<2011> bt[1011][2], h[2011];   int htot;   int ans[2011], pos[2011];   inline void Gauss() {     int nw = 1;     for (int i = 1; i < nn; ++i) {       int id = -1;       for (int hang = nw; hang <= htot; ++hang)         if (h[hang][i]) {           id = hang;           break;         }       if (id == -1) continue;       swap(h[id], h[nw]);       pos[i] = nw;       for (int hang = 1; hang <= htot; ++hang)         if (hang != nw && h[hang][i]) {           h[hang] = h[hang] ^ h[nw];         }       ++nw;       if (nw > htot) break;     }     for (int i = 1; i <= htot; ++i)       if (h[i][nn]) {         bool flag = false;         for (int j = 1; j < nn; ++j)           if (h[i][j]) {             flag = true;             break;           }         if (!flag) {           puts( NO );           exit(0);         }       }     for (int i = 1; i < nn; ++i) {       ans[i] = h[pos[i]][nn];     }     puts( YES );     for (int i = 1; i <= n; ++i) {       if (ans[i] == 0 && ans[i + n] == 0)         putchar( . );       else if (ans[i] == 1 && ans[i + n] == 0)         putchar( R );       else if (ans[i] == 0 && ans[i + n] == 1)         putchar( B );       else         putchar( Y );     }     putchar(  n );   }   int main() {     read(n), read(q);     nn = n + n + 1;     for (int i = 1; i <= n; ++i) bt[i][0][i] = bt[i][1][i + n] = 1;     for (int i = 1; i <= q; ++i) {       char opt[6];       scanf( %s , opt);       if (opt[0] ==  m ) {         int k;         read(k);         htot += 2;         for (int j = 1; j <= k; ++j) {           int p;           read(p);           h[htot - 1] ^= bt[p][0];           h[htot] ^= bt[p][1];         }         char res[3];         scanf( %s , res);         if (res[0] ==  W )           h[htot - 1][nn] = 0, h[htot][nn] = 0;         else if (res[0] ==  R )           h[htot - 1][nn] = 1, h[htot][nn] = 0;         else if (res[0] ==  B )           h[htot - 1][nn] = 0, h[htot][nn] = 1;         else           h[htot - 1][nn] = 1, h[htot][nn] = 1;       } else if (opt[0] ==  R  && opt[1] ==  Y ) {         int k;         read(k);         for (int j = 1; j <= k; ++j) {           int p;           read(p);           bt[p][1] = bt[p][1] ^ bt[p][0];         }       } else if (opt[0] ==  R  && opt[1] ==  B ) {         int k;         read(k);         for (int j = 1; j <= k; ++j) {           int p;           read(p);           swap(bt[p][0], bt[p][1]);         }       } else if (opt[0] ==  Y  && opt[1] ==  B ) {         int k;         read(k);         for (int j = 1; j <= k; ++j) {           int p;           read(p);           bt[p][0] = bt[p][0] ^ bt[p][1];         }       }     }     Gauss();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long i, j, t, n, k, a, b;   double v;   string line;   char s[4];   int main() {     while (cin >> n >> a >> b) {       if (b < 0) b = n + b;       a = a + b;       a = a % n;       if (a == 0)         a = n;       else if (a < 0)         a = n + a;       cout << a;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300005;   pair<int, int> p[N];   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     int i = 0, j = 0;     while (j < n) {       if (a[i] < a[j]) i++;       j++;     }     cout << i << endl;     return 0;   }
#include <bits/stdc++.h>   const int INF = (int)1e9;   using namespace std;   const int MAX = 1e3 + 5;   int n, xa, ya, xb, yb;   pair<pair<int, int>, int> arr[MAX];   vector<pair<int, int> > vec;   bool covered(int x1, int y1, int x2, int y2, int R) {     double dist = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));     return dist <= (double)R;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> xa >> ya >> xb >> yb >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i].first.first >> arr[i].first.second >> arr[i].second;     }     if (xa > xb) swap(xa, xb);     if (ya > yb) swap(ya, yb);     for (int i = ya; i <= yb; i++) {       vec.push_back(make_pair(xa, i));       vec.push_back(make_pair(xb, i));     }     for (int i = xa + 1; i < xb; i++) {       vec.push_back(make_pair(i, ya));       vec.push_back(make_pair(i, yb));     }     int res = 0;     for (int i = 0; i < vec.size(); i++) {       bool flag = false;       for (int j = 0; j < n; j++) {         if (covered(vec[i].first, vec[i].second, arr[j].first.first,                     arr[j].first.second, arr[j].second)) {           flag = true;           break;         }       }       if (!flag) res++;     }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   int n, m, fa[N], f[N], d[N], head[N], xx, yy, ww, fr[N];   int ans;   bool in[N], c[N];   struct nd {     int x, y, w, id;   } a[N];   bool operator<(nd a, nd b) { return a.w < b.w || (a.w == b.w && a.id < b.id); }   struct ndd {     int ne, to, w;   } e[N];   void ins(int x, int y, int w) {     static int cnt;     e[++cnt].to = y;     e[cnt].ne = head[x];     head[x] = cnt;     e[cnt].w = w;   }   int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); }   void dfs(int x) {     for (int i = head[x]; i; i = e[i].ne)       if (e[i].to != f[x]) {         int y = e[i].to;         f[y] = x;         d[y] = d[x] + 1;         fr[y] = e[i].w;         dfs(y);       }   }   void col(int x, int b) {     c[x] = 1;     for (int i = head[x]; i; i = e[i].ne)       if (e[i].to != b) {         int y = e[i].to;         col(y, x);       }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; ++i) {       scanf( %d%d%d , &a[i].x, &a[i].y, &a[i].w);       a[i].id = i;     }     xx = a[1].x, yy = a[1].y, ww = a[1].w;     sort(a + 1, a + m + 1);     for (int i = 1; i <= n; ++i) fa[i] = i;     for (int i = 1; i <= m; ++i) {       int fx = gf(a[i].x), fy = gf(a[i].y);       if (fx != fy) {         fa[fx] = fy;         in[a[i].id] = 1;         ins(a[i].x, a[i].y, a[i].w);         ins(a[i].y, a[i].x, a[i].w);       }     }     d[1] = 1;     dfs(1);     if (!in[1]) {       while (xx != yy) {         if (d[xx] < d[yy]) swap(xx, yy);         ans = max(ans, fr[xx]);         xx = f[xx];       }     } else {       ans = 1e9;       col(yy, xx);       for (int i = 1; i <= m; ++i)         if (!in[a[i].id]) {           if (c[a[i].x] ^ c[a[i].y]) ans = min(ans, a[i].w);         }     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   struct point {     long long x, y, z;     point() {}     point(long long a, long long b, long long c) : x(a), y(b), z(c) {}     double operator()(point y) {       return sqrt((this->x - y.x) * (this->x - y.x) +                   (this->y - y.y) * (this->y - y.y) +                   (this->z - y.z) * (this->z - y.z));     }   };   vector<pair<int, int>> ans;   int taken[10005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     long long a, b, c;     point arr[n];     for (int i = 0; i < n; i++) {       cin >> a >> b >> c;       point p(a, b, c);       arr[i] = p;     }     for (int i = 0; i < n; i++) {       double minimum = 1e11;       int correct;       if (taken[i]) continue;       for (int j = 0; j < n; j++) {         if (i == j || taken[j]) continue;         double x = arr[i](arr[j]);         if (x < minimum) {           minimum = x;           correct = j;         }       }       taken[correct] = 1;       taken[i] = 1;       ans.push_back({i, correct});     }     for (int i = 0; i < n / 2; i++)       cout << ans[i].first + 1 <<     << ans[i].second + 1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 200005, INF = 2000000000000000000;   long double pi = 3.1415926535897932;   long long powere(long long a, long long b, long long p) {     if (a == 0) return 0;     long long res = 1;     a %= p;     while (b > 0) {       if (b & 1) res = (res * a) % p;       b >>= 1;       a = (a * a) % p;     }     return res;   }   void copy(long long a[2][2], long long b[2][2]) {     for (long long i = 0; i < 2; i++) {       for (long long j = 0; j < 2; j++) b[i][j] = a[i][j];     }   }   void matmult(long long m1[2][2], long long m2[2][2], long long m3[2][2]) {     for (long long i = 0; i < 2; i++) {       for (long long j = 0; j < 2; j++) {         m3[i][j] = 0;         for (long long k = 0; k < 2; k++) {           m3[i][j] +=               (m1[i][k] % 1000000007 * m2[k][j] % 1000000007) % 1000000007;           m3[i][j] %= 1000000007;         }       }     }   }   void power(long long mat[2][2], long long b, long long p,              long long finres[2][2]) {     long long res[2][2] = {{0}}, cc[2][2];     res[0][0] = res[1][1] = 1;     while (b > 0) {       copy(res, cc);       if (b & 1) matmult(mat, cc, res);       copy(mat, cc);       b >>= 1;       matmult(cc, cc, mat);     }     copy(res, finres);   }   int32_t main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout.precision(std::numeric_limits<double>::max_digits10);     ;     long long t;     cin >> t;     while (t--) {       long long x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       long long x = abs(x1 - x2), y = abs(y1 - y2);       if (y < x) swap(x, y);       long long ans = (x * (x + 1));       ans += ((y - x - 1) * x);       cout << ans + 1 <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   void fun(long long int a, long long int b, long long int u,            vector<long long int> &t) {     long long int i, j, k, n;     for (i = 1; i < b; i++) {       if (u) t[i]++;     }     u = 1 - u;     i = b;     while (i < 1000) {       for (j = 0; j < a; j++) {         if (i >= 1000) return;         if (u) t[i]++;         i++;       }       u = 1 - u;     }   }   void solve() {     long long int i, j, k, n;     cin >> n;     string s;     cin >> s;     vector<pair<long long int, long long int> > v(n);     vector<long long int> t(1000, 0);     for (i = 0; i < n; i++) {       if (s[i] ==  1 ) t[0]++;     }     for (i = 0; i < n; i++) {       cin >> v[i].first >> v[i].second;     }     for (i = 0; i < n; i++) {       fun(v[i].first, v[i].second, s[i] -  0 , t);     }     long long int mx = t[0];     for (i = 1; i < (int)t.size(); i++) mx = max(mx, t[i]);     cout << mx;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, q, x, y;   char type;   map<int, pair<char, int> > Data;   int solve() {     auto fi = Data.lower_bound(x);     if (fi->first == x) return 0;     if (type ==  L ) fi--;     int ans = abs(x - fi->first);     if (fi->second.first == type) ans += fi->second.second;     Data[x] = make_pair(type, ans);     return ans;   }   int main() {     scanf( %d %d , &n, &q);     Data[0] = make_pair( U , 0);     Data[n + 1] = make_pair( L , 0);     while (q--) {       cin >> x >> y >> type;       printf( %d n , solve());     }   }
#include <bits/stdc++.h>   using namespace std;   const int M = 15, N = 15;   int m, n;   pair<int, int> a[M], b[N];   vector<int> tot, cur;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> m >> n;     for (int i = 1; i <= m; i++) {       cin >> a[i].first >> a[i].second;     }     for (int i = 1; i <= n; i++) {       cin >> b[i].first >> b[i].second;     }     for (int i = 1; i <= m; i++) {       cur.clear();       for (int j = 1; j <= n; j++) {         int cnt = 0;         if (a[i].first == b[j].first || a[i].first == b[j].second) {           cnt++;         }         if (a[i].second == b[j].first || a[i].second == b[j].second) {           cnt++;         }         if (cnt == 1) {           if (a[i].first == b[j].first || a[i].first == b[j].second) {             cur.push_back(a[i].first);           } else {             cur.push_back(a[i].second);           }         }       }       sort(cur.begin(), cur.end());       cur.erase(unique(cur.begin(), cur.end()), cur.end());       if (cur.size() >= 2) {         return cout << -1, 0;       } else if (cur.size() == 1) {         tot.push_back(cur[0]);       }     }     for (int i = 1; i <= n; i++) {       cur.clear();       for (int j = 1; j <= m; j++) {         int cnt = 0;         if (b[i].first == a[j].first || b[i].first == a[j].second) {           cnt++;         }         if (b[i].second == a[j].first || b[i].second == a[j].second) {           cnt++;         }         if (cnt == 1) {           if (b[i].first == a[j].first || b[i].first == a[j].second) {             cur.push_back(b[i].first);           } else {             cur.push_back(b[i].second);           }         }       }       sort(cur.begin(), cur.end());       cur.erase(unique(cur.begin(), cur.end()), cur.end());       if (cur.size() >= 2) {         return cout << -1, 0;       } else if (cur.size() == 1) {         tot.push_back(cur[0]);       }     }     sort(tot.begin(), tot.end());     tot.erase(unique(tot.begin(), tot.end()), tot.end());     if (tot.size() >= 2) {       cout << 0;     } else {       cout << tot[0];     }   }
#include <bits/stdc++.h>   using namespace std;   long long k, b, n, t, ans, cur;   int main() {     ios_base::sync_with_stdio(0);     cin >> k >> b >> n >> t;     ans = n;     cur = k + b;     while (cur <= t) {       cur = cur * k + b;       --ans;     }     if (ans < 0) ans = 0;     cout << ans << endl;     cin.get();     cin.get();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   int n, q, L[maxn << 2], R[maxn << 2];   double sum[maxn << 2], add[maxn << 2], mul[maxn << 2];   void pushup(int o) { sum[o] = sum[o * 2] + sum[o * 2 + 1]; }   void pushdown(int o) {     sum[o * 2] = sum[o * 2] * mul[o] + add[o] * (R[o * 2] - L[o * 2] + 1);     sum[o * 2 + 1] =         sum[o * 2 + 1] * mul[o] + add[o] * (R[o * 2 + 1] - L[o * 2 + 1] + 1);     add[o * 2] = add[o * 2] * mul[o] + add[o];     add[o * 2 + 1] = add[o * 2 + 1] * mul[o] + add[o];     mul[o * 2] = mul[o * 2] * mul[o];     mul[o * 2 + 1] = mul[o * 2 + 1] * mul[o];     mul[o] = 1;     add[o] = 0;   }   void build(int o, int l, int r) {     L[o] = l;     R[o] = r;     add[o] = 0;     mul[o] = 1;     if (l == r) {       cin >> sum[o];       return;     }     int mid = (l + r) >> 1;     build(o * 2, l, mid);     build(o * 2 + 1, mid + 1, r);     pushup(o);   }   double query(int o, int l, int r, int x, int y) {     if (x <= l && r <= y) {       return sum[o];     }     pushdown(o);     int mid = (l + r) >> 1;     double res = 0.0;     if (x <= mid) res += query(o * 2, l, mid, x, y);     if (y > mid) res += query(o * 2 + 1, mid + 1, r, x, y);     return res;   }   void update1(int o, int l, int r, int x, int y, double v) {     if (x <= l && r <= y) {       sum[o] += v * (r - l + 1);       add[o] += v;       return;     }     pushdown(o);     int mid = (l + r) >> 1;     if (x <= mid) update1(o * 2, l, mid, x, y, v);     if (y > mid) update1(o * 2 + 1, mid + 1, r, x, y, v);     pushup(o);   }   void update2(int o, int l, int r, int x, int y, double v) {     if (x <= l && r <= y) {       add[o] *= v;       sum[o] *= v;       mul[o] *= v;       return;     }     pushdown(o);     int mid = (l + r) >> 1;     if (x <= mid) update2(o * 2, l, mid, x, y, v);     if (y > mid) update2(o * 2 + 1, mid + 1, r, x, y, v);     pushup(o);   }   int main() {     scanf( %d%d , &n, &q);     build(1, 1, n);     while (q--) {       int l1, r1, l2, r2;       int id;       scanf( %d , &id);       if (id == 1) {         scanf( %d%d%d%d , &l1, &r1, &l2, &r2);         double sum1 = query(1, 1, n, l1, r1), sum2 = query(1, 1, n, l2, r2);         double len1 = r1 - l1 + 1, len2 = r2 - l2 + 1;         update2(1, 1, n, l1, r1, (len1 - 1) / len1);         update2(1, 1, n, l2, r2, (len2 - 1) / len2);         update1(1, 1, n, l1, r1, 1.0 / len1 * (sum2 / len2));         update1(1, 1, n, l2, r2, 1.0 / len2 * (sum1 / len1));       } else {         scanf( %d%d , &l1, &r1);         printf( %.7lf n , query(1, 1, n, l1, r1));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void connected(vector<vector<bool> > chu, vector<bool>& v, int s) {     v[s] = 1;     for (int i = 0; i < chu.size(); i++) {       if (chu[s][i] && !v[i]) {         connected(chu, v, i);       }     }   }   int main() {     int n, m;     while (cin >> n >> m) {       if (n != m) {         cout <<  NO  << endl;         break;       }       vector<vector<bool> > chu(n, vector<bool>(n, 0));       for (int i = 0; i < m; i++) {         int e1, e2;         cin >> e1 >> e2;         chu[e1 - 1][e2 - 1] = 1;         chu[e2 - 1][e1 - 1] = 1;       }       vector<bool> visisted(n, 0);       connected(chu, visisted, 0);       bool allseen = true;       for (int i = 0; i < visisted.size(); i++) {         if (!visisted[i]) allseen = false;       }       if (allseen) {         cout <<  FHTAGN!  << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   int n, m, op, det;   int dir[2];   long long mv[2];   int ans[1111111];   int main() {     scanf( %d%d , &n, &m);     dir[1] = 1;     dir[0] = -1;     mv[1] = mv[0] = 0LL;     for (int i = 0; i < m; i++) {       scanf( %d , &op);       if (op == 1) {         scanf( %d , &det);         mv[1] += det;         mv[0] += det;         if (det % 2) {           dir[1] = -dir[1];           dir[0] = -dir[0];         }       } else {         mv[1] += dir[1];         mv[0] += dir[0];         dir[1] = -dir[1];         dir[0] = -dir[0];       }     }     mv[1] %= n;     if (mv[1] < 0) mv[1] += n;     mv[0] %= n;     if (mv[0] < 0) mv[0] += n;     for (int i = 1; i <= n; i++) {       int id = i % 2;       int p = i + mv[id];       if (p > n) p -= n;       ans[p] = i;     }     for (int i = 1; i <= n; i++) printf( %d%c , ans[i], i < n ?     :   n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 Rand(time(0));   const int maxn = 1e5 + 5;   const long long maxc = 1e9 + 7;   int n, m, d, a[maxn];   long long sum[maxn];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> d >> m;     for (int i = (1); i <= (n); ++i) cin >> a[i];     sort(a + 1, a + n + 1);     for (int i = (1); i <= (n); ++i) sum[i] = sum[i - 1] + a[i];     if (a[n] <= m) return cout << sum[n], 0;     int id = upper_bound(a + 1, a + n + 1, m) - a;     long long res = a[n] + sum[id - 1];     long long ans = res;     for (int i = (n - 1); i >= (id); --i) {       if (1LL * (n - i) * d > n) continue;       int r = (n - i) * d;       if (r - (i - id) < id) {         ans = max(ans, res + sum[n - 1] - sum[i - 1] - sum[max(0, r - (i - id))]);       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long inf = 0x3f3f3f3f;   const long long llinf = 1e18;   const long long nax = 0;   int n, m, batas;   vector<pair<int, int>> shift;   set<char> simpen;   map<char, bool> sabi;   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     cout.tie();     cin >> n >> m >> batas;     char arr[n + 5][m + 5];     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         cin >> arr[i][j];         if (arr[i][j] ==  S ) {           shift.push_back({i, j});         } else {           simpen.insert(arr[i][j]);         }       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         for (auto x : shift) {           int x1 = i, x2 = x.first, y1 = j, y2 = x.second;           int hitung = ceil(sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));           if (hitung <= batas) {             sabi[arr[i][j]] = 1;           }         }       }     }     int q, ans = 0;     cin >> q;     string s;     cin >> s;     for (int k = 0; k < q; ++k) {       if (s[k] >= 97) {         if (!simpen.count(s[k])) {           cout <<  -1  <<   n ;           return 0;         } else           continue;       } else {         if (shift.empty()) {           cout <<  -1  <<   n ;           return 0;         }         bool ok = 0, ada = 0;         if (!simpen.count(s[k] + 32)) {           cout <<  -1  <<   n ;           return 0;         } else {           if (sabi[s[k] + 32])             continue;           else             ans++;         }       }     }     cout << ans <<   n ;   }