malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, a, b, i, j, ans = 999999;     cin >> n >> m >> i >> j >> a >> b;     if ((i == 1 && j == 1) || (i == 1 && j == m) || (i == n && j == 1) ||         (i == n && j == m))       ans = 0;     else if ((a + i <= n || i - a >= 1) && (j - b >= 1 || b + j <= m)) {       if ((j - 1) % b == 0) {         if ((i - 1) % a == 0) {           if (abs((j - 1) / b - (i - 1) / a) % 2 == 0)             ans = min(ans, max((j - 1) / b, (i - 1) / a));         }         if ((n - i) % a == 0) {           if (abs((j - 1) / b - (n - i) / a) % 2 == 0)             ans = min(ans, max((j - 1) / b, (n - i) / a));         }       }       if ((m - j) % b == 0) {         if ((i - 1) % a == 0) {           if (abs((m - j) / b - (i - 1) / a) % 2 == 0)             ans = min(ans, max((m - j) / b, (i - 1) / a));         }         if ((n - i) % a == 0) {           if (abs((m - j) / b - (n - i) / a) % 2 == 0)             ans = min(ans, max((m - j) / b, (n - i) / a));         }       }     }     if (ans != 999999)       cout << ans << endl;     else       cout <<  Poor Inna and pony!  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100086;   int z[maxn], n, m, num, order[maxn][2], last[maxn], ans[maxn], len, in[maxn];   bool flag, ok[maxn];   char s[2];   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %s , s);       scanf( %d , &num);       if (s[0] ==  - ) {         if (z[num] == 0) z[num] = -1;         order[i][0] = -1;         order[i][1] = num;       } else {         if (z[num] == 0) z[num] = 1;         order[i][0] = 1;         order[i][1] = num;       }     }     num = 0;     for (int i = 1; i <= n; i++) {       if (z[i] == 0)         ans[++len] = i;       else {         if (z[i] == -1) {           in[i] = 1;           num++;         }         ok[i] = 1;       }     }     for (int i = 1; i <= m; i++) {       if (order[i][0] == -1) {         num--;         in[order[i][1]] = 0;         if (num) ok[order[i][1]] = 0;         last[order[i][1]] = i;         if ((i != m) && (order[i + 1][1] != order[i][1])) ok[order[i][1]] = 0;       } else {         in[order[i][1]] = 1;         if (num) ok[order[i][1]] = 0;         if (last[order[i][1]] != i - 1) ok[order[i][1]] = 0;         num++;         last[order[i][1]] = i;       }     }     for (int i = 1; i <= n; i++)       if (ok[i]) ans[++len] = i;     sort(ans + 1, ans + 1 + len);     printf( %d n , len);     if (len) {       for (int i = 1; i < len; i++) printf( %d  , ans[i]);       printf( %d , ans[len]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> g[1002];   bool vis[1002];   bool my[1002], chen[1002];   int dfs(int n) {     if (my[n] == 1) return n;     vis[n] = 1;     for (int i = 0; i < g[n].size(); i++) {       int v = g[n][i];       if (!vis[v]) {         int ans = dfs(v);         if (ans != -1) return ans;       }     }     return -1;   }   void make() {     memset((vis), 0, sizeof(vis));     memset((my), 0, sizeof(my));     memset((chen), 0, sizeof(chen));     for (int i = 0; i < 1002; i++) g[i].clear();   }   int main() {     int t, i, j;     cin >> t;     while (t--) {       make();       int n, k1, k2;       cin >> n;       for (i = 0; i < n - 1; i++) {         int u, v;         cin >> u >> v;         g[u].push_back(v);         g[v].push_back(u);       }       cin >> k1;       for (i = 0; i < k1; i++) {         int u;         cin >> u;         my[u] = 1;       }       cin >> k2;       for (i = 0; i < k2; i++) {         int u;         cin >> u;         chen[u] = 1;       }       int q;       for (i = 1; i <= n; i++)         if (chen[i] == 1) break;       cout <<  B   << i << endl;       cout.flush();       cin >> q;       if (my[q] == 1) {         cout <<  C   << q << endl;         cout.flush();         continue;       }       int ans = dfs(q);       cout <<  A   << ans << endl;       cout.flush();       cin >> q;       if (chen[q] == 1) {         cout <<  C   << ans << endl;         cout.flush();       } else {         cout <<  C   << -1 << endl;         cout.flush();       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int sasha_chiz, masha_chiz, coconut_price, sasha_buy_co,         masha_buy_co, sum_buy_co, given_chiz = 0;     cin >> sasha_chiz >> masha_chiz >> coconut_price;     sasha_buy_co = sasha_chiz / coconut_price;     masha_buy_co = masha_chiz / coconut_price;     if (sasha_chiz % coconut_price != 0 && masha_chiz % coconut_price != 0) {       sasha_chiz = sasha_chiz % coconut_price;       masha_chiz = masha_chiz % coconut_price;       if (sasha_chiz + masha_chiz >= coconut_price) {         if (sasha_chiz >= masha_chiz) {           given_chiz = coconut_price - sasha_chiz;           sasha_buy_co = sasha_buy_co + 1;         } else {           given_chiz = coconut_price - masha_chiz;           masha_buy_co = masha_buy_co + 1;         }       }     }     sum_buy_co = sasha_buy_co + masha_buy_co;     cout << sum_buy_co <<     << given_chiz;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   string s;   long long nb, nc, ns, push_back, pc, ps, money, cntb, cntc, cnts, l, r, mid, mb,       ms, mc;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin >> s >> nb >> ns >> nc >> push_back >> ps >> pc >> money;     for (size_t i = 0; i < s.length(); i++) {       if (s[i] ==  B )         cntb++;       else if (s[i] ==  S )         cnts++;       else         cntc++;     }     l = 0;     r = 1e14;     while (l <= r) {       mid = (l + r) / 2;       mb = max(0ll, (cntb * mid - nb) * push_back);       ms = max(0ll, (cnts * mid - ns) * ps);       mc = max(0ll, (cntc * mid - nc) * pc);       if (mc + mb + ms <= money)         l = mid + 1;       else         r = mid - 1;     }     cout << r;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100005];   int main() {     int i, n;     cin >> n;     for (i = 1; i <= n - 1; i++) cin >> a[i];     sort(a + 1, a + n);     for (i = 1; i <= n; i++)       if (a[i] != i) break;     cout << i << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = int(1e6) + 50, P = int(1e9) + 7;   long long fac_NESC[N], rev[N], pow_NESC[N], revfac[N], w;   int k;   inline void inc(long long &x, long long y) { x = (x + y) % P; }   inline long long M(long long x, long long y) { return x * y % P; }   inline long long S(long long x) { return x * x % P; }   inline long long fpow(long long x, long long y) {     long long r(1);     for (; y; y >>= 1, x = M(x, x))       if (y & 1) r = M(r, x);     return r;   }   int main() {     ios::sync_with_stdio(false);     cin >> k >> w;     rev[1] = 1;     for (int i = 2; i <= k; ++i) rev[i] = ((-rev[P % i] * (P / i)) % P + P) % P;     fac_NESC[0] = 1;     for (int i = 1; i <= k; ++i) fac_NESC[i] = M(fac_NESC[i - 1], i);     pow_NESC[0] = fpow(k, w);     for (int i = 1; i <= k + 20; ++i) pow_NESC[i] = M(pow_NESC[i - 1], rev[k]);     revfac[0] = 1;     for (int i = 1; i <= k; ++i) revfac[i] = M(revfac[i - 1], rev[i]);     long long res(0);     for (int t = 1; t <= k; ++t) {       if (t <= w - 1)         inc(res, M(M(M(t, S(fac_NESC[k])), pow_NESC[t + 1]), S(revfac[k - t])));       if (t > w - 1)         inc(res,             M(M(M(fac_NESC[k], w), fac_NESC[k - t + w - 1]), S(revfac[k - t])));       if (t + 1 <= w - 1)         inc(res, M(M(M(t, S(fac_NESC[k])), pow_NESC[t + 2]),                    M(revfac[k - t], revfac[k - t - 1])));       if (t + 1 > w - 1)         inc(res, M(M(M(fac_NESC[k], w - 1), fac_NESC[k - t + w - 2]),                    M(revfac[k - t], revfac[k - t - 1])));     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0;     bool flg = false;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) flg = true;     for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48);     return flg ? -x : x;   }   int n;   struct P {     long long x, y;   } p[100010];   P operator-(const P &x, const P &y) { return P{x.x - y.x, x.y - y.y}; }   long long cross(const P &x, const P &y) { return x.x * y.y - x.y * y.x; }   long long dot(const P &x, const P &y) { return x.x * y.x + x.y * y.y; }   long long dot(const P &x) { return x.x * x.x + x.y * x.y; }   bool solve() {     n = read();     for (int i(1), _i(n); i <= _i; i++) {       int x = read(), y = read();       p[i] = P{x, y};     }     p[n + 1] = p[1];     if (n & 1) return 0;     int m = n >> 1;     for (int i(1), _i(m); i <= _i; i++) {       if (cross(p[i + m + 1] - p[i + m], p[i + 1] - p[i])) return 0;       if (dot(p[i + m + 1] - p[i + m], p[i + 1] - p[i]) >= 0) return 0;       if (dot(p[i + m + 1] - p[i + m]) != dot(p[i + 1] - p[i])) return 0;     }     return 1;   }   int main() {     for (int T = 1; T--;) puts(solve() ?  yes  :  no );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   string s;   int pre[N], nxt0[N], now = 100002;   int ans[N];   int n;   void init() {     vector<int> v;     for (int i = n - 1; i >= 1; i--) {       int p = s[i] -  0 ;       int pos = upper_bound(v.begin(), v.end(), -p) - v.begin();       if (pos == v.size()) {         v.push_back(-p);       } else {         v[pos] = -p;       }       ans[i] = v.size();     }   }   int main() {     ios::sync_with_stdio(false);     cin >> s;     s =  *  + s;     n = s.length();     init();     for (int i = 1; i < n; i++) pre[i] = pre[i - 1] + (s[i] ==  1 );     for (int i = n - 1; i >= 1; i--) {       nxt0[i] = now;       if (s[i] ==  0 ) now = i;     }     for (int i = 1; i <= n; i++) {       if (s[i] ==  0 ) continue;       if (s[i - 1] ==  1 ) continue;       int zuo1 = pre[i - 1], you1 = pre[n - 1] - pre[i],           you0 = (n - 1 - i) - you1;       int youmx = ans[nxt0[i]];       if (youmx <= you1) {         s[i] =  0 ;       }     }     for (int i = 1; i < n; i++) cout << s[i];   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int mod = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a(n);       for (int &elem : a) cin >> elem;       vector<vector<int>> dp(n, vector<int>(2, -1));       function<int(int, int)> solve = [&](int idx, int turn) -> int {         if (idx >= n) {           return 0;         }         if (dp[idx][turn] != -1) return dp[idx][turn];         int ans = INT_MAX;         if (turn == 1) {           if (a[idx] == 1) {             ans = min(ans, 1 + solve(idx + 1, 0));             if (idx + 1 < n && a[idx + 1] == 1) {               ans = min(ans, 2 + solve(idx + 2, 0));             } else {               ans = min(ans, 1 + solve(idx + 2, 0));             }           } else {             ans = min(ans, solve(idx + 1, 0));             if (idx + 1 < n)               ans = min(ans, (a[idx + 1] == 1) + solve(idx + 2, 0));           }         } else {           ans = min(ans, solve(idx + 1, 1));           ans = min(ans, solve(idx + 2, 1));         }         return dp[idx][turn] = ans;       };       cout << solve(0, 1) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, cnt11 = 0, cnt10 = 0, cnt01 = 0;     string s, t;     cin >> n >> s >> t;     for (int i = 0; i < 2 * n; ++i) {       if (s[i] ==  1  && t[i] ==  1 )         ++cnt11;       else if (s[i] ==  1 )         ++cnt10;       else if (t[i] ==  1 )         ++cnt01;     }     if (cnt11 & 1) {       if (cnt10 >= cnt01)         puts( First );       else if (cnt10 + 1 == cnt01 || cnt10 + 2 == cnt01)         puts( Draw );       else         puts( Second );     } else {       if (cnt10 == cnt01 || cnt10 + 1 == cnt01)         puts( Draw );       else if (cnt01 < cnt10)         puts( First );       else         puts( Second );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int n1, n2, n3;   int c[510];   int sc[510];   int pai[100010];   int type[100010];   int peso[100010];   int dp[510][510];   vector<pair<pair<int, int>, int> > edges;   int find(int i) { return pai[i] = (pai[i] == i) ? i : find(pai[i]); }   void join(int i, int j) {     i = find(i);     j = find(j);     if (i == j) return;     if (peso[i] < peso[j]) swap(i, j);     pai[j] = i;     if (peso[i] == peso[j]) peso[i]++;   }   void init() {     for (int g = 1; g <= n; g++) {       pai[g] = g;       peso[g] = 0;     }   }   int main() {     scanf( %d %d %d , &n, &m, &k);     init();     for (int g = 1; g <= k; g++) {       scanf( %d , &c[g]);       sc[g] = sc[g - 1] + c[g];     }     for (int g = 0; g < m; g++) {       scanf( %d %d %d , &n1, &n2, &n3);       edges.push_back(make_pair(make_pair(n1, n2), n3));       if (n3 == 0) join(n1, n2);     }     for (int g = 1; g <= k; g++)       for (int h = sc[g - 1] + 1; h <= sc[g]; h++) type[h] = g;     bool error = false;     for (int g = 1; g < n; g++)       if (type[g] == type[g + 1] && find(g) != find(g + 1)) error = true;     if (error) {       printf( No n );       return 0;     }     printf( Yes n );     for (int g = 1; g <= k; g++)       for (int h = 1; h <= k; h++) dp[g][h] = 1000000010;     for (int g = 1; g <= k; g++) dp[g][g] = 0;     for (int g = 0; g < m; g++) {       int i = edges[g].first.first;       int j = edges[g].first.second;       int w = edges[g].second;       i = type[i];       j = type[j];       if (i != j) dp[i][j] = dp[j][i] = min(dp[i][j], w);     }     for (int p = 1; p <= k; p++)       for (int q = 1; q <= k; q++)         for (int r = 1; r <= k; r++)           dp[q][r] = min(dp[q][r], dp[q][p] + dp[p][r]);     for (int q = 1; q <= k; q++) {       for (int p = 1; p <= k; p++)         printf( %d  , (dp[p][q] == 1000000010) ? -1 : dp[p][q]);       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   int sum, i, j, a[5][5], n, b[20];   int check() {     int res = 0;     int i, j, nowsum;     for (i = 0; i < n; i++)       for (j = 0; j < n; j++) {         a[i][j] = b[i * n + j];       }     for (i = 0; i < n; i++) {       nowsum = 0;       for (j = 0; j < n; j++) nowsum += a[i][j];       res += abs(sum - nowsum);     }     for (j = 0; j < n; j++) {       nowsum = 0;       for (i = 0; i < n; i++) nowsum += a[i][j];       res += abs(sum - nowsum);     }     nowsum = 0;     for (i = 0; i < n; i++) nowsum += a[i][i];     res += abs(nowsum - sum);     nowsum = 0;     for (i = 0; i < n; i++) nowsum += a[i][n - i - 1];     res += abs(nowsum - sum);     return res;   }   int main() {     srand((unsigned)time(NULL));     cin >> n;     for (i = 0; i < n * n; i++) {       cin >> b[i];       sum += b[i];     }     sum /= n;     int q, p, i, j;     q = check();     while (q) {       random_shuffle(b, b + n * n);       q = check();       for (int iter = 0; iter < 1000; iter++) {         i = (rand() * 257) % (n * n);         j = (rand() * 37) % (n * n);         while (j == i) {           j = (rand() * 37) % (n * n);         }         if (i > j) swap(i, j);         swap(b[i], b[j]);         p = check();         if (p < q) {           q = p;         } else {           swap(b[i], b[j]);         }       }       q = check();     }     cout << sum << endl;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) cout << a[i][j] <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = int(3002), mod = int(1e9) + 7;   char second[N][N];   int n, m;   long long dp1[N][N], dp2[N][N], a, b, c, d;   bool used[N][N];   inline long long dp(int x, int y) {     if (x <= 0 || y <= 0) return 0;     if (second[x][y] ==  # ) return 0;     if (x == 1 && y == 2) return 1;     if (used[x][y]) return dp1[x][y];     used[x][y] = 1;     return dp1[x][y] = (dp(x - 1, y) + dp(x, y - 1)) % mod;   }   inline long long rec(int x, int y) {     if (x <= 0 || y <= 0) return 0;     if (second[x][y] ==  # ) return 0;     if (x == 2 && y == 1) return 1;     if (used[x][y]) return dp2[x][y];     used[x][y] = 1;     return dp2[x][y] = (rec(x - 1, y) + rec(x, y - 1)) % mod;   }   int main() {     scanf( %d%d n , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %s n , second[i] + 1);     }     a = rec(n, m - 1), c = rec(n - 1, m);     memset(used, 0, sizeof(used));     b = dp(n - 1, m), d = dp(n, m - 1);     a = a * b % mod;     c = c * d % mod;     a = (a - c) % mod;     if (a < 0) a += mod;     printf( %d , a);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1200005;   const int OO = 0x3f3f3f3;   int vis[maxn];   vector<int> p;   int N = 1200000;   void find_prime() {     p.clear();     memset(vis, 0, sizeof(vis));     for (int i = 2; i <= N; i++)       if (!vis[i])         for (int j = i * 2; j <= N; j += i) vis[j] = 1;     for (int i = 2; i <= N; i++)       if (!vis[i]) p.push_back(i);   }   vector<int> palin;   void find_palin() {     palin.clear();     for (int i = 1; i <= 9; i++) {       palin.push_back(i);       palin.push_back(i * 11);     }     for (int i = 1; i <= 9; i++)       for (int j = 0; j <= 9; j++) {         palin.push_back(i * 101 + j * 10);         palin.push_back(i * 1001 + j * 110);       }     for (int i = 1; i <= 9; i++)       for (int j = 0; j <= 9; j++)         for (int k = 0; k <= 9; k++) {           palin.push_back(i * 10001 + j * 1010 + k * 100);           palin.push_back(i * 100001 + j * 10010 + k * 1100);         }     for (int i = 0; i <= 1; i++)       for (int j = 0; j <= 9; j++)         for (int k = 0; k <= 9; k++) {           palin.push_back(1000001 + i * 100010 + j * 10100 + k * 1000);         }     sort(palin.begin(), palin.end());   }   int cnt_prime[maxn], cnt_palin[maxn];   int main() {     find_prime();     find_palin();     memset(cnt_palin, 0, sizeof(cnt_palin));     memset(cnt_prime, 0, sizeof(cnt_prime));     for (int i = 2; i <= N; i++) cnt_prime[i] = cnt_prime[i - 1] + 1 - vis[i];     memset(vis, 0, sizeof(vis));     for (int i = 0; i < palin.size(); i++) vis[palin[i]] = 1;     for (int i = 1; i <= N; i++) cnt_palin[i] = cnt_palin[i - 1] + vis[i];     int sz = palin.size();     int ans = -1;     int x, y;     scanf( %d%d , &x, &y);     for (int i = sz - 1; i >= 0; i--)       if (cnt_prime[palin[i]] * y <= cnt_palin[palin[i]] * x) {         ans = palin[i];         break;       }     sz = p.size();     for (int i = sz - 1; i >= 0; i--)       if (cnt_prime[p[i] - 1] * y <= cnt_palin[p[i] - 1] * x) {         if (p[i] - 1 > ans) ans = p[i] - 1;         break;       }     if (ans == -1)       printf( Palindromic tree is better than splay tree n );     else       printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, i, j;     while (~scanf( %d%d , &n, &k)) {       if (n <= 2 * k) {         printf( -1 n );         continue;       } else {         printf( %d n , n * k);         for (i = 1; i <= n; i++) {           for (j = 1; j <= k; j++) {             if (i == n)               printf( %d %d n , i, j);             else if (i + j > n)               printf( %d %d n , i, i + j - n);             else               printf( %d %d n , i, i + j);           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, flag = 0;     vector<int> A, B;     map<int, int> store;     store.clear();     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a);       if (store[a] < 2) {         if (store[a] == 0) {           A.push_back(a);           store[a] = 1;         } else {           flag = 1;           B.push_back(a);           store[a] = 2;         }       }     }     sort(A.begin(), A.end());     sort(B.begin(), B.end());     reverse(B.begin(), B.end());     int ans = A.size() + B.size();     if (flag)       if (A[A.size() - 1] == B[0]) ans--;     cout << ans << endl;     for (int i = 0; i < A.size(); i++) {       cout << A[i] <<    ;     }     for (int i = 0; i < B.size(); i++) {       if (i == 0 && B[i] == A[A.size() - 1]) continue;       cout << B[i] <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 2;   int n, a[N];   long long pref[N];   int get(int pos) {     int lo = 0, hi = min(pos - 1, n - pos);     while (hi - lo > 3) {       int m1 = (lo + lo + hi) / 3;       int m2 = (lo + hi + hi) / 3;       long double r1 = (pref[pos] - pref[pos - m1 - 1] + pref[n] - pref[n - m1]) /                        double(m1 * 2 + 1);       long double r2 = (pref[pos] - pref[pos - m2 - 1] + pref[n] - pref[n - m2]) /                        double(m2 * 2 + 1);       r1 -= a[pos];       r2 -= a[pos];       if (r1 < r2)         lo = m1;       else         hi = m2;     }     int ret = lo;     for (int i = lo; i <= hi; i++) {       long double r1 =           (pref[pos] - pref[pos - ret - 1] + (pref[n] - pref[n - ret])) /           double(ret * 2 + 1);       long double r2 = (pref[pos] - pref[pos - i - 1] + (pref[n] - pref[n - i])) /                        double(i * 2 + 1);       r1 -= a[pos];       r2 -= a[pos];       if (r1 < r2) ret = i;     }     return ret;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) {       pref[i] = pref[i - 1] + a[i];     }     long double mx = 0;     pair<int, int> p = {1, 0};     for (int i = 1; i <= n; i++) {       int best = get(i);       long double ret =           (pref[i] - pref[i - best - 1] + (pref[n] - pref[n - best])) /           double(best * 2 + 1);       ret -= a[i];       if (mx <= ret) {         mx = ret;         p = {i, best};       }     }     vector<int> ans;     for (int i = p.first; i >= (p.first - p.second); i--) ans.push_back(a[i]);     for (int i = n; i > (n - p.second); i--) ans.push_back(a[i]);     sort(ans.begin(), ans.end());     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<pair<long long, long long>>> adj;   vector<long long> d;   long long n;   vector<bool> mark;   vector<long long> trains;   void dijktras(long long s) {     d[s] = 0;     priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,                    greater<pair<long long, long long>>>         pq;     pq.push({0, s});     for (long long i = 2; i <= n; i++) {       if (trains[i] != INT_MAX) pq.push({trains[i], i});     }     while (!pq.empty()) {       long long v = pq.top().second;       long long d_v = pq.top().first;       pq.pop();       if (d_v != d[v]) continue;       for (auto edge : adj[v]) {         long long to = edge.first;         long long len = edge.second;         if (d[to] > d[v] + len) {           d[to] = d[v] + len;           pq.push({d[to], to});         } else if (d[to] == d[v] + len) {           if (d[to] == trains[to]) mark[to] = true;         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long m, k;     cin >> n >> m >> k;     adj.resize(n + 1);     d.assign(n + 1, INT_MAX);     mark.assign(n + 1, false);     while (m--) {       long long u, v, w;       cin >> u >> v >> w;       adj[u].push_back({v, w});       adj[v].push_back({u, w});     }     long long ans = 0;     trains.assign(n + 1, INT_MAX);     while (k--) {       long long s, y;       cin >> s >> y;       if (d[s] == INT_MAX) {         d[s] = y;         trains[s] = y;       } else {         ans++;         trains[s] = min(trains[s], y);         d[s] = min(d[s], y);       }     }     dijktras(1);     for (int i = 2; i <= n; i++)       if (d[i] < trains[i] && trains[i] != INT_MAX) {         mark[i] = true;       }     for (int i = 2; i <= n; i++)       if (mark[i]) ans++;     cout << ans <<   n ;     cout <<   n ;     return 0;   }