Just to remind, girls in Arpa's land are really nice.

Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight w_{i} and some beauty b_{i}. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if there is a sequence of Hoses a_1, a_2, ..., a_{k} such that a_{i} and a_{i} + 1 are friends for each 1 ≤ i < k, and a_1 = x and a_{k} = y.

 [Image] 

Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most w weight on it. 

Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than w and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed w.


-----Input-----

The first line contains integers n, m and w (1  ≤  n  ≤  1000, $0 \leq m \leq \operatorname{min}(\frac{n \cdot(n - 1)}{2}, 10^{5})$, 1 ≤ w ≤ 1000) — the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited.

The second line contains n integers w_1, w_2, ..., w_{n} (1 ≤ w_{i} ≤ 1000) — the weights of the Hoses.

The third line contains n integers b_1, b_2, ..., b_{n} (1 ≤ b_{i} ≤ 10^6) — the beauties of the Hoses.

The next m lines contain pairs of friends, the i-th of them contains two integers x_{i} and y_{i} (1 ≤ x_{i}, y_{i} ≤ n, x_{i} ≠ y_{i}), meaning that Hoses x_{i} and y_{i} are friends. Note that friendship is bidirectional. All pairs (x_{i}, y_{i}) are distinct.


-----Output-----

Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed w.


-----Examples-----
Input
3 1 5
3 2 5
2 4 2
1 2

Output
6

Input
4 2 11
2 4 6 6
6 4 2 1
1 2
2 3

Output
7



-----Note-----

In the first sample there are two friendship groups: Hoses {1, 2} and Hos {3}. The best way is to choose all of Hoses in the first group, sum of their weights is equal to 5 and sum of their beauty is 6.

In the second sample there are two friendship groups: Hoses {1, 2, 3} and Hos {4}. Mehrdad can't invite all the Hoses from the first group because their total weight is 12 > 11, thus the best way is to choose the first Hos from the first group and the only one from the second group. The total weight will be 8, and the total beauty will be 7.

Difficulty: competition

Starter code:

Solutions:
f = lambda: map(int, input().split())
n, m, w = f()
wb = [(0, 0)] + list(zip(f(), f()))
t = list(range(n + 1))


def g(x):
    if x == t[x]: return x
    t[x] = g(t[x])
    return t[x]


for i in range(m):
    x, y = f()
    x, y = g(x), g(y)
    if x != y: t[y] = x

p = [[] for j in range(n + 1)]
for i in range(1, n + 1): p[g(i)].append(i)

d = [1] + [0] * w
for q in p:
    if len(q) > 1:
        WB = [wb[i] for i in q]
        SW = sum(q[0] for q in WB)
        SB = sum(q[1] for q in WB)

        for D in range(w, -1, -1):
            if d[D]:
                if D + SW <= w: d[D + SW] = max(d[D + SW], d[D] + SB)
                for W, B in WB:
                    if D + W <= w: d[D + W] = max(d[D + W], d[D] + B)

    elif len(q) == 1:
        W, B = wb[q[0]]
        for D in range(w - W, -1, -1):
            if d[D]: d[D + W] = max(d[D + W], d[D] + B)

print(max(d) - 1)

f = lambda: map(int, input().split())
n, m, s = f()
wb = [(0, 0)] + list(zip(f(), f()))
t = list(range(n + 1))

def g(x):
    if x == t[x]: return x
    t[x] = g(t[x])
    return t[x]

for i in range(m):
    x, y = f()
    x, y = g(x), g(y)
    if x != y: t[y] = x

p = [[] for j in range(n + 1)]
for i in range(1, n + 1): p[g(i)].append(i)

d = [1] + [0] * s
for q in p:
    if len(q) > 1:
        t = [wb[i] for i in q]
        t.append((sum(x[0] for x in t), sum(x[1] for x in t)))
        t.sort(key=lambda x: x[0])

        for j in range(s, -1, -1):
            if d[j]:
                for w, b in t:
                    if j + w > s: break
                    d[j + w] = max(d[j + w], d[j] + b)

    elif len(q) == 1:
        w, b = wb[q[0]]
        for j in range(s - w, -1, -1):
            if d[j]: d[j + w] = max(d[j + w], d[j] + b)

print(max(d) - 1)

f = lambda: list(map(int, input().split()))

n, m, w = f()

wb = [(0, 0)] + list(zip(f(), f()))

t = list(range(n + 1))





def g(x):

    if x == t[x]: return x

    t[x] = g(t[x])

    return t[x]





for i in range(m):

    x, y = f()

    x, y = g(x), g(y)

    if x != y: t[y] = x



p = [[] for j in range(n + 1)]

for i in range(1, n + 1): p[g(i)].append(i)



d = [1] + [0] * w

for q in p:

    if len(q) > 1:

        WB = [wb[i] for i in q]

        SW = sum(q[0] for q in WB)

        SB = sum(q[1] for q in WB)



        for D in range(w, -1, -1):

            if d[D]:

                if D + SW <= w: d[D + SW] = max(d[D + SW], d[D] + SB)

                for W, B in WB:

                    if D + W <= w: d[D + W] = max(d[D + W], d[D] + B)



    elif len(q) == 1:

        W, B = wb[q[0]]

        for D in range(w - W, -1, -1):

            if d[D]: d[D + W] = max(d[D + W], d[D] + B)



print(max(d) - 1)



# Made By Mostafa_Khaled


R = lambda: map(int, input().split())
n, m, w = R()
ws = [0] + list(R())
bs = [0] + list(R())
g = [[] for x in range(n + 1)]
for i in range(m):
    x, y = R()
    g[x].append(y)
    g[y].append(x)
