Cooking

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

Stephen and Sergey are enrolled at the university and live on campus. So now they need to learn to cook. 

The friends have learned to cook nn different dishes. After buying all the necessary food, the guys have decided that before they go shopping next time, they will cook the ii-th dish exactly a_ia\_i times. 

Each day Sergey and Stephen choose two dishes ii and jj and cook them, cooking takes c_i,jc\_{i, j} units of time. It's possible that i=ji=j, that means that the ii-th dish is cooked twice on that day.

The guys are quite lazy, so they want to minimize the total cooking time for all the days before the next shopping. Help them to do it!

입력

The first line contains a single integer nn (1n101 \le n \le 10) --- the number of dishes that the guys can cook. 

The second line contains nn positive integers a_1,a_2,,a_na\_1, a\_2, \ldots, a\_n (1a_i501 \leq a\_i \leq 50) --- the number of times it must be cooked for each dish.

The next nn lines contain nn space separated integers c_i,jc\_{i, j} (1c_i,j1001 \le c\_{i, j} \le 100), the jj-th number in the ii-th line denotes cooking time of pair of dishes ii and jj. It is guaranteed that c_i,j=c_j,ic\_{i, j}=c\_{j, i}.

출력

Print one integer: the minimum total time of cooking, or 1-1, if it is impossible to make a cooking plan such that the ii-th dish is cooked exactly a_ia\_i times.

힌트

In the first test case it is optimal to cook the following pairs of dishes: (1,3)(1, 3), (1,3)(1, 3), (2,2)(2, 2).