Under construction

Still being built. Things may change

Diagonal Dominance

Time limit2sMemory limit1024 MB

Summary
Given an n by n matrix of nonnegative integers, check whether it is diagonally dominant and count the strictly dominant diagonal elements.
Level

Easy2 of 10

Topics
Matrix, Implementation
Solved
No attempts yet

Problem

Macrohard studies diagonally dominant matrices, which are needed to write their new operating system Doors 8. An n×nn \times n matrix AA is called a diagonally dominant matrix if all three of the following conditions hold:

  1. Ai,j≥0A_{i,j} \ge 0 (1≤i,j≤n)(1 \le i,j \le n)
  2. Ai,i≥∑j=1i−1Ai,j+∑j=i+1nAi,jA_{i,i} \ge \sum_{j=1}^{i-1} A_{i,j} + \sum_{j=i+1}^{n} A_{i,j} (1≤i≤n)(1 \le i \le n)
  3. There exists an ii such that Ai,i>∑j=1i−1Ai,j+∑j=i+1nAi,jA_{i,i} > \sum_{j=1}^{i-1} A_{i,j} + \sum_{j=i+1}^{n} A_{i,j}

A diagonal element Ai,iA_{i,i} is called dominant if

Ai,i>∑j=1i−1Ai,j+∑j=i+1nAi,jA_{i,i} > \sum_{j=1}^{i-1} A_{i,j} + \sum_{j=i+1}^{n} A_{i,j}

Until recently, the Macrohard staff checked matrices by hand with a calculator. Yesterday they went on strike, because they were tired of doing the same operations on large matrices. The Macrohard chief hired you to write a program that automates their tedious calculations. Don't make a mistake!

Input

The first line contains an integer nn (2≤n≤10002 \le n \le 1000), the size of the matrix. Each of the next nn lines contains nn integers, the elements of the matrix (0≤Ai,j≤10000 \le A_{i,j} \le 1000).

Output

If the matrix is a "beautiful" matrix, print "YES". Otherwise, print "NO". If the matrix is diagonally dominant, print the number of dominant elements on the next line.

Examples2

  1. Example 1

    Input
    3
    10 5 5
    0 1 0
    2 2 5
    
    Expected output
    YES
    2
    
  2. Example 2

    Input
    3
    10 5 5
    0 1 0
    2 2 3
    
    Expected output
    NO