malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   bool func(vector<pair<int, int> > vd, vector<pair<int, int> > vu) {     for (int i = 0; i < vd.size(); i++) {       if ((vd[i].first < vu[i].first && vd[i].second < vu[i].second) ||           (vd[i].first > vu[i].first && vd[i].second > vu[i].second)) {         return true;       }     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t, i, j, k, n, m,         a = 1, b = 1, c, p, prev, q, r, width, o, rc, height, mx = -999999999,         mn = 99999999, ct = 0, ans = 0, flag = 1, sum = 0, pos1, pos2;     cin >> n >> m >> k;     std::vector<pair<long long int, long long int> > row(n), col(m);     for (i = 1; i <= k; i++) {       cin >> o >> rc >> a;       if (o == 1) {         row[rc - 1] = {a, i};       } else {         col[rc - 1] = {a, i};       }     }     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         if (col[j].second > row[i].second)           cout << col[j].first <<    ;         else           cout << row[i].first <<    ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   priority_queue<pair<long long, int> > q;   vector<pair<long long, pair<int, int> > > E;   vector<pair<int, int> > e[120000];   int n, m, x, y, k, z, fa[120000], i, be[120000], flag[120000];   long long dis[120000], ans;   int get(int x) { return fa[x] == x ? x : (fa[x] = get(fa[x])); }   int main() {     scanf( %d%d , &n, &m);     for (i = 1; i <= m; ++i) {       scanf( %d%d%d , &x, &y, &k);       e[x].push_back(make_pair(y, k));       e[y].push_back(make_pair(x, k));     }     memset(dis, 3, sizeof(dis));     scanf( %d , &k);     for (i = 1; i <= k; ++i) {       scanf( %d , &x);       dis[x] = 0;       fa[x] = x;       q.push(make_pair(0, x));       be[x] = x;     }     while (!q.empty()) {       x = q.top().second;       q.pop();       if (flag[x]) continue;       flag[x] = 1;       for (i = 0; i < e[x].size(); ++i) {         y = e[x][i].first;         z = e[x][i].second;         if (be[y])           E.push_back(make_pair(dis[x] + dis[y] + z, make_pair(be[x], be[y])));         if (dis[x] + z < dis[y]) {           dis[y] = dis[x] + z;           be[y] = be[x];           q.push(make_pair(-dis[y], y));         }       }     }     sort(E.begin(), E.end());     for (i = 0; i < E.size(); ++i) {       x = E[i].second.first;       y = E[i].second.second;       if (get(x) != get(y)) {         ans += E[i].first;         fa[get(x)] = get(y);       }     }     printf( %I64d n , ans + dis[1]);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int dp[N], a[N], n;   int main() {     cin >> n;     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     if (n == 1) {       cout << 1;       return 0;     }     for (int i = 0; i < n; ++i) {       if (a[i] == 1) continue;       int d = 2, mx = 0, x = a[i];       while (d * d <= x)         if (x % d == 0) {           mx = max(mx, dp[d] + 1);           x /= d;         } else           ++d;       mx = max(mx, dp[x] + 1);       d = 2;       x = a[i];       while (d * d <= x)         if (x % d == 0) {           dp[d] = max(dp[d], mx);           x /= d;         } else           ++d;       dp[x] = max(dp[x], mx);     }     int mx = 0;     for (int i = 1; i < N; ++i) mx = max(mx, dp[i]);     cout << mx;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int oo = 1 << 30;   const double PI = M_PI;   const double EPS = 1e-15;   double w, h, u;   double cross(const complex<double> &a, const complex<double> &b) {     return imag(conj(a) * b);   }   complex<double> rotate_by(const complex<double> &p,                             const complex<double> &about, double radians) {     return (p - about) * exp(complex<double>(0, radians)) + about;   }   complex<double> intersect(const complex<double> &a, const complex<double> &b,                             const complex<double> &p, const complex<double> &q) {     double d1 = cross(p - a, b - a);     double d2 = cross(q - a, b - a);     return (d1 * q - d2 * p) / (d1 - d2);   }   int main() {     cin.sync_with_stdio(false);     cin >> w >> h >> u;     if (w < h) swap(w, h);     if (u > 90) u = 180 - u;     u = u * M_PI / 180.;     cout.precision(10);     if (u == 0) {       cout << fixed << w * h << endl;       return 0;     }     if (u >= (M_PI - 2. * atan(w / (double)h))) {       cout << fixed << h * h / sin(u) << endl;     } else {       double answer = w * h;       complex<double> a1 =           rotate_by(complex<double>(+w / 2., -h / 2), complex<double>(0, 0), u);       complex<double> a2 =           rotate_by(complex<double>(+w / 2., +h / 2), complex<double>(0, 0), u);       complex<double> a3 =           rotate_by(complex<double>(-w / 2., +h / 2), complex<double>(0, 0), u);       complex<double> b1 = intersect(a1, a2, complex<double>(-w / 2., h / 2.),                                      complex<double>(w / 2., h / 2.));       complex<double> b2 = intersect(a2, a3, complex<double>(-w / 2., h / 2.),                                      complex<double>(w / 2., h / 2.));       {         double side1 = b1.real() - b2.real();         double side2 = side1 * cos(u);         double area = side1 * side2 * sin(u);         answer = answer - area;       }       {         double side1 = w / 2. - b1.real();         double side2 = side1 * tan(M_PI / 2. - u);         double area = side1 * side2;         answer = answer - area;       }       cout << fixed << answer << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void lemon() {     double R1, R2;     int k;     scanf( %lf%lf%d , &R1, &R2, &k);     k++;     double xl = 1 / (R1 * 2), xr = 1 / (R2 * 2);     double xc = (xl + xr) / 2, rad = abs(xc - xl);     double yc = rad * (k - 1) * 2;     double len = sqrt(xc * xc + yc * yc);     double final = (1 / (len - rad) - 1 / (len + rad)) / 2;     printf( %.16lf n , final);   }   int main() {     ios::sync_with_stdio(true);     int tcase;     scanf( %d , &tcase);     while (tcase--) lemon();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int pp = (1e9) + 7;   long long P[1000010];   long long ans, now;   int N, K;   long long quick(int x, int y) {     long long s = 1, t = x;     for (; y; y >>= 1) {       if (y & 1) s = s * t % pp;       t = t * t % pp;     }     return s;   }   long long get0() {     long long t = 1;     for (int i = N - K - 1; i < N; i++) t = t * i % pp;     for (int i = 1; i <= K + 1; i++) t = t * quick(pp - i, pp - 2) % pp;     return t;   }   int main() {     scanf( %d%d , &N, &K);     if (!K) {       printf( %d n , N);       return 0;     }     for (int i = 1; i <= K + 2; i++) P[i] = (P[i - 1] + quick(i, K)) % pp;     if (N <= K + 2) {       printf( %I64d n , P[N]);       return 0;     }     ans = 0;     now = get0();     for (int i = 1; i <= K + 1; i++) {       now = now * quick(i, pp - 2) % pp * (N - i + 1) % pp *             quick(N - i, pp - 2) % pp * (pp - (K - i + 2)) % pp;       ans = (ans + P[i] * now) % pp;     }     printf( %I64d , ans);   }
#include <bits/stdc++.h>   using namespace std;   long long G[333][333];   long long min(long long a, long long b, long long c) {     return min(a, min(b, c));   }   int main() {     int N;     cin >> N;     for (int i = 1; i <= N; i++)       for (int j = 1; j <= N; j++) cin >> G[i][j];     int M;     cin >> M;     while (M--) {       long long u, v, x;       cin >> u >> v >> x;       for (int i = 1; i <= N; i++)         for (int j = 1; j <= N; j++) {           G[i][j] = min(G[i][j], G[i][u] + G[v][j] + x, G[i][v] + G[u][j] + x);         }       long long sum = 0;       for (int i = 1; i <= N; i++)         for (int j = i; j <= N; j++) sum += G[i][j];       cout << sum <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   set<int> m;   using namespace std;   bool check(int a) {     m.erase(m.begin(), m.end());     int i = 0;     while (a > 0) {       int re = a % 10;       m.insert(re);       a /= 10;       i++;     }     if (m.size() == i) {       return true;     } else       return false;   }   int main() {     int l, r, flag = 0;     long long int ans = 0;     cin >> l >> r;     for (int i = l; i <= r; i++) {       if (check(i) == true) {         ans = i;         flag = 1;         break;       }     }     if (flag == 1) {       cout << ans << endl;     } else       cout <<  -1  << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, l;   int cnt[N];   long long sum[N];   int main() {     cin >> n >> l;     for (int i = 1; i < n; i++) {       cin >> cnt[i];       sum[i] = sum[i - 1] + cnt[i];     }     long long ans = 2e18;     for (int i = l; i < n; i++) {       ans = min(ans, sum[i] - sum[i - l]);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   int n, k;   string s;   int main(void) {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       cin >> n >> k;       vector<int> alpha(26, 0);       vector<int> cpy(26, 0);       vector<int> cnt(26, 0);       cin >> s;       int ans = 0;       for (char c : s) {         alpha[c -  a ]++;         cpy[c -  a ]++;       }       for (int i = 1; i <= min(n, k); i++)         if (k % i == 0)           for (int l = 1; l <= n; l++) {             int tmp = 0;             for (int a = 0; a < 26; a++) tmp += alpha[a] / l;             if (tmp >= i) ans = max(ans, l * i);           }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     map<char, int> cnt;     if (s.size() > 2)       for (int i = 1; i <= s.size() - 2; i++) {         cnt.clear();         cnt[s[i - 1]]++;         cnt[s[i]]++;         cnt[s[i + 1]]++;         if (cnt[ A ] == 1 && cnt[ B ] == 1 && cnt[ C ] == 1) {           cout <<  Yes n ;           return 0;         }       }     cout <<  No n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[1000001], s1[1000001], s2[1000001];   int n, ci, dian = -1, en, e2;   int main() {     scanf( %s , s);     n = strlen(s);     if (n == 1 && s[0] ==  0 ) {       puts( 0 );       return 0;     }     for (int i = 0; i < n; ++i)       if (s[i] ==  . ) dian = i;     if (dian == -1) s[dian = n++] =  . ;     for (int i = 0; i < n; ++i)       if (s[i] !=  0  && s[i] !=  . ) {         if (dian > i)           ci = dian - i - 1;         else           ci = dian - i;         for (int j = 0; j <= i; ++j)           if (s[j] !=  . ) s1[en++] = s[j];         for (int j = i + 1; j < n; ++j)           if (s[j] !=  . ) s2[e2++] = s[j];         break;       }     for (int i = 0; i < en; ++i)       if (s1[i] !=  0 ) {         for (int j = i; j < en; ++j) putchar(s1[j]);         break;       }     if (e2 != 0) {       bool flag = 0;       for (int i = e2 - 1; i >= 0; --i)         if (s2[i] !=  0 ) {           flag = 1;           break;         }       if (flag) putchar( . );       for (int i = e2 - 1; i >= 0; --i)         if (s2[i] !=  0 ) {           for (int j = 0; j <= i; ++j) putchar(s2[j]);           break;         }     }     if (ci != 0) printf( E%d n , ci);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool same(int l1, int r1, int l2, int r2) {     if (r1 < l2 || r2 < l1) {       return 0;     }     return 1;   }   signed main() {     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       int l = 1e9 + 5, r = 0;       for (int i = 0; i < n; i++) {         int l3, r3;         cin >> l3 >> r3;         r = max(r, l3);         l = min(l, r3);       }       cout << max(0, r - l) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int chkpower2(int x) { return (x && !(x & x - 1)); }   void solve() {     long long int n;     cin >> n;     long long int a[n], sum = 0;     for (int i1 = 0; i1 < n; i1++) {       cin >> a[i1];       sum += a[i1];     }     sort(a, a + n);     if (sum % (n - 1)) {       sum = sum / (n - 1) + 1;     } else {       sum = sum / (n - 1);     }     cout << max(a[n - 1], sum);     return;   }   int main() {     int t;     t = 1;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool vowel(char a) {     a = toupper(a);     if ((a ==  A ) || (a ==  E ) || (a ==  I ) || (a ==  O ) || (a ==  U ))       return 1;     return 0;   }   long long int n, m, q, a, b, c, sum = 0, cnt = 0;   long long int arr[500055];   map<long long int, bool> mp;   string str;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     bool one = 1, two = 1, tr = 1;     for (int i = 0; i < n; i++) {       if (arr[i] > arr[i - 1]) {         if (!tr || !two) {           cout <<  NO  << endl;           return 0;         }       }       if (arr[i] == arr[i - 1]) {         two = 0;         if (tr)           continue;         else {           cout <<  NO  << endl;           return 0;         }       }       if (arr[i] < arr[i - 1]) {         tr = 0;       }     }     cout <<  YES  << endl;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, m;     cin >> n >> m;     ;     int a[n + 1];     memset(a, 0, sizeof(a));     for (long long i = 0; i < m; i++) {       long long t;       cin >> t;       ;       for (long long j = t; j < n + 1; j++) {         if (a[j] == 0) a[j] = t;       }     }     for (long long i = 1; i < n + 1; i++) {       cout << a[i] <<    ;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, K;   vector<int> tabs;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> N >> K;     tabs.resize(N);     for (int i = 0; i < N; i++) cin >> tabs[i];     int most = 0;     for (int b = 0; b < N; b++) {       int sum = 0;       for (int i = 0; i < N; i++)         if (i % K != b % K) sum += tabs[i];       most = max(most, abs(sum));     }     cout << most <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void setmax(T& x, T y) {     x = max(x, y);   }   template <typename T>   void setmin(T& x, T y) {     x = min(x, y);   }   const double PI = acos(-1.0);   const long long INF = 1e9 + 47;   const long long LINF = INF * INF;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int N = 1e7 + 7;   int lp[N];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     iota(lp, lp + N, 0);     for (int i = (2); i < (N); ++i)       if (lp[i] == i)         for (int j = i + i; j < N; j += i) setmin(lp[j], i);     int n;     cin >> n;     vector<pair<int, int> > ans(n, make_pair(-1, -1));     for (int i = (0); i < (n); ++i) {       int x;       cin >> x;       int p = lp[x];       int t = x;       while (t % p == 0) t /= p;       if (t > 1) {         ans[i] = {t, p};       }     }     for (int i = (0); i < (n); ++i) {       cout << ans[i].first <<    ;     }     cout << endl;     for (int i = (0); i < (n); ++i) {       cout << ans[i].second <<    ;     }     cout << endl;     cerr <<  Time elapsed:   << clock() / (double)CLOCKS_PER_SEC << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1 << 30;   const int md = 1e9 + 7;   const int N = 1e5 + 10;   int n, m;   int T;   int k;   long long p;   long long q[N];   long long ar[N];   int now = -1;   set<long long> se[N];   inline long long up(long long x, long long y) {     long long re = x / y - 1;     while (re * y < x) re++;     return re;   }   inline long long down(long long x, long long y) {     long long re = x / y + 1;     while (re * y > x) re--;     return re;   }   bool dfs(int x) {     if (x >= N - 5) return 0;     if (se[x].count(q[x])) return 0;     se[x].insert(q[x]);     if (0 <= q[x] && q[x] < k) {       now = x;       ar[0] = q[0] * k + p;       for (int i = 0; i <= x - 1; i++) ar[i + 1] = q[i] + q[i + 1] * k;       ar[x + 1] = q[x];       return 1;     }     for (q[x + 1] = up(-q[x], k); q[x + 1] <= 1 + down(-q[x], k); q[x + 1]++) {       if (dfs(x + 1)) return 1;     }     return 0;   }   void solve() {     long long l = up(-p, k);     long long r = 1 + down(-p, k);     for (q[0] = l; q[0] <= r; q[0]++)       if (dfs(0)) break;     if (now >= 0) {       now++;       while (ar[now] == 0) now--;       printf( %d n , now + 1);       for (int i = 0; i <= now; i++)         printf( %I64d%c , ar[i], i == now ? 10 :    );     } else {       puts( -1 );     }   }   int main() {     scanf( %I64d%d , &p, &k);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5005;   int n, m, w, o[N], K[N], P[N], C[N];   int vis[N];   vector<int> adj[N];   void bfs(int src) {     for (int i = 0; i <= n; ++i) vis[i] = -1;     queue<int> q, qw;     q.push(src);     qw.push(0);     vis[src] = 0;     while (!q.empty()) {       int u = q.front();       q.pop();       int w = qw.front();       qw.pop();       for (auto v : adj[u]) {         if (vis[v] == -1) {           vis[v] = w + 1;           q.push(v);           qw.push(w + 1);         }       }     }   }   int q;   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; ++i) {       int u, v;       scanf( %d%d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     scanf( %d , &w);     for (int i = 0; i < w; ++i) {       int c, k, p;       scanf( %d%d%d , &c, &k, &p);       o[i] = i;       K[i] = k;       P[i] = p;       C[i] = c;     }     sort(o, o + w, [](int i, int j) { return P[i] < P[j]; });     scanf( %d , &q);     while (q--) {       int g, r, a;       scanf( %d%d%d , &g, &r, &a);       int L = 0, R = n;       bfs(g);       while (L < R) {         int M = (L + R) / 2;         long long totalCost = 0;         int shovels = 0;         for (int i = 0; i < w; ++i) {           int id = o[i];           if (vis[C[id]] != -1 && vis[C[id]] <= M) {             int need = min(r - shovels, K[id]);             totalCost += 1ll * need * P[id];             shovels += need;             if (shovels >= r) break;           }         }         if (totalCost > a || shovels < r) {           L = M + 1;         } else {           R = M;         }       }       if (L == n) {         L = -1;       }       printf( %d n , L);     }   }
#include <bits/stdc++.h>   using namespace std;   int n;   void solve_1() {     if (n < 6) {       printf( -1 n );       return;     }     puts( 1 2 );     puts( 2 3 );     puts( 2 4 );     puts( 4 5 );     puts( 4 6 );     for (int i = 7; i <= n; i++) {       printf( 2 %d n , i);     }   }   void solve_2() {     for (int i = 2; i <= n; i++) {       printf( 1 %d n , i);     }   }   int main() {     scanf( %d , &n);     solve_1();     solve_2();   }
#include <bits/stdc++.h>   using namespace std;   int head[2 * 200005], nex[2 * 200005], from[2 * 200005], to[2 * 200005], cnt, n;   int sn[200005], num[200005];   long long d[200005], ans;   void add(int u, int v) {     nex[++cnt] = head[u];     from[cnt] = u;     to[cnt] = v;     head[u] = cnt;     nex[++cnt] = head[v];     from[cnt] = v;     to[cnt] = u;     head[v] = cnt;   }   void dfs(int x, int p) {     sn[x] = 1;     for (int i = head[x]; i; i = nex[i]) {       int u = to[i];       if (u == p) continue;       dfs(u, x);       for (int j = head[u]; j; j = nex[j]) {         int v = to[j];         if (v == x) continue;         d[x] += d[v] + sn[v];       }       d[x]++;       sn[x] += sn[u];     }   }   void dfs2(int x, int p) {     ans += d[x];     for (int i = head[x]; i; i = nex[i]) {       int u = to[i];       if (u == p) continue;       for (int j = head[u]; j; j = nex[j]) {         int v = to[j];         if (v == x) continue;         d[v] = d[x] - sn[v] + n - sn[u];         dfs2(v, u);       }       if (p == 0) {         d[u]++;         dfs2(u, x);       }     }   }   int main() {     cin >> n;     int u, v;     for (int i = 1; i < n; i++) {       scanf( %d%d , &u, &v);       add(u, v);       num[u]++;       num[v]++;     }     int root;     for (int i = 1; i <= n; i++)       if (num[i] == 1) {         root = i;         break;       }     dfs(root, 0);     dfs2(root, 0);     cout << ans / 2 << endl;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma comment(linker,  /STACK:100000000 )   const double pi = acos(-1);   const int MOD = 1e9 + 7;   const int INF = 1e9 + 7;   const int MAXN = 5e3 + 5;   const double eps = 1e-9;   using namespace std;   bool vis[MAXN];   int a[MAXN * 20], L[MAXN], R[MAXN], mx[MAXN];   double dp[MAXN][MAXN], P[MAXN], tmp2[MAXN];   set<int> ind;   int main() {     int n, q;     scanf( %d , &(n)), scanf( %d , &(q));     for (int i = 0; i < n; i++) ind.insert(i);     for (int i = 0; i < (n); i++) scanf( %d , &(a[i]));     for (int i = 0; i < q; i++) {       scanf( %d %d %lf , L + i, R + i, P + i);       L[i]--, R[i]--;       for (int j = 0; j < i; j++)         if (R[j] - L[j] > R[i] - L[i])           swap(L[i], L[j]), swap(R[i], R[j]), swap(P[i], P[j]);     }     L[q] = 0, R[q] = n - 1, P[q] = 0, q++;     for (int i = 0; i < q; i++) {       vector<int> tmp;       for (int j = 0; j < i; j++)         if (L[i] <= L[j] && R[j] <= R[i] && !vis[j]) {           vis[j] = 1;           tmp.push_back(j);           mx[i] = max(mx[i], mx[j]);         }       while (1) {         set<int>::iterator it = ind.lower_bound(L[i]);         if (it != ind.end() && *it <= R[i])           mx[i] = max(mx[i], a[*it]), ind.erase(it);         else           break;       }       for (int j = 0; j <= q; j++) tmp2[j] = 1;       for (int x = 0; x < tmp.size(); x++) {         int j = tmp[x];         for (int k = 0; k <= q; k++)           if (mx[i] + k - mx[j] <= q) tmp2[k] *= dp[j][mx[i] + k - mx[j]];       }       for (int j = q; j > 0; j--) tmp2[j] -= tmp2[j - 1];       dp[i][0] = (1 - P[i]) * tmp2[0];       for (int j = 1; j <= q; j++)         dp[i][j] = dp[i][j - 1] + P[i] * tmp2[j - 1] + (1 - P[i]) * tmp2[j];     }     double ans = dp[q - 1][0] * mx[q - 1];     for (int i = 1; i <= q; i++)       ans += (dp[q - 1][i] - dp[q - 1][i - 1]) * (mx[q - 1] + i);     printf( %.15f n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int num = sqrt(n);     if (num * num == n) {       for (int i = n - num + 1; i >= 1; i -= num) {         for (int j = 0; j < num; j++) {           printf( %d  , i + j);         }       }       printf(  n );       return 0;     } else {       int index1 = n / num;       int index2 = n % num;       for (int i = index1 * num + 1; i <= n; i++) printf( %d  , i);       for (int i = n - index2 - num + 1; i >= 1; i -= num) {         for (int j = 0; j < num; j++) printf( %d  , i + j);       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n;     cin >> n;     vector<pair<int, int>> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i].first;     }     for (int i = 0; i < n; i++) {       cin >> a[i].second;     }     sort(a.begin(), a.end());     a.push_back(make_pair(static_cast<int>(2e9), 0));     n++;     multiset<int> s;     int recent = 0;     long long ans = 0LL, sum = 0LL;     for (int i = 0; i < n; i++) {       while (a[i].first > recent && s.size()) {         recent++;         auto it = prev(s.end());         sum -= *it;         ans += sum;         s.erase(it);       }       recent = a[i].first;       sum += a[i].second;       s.insert(a[i].second);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       int k;       int a[n];       for (k = 0; k < n; k++) scanf( %d , &a[k]);       int p = n - 2;       int i, j;       for (i = 0; i < p; i++) {         for (j = i + 2; j < n; j++) {           if (a[i] == a[j]) {             printf( YES n );             break;           }         }         if (a[i] == a[j]) {           break;         }       }       if (a[i] == a[j]) continue;       printf( NO n );     }     return 0;   }