eolymp
bolt
Try our new interface for solving problems
Problems

Frame-workout 2

Frame-workout 2

Find a pair of vertices in a complete undirected weighted graph according to specified criteria.

Input

In the input file is given a number N (from 2 to 100) and the adjacency matrix of a complete undirected weighted graph (complete graph - a graph in which there are edges between all pairs of vertices). All the weights of the edges - natural numbers from 1 to 1000. Further, given N numbers, each of which is either 0 or 1 - it is believed that these numbers are written in the tops. It is guaranteed that at least one 0 and at least one 1.

Output

Locate and bring in the output file are the two vertices that:

  • the first of these is 0
  • the second of which is worth 1
  • weight of the edge between the vertices of the minimum possible.

If several such pairs, display any of them.

Time limit 1 second
Memory limit 64 MiB
Input example #1
3
0 1 2 
1 0 4 
2 4 0
1 0 0
Output example #1
2 1