malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   namespace WorkSpace {   const int max_num = 100010;   unsigned int F[max_num >> 1];   void Main() {     register int N;     scanf( %d , &N);     if (N & 1) {       printf( 0 n );       return;     }     static char S[max_num];     register int Half = N >> 1;     scanf( %s , S + 1);     F[0] = 1;     register int Num = 0;     for (register int i = 1; i <= N; ++i) {       if (S[i] ==  ? ) {         for (register int j = i >> 1; j && j >= i - Half; --j) F[j] += F[j - 1];       } else         ++Num;     }     register unsigned int ans = F[Half];     for (register int i = 0; i < Half - Num; ++i) ans *= 25;     printf( %u n , ans);   }   }  // namespace WorkSpace   int main() {     WorkSpace ::Main();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2 * 1e5 + 5;   int v[N];   int c[N];   bool viz[N];   bool check(int len, vector<int> v) {     int n = v.size();     for (int i = 0; i < len; i++) {       int p = (i + len) % n;       while (v[p] == v[(p + len) % n] && p != i) {         p = (p + len) % n;       }       if (p == i) return true;     }     return false;   }   int getscore(vector<int> v) {     int n = v.size();     for (int d = 1; d <= n; d++) {       if (n % d == 0) {         if (check(d, v)) {           return d;         }       }     }     return n;   }   void solve() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> v[i];     }     for (int i = 1; i <= n; i++) cin >> c[i];     int ans = N;     vector<int> sir;     for (int i = 1; i <= n; i++) {       if (viz[i] == false) {         sir.clear();         int p = i;         while (viz[p] == false) {           sir.push_back(c[p]);           viz[p] = true;           p = v[p];         }         ans = min(ans, getscore(sir));       }     }     cout << ans <<   n ;     for (int i = 1; i <= n; i++) {       viz[i] = false;     }   }   int main() {     int n;     cin >> n;     while (n--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void sol() {     long long int n, x;     cin >> n >> x;     if (n <= 2)       cout <<  1 n ;     else {       n = n - 2;       long long int ans = 1;       long long int z = n / x;       if (n - z * x > 0) z++;       ans += z;       cout << ans <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     cin >> t;     while (t--) {       sol();     }   }
#include <bits/stdc++.h>   using namespace std;   long long ans, n, k, m, v, l, r, asdfghjkl, qwertyui, zxcvbnm, oiuytre,       lkjgfdsa, mnbvcxz, x, y;   long long i, j, a[100002], b[100002], d[100002], l1, l2, r1, r2;   long long mn, xm, ym, mnd, mnv, pos;   long long s;   char c;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> a[0] >> a[1] >> a[2];     sort(a, a + 3);     if (a[2] == a[1] && a[1] == a[0]) return cout << 0, 0;     if (a[2] == a[1]) {       ans = a[2] - a[0] - 1;       cout << ans;       return 0;     }     ans = 2 * a[2] - a[1] - a[0] - 2;     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T sqr(const T& a) {     return a * a;   }   const long double EPS = 1e-9;   const long double PI = 2 * acos(0.0);   const int N = 100000;   int counts[N];   int xors[N];   vector<int> g[N];   queue<int> qq;   vector<pair<int, int> > ans;   inline void Add(int x, int y) {     ans.push_back({x, y});     g[x].push_back(y);     g[y].push_back(x);     if (int(g[x].size()) + 1 == counts[x]) qq.push(x);     if (int(g[y].size()) + 1 == counts[y]) qq.push(y);   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d%d , &counts[i], &xors[i]);       if (counts[i] == 1) qq.push(i);     }     while (!qq.empty()) {       int x = qq.front();       qq.pop();       assert(counts[x] >= int(g[x].size()));       if (counts[x] != 1 + int(g[x].size())) continue;       int s = 0;       for (int to : g[x]) {         s ^= to;       }       Add(x, xors[x] ^ s);     }     printf( %d n , int(ans.size()));     for (pair<int, int>& p : ans) printf( %d %d n , p.first, p.second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> flavors[300001];   vector<int> adj[300001];   int color[300001];   void dfs(int v, int p) {     set<int> colors;     for (auto f : flavors[v])       if (color[f] != -1) colors.insert(color[f]);     int first = 1;     for (auto f : flavors[v])       if (color[f] == -1) {         while (colors.find(first) != colors.end()) first++;         color[f] = first++;       }     for (auto w : adj[v])       if (w != p) dfs(w, v);   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     int ans = 0;     int start = 0;     for (int i = 0; i < n; i++) {       int s;       scanf( %d , &s);       if (ans < s) {         ans = s;         start = i;       }       for (int j = 0; j < s; j++) {         int tmp;         scanf( %d , &tmp);         flavors[i].push_back(tmp - 1);       }     }     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d %d , &u, &v);       adj[u - 1].push_back(v - 1);       adj[v - 1].push_back(u - 1);     }     memset(color, -1, sizeof color);     dfs(0, 0);     printf( %d n , max(1, ans));     for (int i = 0; i < m; i++) printf( %d  , color[i] != -1 ? color[i] : 1);     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int alpha[26], kitta = 0;     for (int i = 0; i < 26; i++) alpha[i] = 0;     for (int i = 0; i < s.length(); i++) {       alpha[s[i] -  a ]++;       if (alpha[s[i] -  a ] == 1) kitta++;     }     if (kitta > 4 || kitta < 2) {       cout <<  No ;       return 0;     }     for (int i = 0; i < s.length(); i++) {       if (alpha[s[i] -  a ] > 1) {         kitta++;         alpha[s[i] -  a ] = 1;       }     }     if (kitta > 3)       cout <<  Yes ;     else       cout <<  No ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long len = 40;   long long n, next_free = 0;   long long a[2][200500 * len];   void add(long long x) {     vector<long long> b;     long long i;     for (i = 0; i < len; i++) {       long long last = x % 2;       b.push_back(last);       x /= 2;     }     reverse(b.begin(), b.end());     long long cur = 0;     for (i = 0; i < len; i++) {       if (a[b[i]][cur] != 0)         cur = a[b[i]][cur];       else {         next_free++;         a[b[i]][cur] = next_free;         cur = next_free;       }     }   }   long long get_max(long long x) {     vector<long long> b;     long long i;     for (i = 0; i < len; i++) {       long long last = x % 2;       b.push_back(1 - last);       x /= 2;     }     reverse(b.begin(), b.end());     long long ans = 0;     long long big = 1;     for (i = 0; i < len - 1; i++) big *= 2;     long long cur = 0;     for (i = 0; i < len; i++) {       if (a[b[i]][cur] != 0) {         cur = a[b[i]][cur];         ans += big;       } else {         cur = a[1 - b[i]][cur];       }       big /= 2;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     long long i, j;     vector<long long> a;     a.push_back(0);     for (i = 0; i < n; i++) {       long long q;       cin >> q;       a.push_back(q);     }     a.push_back(0);     add(0);     vector<long long> pref(200500, 0);     for (i = 1; i <= n; i++) {       pref[i] = pref[i - 1] ^ a[i];     }     long long ans = 0;     long long suff = 0;     for (i = n; i >= 0; i--) {       ans = max(ans, get_max(pref[i]));       suff ^= a[i];       add(suff);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     string s;     cin >> s;     int res = 1;     int n = s.length();     int cur = 1;     for (int i = 0; i < n; i++) {       if (s[i] ==  A  or s[i] ==  E  or s[i] ==  I  or s[i] ==  O  or           s[i] ==  U  or s[i] ==  Y ) {         res = max(cur, res);         cur = 1;       } else         cur++;     }     res = max(cur, res);     cout << res;   }
#include <bits/stdc++.h>   template <typename Iter>   long long maxsum(Iter begin, Iter end) {     long long mins = 0, s = 0;     long long maxs = 0;     long long max = *begin;     while (begin != end) {       s += *begin;       max = std::max(max, *begin);       maxs = std::max(maxs, s - mins);       mins = std::min(mins, s);       ++begin;     }     return (maxs == 0 ? max : maxs);   }   int main() {     int t;     std::cin >> t;     for (int ti = 0; ti < t; ++ti) {       int n;       std::cin >> n;       std::vector<long long> a(n);       for (auto &e : a) std::cin >> e;       long long maxs = std::max(maxsum(a.begin(), a.end() - 1),                                 maxsum(a.begin() + 1, a.end()));       std::cout << (std::accumulate(a.begin(), a.end(), 0ll) > maxs ?  YES                                                                      :  NO )                 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int INF = (1LL << 60) - 1;   const long long int MAX = 1000000001;   const long long int mod = 1000000007;   long long int s[1000001] = {0};   long long int f[1000001] = {0};   long long int po[1000001] = {0};   long long int fast_exp(long long int base, long long int exp, long long int m) {     long long int res = 1;     while (exp > 0) {       if (exp % 2 == 1) {         res = (res * base) % m;       }       base = (base * base) % m;       exp /= 2;     }     return res % m;   }   long long int gcd(int a, int b);   long long int power(long long int x, long long int y, long long int m);   long long int modInverse(long long int a, long long int m) {     return power(a, m - 2, m);   }   long long int power(long long int x, long long int y, long long int m) {     if (y == 0) return 1;     long long int p = power(x, y / 2, m) % m;     p = (p * p) % m;     return (y % 2 == 0) ? p : (x * p) % m;   }   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int main() {     ios ::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int a[6] = {0}, sum = 0;     int freq[101] = {0};     for (int i = 1; i <= 5; i++) {       cin >> a[i];       freq[a[i]]++;       sum += a[i];     }     int temp1 = 0, temp2 = 0;     for (int i = 1; i <= 100; i++) {       if (freq[i] == 2)         temp1 = freq[i] * i;       else if (freq[i] >= 3)         temp2 = 3 * i;     }     cout << min(sum - temp1, sum - temp2) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   const long double pi = 3.14159265358979323846;   const char nl =   n ;   const long long inf = 1e15;   long long mul(long long x, long long y) { return (1ll * (x) * (y)); }   long long power(long long x, long long y) {     long long z = 1;     while (y > 0) {       if (y % 2) z = mul(z, x);       x = mul(x, x);       y /= 2;     }     return z;   }   void solve() {     int n;     cin >> n;     vector<long long> v(n);     for (auto &x : v) {       cin >> x;     };     sort(((v).begin()), ((v).end()));     long long i = 1;     long long ans = inf;     while (true) {       long long c = 0;       long long p = 1;       bool f = true;       for (int j = 0; j < n; j++) {         c += abs(v[j] - p);         p *= i;         if (p >= 100000000000000) {           f = false;           break;         }       }       if (f) {         ans = min(ans, c);       } else {         break;       }       i++;     }     cout << ans <<   n ;     return;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   long long mypow(int n, int m) {     long long ans = 1, a = 3;     while (n > 0) {       if (n & 1) ans = ans * a % m;       a = a * a % m;       n >>= 1;     }     return ans;   }   int main() {     while (~scanf( %d%d , &n, &m)) {       long long ans = mypow(n, m) % m;       ans = (ans - 1) % m;       ans = (ans + m) % m;       printf( %d n , (int)ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300000;   int n, balance[MAXN + 9] = {0};   int min_balance = MAXN;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       char ch;       cin >> ch;       balance[i] = balance[i - 1] + ((ch ==  ( ) ? 1 : -1);       min_balance = min(min_balance, balance[i]);     }     if (balance[n] != 0) {       cout << 0 <<   n ;       cout << 1 <<     << 1 <<   n ;     } else {       int count[3] = {0};       int firstIndex[3], lastIndex[3];       for (int i = 1; i <= n; i++) {         int diff = balance[i] - min_balance;         if (diff <= 2) {           count[diff]++;           if (count[diff] == 1) {             firstIndex[diff] = i;           }           lastIndex[diff] = i;         }       }       int max_beauty = count[0];       pair<int, int> swap_pair = make_pair(1, 1);       if (lastIndex[0] != n) {         int candidate_beauty = count[1];         for (int i = firstIndex[0]; i <= lastIndex[0]; i++) {           if (balance[i] == min_balance + 1) {             candidate_beauty--;           }         }         if (max_beauty < candidate_beauty) {           max_beauty = candidate_beauty;           swap_pair = make_pair(firstIndex[0], lastIndex[0] + 1);         }       }       if (max(lastIndex[0], lastIndex[1]) != n) {         int candidate_beauty = count[0] + count[2];         int l = min(firstIndex[0], firstIndex[1]);         int r = max(lastIndex[0], lastIndex[1]);         for (int i = l; i <= r; i++) {           if (balance[i] == min_balance + 2) {             candidate_beauty--;           }         }         if (max_beauty < candidate_beauty) {           max_beauty = candidate_beauty;           swap_pair = make_pair(l, r + 1);         }       }       int c1 = 0, c2 = 0, j = 1, k = 1;       for (int i = 1; i <= n; i++) {         if (balance[i] - min_balance <= 1 && j <= i) {           if (max_beauty < count[0] + c2) {             max_beauty = count[0] + c2;             swap_pair = make_pair(j, i);           }           c2 = 0;           j = i + 1;         }         if (balance[i] - min_balance == 2) {           c2++;         }         if (balance[i] - min_balance == 0 && k <= i) {           if (max_beauty < c1) {             max_beauty = c1;             swap_pair = make_pair(k, i);           }           c1 = 0;           k = i + 1;         }         if (balance[i] - min_balance == 1) {           c1++;         }       }       cout << max_beauty <<   n ;       cout << swap_pair.first <<     << swap_pair.second <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void scan() {}   template <typename F, typename... R>   void scan(F &f, R &...r) {     cin >> f;     scan(r...);   }   int di_;   string dnms_, co_ =  , ;   void debug_() { cout << endl; }   template <typename F, typename... R>   void debug_(F f, R... r) {     while (dnms_[di_] !=  , ) cout << dnms_[di_++];     di_++;     cout <<  :   << f <<  , ;     debug_(r...);   }   const int MAX = 200001;   int n, __ptr = 0, arr[MAX];   inline int top() { return arr[__ptr]; }   inline int pop() { return arr[__ptr++]; }   inline bool empty() { return __ptr >= n; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     scan(n);     for (int i = 0; i < n; ++i) scan(arr[i]);     sort(arr, arr + n);     int best = 0;     for (int i = 1;; i++) {       while (!empty() && top() < i) pop();       if (empty())         break;       else         pop();       best = max(best, i);     }     printf( %d n , best);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dis(long long x1, long long x2, long long y1, long long y2) {     return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);   }   int main() {     int n;     cin >> n;     long long x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     long long x[n + 1], y[n + 1];     for (int i = 0; i < (int)(n); ++i) {       cin >> x[i] >> y[i];     }     x[n] = x1, y[n] = y1;     long long ans = 1e18;     for (int i = 0; i < n + 1; i++) {       long long r1 = dis(x[i], x1, y[i], y1);       long long r2 = 0;       for (int j = 0; j < n + 1; j++) {         long long val = dis(x[j], x2, y[j], y2);         long long val1 = dis(x[j], x1, y[j], y1);         if (val1 > r1) {           r2 = max(r2, val);         }       }       ans = min(ans, r1 + r2);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) {       int temp1, temp2;       if (a[i] != i) {         temp1 = a[a[i]];         temp2 = a[a[a[i]]];         if (i == temp2) {           cout <<  yes  << endl;           break;         }         if (i == n && (temp2 != i)) {           cout <<  no  << endl;           break;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, a[101], dp[101], ans;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] == 0) {         dp[i] = 0;         ans++;       } else if (a[i] == 3) {         if (dp[i - 1] == 0 || dp[i - 1] == 3)           dp[i] = 3;         else if (dp[i - 1] == 1)           dp[i] = 2;         else if (dp[i - 1] == 2)           dp[i] = 1;       } else if (a[i] == 1) {         if (dp[i - 1] == 1) {           dp[i] = 0;           ans++;         } else if (dp[i - 1] == 0 || dp[i - 1] == 3 || dp[i - 1] == 2)           dp[i] = 1;       } else if (a[i] == 2) {         if (dp[i - 1] == 2) {           dp[i] = 0;           ans++;         } else if (dp[i - 1] == 0 || dp[i - 1] == 3 || dp[i - 1] == 1)           dp[i] = 2;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int max(int a, int b) {     if (a > b)       return a;     else       return b;   }   int min(int a, int b) {     if (a < b)       return a;     else       return b;   }   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int lcm(int a, int b) { return a * (b / gcd(a, b)); }   vector<bool> isPrime(1000005 + 1, true);   string tos(int n) {     stringstream ss;     ss << n;     return ss.str();   }   void seive() {     isPrime[0] = 0, isPrime[1] = 0;     for (long long i = 2; i * i <= 1000005; i++)       if (isPrime[i])         for (long long j = i * i; j <= 1000005; j += i) isPrime[j] = 0;   }   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, 1, -1};   int n, m, ans, mid;   int main() {     cin >> n >> m;     if (n == 1) {       cout << 1 <<   n ;       return 0;     }     mid = (n) / 2;     ans = m;     if (abs(mid - (m - 1)) < abs(mid - m))       ans--;     else if (abs(mid - (m + 1)) < abs(mid - m))       ans++;     else       ans++;     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, i, nr, k[7], m;   int main(void) {     cin >> n;     m = 0;     for (i = 1; i <= n; i++) {       cin >> nr;       k[nr]++;     }     if ((k[1] + k[2] * 2 + k[3] * 3 + k[4] * 4 == 5) ||         (k[1] + k[2] * 2 + k[3] * 3 + k[4] * 4 < 3)) {       cout <<  -1 ;       return 0;     }     if (k[2] > k[1]) {       k[2] = k[2] - k[1];       k[3] = k[3] + k[1];       m = m + k[1];       k[1] = 0;       m = m + (k[2] / 3) * 2;       k[3] = k[3] + (k[2] / 3) * 2;       k[2] = k[2] % 3;       if (k[2] == 1) {         if (k[4] > 0)           m++;         else           m = m + 2;       } else if (k[2] == 2) {         m = m + 2;       }     } else if (k[2] < k[1]) {       m = m + k[2];       k[3] = k[3] + k[2];       k[1] = k[1] - k[2];       k[2] = 0;       k[3] = k[3] + k[1] / 3;       m = m + (k[1] / 3) * 2;       k[1] = k[1] % 3;       if (k[3] != 0)         m = m + k[1];       else         m = m + 2;     } else if (k[2] == k[1])       m = k[1];     cout << m;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 500010;   struct E {     int u, v, w, I;   } e[N];   int n, m, F[N], T[N], q, k, a[N], A[N], V, d, L[N], C[N];   vector<int> G[N];   bool M(E a, E b) { return a.w < b.w; }   int P(int x) { return x == A[x] ? x : A[x] = P(A[x]); }   void D(int b, int x) {     if (L[x] == b) return;     L[x] = b;     V++;     d += G[x].size();     for (int J = 0; J < G[x].size(); J++) D(b, G[x][J]);   }   bool K(int b, int x) {     V = d = 0;     D(b, x);     return d == 2 * (V - 1);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &e[i].u, &e[i].v, &e[i].w);       e[i].I = i;       F[i] = e[i].u;       T[i] = e[i].v;     }     for (int i = 1; i <= n; i++) A[i] = i;     sort(e + 1, e + m + 1, M);     for (int i = 1; i <= m; i++) {       int o = i;       while (e[o].w == e[i].w && o <= m) {         int u = P(e[o].u), v = P(e[o].v);         F[e[o].I] = u;         T[e[o].I] = v;         C[e[o].I] = u != v;         o++;       }       for (; i < o; i++) A[P(e[i].u)] = P(e[i].v);       i--;     }     scanf( %d , &q);     for (int c = 1; c <= q; c++) {       scanf( %d , &k);       bool Y = 1;       for (int i = 1; i <= k; i++) {         scanf( %d , &a[i]);         if (!C[a[i]]) Y = 0;         G[F[a[i]]].clear();         G[T[a[i]]].clear();       }       for (int i = 1; i <= k; i++)         G[F[a[i]]].push_back(T[a[i]]), G[T[a[i]]].push_back(F[a[i]]);       for (int i = 1; i <= k; i++) {         int x = F[a[i]], y = T[a[i]];         if (L[x] != c) Y &= K(c, x);         if (L[y] != c) Y &= K(c, y);       }       puts(Y ?  YES  :  NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, const char* argv[]) {     int x1, x2, y1, y2, dx, dy, px, py;     cin >> x1 >> y1 >> x2 >> y2 >> px >> py;     dx = abs(x2 - x1);     dy = abs(y2 - y1);     if (dx % px != 0 || dy % py != 0) {       cout <<  NO ;       exit(0);     }     int a = dx / px;     int b = dy / py;     if (a % 2 == b % 2) {       cout <<  YES ;     } else {       cout <<  NO ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[100005];   int p[100005];   long long size[100005];   struct edge {     int u, v, w;     edge(int u = 0, int v = 0, int w = 0) : u(u), v(v), w(w) {}     bool operator<(const edge &e1) const { return w > e1.w; }   } eList[100005];   int findR(int x) {     if (p[x] == x) return x;     return p[x] = findR(p[x]);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int u, v;     for (int i = 1; i <= m; i++) {       scanf( %d%d , &u, &v);       eList[i] = edge(u, v, min(a[u], a[v]));     }     for (int i = 1; i <= n; i++) {       p[i] = i;       size[i] = 1;     }     sort(eList + 1, eList + m + 1);     long long ans = 0;     int x, y;     for (int i = 1; i <= m; i++) {       u = eList[i].u;       v = eList[i].v;       x = findR(u);       y = findR(v);       if (x != y) {         ans += eList[i].w * (size[x] * size[y]);         p[x] = y;         size[y] += size[x];       }     }     printf( %.6lf , ans * 2.0 / n / (n - 1));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, p;   set<int> ss;   int idx[500500];   char str[500500], op[500500];   int main() {     cin >> n >> m >> p;     scanf( %s%s , str + 1, op + 1);     stack<int> s;     ss.insert(0);     for (int i = 1; i <= n; i++) {       ss.insert(i);       if (str[i] ==  ( )         s.push(i);       else         idx[s.top()] = i, idx[i] = s.top(), s.pop();     }     for (int i = 1; i <= m; i++) {       if (op[i] ==  R )         p = *ss.upper_bound(p);       else if (op[i] ==  L )         p = *prev(ss.lower_bound(p));       else {         auto it = ss.lower_bound(p);         int from = *it;         int to = idx[from];         int val;         do {           val = *it;           auto nxt = it;           if (from < to)             nxt++;           else             nxt--;           ss.erase(it);           it = nxt;         } while (val != to);         if (from > to) it++;         if (it == ss.end()) it--;         p = *it;       }     }     for (auto it : ss)       if (it) printf( %c , str[it]);     puts(  );     return 0;   }