func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, m, s, t, g;   int dl[200009], head, last, q[20009];   int dep[20010];   int h[20010], top = 1;   struct edge {     int to, net;     long long w;   } es[200009];   void add(int u, int v, long long w) {     top++;     es[top].w = w;     es[top].net = h[u];     h[u] = top;     es[top].to = v;     return;   }   inline int read() {     int sum = 0, fh = 1;     char c = getchar();     while (c >  9  || c <  0 ) {       if (c ==  - ) fh = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       sum *= 10;       sum += c -  0 ;       c = getchar();     }     return sum * fh;   }   bool bfs() {     for (int i = 1; i <= t; i++) dep[i] = 0;     head = 1;     last = 1;     dl[1] = s;     dep[s] = 1;     while (head <= last) {       int u = dl[head];       head++;       for (int i = h[u]; i; i = es[i].net) {         if (dep[es[i].to] == 0 && es[i].w) {           dep[es[i].to] = dep[u] + 1;           last++;           dl[last] = es[i].to;         }       }     }     return dep[t];   }   long long ans = 0, ssm = 0;   long long dfs(int now, long long zg) {     if (now == t) {       return zg;     }     long long sum = 0;     for (int i = h[now]; i; i = es[i].net) {       int v = es[i].to;       if (dep[v] == dep[now] + 1 && es[i].w) {         long long res = dfs(v, min(es[i].w, zg));         sum += res;         zg -= res;         es[i].w -= res;         es[i ^ 1].w += res;       }     }     if (sum == 0) dep[now] = 0;     return sum;   }   int main() {     n = read();     m = read();     g = read();     s = 0;     t = n + m + 2;     for (int i = 1; i <= n; i++) q[i] = read();     for (int i = 1; i <= n; i++) {       int x = read();       if (q[i] == 0)         add(s, i, x), add(i, s, 0);       else         add(i, t, x), add(t, i, 0);     }     for (int i = 1; i <= m; i++) {       int opt = read(), w = read(), k = read();       ssm += w;       for (int j = 1; j <= k; j++) {         int x = read();         if (opt == 0) {           add(n + i, x, 1e18);           add(x, n + i, 0);         } else {           add(x, n + i, 1e18);           add(n + i, x, 0);         }       }       int gt = read();       if (opt == 0) {         add(s, n + i, w + g * gt);         add(n + i, s, 0);       } else {         add(n + i, t, w + g * gt);         add(t, n + i, 0);       }     }     while (bfs()) {       ans += dfs(s, 1e18);     }     cout << ssm - ans;     return 0;   }   