malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1000 * 1000 * 1000 + 7;   const double PI = 3.14159265358979323846264;   const pair<long long int, long long int> steps[] = {       {1, 0}, {0, 1}, {-1, 0}, {0, -1}, {1, -1}, {1, 1}, {-1, -1}, {-1, 1}};   template <typename... T>   void read(T&... args) {     ((cin >> args), ...);   }   template <typename... T>   void write(T&&... args) {     ((cout << args <<    ), ...);   }   void fio() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   void setUpLocal() {}   const long long int maxN = 2 * 1e3;   const long long int gp_size = maxN;   vector<long long int> gp[gp_size];   long long int vis[gp_size];   long long int cnt[gp_size];   void dfs(long long int i) {     vis[i] = 1;     for (long long int child : gp[i])       if (!vis[child]) dfs(child);   }   long long int modPow(long long int n, long long int k) {     long long int ret = 1;     while (k) {       if (k & 1) ret = ret * n % mod;       k >>= 1;       n = n * n % mod;     }     return ret;   }   void solve() {     long long int n, m, k;     cin >> n >> m >> k;     for (long long int i = 1; i <= n - k + 1; i++) {       for (long long int f = i, b = i + k - 1; f <= b; f++, b--) {         gp[f].push_back(b);         gp[b].push_back(f);       }     }     long long int cc = 0;     for (long long int i = 1; i <= n; i++) {       if (!vis[i]) {         cc++;         dfs(i);       }     }     cout << modPow(m, cc);   }   int32_t main() {     fio();     setUpLocal();     return solve(), 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double EPS = 1e-9;   const int oo = 210000000;   int n;   vector<int> p[4];   vector<int> g[201];   int solve(int x) {     bool used[201];     for (int i = 1; i <= n; i++) used[i] = 0;     int ans = 0, m = 0;     while (m < n) {       bool flag1 = 0;       for (int i = 0; i < p[x].size(); i++) {         int cur = p[x][i];         if (used[cur]) continue;         bool flag = 1;         for (int j = 0; j < g[cur].size(); j++)           if (!used[g[cur][j]]) {             flag = 0;             break;           }         if (flag) {           flag1 = 1;           m++;           used[cur] = 1;         }       }       if (!flag1) {         x++;         if (x > 3) x = 1;         ans++;       }     }     return ans;   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       int tmp;       cin >> tmp;       p[tmp].push_back(i);     }     for (int i = 1; i <= n; i++) {       int k;       cin >> k;       for (int j = 0; j < k; j++) {         int tmp1;         cin >> tmp1;         g[i].push_back(tmp1);       }     }     int ans = oo;     ans = min(ans, solve(1));     ans = min(ans, solve(2));     ans = min(ans, solve(3));     cout << ans + n << endl;     return (0);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     cin >> a >> b >> c;     if (a == b)       cout <<  YES ;     else if (b - a > 0 && c > 0) {       if ((b - a) % c == 0)         cout <<  YES ;       else         cout <<  NO ;     } else if (b - a > 0 && c < 0) {       cout <<  NO ;     } else if (b - a < 0 && c > 0) {       cout <<  NO ;     } else if (b - a < 0 && c < 0) {       if ((a - b) % c == 0)         cout <<  YES ;       else         cout <<  NO ;     } else if (c == 0)       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using db = double;   using vi = vector<int>;   const int l = 20;   const int maxn = 300006;   int e[maxn][l];   int tote;   map<int, int> S;   int a[maxn];   int yy[maxn];   int rr[maxn];   int h[maxn][1000 / l];   int n, q;   int app[maxn];   int sum[maxn];   int Get(int a, int b) { return e[h[a][b / l]][b % l]; }   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       S[a[i]] = 0;     }     int tot = 0;     for (auto &p : S) {       rr[tot] = p.first;       p.second = tot;       tot++;     }     for (int i = 1; i <= n; ++i) a[i] = S[a[i]];     int m = (int)sqrt(n * 5) + 3;     for (int i = 1; i <= n; ++i) app[a[i]]++;     vi big;     for (int i = 0; i < tot; ++i)       if (app[i] > m / 5 - 3) {         big.push_back(i);         yy[i] = big.size() - 1;       } else         yy[i] = -1;     int maxs = big.size() / l;     memset(h, 0, sizeof(h));     memset(e, 0, sizeof(e));     tote = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 0; j <= maxs; ++j) h[i][j] = h[i - 1][j];       if (yy[a[i]] != -1) {         int no = yy[a[i]];         tote++;         for (int j = 0; j < l; ++j) e[tote][j] = e[h[i - 1][no / l]][j];         e[tote][no % l]++;         h[i][no / l] = tote;       }     }     for (int i = 1; i <= q; ++i) {       int l, r, k;       scanf( %d%d%d , &l, &r, &k);       int ans = -1;       for (auto x : big)         if (Get(r, yy[x]) - Get(l - 1, yy[x]) > (r - l + 1) / k)           if (ans == -1 || x < ans) ans = x;       if (r - l + 1 <= m) {         vi tr;         for (int i = l; i <= r; ++i) {           tr.push_back(a[i]);           sum[a[i]]++;         }         for (auto x : tr)           if (sum[x] > (r - l + 1) / k)             if (ans == -1 || x < ans) ans = x;         for (auto x : tr) sum[x] = 0;       }       printf( %d n , (ans == -1) ? -1 : rr[ans]);     }   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   const ll INF = 1e16 + 2;   signed main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     vector<pair<ll, ll>> pts;     pts.emplace_back();     ll ax, ay, bx, by;     cin >> pts[0].first >> pts[0].second >> ax >> ay >> bx >> by;     ll x, y, t;     cin >> x >> y >> t;     while (pts.back().first < INF && pts.back().second < INF)       pts.emplace_back(pts.back().first * ax + bx, pts.back().second * ay + by);     int m = pts.size();     vector<int> dp(m);     for (int i = 0; i < m; i++) {       ll len;       len = abs(pts[i].first - x) + abs(pts[i].second - y);       ll cur_t = t;       if (len > cur_t) {         dp[i] = 0;         continue;       }       cur_t -= len;       dp[i] = 1;       for (int j = i - 1; j >= 0; j--) {         len = abs(pts[j].first - pts[j + 1].first) +               abs(pts[j].second - pts[j + 1].second);         if (cur_t >= len) dp[i] = i - j + 1;         cur_t -= len;       }       len = abs(pts[i].first - x) + abs(pts[i].second - y);       cur_t = t - len;       len = abs(pts[i].first - pts[0].first) + abs(pts[i].second - pts[0].second);       if (cur_t < 2 * len) continue;       cur_t -= 2 * len;       dp[i] = max(dp[i], i + 1);       for (int j = i + 1; j < m; j++) {         ll len = abs(pts[j].first - pts[j - 1].first) +                  abs(pts[j].second - pts[j - 1].second);         if (cur_t >= len) dp[i] = max(dp[i], i + 1 + j - i);         cur_t -= len;       }     }     ll ans = *max_element(dp.begin(), dp.end());     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   int n, a[maxn], tot, b[maxn], ans;   inline int read() {     int ret = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -f;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       ret = ret * 10 + ch -  0 ;       ch = getchar();     }     return ret * f;   }   inline int BinarySearch(int l, int x) {     int L = l, R = tot, mid;     while (L <= R) {       mid = L + R >> 1;       b[mid] >= x ? R = mid - 1 : L = mid + 1;     }     return L;   }   int main() {     n = read();     for (int i = 1; i <= n; i++) a[i] = read();     sort(a + 1, a + 1 + n);     int cnt = 1;     for (int i = 2; i <= n + 1; i++) {       if (a[i] != a[i - 1]) {         b[++tot] = cnt;         cnt = 1;       } else         cnt++;     }     sort(b + 1, b + 1 + tot);     for (int i = 1; i <= tot; i++) {       for (int j = b[i - 1] + 1; j <= b[i]; j++) {         int now = j, lst = j, ret = BinarySearch(i + 1, 2 * lst);         while (ret <= tot) {           lst *= 2;           now += lst;           ret = BinarySearch(ret + 1, 2 * lst);         }         if (now > ans) ans = now;       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       string s;       int n, l = 0, r = 0, u = 0, d = 0;       cin >> s;       for (int i = 0; i < s.size(); i++) {         if (s[i] ==  L )           l++;         else if (s[i] ==  R )           r++;         else if (s[i] ==  U )           u++;         else           d++;       }       int a = min(l, r);       int b = min(u, d);       if (a == 0 && b == 0) {         cout << 0 << endl;       } else if (a == 0) {         cout << 2 << endl;         cout <<  UD  << endl;       } else if (b == 0) {         cout << 2 << endl;         cout <<  LR  << endl;       } else {         cout << 2 * (a + b) << endl;         for (int i = 0; i < a; i++) {           cout <<  L ;         }         for (int i = 0; i < b; i++) {           cout <<  U ;         }         for (int i = 0; i < a; i++) {           cout <<  R ;         }         for (int i = 0; i < b; i++) {           cout <<  D ;         }         cout << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 7;   const string alpha =  abcdefghijklmnopqrstuvwxyz ;   long long power(long long x, long long y) {     long long res = 1;     x = x;     while (y > 0) {       if (y & 1) res = (res * x);       y = y >> 1;       x = (x * x);     }     return res;   }   template <typename T>   T gcd(T a, T b) {     if (a == 0) return b;     return gcd(b % a, a);   }   template <typename T>   T powm(T a, T b, long long m) {     T cnt = 1;     while (b > 0) {       if (b % 2 == 1) cnt = (cnt * a) % m;       b /= 2;       a = (a * a) % m;     }     return cnt % m;   }   long long ncr(long long n, long long r) {     long long res = 1;     if (r > n) return 0;     if (r > n - r) r = n - r;     for (long long i = 0; i < r; i++) {       res *= (n - i);       res /= (i + 1);     }     return res;   }   long long sqr(long long x) { return x * x; }   void solve() {     long long int n;     cin >> n;     vector<long long> a(n), b(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];       a[i] = a[i] * (i + 1) * (n - i);     }     for (int i = 0; i < n; ++i) {       cin >> b[i];     }     sort((a).begin(), (a).end());     sort((b).rbegin(), (b).rend());     long long ans = 0;     for (int i = 0; i < n; ++i) {       a[i] %= 998244353;       ans = (ans + a[i] * b[i]) % 998244353;     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int tc;     tc = 1;     while (tc--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, M;   int main() {     cin >> M >> N;     if (M == N) {       cout << N <<  1  <<     << N <<  2 ;       return 0;     }     if (N - M == 1) {       cout << M <<  9  <<     << N <<  0 ;       return 0;     }     if (M == 9 && N == 1) {       cout <<  9 10 ;       return 0;     }     cout << -1;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, ctr{};     cin >> n;     string vec;     cin >> vec;     int likh = count(vec.begin(), vec.end(),  8 );     if (likh > 0) {       int m = min(likh, n % 11);       int len = n - m;       len = len / 10;       ctr = min(len, likh);     }     cout << ctr <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1e5 + 5;   char s[MAX_N];   vector<int> v;   int main() {     scanf( %s , s + 1);     int n = strlen(s + 1);     int tot = 0;     for (int i = 1; i <= n; i++) {       if (s[i] ==  ( )         tot++;       else if (s[i] ==  ) )         tot--;     }     if (tot <= 0) {       printf( -1 n );       return 0;     }     int res = 0;     for (int i = 1; i <= n; i++) {       if (s[i] ==  ( )         res++;       else if (s[i] ==  ) )         res--;       else         res--, v.push_back(1), tot--;       if (res < 0) {         printf( -1 n );         return 0;       }     }     if (tot < 0) {       printf( -1 n );       return 0;     }     v[v.size() - 1] += tot;     res = 0;     int pos = -1;     for (int i = n; i; i--) {       if (s[i] ==  # ) {         pos = i;         break;       }     }     for (int i = 1; i <= n; i++) {       if (s[i] ==  ( )         res++;       else if (s[i] ==  ) )         res--;       else {         if (i == pos)           res -= 1 + tot;         else           res--;       }       if (res < 0) {         printf( -1 n );         return 0;       }     }     for (int i = 0; i < v.size(); i++) printf( %d n , v[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int dis[40];   long long adj[40];   vector<long long> v1;   vector<long long> v2;   void bt(int l, int r, long long mask) {     if (l == r) {       v1.emplace_back(mask);       return;     }     bt(l + 1, r, mask);     if (adj[l] & mask) return;     bt(l + 1, r, mask | (1ll << l));   }   long long f[1 << 21];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int m;     cin >> m;     long long ans = 1;     for (int i = 0; i < n; ++i) ans *= 2;     for (int i = 0; i < m; ++i) {       int x;       cin >> x;       --x;       int y;       cin >> y;       --y;       adj[x] |= (1ll << y);       adj[y] |= (1ll << x);     }     long long cnt1 = 1;     long long cnt01 = 1;     long long cnt02 = 1;     for (int j = 0; j < n; ++j)       if (adj[j] == 0) cnt01 *= 2;     fill(dis, dis + n, -1);     for (int i = 0; i < n; ++i)       if (dis[i] < 0) {         cnt1 *= 2;         cnt02 *= 2;         int S = 0;         queue<int> qu;         qu.push(i);         dis[i] = 0;         while (qu.size()) {           int u = qu.front();           qu.pop();           S++;           for (int v = 0; v < n; ++v)             if (adj[u] >> v & 1) {               if (dis[v] < 0) dis[v] = dis[u] ^ 1, qu.push(v);               if (dis[v] == dis[u]) cnt02 = 0;             }         }       }     if (ans == cnt1) ans = 0;     ans -= cnt1;     ans += cnt01 * 2;     ans += cnt02;     m = n / 2;     bt(m, n, 0);     v1.swap(v2);     bt(0, m, 0);     for (long long x : v2) {       int M = 0;       for (int i = 0; i < m; ++i) {         if (adj[i] & x)           continue;         else           M |= (1 << i);       }       f[M]++;     }     for (int i = 0; i < m; ++i)       for (int j = 0; j < (1 << m); ++j)         if (j >> i & 1) f[j ^ (1 << i)] += f[j];     for (long long x : v1) ans -= f[x], ans -= f[x];     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long n, m;     cin >> n >> m;     vector<long long> a(n), b(m);     for (long long i = 0; i < n; ++i) cin >> a[i];     for (long long i = 0; i < m; ++i) cin >> b[i];     long long tot = 0;     for (long long i = 0; i < n; ++i) tot ^= a[i];     for (long long i = 0; i < m; ++i) tot ^= b[i];     if (tot == 0) {       cout <<  YES n ;       for (long long i = 0; i < n - 1; ++i) {         for (long long j = 0; j < m - 1; ++j) {           cout << 0 <<    ;         }         cout << a[i] <<   n ;       }       long long last = a[n - 1];       for (long long j = 0; j < m - 1; ++j) {         cout << b[j] <<    ;         last ^= b[j];       }       cout << last <<   n ;     } else {       cout <<  NO n ;     }     return 0;   }
#include <bits/stdc++.h>   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 sub(int a, int b) {     int s = a - b;     if (s < 0) s += mod;     return s;   }   int mult(int a, int b) { return (1LL * a * b) % mod; }   int n, k;   int len;   const int maxN = (int)1e5 + 10;   const int maxK = 105;   int dp[maxN][maxK];   int sum_pref[maxN];   int a[maxN];   int f[maxN][maxK];   int all[maxN];   bool can(int l, int r, int color) {     return (all[r] - all[l - 1] == f[r][color] - f[l - 1][color]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     srand(239);     cin >> n >> k >> len;     for (int i = 1; i <= n; i++) {       cin >> a[i];       for (int color = 1; color <= k; color++) {         f[i][color] = f[i - 1][color];         f[i][color] += (color == a[i]);       }       all[i] = all[i - 1] + (a[i] > 0);     }     if (len == 1) {       cout << 0;       return 0;     }     sum_pref[0] = 1;     for (int i = 1; i <= n; i++) {       for (int color = 1; color <= k; color++) {         if (a[i] != -1 && a[i] != color) continue;         dp[i][color] = sum_pref[i - 1];         if (i >= len && can(i - len + 1, i, color)) {           dp[i][color] =               sub(dp[i][color], sub(sum_pref[i - len], dp[i - len][color]));         }         sum_pref[i] = sum(sum_pref[i], dp[i][color]);       }     }     cout << sum_pref[n];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char **argv) {     string i, o;     cin >> i >> o;     sort(i.begin(), i.end());     if (i ==  0  && i == o) {       cout <<  OK  << endl;       return 0;     }     unsigned int z;     for (z = 0; z < i.length() && i[z] ==  0 ; ++z)       ;     while (!i.empty() && i[0] ==  0 ) i = i.substr(1);     while (z--) i.insert(i.empty() ? 0 : 1,  0 );     cout << ((i == o) ?  OK  :  WRONG_ANSWER ) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long k = 2;   struct node {     vector<node*> to;     node() { to.resize(k, 0); }     long long cnt = 0;   };   node* root = new node();   inline bool getbit(long long a, long long pos) { return a & (1 << pos); }   void addstring(long long b) {     vector<long long> a;     for (long long i = 0; i < 30; ++i) {       a.push_back(getbit(b, i));     }     reverse(a.begin(), a.end());     node* cur = root;     for (long long i = 0; i < a.size(); ++i) {       long long c = a[i];       if (cur->to[c] == 0) {         cur->to[c] = new node();       }       cur = cur->to[c];       cur->cnt++;     }   }   long long get(long long b) {     vector<long long> a;     long long ans = 0;     for (long long i = 0; i < 30; ++i) {       a.push_back(getbit(b, i));     }     reverse(a.begin(), a.end());     node* cur = root;     for (long long i = 0; i < a.size(); ++i) {       long long bet = a[i];       if (cur->to[bet] && cur->to[bet]->cnt > 0) {         cur = cur->to[bet];         ans += bet * (1 << (29 - i));         cur->cnt--;       } else {         cur = cur->to[1 - bet];         ans += (1 - bet) * (1 << (29 - i));         cur->cnt--;       }     }     return ans;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<long long> a(n);     vector<long long> b(n);     for (long long i = 0; i < n; ++i) {       cin >> a[i];     }     for (long long i = 0; i < n; ++i) {       cin >> b[i];       addstring(b[i]);     }     for (long long i = 0; i < n; ++i) {       cout << (get(a[i]) ^ a[i]) <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long k4, k7, i, l;     char s[100];     long long n;     gets(s);     l = strlen(s);     k4 = 0;     k7 = 0;     for (i = 0; i < l; i++) {       if (s[i] ==  4 ) k4++;       if (s[i] ==  7 ) k7++;     }     if (k4 == 0 && k7 == 0)       cout << -1;     else if (k7 > k4)       cout << 7;     else       cout << 4;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int a[1000005];   int main() {     long long int i, j, k, l, n, m;     cin >> n >> m;     if (n / m < 3) {       cout << -1;       return 0;     }     j = 1;     long long int f = 0;     long long int x, y;     x = 1, y = n - 1;     while (y - x >= 4 && j < m) {       a[x] = a[x + 1] = a[y] = j;       j++;       x += 2;       y--;     }     while (x <= y) {       a[x] = j;       x++;     }     a[n] = j;     for (i = 1; i <= n; i++) cout << a[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void vout(T x) {     cout << x << endl;     exit(0);   }   int gcd(int a, int b) {     while (a && b) {       if (a > b)         a %= b;       else         b %= a;     }     return a + b;   }   const long long inf = -1e18;   const long long mod = 1e9;   long long dp[300][300], a[400];   int n, k, x;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k >> x;     if (n / k > x) vout(-1);     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 0; i < 300; ++i) {       for (int j = 0; j < 300; ++j) dp[i][j] = inf;     }     dp[0][x] = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < x; ++j) {         for (int t = max(0, i - k); t <= i; ++t) {           if (dp[t][j + 1] >= 0) dp[i][j] = max(dp[i][j], dp[t][j + 1] + a[i]);         }       }     }     long long ans = 0;     for (int i = n - k + 1; i <= n; ++i) ans = max(ans, dp[i][0]);     vout(ans);     return 0;   }
#include <bits/stdc++.h>   const long long INF = 0x3f3f3f3f;   using namespace std;   void sol() {     long long n, m;     while (cin >> n >> m) {       string s;       cin.ignore();       cin >> s;       long long x[6][n];       string a[6] = { abc ,  acb ,  bca ,  bac ,  cab ,  cba };       memset(x, 0, sizeof(x));       ;       for (long long i = 0; i < s.size(); i++) {         if (i) {           for (long long j = 0; j < 6; j++) {             x[j][i] = x[j][i - 1];             if (s[i] != a[j][i % 3]) x[j][i]++;           }         } else {           for (long long j = 0; j < 6; j++) {             x[j][i] = 0;             if (s[i] != a[j][i % 3]) x[j][i]++;           }         }       }       while (m--) {         long long a, b;         cin >> a >> b;         long long ans = INF;         if (a > 1) {           for (long long i = 0; i < 6; i++) {             ans = (x[i][b - 1] - x[i][a - 2] < ans ? x[i][b - 1] - x[i][a - 2]                                                    : ans);           }         } else {           for (long long i = 0; i < 6; i++) {             ans = (x[i][b - 1] < ans ? x[i][b - 1] : ans);           }         }         cout << ans <<   n ;       }     }   }   signed main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     long long t = 1;     while (t--) {       sol();       cout.flush();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};   const int dy[] = {0, 1, 0, -1, -1, 1, -1, 1};   const int OO = INT_MAX;   long long tolong(string s) {     stringstream ss;     ss << s;     long long n;     ss >> n;     return n;   }   string toString(long long s) {     stringstream ss;     ss << s;     string n;     ss >> n;     return n;   }   int main() {     string x;     cin >> x;     long long n = tolong(x);     if (x == toString(n)) {       if (n >= -128 && n <= 127) {         cout <<  byte ;       } else if (n >= -32768 && n <= 32767) {         cout <<  short ;       } else if (n >= -2147483648 && n <= 2147483647) {         cout <<  int ;       } else {         cout <<  long ;       }     } else {       cout <<  BigInteger ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int pow1(long long int a, long long int b) {     long long int ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % 1000000007;       a = (a * a) % 1000000007;       b = b >> 1;     }     return ans;   }   int n, m;   pair<int, int> a[100005];   vector<int> v[100005];   bool vis[100005] = {0};   void dfs(int x) {     vis[x] = 1;     for (int i = 0; i < v[x].size(); i++)       if (!vis[v[x][i]]) dfs(v[x][i]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = i + 1;     }     sort(a, a + n);     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     long long int sum = 0;     for (int i = 0; i < n; i++) {       if (!vis[a[i].second]) {         sum += a[i].first;         dfs(a[i].second);       }     }     cout << sum;     return 0;   }