Time is Mooney
Bessie is conducting a business trip in Bovinia, where there are n cities labeled 1 ... n connected by m one-way roads. Every time Bessie visits city i, Bessie earns m[i]
moonies. Starting at city 1 Bessie wants to visit cities to make as much mooney as she can, ending back at city 1. To avoid confusion, m[1]
= 0.
Mooving between two cities via a road takes one day. Preparing for the trip is expensive; it costs c * t^2
moonies to travel for t days.
What is the maximum amount of moonies Bessie can make in one trip? Note that it may be optimal for Bessie to visit no cities aside from city 1, in which case the answer would be zero.
Input
The first line contains three integers n (2 ≤ n ≤ 1000), m (1 ≤ m ≤ 2000) and c (1 ≤ c ≤ 1000). The second line contains the n integers m[1]
, m[2]
,..., m[n]
(0 ≤ m[i]
≤ 1000).
The next m lines each contain two space separated integers a and b (a ≠ b) denoting a one-way road from city a to city b.
Output
Print the maximum amount of moonies Bessie can make in one trip.
Example
The optimal trip is 1 → 2 → 3 → 1 → 2 → 3 → 1. Bessie can get 10 + 20 + 10 + 20 − 1 * 36 = 24 moonies.