cs = [0] * (n + 1)
cnt = 1
for i in range(1, n + 1):
    if not cs[i]:
        cs[i] = cnt
        q = []
        q.append(i)
        while q:
            nxt = q.pop()
            for x in g[nxt]:
                if not cs[x]:
                    cs[x] = cnt
                    q.append(x)
        cnt += 1
gs = [[] for i in range(cnt)]
for i in range(1, n + 1):
    gs[cs[i]].append(i)
dp = [[0] * (w + 1) for i in range(cnt)]
for i in range(1, cnt):
    tw = sum(ws[k] for k in gs[i])
    tb = sum(bs[k] for k in gs[i])
    for j in range(1, w + 1):
        dp[i][j] = max(dp[i][j], dp[i - 1][j], (dp[i - 1][j - tw] + tb if j >= tw else 0))
        for k in gs[i]:
            dp[i][j] = max(dp[i][j], dp[i - 1][j], (dp[i - 1][j - ws[k]] + bs[k] if j >= ws[k] else 0))
print(dp[-1][w])

R = lambda: map(int, input().split())
n, m, w = R()
ws = list(R())
bs = list(R())
anc = [-1] * n

def get(x):
    if anc[x] < 0:
        return x
    anc[x] = get(anc[x])
    return anc[x]

def join(x1, x2):
    x1, x2 = get(x1), get(x2)
    if x1 != x2:
        anc[x1] = x2

for i in range(m):
    x1, x2 = R()
    join(x1 - 1, x2 - 1)
gs = [list() for i in range(n)]
for i in range(n):
    gs[get(i)].append(i)
gs = [x for x in gs if x]
dp = [[0] * (w + 1) for i in range(len(gs) + 1)]
for i in range(len(gs)):
    tw = sum(ws[k] for k in gs[i])
    tb = sum(bs[k] for k in gs[i])
    for j in range(w + 1):
        dp[i][j] = max(dp[i][j], dp[i - 1][j], (dp[i - 1][j - tw] + tb if j >= tw else 0))
        for k in gs[i]:
            dp[i][j] = max(dp[i][j], dp[i - 1][j], (dp[i - 1][j - ws[k]] + bs[k] if j >= ws[k] else 0))
print(dp[len(gs) - 1][w])

R = lambda: map(int, input().split())
n, m, w = R()
ws = list(R())
bs = list(R())
anc = [-1] * n

def get(x):
    if anc[x] < 0:
        return x
    anc[x] = get(anc[x])
    return anc[x]

def join(x1, x2):
    x1, x2 = get(x1), get(x2)
    if x1 != x2:
        anc[x1] = x2

for i in range(m):
    x1, x2 = R()
    join(x1 - 1, x2 - 1)
gs = [list() for i in range(n)]
for i in range(n):
    gs[get(i)].append(i)
gs = [x for x in gs if x]
dp = [[0] * (w + 1) for i in range(len(gs) + 1)]
for i in range(len(gs)):
    tw = sum(ws[k] for k in gs[i])
    tb = sum(bs[k] for k in gs[i])
    for j in range(w + 1):
        dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - tw] + tb) if j >= tw else dp[i - 1][j]
        for k in gs[i]:
            dp[i][j] = max(dp[i][j], (dp[i - 1][j - ws[k]] + bs[k] if j >= ws[k] else 0))
print(dp[len(gs) - 1][w])

R = lambda: map(int, input().split())
n, m, w = R()
ws = list(R())
bs = list(R())
anc = [-1] * n

def get(x):
    if anc[x] < 0:
        return x
    anc[x] = get(anc[x])
    return anc[x]

def join(x1, x2):
    x1, x2 = get(x1), get(x2)
    if x1 != x2:
        anc[x1] = x2

for i in range(m):
    x1, x2 = R()
    join(x1 - 1, x2 - 1)
gps = [list() for i in range(n)]
for i in range(n):
    gps[get(i)].append(i)
gps = [x for x in gps if x]
dp = [[0] * (w + 1) for i in range(len(gps) + 1)]
for i in range(len(gps)):
    tw = sum(ws[x] for x in gps[i])
    tb = sum(bs[x] for x in gps[i])
    for j in range(w + 1):
        dp[i][j] = max(tb + dp[i - 1][j - tw] if tw <= j else 0, dp[i - 1][j])
        for k in gps[i]:
            dp[i][j] = max(dp[i][j], (dp[i - 1][j - ws[k]] + bs[k] if ws[k] <= j else 0))
print(dp[len(gps) - 1][w])

def inp():
    return [int(x) for x in input().split()]


def dfs(u, adj, visited, s, W, B):
    visited[u] = True
    total_w = W[u]
    total_b = B[u]
    s.append(u)
    for v in adj[u]:
        if not visited[v]:
            w, b = dfs(v, adj, visited, s, W, B)
            total_w += w
            total_b += b
    return total_w, total_b


def main():
    n, m, w = inp()
    W = inp()
    B = inp()
    adj = [[] for _ in range(n)]
    for _ in range(m):
        x, y = inp()
        x -= 1
        y -= 1
        adj[x].append(y)
        adj[y].append(x)
    visited = [False] * n
    f = [0] * (w + 1)
    for i in range(n):
        if visited[i]:
            continue
        s = []
        total_w, total_b = dfs(i, adj, visited, s, W, B)
        for j in range(w, -1, -1):
            jw = j + total_w
            if jw <= w:
                f[jw] = max(f[jw], f[j] + total_b)
            for v in s:
                jw = j + W[v]
                if jw <= w:
                    f[jw] = max(f[jw], f[j] + B[v])
    print(f[w])


def __starting_point():
    main()


__starting_point()