malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long k = 1000003;   long long exp(long long p, long long q) {     if (q == 1) return (long long)p;     if (q == 0) return 1;     long long temp = (long long)(exp(p, q / 2) % k);     if (q % 2 == 0) {       return (long long)((temp) * (temp)) % k;     } else {       return (long long)((((temp) * (temp)) * p) % k);     }   }   int main() {     string str;     getline(cin, str);     int bin[str.size() + 1];     bin[0] = 0;     for (int i = 0; i < str.size(); i++) {       int k = (int)str[i];       int val = 0;       long long bina = 0;       while (k > 0) {         bina += k % 2;         k /= 2;         bina *= (long long)10;       }       int count = 0;       int u = log10(bina);       if ((int)str[i] < 64) bina *= 10;       while (bina > 0) {         long long t = bina % 10;         val += t * pow((double)2, count);         bina /= 10;         count++;       }       int prev = bin[i];       int s = bin[i] - val;       bin[i + 1] = val;       while (s < 0) s += 256;       cout << s << endl;     }     return 0;   }
//#include  bits/stdc++.h       #define _USE_MATH_DEFINES   #include<cstdio>   #include <cstring>   #include <cmath>   #include <cstdlib>   #include <deque>   #include <algorithm>   #include <functional>   #include <iostream>   #include <list>   #include <map>   #include <array>   #include <unordered_map>   #include<unordered_set>   #include <numeric>   #include <queue>   #include <set>   #include <sstream>   #include <stack>   #include <string>   #include <utility>   #include <vector>   #include <iterator>   #include<iomanip>   #include<complex>   #include<fstream>   #include<assert.h>      #include<stdio.h>      using namespace std;      #define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)   #define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)   #define all(c) begin(c),end(c)      #define int ll   #define SZ(x) ((int)(x).size())   #define pb push_back   #define mp make_pair      //typedef unsigned long long ull;   typedef long long ll;   typedef pair<int, int> pii;   typedef pair<ll, ll> pll;   typedef pair<ll, int> pli;   typedef pair<int, double> pid;   typedef pair<double, int> pdi;   typedef pair<double, double> pdd;   typedef vector< vector<int> > mat;      template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }   template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }      const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;   const int MOD = (int)1e9 + 7;      const double EPS = 1e-9;      signed main()   {    cin.tie(0);    ios::sync_with_stdio(false);       int N, K, Q;    cin >> N >> K >> Q;       vector<int> A(N);    rep(i, 0, N)cin >> A[i];       vector<vector<int>> WAY(N, vector<int>(K + 1, 0));    vector<vector<int>> DP(N, vector<int>(K + 1, 0));    rep(i, 0, N)DP[i][K] = 1;    rep(i, 0, N)WAY[i][0] = 1;       rrep(k, 1, K + 1)    {     rep(i, 0, N)     {      if (0 < i)      {       DP[i - 1][k - 1] += DP[i][k];       DP[i - 1][k - 1] %= MOD;      }      if (i < N - 1)      {       DP[i + 1][k - 1] += DP[i][k];       DP[i + 1][k - 1] %= MOD;      }     }    }    rep(k, 0, K)    {     rep(i, 0, N)     {      if (0 < i)      {       WAY[i - 1][k + 1] += WAY[i][k];       WAY[i - 1][k + 1] %= MOD;      }      if (i < N - 1)      {       WAY[i + 1][k + 1] += WAY[i][k];       WAY[i + 1][k + 1] %= MOD;      }     }    }       vector<int> CNT(N,0);       int ans = 0;    rep(i, 0, N)    {     rep(k, 0, K + 1)     {      CNT[i] += (DP[i][k] * WAY[i][k]) % MOD;      CNT[i] %= MOD;     }     ans += (CNT[i] * A[i])%MOD;     ans %= MOD;    }       int x, y;    rep(i, 0, Q)    {     cin >> x >> y;     x--;     ans = (ans - ((CNT[x] * A[x]) % MOD) + MOD) % MOD;     A[x] = y;     ans = (ans + ((CNT[x] * A[x]) % MOD)) % MOD;     cout << ans << endl;    }       return 0;   }
#include <cstdio>   #include <iostream>   #include <cstring>   #include <queue>   using namespace std;   const int M = 2005;   const int inf = 0x3f3f3f3f;   #define int long long   int read()   {    int x=0,f=1;char c;    while((c=getchar())< 0  || c> 9 ) {if(c== - ) f=-1;}    while(c>= 0  && c<= 9 ) {x=(x<<3)+(x<<1)+(c^48);c=getchar();}    return x*f;   }   int n,m,k,t,mx,a[M],b[M],d[M],del[M];   int tot,S,T,f[M],dis[M],dp[55][55],pre[55][55];   struct edge   {    int v,c,next;   }e[2*M];   void add(int u,int v,int c)   {    e[++tot]=edge{v,c,f[u]},f[u]=tot;    e[++tot]=edge{u,0,f[v]},f[v]=tot;   }   int bfs()   {    for(int i=S;i<=T;i++) dis[i]=0;    queue<int> q;    q.push(S);dis[S]=1;    while(!q.empty())    {     int u=q.front();q.pop();     if(u==T) return 1;     for(int i=f[u];i;i=e[i].next)     {      int v=e[i].v;      if(e[i].c>0 && !dis[v])      {       dis[v]=dis[u]+1;       q.push(v);      }     }    }    return 0;   }   int dfs(int u,int ept)   {    if(u==T) return ept;    int flow=0,tmp=0;    for(int i=f[u];i;i=e[i].next)    {     int v=e[i].v;     if(e[i].c>0 && dis[v]==dis[u]+1)     {      tmp=dfs(v,min(e[i].c,ept));      if(!tmp) continue;      ept-=tmp;      e[i].c-=tmp;      e[i^1].c+=tmp;      flow+=tmp;      if(!ept) break;     }    }    return flow;   }   int get()   {    S=0;T=2*n+1;tot=1;    for(int i=S;i<=T;i++) f[i]=0;    for(int i=1;i<=m;i++)    {     int u=a[i],v=b[i];     add(u+n,v,1);//x is in / x+n is out;    }    for(int i=1;i<=n;i++)       {           if(!del[i+n]) add(S,i+n,1);           if(!del[i]) add(i,T,1);       }    int res=0;    while(bfs()) res+=dfs(S,inf);    return res;   }   void print(int x,int y)   {    if(!x) return ;    print(x-1,pre[x][y]);    for(int i=pre[x][y]+1;i<=y;i++)    {     if(d[i]>n) printf( %lld  ,d[i]-n);     else printf( %lld  ,-d[i]);    }    printf( 0  );   }   signed main()   {    n=read();m=read();k=read();    for(int i=1;i<=m;i++)     a[i]=read(),b[i]=read();    mx=get();    for(int i=1;i<=mx;i++)     for(int j=1;j<=2*n;j++)      if(!del[j])      {       del[j]=1;       if(get()==mx-i)//we can delete j to reduce the maxmatch       {        d[++t]=j;        break;       }       del[j]=0;      }    memset(dp,-0x3f,sizeof dp);    dp[0][0]=0;    for(int i=1;i<=k;i++)    {     int x=read(),y=read();     for(int j=0;j<=t;j++)     {      if(i-j>=n-mx) continue;//illegal      for(int k=0;k<=j;k++)//we choose k now       if(dp[i][j]<dp[i-1][j-k]+max(0ll,x-k*y))       {        dp[i][j]=dp[i-1][j-k]+max(0ll,x-k*y);        pre[i][j]=j-k;       }     }    }    int p=0;    for(int i=0;i<=t;i++)     if(dp[k][i]>dp[k][p])      p=i;    printf( %lld n ,k+p);    print(k,p);   }
#include <bits/stdc++.h>   using namespace std;   long long int n, m, modu = 1e9 + 7, prod = 1, sum = 0;   long long int power(long long int x, long long int y) {     if (y == 0) return 1;     if (y & 1) return (x * power((x * x) % modu, y >> 1)) % modu;     return power((x * x) % modu, y >> 1);   }   long long int combine(long long int n, long long int r) {     long long int p1 = 1, p2 = 1;     for (int i = 1; i <= n; i++) p1 = (p1 * i) % modu;     for (int i = 1; i <= r; i++) p2 = (p2 * i) % modu;     for (int i = 1; i <= (n - r); i++) p2 = (p2 * i) % modu;     return (p1 * (power(p2, modu - 2))) % modu;   }   int main() {     cin >> n >> m;     int prev = 0;     vector<int> aa;     for (int i = 0; i < m; i++) {       long long int x;       cin >> x;       aa.push_back(x);     }     sort(aa.begin(), aa.end());     for (int i = 0; i < m; i++) {       long long int a = aa[i];       long long int c = a;       a = a - prev - 1;       if (a > 0) {         sum += a;         if (i > 0 && i <= m - 1) prod = (prod * power(2, a - 1)) % modu;         prod = (prod * combine(sum, a)) % modu;       }       prev = c;     }     if (n - prev > 0) {       sum += (n - prev);       prod = (prod * (combine(sum, n - prev))) % modu;     }     cout << prod << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int mxN = 1000000;   int a[mxN];   void solve() {     int n, k;     cin >> n >> k;     int idx = ceil((double)n / 2);     int sub = (n - idx) + 1;     for (int i = 0; i < n * k; i++) {       cin >> a[i];     }     long long ans = 0, cnt = 0;     for (int i = n * k - sub; cnt < k; i -= sub) {       ans += a[i];       cnt++;     }     cout << ans <<   n ;   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + (c ^ 48);       c = getchar();     }     return f == 1 ? x : -x;   }   inline void print(int x) {     if (x < 0) putchar( - ), x = ~x + 1;     if (x >= 10) print(x / 10);     putchar((x % 10) | 48);   }   int n;   int c, d;   long long ans;   int t[100010];   char tp[100010];   int main() {     n = read();     c = read(), d = read();     for (int i = 1; i <= n; ++i) {       t[i] = read();       char c = getchar();       while (c !=  P  && c !=  W ) c = getchar();       tp[i] = c;     }     t[n + 1] = read();     tp[n + 1] =  A ;     ans = 1ll * d * n;     long long sum = 0;     int last = t[n + 1];     for (int i = n; i >= 1; --i) {       ans = min(ans, 1ll * c * (t[n + 1] - t[i]) + sum + 1ll * d * (i - 1));       if (tp[i - 1] == tp[i]) {         sum += min(d, c * (last - t[i]));       } else {         last = t[i];       }     }     printf( %lld n , ans);   }
#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast,no-stack-protector )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   template <typename T>   void read(T &a) {     T x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + (ch ^ 48);       ch = getchar();     }     a = x * f;   }   template <typename T>   void print(T x) {     if (!x) return;     if (x < 0) putchar( - ), x = -x;     print(x / 10);     putchar(x % 10 +  0 );   }   template <typename T, typename... Args>   void read(T &t, Args &...args) {     read(t);     read(args...);   }   long long n, a[200005 << 1], res = 0, las[200005 << 1];   map<long long, long long> mp;   signed main() {     read(n);     for (long long i = 1; i <= n; i++) read(a[i]), mp[a[i]]++;     long long maxid, maxx = -1;     for (map<long long, long long>::iterator it = mp.begin(); it != mp.end();          it++) {       if (maxx < it->second) {         maxx = it->second;         maxid = it->first;       }     }     for (map<long long, long long>::iterator it = mp.begin(); it != mp.end();          it++) {       if (it->first == maxid) continue;       long long sum = n;       memset(las, -1, sizeof(las));       las[n] = 0;       for (long long i = 1; i <= n; i++) {         if (a[i] == it->first) sum--;         if (a[i] == maxid) sum++;         if (las[sum] != -1)           res = max(res, i - las[sum]);         else           las[sum] = i;       }     }     printf( %lld n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   int a[MAXN], b[MAXN], pos[MAXN];   map<int, int> zoom;   bool vis[MAXN];   int main() {     ios::sync_with_stdio(false);     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       b[i] = a[i];     }     sort(b + 1, b + 1 + n);     for (int i = 1; i <= n; i++) {       zoom[b[i]] = i;       b[i] = i;     }     for (int i = 1; i <= n; i++) {       a[i] = zoom[a[i]];       pos[a[i]] = i;     }     vector<vector<int>> res;     for (int i = 1; i <= n; i++) {       if (!vis[pos[i]]) {         vector<int> cur;         for (int j = pos[i]; !vis[j]; j = pos[j]) {           cur.push_back(j);           vis[j] = true;         }         res.push_back(cur);       }     }     cout << res.size() <<   n ;     for (auto v : res) {       cout << v.size() <<    ;       for (auto x : v) {         cout << x <<    ;       }       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     double n;     long int sum = 0;     for (int i = 0; i < q; i++) {       cin >> n;       long long int a;       for (int j = 0; j < n; j++) {         cin >> a;         sum += a;       }       cout << fixed << setprecision(0) << ceill((sum / n)) << endl;       sum = 0;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5, MOD = 1e9 + 7;   long long k, p, q;   string ans;   set<long long> s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> k;     if (k < 25) {       cout << -1 << endl;       return 0;     }     char str[5] = { a ,  e ,  i ,  o ,  u };     for (long long i = 1; i * i <= k; i++) {       if (k % i == 0) {         if (i >= 5 && k / i >= 5) {           p = i;           q = k / i;           break;         }       }     }     if (p == 0 && q == 0) {       cout << -1 << endl;       return 0;     }     for (long long i = 0; i < p; i++) {       for (long long j = 0; j < q; j++) cout << str[(i + j) % 5];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     long long a[100];     long long b[100];     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= m; i++) cin >> b[i];     long long ans = 1000000000000000000LL;     for (int i = 1; i <= n; i++) {       long long mn = -1000000000000000000LL;       for (int j = 1; j <= m; j++)         for (int k = 1; k <= n; k++) {           if (k == i) continue;           mn = max(mn, a[k] * b[j]);         }       ans = min(ans, mn);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   using ull = unsigned long long;   using ll = long long;   using ld = long double;   const int mod = 1e9 + 7;   const int inf = INT_MAX;   vector<string> l = { x^y^z ,  x^z^y ,  (x^y)^z ,  (x^z)^y ,                        y^x^z ,  y^z^x ,  (y^x)^z ,  (y^z)^x ,                        z^x^y ,  z^y^x ,  (z^x)^y ,  (z^y)^x };   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     ld x, y, z;     cin >> x >> y >> z;     if (x < 1 and y < 1 and z < 1) {       ld ans = pow(x, pow(y, z));       int cur = 0;       if (pow(x, pow(z, y)) > ans) {         ans = pow(x, pow(z, y));         cur = 1;       }       if (pow(x, y * z) > ans) {         ans = pow(x, y * z);         cur = 2;       }       if (pow(y, pow(x, z)) > ans) {         ans = pow(y, pow(x, z));         cur = 4;       }       if (pow(y, pow(z, x)) > ans) {         ans = pow(y, pow(z, x));         cur = 5;       }       if (pow(y, x * z) > ans) {         ans = pow(y, x * z);         cur = 6;       }       if (pow(z, pow(x, y)) > ans) {         ans = pow(z, pow(x, y));         cur = 8;       }       if (pow(z, pow(y, x)) > ans) {         ans = pow(z, pow(y, x));         cur = 9;       }       if (pow(z, x * y) > ans) {         ans = pow(z, x * y);         cur = 10;       }       cout << l[cur] <<   n ;       return 0;     }     ld ans = 0;     int cur = 0;     if (x < 1)       ans = -1e18;     else if (x == 1)       ans = -1000;     else       ans = z * log(y) + log(log(x));     if (x > 1 and y * log(z) + log(log(x)) > ans) {       ans = y * log(z) + log(log(x));       cur = 1;     }     if (x > 1 and log(y) + log(z) + log(log(x)) > ans) {       ans = log(y) + log(z) + log(log(x));       cur = 2;     }     if (y == 1 and ans < -1000) {       ans = -1000;       cur = 4;     }     if (y > 1 and z * log(x) + log(log(y)) > ans) {       ans = z * log(x) + log(log(y));       cur = 4;     }     if (y > 1 and x * log(z) + log(log(y)) > ans) {       ans = x * log(z) + log(log(y));       cur = 5;     }     if (y > 1 and log(x) + log(z) + log(log(y)) > ans) {       ans = log(x) + log(z) + log(log(y));       cur = 6;     }     if (z == 1 and ans < -1000) {       ans = -1000;       cur = 8;     }     if (z > 1 and y * log(x) + log(log(z)) > ans) {       ans = y * log(x) + log(log(z));       cur = 8;     }     if (z > 1 and x * log(y) + log(log(z)) > ans) {       ans = x * log(y) + log(log(z));       cur = 9;     }     if (z > 1 and log(x) + log(y) + log(log(z)) > ans) {       ans = log(x) + log(y) + log(log(z));       cur = 10;     }     cout << l[cur];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t, n;     string s;     cin >> t;     while (t--) {       cin >> n >> s;       long long ans = 0, o = 0, ans1 = 0;       for (long long i = 0; i < n; i++) {         if ((s[i] - 48) % 2 == 1) {           ans = (ans * 10) + (s[i] - 48);           ans1 += ans;           if (ans1 % 2 == 0) {             o = 1;             break;           }         }       }       if (o == 0)         cout << -1 <<   n ;       else         cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j, pos, num[100005];     cin >> n;     for (i = 1; i <= n; i++) scanf( %d , &num[i]);     pos = upper_bound(num + 1, num + 1 + n, 5e5) - num;     if (pos > n)       cout << num[n] - 1 << endl;     else if (pos <= 1)       cout << 1e6 - num[1] << endl;     else {       cout << max((int)1e6 - num[pos], num[pos - 1] - 1) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int suspect[100000];   int justify[100000];   bool killer[100000];   pair<int, int> a[100000];   int main() {     int n, m;     scanf( %d%d , &n, &m);     int cnt = 0;     for (int i = 0; i < n; i++) {       killer[i] = false;       char x;       int k;       scanf( %d , &k);       if (k < 0) {         x =  - ;         k *= -1;       } else         x =  + ;       k--;       if (x ==  + ) {         suspect[k]++;         a[i].second = 1;       } else {         a[i].second = 0;         justify[k]++;         cnt++;       }       a[i].first = k;     }     int cntkiller = 0;     for (int i = 0; i < n; i++)       if (suspect[i] + cnt - justify[i] == m) {         killer[i] = true;         cntkiller++;       }     for (int i = 0; i < n; i++) {       if (a[i].second == 1 && killer[a[i].first] && cntkiller == 1)         printf( Truth n );       else if (a[i].second == 0 && killer[a[i].first] && cntkiller == 1)         printf( Lie n );       else if (a[i].second == 1 && killer[a[i].first])         printf( Not defined n );       else if (a[i].second == 1 && !killer[a[i].first])         printf( Lie n );       else if (a[i].second == 0 && !killer[a[i].first])         printf( Truth n );       else         printf( Not defined n );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i, j, k, l, a, b, c, d, m, s, f;     cin >> n >> m;     c = 0;     for (i = 1; i <= n; i++) {       c++;       if (i % m == 0) {         n++;       }     }     cout << c << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int Dx[] = {1, -1, 0, 0};   int Dy[] = {0, 0, 1, -1};   double x, y, n, mn = 10000000.0, a, b, i;   bool ok(int m) {     if (x * i > m * y) return 1;     return 0;   }   int main() {     cin >> x >> y >> n;     for (i = 1; i <= n; i++) {       int s = 0, e = 1e9;       while (s < e) {         int m = (e + s + 1) / 2;         if (ok(m))           s = m;         else           e = m - 1;       }       double z = abs(x / y - s / i), zz = abs((s + 1) / i - x / y);       if (z < mn)         mn = z, a = s, b = i;       else if (z == mn && s < a)         a = s;       if (zz < mn)         mn = zz, a = s + 1, b = i;       else if (zz == mn && s + 1 < a)         a = s + 1;     }     cout << a <<  /  << b << endl;     ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100100;   vector<int> v;   struct mmp {     int to, next, len;     mmp() {}     mmp(int a, int b, int c) { to = a, next = b, len = c; }   } e[maxn << 1];   int vis[maxn], st, ed, cnt, head[maxn], val[maxn], len;   void add(int u, int v, int len) {     e[++cnt] = mmp(v, head[u], len);     head[u] = cnt;   }   void add(int x) {     for (int i = 0; i < (int)v.size(); i++) {       x = min(x, x ^ v[i]);     }     if (x) v.push_back(x);   }   void dfs(int x, int now) {     vis[x] = 1;     for (int i = head[x]; i; i = e[i].next) {       int to = e[i].to;       if (vis[to])         add(val[to] ^ now ^ e[i].len);       else {         val[to] = now ^ e[i].len;         dfs(to, val[to]);       }     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d%d%d , &st, &ed, &len);       add(st, ed, len);       add(ed, st, len);     }     dfs(1, 0);     for (int i = 0; (int)i < v.size(); i++) {       val[n] = min(val[n], val[n] ^ v[i]);     }     return 0 * printf( %d , val[n]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, b;     cin >> n >> b;     vector<int> arr(n);     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     vector<int> s;     for (int i = 0; i < n - 1; i++) {       if (arr[i] <= b) {         int m = INT_MIN;         for (int j = i + 1; j < n; j++) m = max(m, arr[j]);         if (arr[i] < m) s.push_back(b + (m - arr[i]) * (b / arr[i]));       }     }     if (!s.empty())       cout << *max_element(s.begin(), s.end()) << endl;     else       cout << b << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int NMAX = 1000 + 5;   int n, m, W;   int w[NMAX];   int b[NMAX];   vector<int> graph[NMAX];   int comp[NMAX];   void dfs(int node, int cmp) {     comp[node] = cmp;     for (auto it : graph[node])       if (!comp[it]) dfs(it, cmp);   }   vector<pair<int, int> > groups[NMAX];   int dp[NMAX][NMAX];   int main() {     cin >> n >> m >> W;     for (int i = 1; i <= n; ++i) cin >> w[i];     for (int i = 1; i <= n; ++i) cin >> b[i];     for (int i = 1; i <= m; ++i) {       int a, b;       cin >> a >> b;       graph[a].push_back(b);       graph[b].push_back(a);     }     int cmp = 0;     for (int i = 1; i <= n; ++i)       if (!comp[i]) dfs(i, ++cmp);     for (int i = 1; i <= n; ++i) groups[comp[i]].push_back(make_pair(w[i], b[i]));     for (int i = 1; i <= cmp; ++i) {       int sumW = 0;       int sumB = 0;       for (auto it : groups[i]) {         sumW += it.first;         sumB += it.second;       }       groups[i].push_back(make_pair(sumW, sumB));     }     for (int i = 1; i <= cmp; ++i) {       for (int j = 1; j <= W; ++j) {         dp[i][j] = dp[i - 1][j];         for (auto it : groups[i])           if (j - it.first >= 0)             dp[i][j] = max(dp[i][j], dp[i - 1][j - it.first] + it.second);       }     }     cout << dp[cmp][W] <<   n ;     return 0;   }