Let's solve the puzzle by programming.

The numbers n x n are arranged in a grid pattern. Some of the numbers are circled and we will call them the starting point. The rules of the puzzle are as follows:

* Draw one line that goes vertically and horizontally from each starting point (cannot be drawn diagonally).
* Extend the line so that the sum of the numbers passed is the same as the starting number.
* The line must not be branched.
* Lines cannot pass through numbers already drawn (lines must not intersect).
* A line cannot pass through more than one origin.



As shown in the figure below, the goal of the puzzle is to use all the starting points and draw lines on all the numbers.


<image>


Your job is to create a puzzle-solving program. However, in this problem, it is only necessary to determine whether the given puzzle can be solved.



Input

The input consists of multiple datasets. The format of each dataset is as follows:


n
n x n numbers


Indicates a puzzle given a number of n x n, the starting number is given as a negative number.

When n is 0, it indicates the end of input.

It can be assumed that n is 3 or more and 8 or less, numbers other than the starting point are 1 or more and 50 or less, and the starting point is -50 or more and -1 or less. You may also assume the following as the nature of the puzzle being entered:

* Each row and column of a given puzzle has at least one starting point.
* The number of starting points is about 20% to 40% of the total number of numbers (n x n).

Output

For each dataset, print "YES" if the puzzle can be solved, otherwise "NO" on one line.

Example

Input

3
-3 1 1
2 -4 1
2 1 -1
3
-4 1 1
1 1 -6
1 -5 3
4
-8 6 -2 1
2 -7 -2 1
1 -1 1 1
1 1 1 -5
6
2 2 3 -7 3 2
1 -10 1 1 3 2
2 6 5 2 -6 1
3 4 -23 2 2 5
3 3 -6 2 3 7
-7 2 3 2 -5 -13
6
2 2 3 -7 3 2
1 -10 1 1 3 2
2 6 5 2 -6 1
3 4 -23 2 2 5
3 3 -6 2 3 7
-7 2 3 2 -5 -12
0


Output

YES
NO
NO
YES
NO
#include <iostream>
using namespace std;

int n;
int data[8][8];
bool flag;
struct A{
  bool visited[8][8];
};

void rec(A);
void rec2(int, int, int, int, A);

void print(A a) {
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      if(a.visited[i][j]) cout << '#';
      else cout << ' ';
    }
    cout << endl;
  }
  cout << endl;
}

void rec(A a) {
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      if(!a.visited[i][j] && data[i][j] < 0) {
	a.visited[i][j] = true;
	rec2(j, i, -data[i][j], 0, a);
	return;
      }
    }
  }
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      if(!a.visited[i][j]) return;
    }
  }
  flag = true;
}

void rec2(int x, int y, int cost, int sum, A a) {
  static int d[4][2] = {{1,0}, {0,1}, {-1,0}, {0,-1}};
  if(sum == cost) {rec(a);return;}
  if(sum > cost) return;

  for(int i = 0; i < 4; i++) {
    int nx = x + d[i][0];
    int ny = y + d[i][1];
    if(nx < 0 || nx >= n) continue;
    if(ny < 0 || ny >= n) continue;
    if(a.visited[ny][nx]) continue;
    if(data[ny][nx] < 0) continue;

    a.visited[ny][nx] = true;
    rec2(nx, ny, cost, sum+data[ny][nx], a);
    a.visited[ny][nx] = false;
  }
}

int main() {
  while(1) {
    cin >> n;
    if(n == 0) break;
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < n; j++) {
	cin >> data[i][j];
      }
    }
    A a;
    for(int i = 0; i < 8; i++) {
      for(int j = 0; j < 8; j++) {
	a.visited[i][j] = false;
      }
    }
    flag = false;
    rec(a);
    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}