malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000010;   long long a[maxn], s1, s2;   double ans[maxn];   int l[maxn], r[maxn];   vector<int> gao[6][maxn];   int n, m, pos;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]);     l[1] = 1;     for (int i = 2; i <= n; i++) {       l[i] = i;       while (l[i] != 1 && a[l[i] - 1] > a[i]) l[i] = l[l[i] - 1];     }     r[n] = n;     for (int i = n - 1; i >= 1; i--) {       r[i] = i;       while (r[i] != n && a[r[i] + 1] >= a[i]) r[i] = r[r[i] + 1];     }     for (int i = 1; i <= n; i++) {       int a1 = r[i] + 1 - i;       int a2 = i + 1 - l[i];       if (a1 <= a2) {         gao[0][a1].push_back(i);         gao[1][a2 + 1].push_back(i);         gao[2][r[i] - l[i] + 3].push_back(i);       } else {         gao[3][a2].push_back(i);         gao[4][a1 + 1].push_back(i);         gao[5][r[i] - l[i] + 3].push_back(i);       }     }     for (int i = 1; i <= n; i++) s1 += a[i];     for (int L = 1; L <= n; L++) {       for (int i = 0, sz = gao[0][L].size(); i < sz; i++) {         pos = gao[0][L][i];         s1 -= a[pos];         s2 += (r[pos] - pos + 1LL) * a[pos];       }       for (int i = 0, sz = gao[1][L].size(); i < sz; i++) {         pos = gao[1][L][i];         s2 += (pos - l[pos] + 1LL) * a[pos];         s1 -= a[pos];       }       for (int i = 0, sz = gao[2][L].size(); i < sz; i++) {         pos = gao[2][L][i];         s2 -= (r[pos] - l[pos] + 2LL) * a[pos];         s1 += a[pos];       }       for (int i = 0, sz = gao[3][L].size(); i < sz; i++) {         pos = gao[3][L][i];         s1 -= a[pos];         s2 += (pos - l[pos] + 1LL) * a[pos];       }       for (int i = 0, sz = gao[4][L].size(); i < sz; i++) {         pos = gao[4][L][i];         s2 += (r[pos] - pos + 1LL) * a[pos];         s1 -= a[pos];       }       for (int i = 0, sz = gao[5][L].size(); i < sz; i++) {         pos = gao[5][L][i];         s2 -= (r[pos] - l[pos] + 2LL) * a[pos];         s1 += a[pos];       }       long long temp = s1 * L + s2;       ans[L] = 1.0 * temp / (n - L + 1);     }     scanf( %d , &m);     while (m--) {       int k;       scanf( %d , &k);       printf( %.10f n , ans[k]);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     char arr[105];     scanf( %d%*c , &t);     while (t--) {       gets(arr);       int len = strlen(arr);       char temp[20] = {arr[len - 5], arr[len - 4], arr[len - 3], arr[len - 2],                        arr[len - 1]};       char tem[20] = {arr[0], arr[1], arr[2], arr[3], arr[4]};       if (strcmp(temp,  lala. ) == 0 && strcmp(tem,  miao. ) == 0)         printf( OMG>.< I don t know! n );       else if (strcmp(temp,  lala. ) == 0)         printf( Freda s n );       else if (strcmp(tem,  miao. ) == 0)         printf( Rainbow s n );       else         printf( OMG>.< I don t know! n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, a, pertama, kedua, sum;   vector<pair<long long, int> > v;   priority_queue<pair<long long, int>, vector<pair<long long, int> >,                  greater<pair<long long, int> > >       pq;   bool cmp(pair<int, int> a, pair<int, int> b) {     if (a.second == b.second) return a.first < b.first;     return a.second < b.second;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a;       pq.push(make_pair(a, i));     }     while (!pq.empty()) {       pertama = pq.top().first;       kedua = pq.top().second;       pq.pop();       if (pertama == pq.top().first) {         pq.push(make_pair(2 * pertama, pq.top().second));         pq.pop();       } else {         v.push_back(make_pair(pertama, kedua));       }       if (pq.empty()) v.push_back(make_pair(pertama, kedua));     }     sort(v.begin(), v.end(), cmp);     sum = v.size();     cout << sum << endl;     for (int i = 0; i < sum; i++) {       if (i != 0) cout <<    ;       cout << v[i].first;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> prime_pair;   int least[1001];   void sieve(int n) {     vector<int> pr, prime;     for (int i = 2; i <= n; i++) {       if (!least[i]) {         least[i] = i;         pr.push_back(i);       }       for (int j = 0; j < pr.size() && pr[j] <= least[i] && i * pr[j] <= n; j++) {         least[i * pr[j]] = pr[j];       }     }     for (int i = 2; i <= n; i++)       if (least[i] == i) prime.push_back(i);     for (int i = 1; i < prime.size(); i++) {       int temp = prime[i] + prime[i - 1];       prime_pair.push_back(temp);     }   }   bool bi_search(int val) {     int left = 0, right = prime_pair.size() - 1;     while (right >= left) {       int mid = (left + right) / 2;       if (prime_pair[mid] == val) return true;       if (prime_pair[mid] > val)         right = mid - 1;       else         left = mid + 1;     }     return false;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, k;     cin >> n >> k;     sieve(n);     int res = 0;     for (int i = 13; i <= n; i++) {       if (least[i] == i && bi_search(i - 1)) {         res++;       }     }     if (res >= k)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, q, ar[200000], ans[200000];   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> ar[i];     for (int i = 0; i < n - 1; i++) {       q = 1;       while (i + q * 2 < n) q *= 2;       ar[i + q] += ar[i];       if (i) ans[i] = ans[i - 1];       ans[i] += ar[i];       ar[i] = 0;     }     for (int i = 0; i < n - 1; i++) cout << ans[i] << endl;     cin.get();     cin.get();     return 0;   }
#include <bits/stdc++.h>   int main() {     static int aa[200000], pp[200000], qq[200000];     int n, k, i, p, q;     long long x, xk, ans, a;     scanf( %d%d%lld , &n, &k, &x);     for (i = 0; i < n; i++) scanf( %d , &aa[i]);     for (i = 0, p = 0; i < n; i++) {       pp[i] = p;       p |= aa[i];     }     for (i = n - 1, q = 0; i >= 0; i--) {       qq[i] = q;       q |= aa[i];     }     xk = 1;     while (k--) xk *= x;     ans = 0;     for (i = 0; i < n; i++)       if (ans < (a = pp[i] | aa[i] * xk | qq[i])) ans = a;     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   double ans;   int cnt[200];   vector<int> v[200];   int main() {     cin >> s;     double n = s.size();     for (int i = 0; i < n; i++) v[s[i]].push_back(i);     for (char i =  a ; i <=  z ; i++) {       if (!v[i].empty()) {         int x = v[i][0];         int y = 0;         for (int k = 0; k < n; k++) {           memset(cnt, 0, sizeof cnt);           for (int j = 0; j < v[i].size(); j++) {             v[i][j]++;             v[i][j] %= (int)n;             cnt[s[v[i][j]]]++;           }           int cur = 0;           for (int j =  a ; j <=  z ; j++) cur += (cnt[j] == 1);           y = max(y, cur);         }         ans += y;       }     }     cout << fixed << setprecision(8) << (ans / n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int sz = 2e5;   int n, k;   long long add[sz], cost[sz], pre[sz], suf[sz], mnpre[sz], mnsuf[sz],       bestSufTake[sz], bestSufTakeFromPre[sz];   void input() {     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> add[i];     for (int i = 0; i < n; i++) cin >> cost[i];   }   void initPreSuf() {     for (int i = 0; i < n; i++) pre[i] = add[i] + (i ? pre[i - 1] : 0);     for (int i = n - 1; i >= 0; i--)       suf[i] = add[i] + (i != n - 1 ? suf[i + 1] : 0);     for (int i = 0; i < n; i++)       mnpre[i] = (i ? min(mnpre[i - 1], cost[i]) : cost[i]);     for (int i = n - 1; i >= 0; i--)       mnsuf[i] = (i != n - 1 ? min(mnsuf[i + 1], cost[i]) : cost[i]);     for (int i = n - 1; i >= 0; i--)       bestSufTake[i] = max(bestSufTake[i + 1], suf[i] - cost[i]);     for (int i = 0; i < n; i++) {       if (!i)         bestSufTakeFromPre[i] = suf[i] - cost[i];       else         bestSufTakeFromPre[i] = max(bestSufTakeFromPre[i - 1], suf[i] - cost[i]);     }   }   void solveZero() { cout << max(0LL, bestSufTake[0]) << endl; }   void solveEven() {     long long bst = max(0LL, bestSufTake[0]);     for (int i = 0; i < n - 1; i++) bst = max(bst, pre[n - 1] - cost[i]);     cout << bst << endl;   }   void solveOne() {     long long bst = max(0LL, bestSufTake[1]);     for (int i = 1; i < n - 1; i++)       bst = max(bst, pre[i] - mnpre[i] + bestSufTake[i + 1]);     for (int i = 1; i < n - 1; i++)       bst = max(bst, max(bestSufTakeFromPre[i - 1] - add[i], bestSufTake[i + 1]) +                          max(0LL, add[i] - cost[i]));     cout << bst << endl;   }   void solveOdd() {     long long bst = max(0LL, bestSufTake[1]);     long long best = add[0] - cost[0];     for (int i = n - 2; i >= 0; i--) {       if (i == 1) continue;       bst = max(bst, pre[n - 1] - cost[i]);     }     if (n == 4) {       bst = max(bst, pre[n - 1] - cost[1]);       bst = max(bst, pre[n - 1] - cost[0]);     } else {       bst = max(bst, pre[n - 1] - add[n - 1] - cost[1]);       for (int i = 0; i < n; i++) {         if (i == 1 || i == 2) continue;         bst = max(bst, pre[n - 1] - add[i] - cost[1]);       }     }     cout << bst << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     input();     initPreSuf();     if (k == 0)       solveZero();     else if (k == 1)       solveOne();     else if (k % 2 == 0)       solveEven();     else       solveOdd();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, i, x, y, lsum = 1, root, tot, Ans1, Ans2;   int head[400010], f[400010], size[400010], d[400010], p[400010], l[400010],       g[400010], o[400010];   vector<int> son[400010];   map<int, int> M;   struct Edge {     int t, next, l;   } e[400010 * 8];   inline int Find(int x) { return (x == p[x]) ? x : p[x] = Find(p[x]); }   inline void Add(int s, int t) {     e[lsum].t = t;     e[lsum].next = head[s];     head[s] = lsum++;   }   inline int Abs(int x) { return (x < 0) ? -x : x; }   inline void Swap(int &a, int &b) { a ^= b ^= a ^= b; }   inline int Min(int a, int b) { return (a < b) ? a : b; }   inline int Max(int a, int b) { return (a > b) ? a : b; }   inline int read() {     int p = 0, f = 1;     char c = getchar();     while (c < 48 || c > 57) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >= 48 && c <= 57) p = (p << 1) + (p << 3) + c - 48, c = getchar();     return p * f;   }   inline void Maketree(int x, int fa) {     int i = 0;     size[x] = 1;     for (i = head[x]; i; i = e[i].next) {       if (e[i].t == fa) continue;       f[e[i].t] = x;       son[x].push_back(e[i].t);       Maketree(e[i].t, x);       size[x] += size[e[i].t];     }   }   inline void Dfs(int x) {     if (!son[x].size()) {       o[p[x]] = 1;       return;     }     for (auto i : son[x]) {       Dfs(i);       g[p[x]] += o[p[i]];       o[p[x]] += g[p[i]];     }     if (g[p[x]] && o[p[x]]) Ans1 = 3;   }   int main() {     n = read();     for (i = 1; i < n; i++) {       x = read();       y = read();       Add(x, y);       Add(y, x);       d[x]++;       d[y]++;     }     for (i = 1; i <= n; i++)       if (d[i] > 1) {         root = i;         break;       }     Maketree(root, 0);     for (i = 1; i <= n; i++) p[i] = n + i;     for (i = 1; i <= n; i++)       if (!son[i].size()) p[i] = p[f[i]];     for (i = 1; i <= n; i++)       if (p[i] == n + i) p[i] = i;     for (i = 1; i <= n; i++)       if (!M[p[i]]) Ans2++, M[p[i]]++;     Ans1 = 1;     Dfs(root);     printf( %d %d n , Ans1, Ans2 - 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long n, l = 1, r;     cin >> n;     r = n;     if (n == 1) {       cout << 1 << endl << 1;       return 0;     }     if (n == 2) {       cout << 1 << endl << 1;       return 0;     }     if (n == 3) {       cout << 2 << endl << 1 <<     << 3;       return 0;     }     if (n == 4) {       cout << 4 << endl << 2 <<     << 4 <<     << 1 <<     << 3;       return 0;     }     if (n == 5) {       cout << 5 << endl << 1 <<     << 3 <<     << 5 <<     << 2 <<     << 4;       return 0;     }     vector<long long> a(n + 1);     long long f = 0;     for (long long i = 1; i <= n; i++) {       if (f) {         a[l] = i;         l++;       } else {         a[r] = i;         r--;       }       f += 1;       f %= 2;     }     for (long long i = 1; i < n; i++) {       if (abs(a[i] - a[i + 1]) == 1) {         swap(a[i + 1], a[n]);       }     }     cout << n <<   n ;     ;     for (long long i = 1; i <= n; i++) {       cout << a[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream& operator<<(ostream& os, vector<T> v) {     os <<  [ ;     string sep;     for (const T& el : v) os << sep << el, sep =  ,  ;     return os <<  ] ;   }   void dbg_out() { cerr << endl; }   template <typename Head, typename... Tail>   void dbg_out(Head H, Tail... T) {     cerr <<     << H;     dbg_out(T...);   }   int dsu_find(vector<int>& parents, int a) {     return (parents[a] == a) ? a : (parents[a] = dsu_find(parents, parents[a]));   }   bool dsu_union(vector<int>& parents, int a, int b) {     int pa = dsu_find(parents, a);     int pb = dsu_find(parents, b);     if (pa != pb) {       parents[pa] = pb;       return true;     }     return false;   }   void run() {     int m, n;     cin >> m >> n;     vector<long long> a(m + 1), b(n + 1);     for (int i = 1; i < m + 1; i++) cin >> a[i];     for (int j = 1; j < n + 1; j++) cin >> b[j];     auto cost = [&](int x, int y) -> long long {       int u = min(x, y), v = max(x, y);       return a[u] + b[v - m];     };     long long tot_cost = 0;     vector<pair<long long, pair<int, int> > > edgelist;     for (int i = 1; i < m + 1; i++) {       int s;       cin >> s;       for (int x = 0; x < s; x++) {         int j;         cin >> j;         edgelist.push_back(make_pair(a[i] + b[j], make_pair(i, m + j)));         tot_cost += (a[i] + b[j]);       }     }     sort(edgelist.begin(), edgelist.end(),          greater<pair<long long, pair<int, int> > >());     vector<int> parents(m + n + 1);     for (int i = 1; i < m + n + 1; i++) parents[i] = i;     long long mst_cost = 0;     for (pair<long long, pair<int, int> > e : edgelist) {       ;       if (dsu_find(parents, e.second.first) !=           dsu_find(parents, e.second.second)) {         mst_cost += e.first;         dsu_union(parents, e.second.first, e.second.second);         ;       }     }     cout << tot_cost - mst_cost <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     run();   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int mod = 998244353;   int sum(int a, int b) {     int s = a + b;     if (s >= mod) s -= mod;     return s;   }   int mult(int a, int b) { return (1LL * a * b) % mod; }   int pw(int a, int b) {     if (b == 0) return 1;     if (b & 1) return mult(a, pw(a, b - 1));     int res = pw(a, b / 2);     return mult(res, res);   }   int sub(int a, int b) {     int s = a - b;     if (s < 0) s += mod;     return s;   }   int n;   const int maxN = (int)1e6 + 100;   string s;   int invfact[maxN];   int fact[maxN];   int inv[maxN];   int cnk(int a, int b) {     if (a < b || b < 0) return 0;     return mult(fact[a], mult(invfact[b], invfact[a - b]));   }   int tp[maxN];   int cnt0[maxN], cnt1[maxN];   int c_pref[maxN];   int c_2[maxN];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     inv[1] = fact[0] = fact[1] = invfact[0] = invfact[1] = 1;     for (int i = 2; i < maxN; i++) {       fact[i] = mult(fact[i - 1], i);       inv[i] = mult(inv[mod % i], mod - mod / i);       invfact[i] = mult(invfact[i - 1], inv[i]);     }     cin >> s;     n = s.size();     int que = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  ( )         tp[i + 1] = 1;       else if (s[i] ==  ) )         tp[i + 1] = 0;       else         tp[i + 1] = 2;       que += tp[i + 1] == 2;     }     cnt1[0] = 0;     for (int i = 1; i <= n; i++) {       cnt1[i] = cnt1[i - 1] + (tp[i] == 1);     }     cnt0[n + 1] = 0;     for (int i = n; i >= 1; i--) {       cnt0[i] = cnt0[i + 1] + (tp[i] == 0);     }     c_pref[que + 1] = 0;     for (int i = que; i >= 0; i--) {       c_pref[i] = sum(c_pref[i + 1], cnk(que, i));     }     c_2[que] = 0;     for (int i = que - 1; i >= 0; i--) {       c_2[i] = sum(c_2[i + 1], cnk(que - 1, i));     }     int val = 0;     int que1 = 0;     for (int pref = 1; pref < n; pref++) {       if (tp[pref] == 0) continue;       if (tp[pref] == 1) {         int at_most = min(que + 1, que1 + 1 + cnt1[pref - 1] - cnt0[pref + 1]);         at_most = max(at_most, 0);         val = sum(val, c_pref[at_most]);         que1 += (tp[pref] == 2);       } else {         int at_most = min(que + 1, que1 + 1 + cnt1[pref - 1] - cnt0[pref + 1]);         at_most = max(at_most, 0);         val = sum(val, c_2[at_most]);         que1 += (tp[pref] == 2);       }     }     cout << val;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const static int inf = 10000000;   const static int mod = 1000000007;   int check(const vector<string>& s, const vector<string>& t) {     int n = s.size();     vector<int> idx(n);     for (int i = 0; i < (int)(n); i++) {       idx[i] = i;     }     int ret = 0;     do {       vector<string> ss(n);       for (int i = 0; i < (int)(n); i++) {         ss[i] = s[idx[i]];       }       int pos = 0;       for (int i = 0; i < t.size() && pos < s.size(); ++i) {         if (ss[pos] == t[i]) {           ++pos;         }       }       if (pos != s.size()) {         continue;       }       int inv = 0;       for (int i = 0; i < (int)(n); i++) {         for (int j = i + 1; j < n; ++j) {           if (idx[i] > idx[j]) {             ++inv;           }         }       }       int buf = n * (n - 1) / 2 - inv + 1;       ret = max(ret, buf);     } while (next_permutation((idx).begin(), (idx).end()));     return ret;   }   int main() {     int n;     while (cin >> n) {       vector<string> s(n);       for (int i = 0; i < (int)(n); i++) {         cin >> s[i];       }       int mxp = 0;       int idx = -1;       int k;       cin >> k;       for (int i = 0; i < (int)(k); i++) {         int m;         cin >> m;         vector<string> t(m);         for (int j = 0; j < (int)(m); j++) {           cin >> t[j];         }         int p = check(s, t);         if (p > mxp) {           mxp = p;           idx = i;         }       }       if (idx == -1) {         cout <<  Brand new problem!  << endl;       } else {         cout << idx + 1 << endl;         cout <<  [: ;         for (int i = 0; i < (int)(mxp); i++) {           cout <<  | ;         }         cout <<  :]  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   bool ask(int x, int y) {     if (x < 0 || y > n) return 0;     string s;     cout << 1 <<     << x <<     << y << endl;     cin >> s;     return s ==  TAK ;   }   int solve(int l, int r) {     if (l > r) return -1;     int mid;     while (l < r) {       mid = (l + r) >> 1;       if (ask(mid, mid + 1))         r = mid;       else         l = mid + 1;     }     return l;   }   int main() {     int i, j;     cin >> n >> k;     int ans1 = solve(1, n);     int ans2 = solve(1, ans1 - 1);     if (!ask(ans2, ans1)) ans2 = solve(ans1 + 1, n);     cout << 2 <<     << ans1 <<     << ans2 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200200;   const int INF = 1000000007;   struct Ramp {     int i, x, d, t, p;     bool operator<(int o) const { return x < o; }     bool operator<(const Ramp& o) const { return x < o.x; }   } r[MAXN], rr;   struct Edge {     int a, b, c, t;     Edge(int a, int b, int c, int t = -1) : a(a), b(b), c(c), t(t) {}   };   vector<Edge> e[MAXN];   int d[MAXN];   const Edge* pre[MAXN];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) {       r[i].i = i + 1;       scanf( %d%d%d%d , &r[i].x, &r[i].d, &r[i].t, &r[i].p);       r[n + i].i = -1;       r[n + i].x = r[i].x + r[i].d;     }     n += n;     r[n].x = 0;     r[n + 1].x = m;     r[n].i = r[n + 1].i = -1;     n += 2;     sort(r, r + n);     for (int i = 1; i < n; ++i) {       e[i - 1].push_back(Edge(i - 1, i, r[i].x - r[i - 1].x));       e[i].push_back(Edge(i, i - 1, r[i].x - r[i - 1].x));     }     for (int i = 0; i < n; ++i) {       if (r[i].i == -1 || r[i].x < r[i].p) {         continue;       }       rr.x = r[i].x - r[i].p;       int a = lower_bound(r, r + n, rr) - r;       rr.x = r[i].x + r[i].d;       int b = lower_bound(r, r + n, rr) - r;       for (int aa = a - 1; aa <= a; ++aa) {         for (int bb = b; bb <= b; ++bb) {           if (0 <= aa && aa < bb && bb < n) {             int cc = r[i].p + r[i].t;             cc += abs(r[i].x - r[i].p - r[aa].x);             cc += abs(r[i].x + r[i].d - r[bb].x);             e[aa].push_back(Edge(aa, bb, cc, r[i].i));           }         }       }     }     priority_queue<pair<int, int>, vector<pair<int, int> >,                    greater<pair<int, int> > >         q;     fill(d, d + n, INF);     fill(pre, pre + n, (Edge*)NULL);     d[0] = 0;     q.push({d[0], 0});     while (!q.empty()) {       int t = q.top().first;       int v = q.top().second;       q.pop();       if (d[v] != t) {         continue;       }       for (const Edge& w : e[v]) {         if (d[w.b] > t + w.c) {           d[w.b] = t + w.c;           q.push({d[w.b], w.b});           pre[w.b] = &w;         }       }     }     printf( %d n , d[n - 1]);     vector<int> ans;     for (int i = n - 1; i > 0; i = pre[i]->a) {       if (pre[i]->t != -1) {         ans.push_back(pre[i]->t);       }     }     reverse(ans.begin(), ans.end());     printf( %d n , (int)ans.size());     for (int i : ans) {       printf( %d  , i);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   set<string> st;   set<string>::iterator it;   vector<long long> v, vv;   int main() {     int n, a[100000], cnt = 0, cnt2 = 0, k;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] > 0)         cnt++;       else if (a[i] < 0)         cnt2++;     }     if (n % 2 == 0)       k = n / 2;     else       k = (n / 2) + 1;     if (cnt > cnt2) {       if (cnt >= k)         cout << 2 << endl;       else         cout << 0 << endl;     } else {       if (cnt2 >= k)         cout << -2 << endl;       else         cout << 0 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[12][12];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) scanf( %d , &a[i][j]);     for (int k = 1; k <= n; k++) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           a[i][j] = min(a[i][j], a[i][k] + a[k][j]);         }       }     }     int ans = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) ans = max(ans, a[i][j]);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int64_t ans;   int n, m, ve, ts[1000001], nn[1000001], t, cut[1000001], p[1000001],       vis[1000001], low[1000001];   vector<int> e[1000001];   void dfs(int i) {     low[i] = ts[i] = ++t;     vis[i] = 1;     for (auto&& x : e[i])       if (!vis[x]) {         p[x] = i;         dfs(x);         low[i] = min(low[i], low[x]);         if (low[x] > ts[i]) cut[x] = 1;       } else if (x != p[i])         low[i] = min(low[i], low[x]);   }   int main() {     scanf( %d%d , &n, &m);     if (m < 2) return puts( 0 ), 0;     for (int _ = 0; _ < m; ++_) {       int s, t;       scanf( %d%d , &s, &t);       if (s == t)         ++nn[s];       else         e[s].push_back(t), e[t].push_back(s);     }     for (int i = 1; i <= n; ++i)       if (e[i].size()) {         dfs(i);         break;       }     for (int i = 1; i <= n; ++i)       if ((nn[i] || e[i].size()) && !vis[i]) return puts( 0 ), 0;     int64_t slc = accumulate(nn, nn + n + 1, 0);     ans = slc * (slc - 1);     for (int i = 1; i <= n; ++i) {       int no = nn[i];       nn[i] = 0;       nn[i] = e[i].size();       ans += nn[i] * int64_t(nn[i] - 1);       ans += slc * nn[i];     }     cout << ans / 2;   }