You are given a map of a city's road network. The network consists of intersections and bidirectional streets connecting them. Streets meet only at intersections, but elsewhere they may cross via tunnels or overpasses. Each pair of intersections is joined by at most one street.
At every intersection v there is a police station staffed by p(v) officers. A street joining intersections u and v is safe if the two stations at its ends hold at least b(u,v) officers in total. Initially p(u)+p(v)≥b(u,v) holds for every street.
Because of an ongoing crisis, the mayor has decreed the Minimalist Security Act (MSA):
These rules do not fix the dismissals uniquely. Find the minimum and the maximum possible total number of dismissed officers, that is the sum of z(v) over all intersections, or report that the decree cannot be carried out.
The first line contains two integers n and m (1≤n≤500,000, 0≤m≤3,000,000): the number of intersections and the number of streets. Intersections are numbered from 1 to n.
The second line contains n nonnegative integers p(1),p(2),…,p(n) (0≤p(i)≤106): the number of officers currently at each station.
Each of the next m lines contains three integers ui, vi, b(ui,vi) (1≤ui,vi≤n, ui=vi, 0≤b(ui,vi)≤106): the two intersections joined by the street and the minimum total number of officers required at its ends.
A subset of the tests additionally satisfies n≤2,000 and m≤8,000.
If the decree can be carried out, print one line with two integers separated by a single space: the minimum and the maximum total number of officers that must be dismissed.
If the decree cannot be carried out, print a single line containing the word NIE (Polish for no).