**4 人解决**，4 人已尝试。

**4 份提交通过**，共有 4 份提交。

**6.1** EMB 奖励。

**单点时限: **1.0 sec

**内存限制: **256 MB

As more and more computers are equipped with dual core CPU, SetagLilb, the Chief Technology Officer of TinySoft Corporation, decided to update their famous product - SWODNIW.

The routine consists of modules, and each of them should run in a certain core. The costs for all the routines to execute on two cores has been estimated. Let’s define them as and . Meanwhile, pairs of modules need to do some data-exchange. If they are running on the same core, then the cost of this action can be ignored. Otherwise, some extra cost are needed. You should arrange wisely to minimize the total cost.

There are two integers in the first line of input data, and .

The next lines, each contains two integer, and .

In the following lines, each contains three integers: . We guarantee no appears twice. The meaning is that if module and module don’t execute on the same core, you should pay extra dollars for the data-exchange between them.

Output only one integer, the minimum total cost.

Input

3 1 1 10 2 10 10 3 2 3 1000

Output

13

**4 人解决**，4 人已尝试。

**4 份提交通过**，共有 4 份提交。

**6.1** EMB 奖励。

题目标签