#define _CRT_SECURE_NO_WARNINGS // preprocessor property for Visual Studio
#include <stdio.h>
using namespace std;
inline void array_input(int **&arr, int &n) {
for (int i = 0; i < n; ++i) {
arr[i] = new int[n];
for (int j = 0; j < n; ++j) {
scanf("%d", &arr[i][j]);
}
}
}
inline void array_delete(int **&arr, int &n) {
for (int i = 0; i < n; ++i) {
delete[]arr[i];
}
delete[]arr;
}
int main()
{
int n; // processing 1 testcase at a time
while (scanf("%d", &n) && n) {
int **number_of_roads = new int *[n];
array_input(number_of_roads, n);
int **friend_answers = new int *[n];
array_input(friend_answers, n);
int correct_answer;
bool is_correct = true;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n && is_correct; ++j) { // stop calculation when error detected
correct_answer = 0;
for (int k = 0; k < n; ++k) {
correct_answer += number_of_roads[i][k] * number_of_roads[k][j];
}
if (friend_answers[i][j] != correct_answer) {
is_correct = false;
}
}
}
printf(is_correct ? "YES\n" : "NO\n");
array_delete(number_of_roads, n);
array_delete(friend_answers, n);
}
return 0;
}
I2RlZmluZSBfQ1JUX1NFQ1VSRV9OT19XQVJOSU5HUyAvLyBwcmVwcm9jZXNzb3IgcHJvcGVydHkgZm9yIFZpc3VhbCBTdHVkaW8KI2luY2x1ZGUgPHN0ZGlvLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbmxpbmUgdm9pZCBhcnJheV9pbnB1dChpbnQgKiomYXJyLCBpbnQgJm4pIHsKCWZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKSB7CgkJYXJyW2ldID0gbmV3IGludFtuXTsKCQlmb3IgKGludCBqID0gMDsgaiA8IG47ICsraikgewoJCQlzY2FuZigiJWQiLCAmYXJyW2ldW2pdKTsKCQl9Cgl9Cn0KCmlubGluZSB2b2lkIGFycmF5X2RlbGV0ZShpbnQgKiomYXJyLCBpbnQgJm4pIHsKCWZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKSB7CgkJZGVsZXRlW11hcnJbaV07Cgl9CglkZWxldGVb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