Airports#8181

Airports

1 secondo
128 megabyte
Molto facile

An airline operates flights between airports, numbered from to . For every pair of airports and , the flight time t_{ij} from to is known. In general, t_{ij} \ne t_{ji} due to wind conditions or geographical factors.

After arriving at an airport, an aircraft must undergo a technical inspection before it can depart again. The inspection time is p_i and depends only on the airport where it takes place.

There are required flights. Determine the minimum number of aircraft the airline needs to perform all of them. The airline is allowed to operate additional (non-scheduled) empty flights to reposition aircraft if this reduces the total number of aircraft required.

Input

The first line contains two integers and m~(1 \le n, m \le 500).

The second line contains integers p_1, p_2, \dots, p_n~(0 \le p_i \le 10^6).

The next lines each contain integers. The -th number in the -th line represents t_{ij}~(0 \le t_{ij} \le 10^6). It is guaranteed that t_{ii} = 0 for all . For i \ne j, it is possible that t_{ij} \ne t_{ji}.

The following lines each contain three integers s_i, f_i and t_i~(1 \le s_i, f_i \le n, s_i \ne f_i, 1 \le t_i \le 10^6). This means that the airline must operate a flight from airport s_i to airport f_i with an exact departure time t_i.

Output

Output the minimum number of aircraft required for the airline to perform all given flights.

Esempi

Esempio 1

Loading
Loading

Esempio 2

Loading
Loading

Esempio 3

Loading
Loading