# Maximum flow and matchings

# Airports

An airline company offers flights out of **n** airports, conveniently labeled from **1** to **n**. The flight
time `t`

from airport _{ij}**i** to airport **j** is known for every **i** and **j**. It may be the case that `t`

≠ _{ij}`t`

, due to things like wind or geography. Upon landing at a given airport, a plane must be inspected before it can be own again. This inspection time _{ji}`p`

is dependent only on the airport at which the inspection is taking place and not where the previous flight may have originated._{i}

Given a set of m flights that the airline company must provide, determine the minimum number of planes that the company needs to purchase. The airline may add unscheduled flights to move the airplanes around if that would reduce the total number of planes needed.

#### Input

The first line contains two space-separated integers **n** and **m** (**1** ≤ **n**, **m** ≤ **500**). The next line contains **n** space-separated integers `p`

, ..., _{1}`p`

(_{n}**0** ≤ `p`

≤ _{i}`10`

).^{6}

Each of the next **n** lines contains **n** space-separated integers. The **j**-th integer in line **i** + **2** is `t`

(_{ij}**0** ≤ `t`

≤ _{ij}`10`

). It is guaranteed that ^{6}`t`

= _{ii}**0** for all **i**. However, it may be the case that `t`

≠ _{ij}`t`

when _{ji}**i** ≠ **j**.

Each of the next **m** lines contains three space-separated integers `s`

, _{i}`f`

and _{i}`t`

(_{i}**1** ≤ `s`

, _{i}`f`

≤ _{i}**n**, `s`

≠ _{i}`f`

, _{i}**1** ≤ `t`

≤ _{i}`10`

), indicating that the airline company must provide a flight that flies out from airport ^{6}`s`

at exactly time _{i}`t`

, heading directly to airport _{i}`f`

._{i}

#### Output

Print, on a single line, a single integer indicating the minimum number of planes the airline company must purchase in order to provide the **m** requested flights.

2 2 1 1 0 1 1 0 1 2 1 2 1 1

2

2 2 1 1 0 1 1 0 1 2 1 2 1 3

1

5 5 72 54 71 94 23 0 443 912 226 714 18 0 776 347 810 707 60 0 48 923 933 373 881 0 329 39 511 151 364 0 4 2 174 2 1 583 4 3 151 1 4 841 4 3 993

3