Comparing Answers

Time limit10sMemory limit128 MB

Problem

In a place in Southwestern Europe, the name of which I do not wish to recall, not long ago there were $n$ cities connected by one-way roads, possibly with more than one road connecting a city to another, or even a road from a city to itself. As a homework assignment for your geography class, you need to compute the number of paths of length exactly two between each ordered pair of cities. However, you have been too busy celebrating the Spanish victory in the World Cup, so now you are copying the answers from your friend. Before handing in your homework, you would like to make sure his answers are correct.

Input

The input consists of several test cases, separated by single blank lines. Each test case begins with a line containing the integer $n$ ($1 \le n \le 1000$). The following $n$ lines contain $n$ elements each; element $j$ of line $i$ is the number of roads from city $i$ to city $j$ (an integer between $0$ and $10$, inclusive). After that come $n$ more lines, again with $n$ elements each; element $j$ of line $i$ is your friend's answer for the number of length-2 paths from city $i$ to city $j$, an integer between $0$ and $100000$, inclusive.

The test cases finish with a line containing only the number zero (also preceded by a blank line).

Note: the input file is large; use fast I/O routines.

Output

For each test case, output a single line. The line should contain YES if your friend's answers for that assignment are all correct, and NO otherwise.