#include <iostream>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    char ops;
    int num;

    bool fa[10], tr[10], re;
    for(int i = 0; i < n; ++i){
        fa[i] = false;
        tr[i] = true;
    }

    for(int i = 0; i < n; ++i){
        cin >> ops >> num;
        for(int j = 0; j < 10; ++j){
            re =  (bool)(num%2);
            if(ops == '&'){
                fa[j] &= re;
                tr[j] &= re;
            }else if (ops == '^'){
                fa[j] ^= re;
                tr[j] ^= re;
            }else{
                fa[j] |= re;
                tr[j] |= re;
            }
            num /= 2;
        }
    }
   int a = 0, b = 0;
   for (int i = 9; i >= 0; --i){
       a *= 2; b *= 2;
       a += !(fa[i] == tr[i]);
       b += fa[i];
   }

   cout << "2\n";
   cout << "& " << a << '\n';
   cout << "^ " << b << '\n';
}


/* Farewell. */
#include <iostream>
#include <vector>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <set>
using namespace std;
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MP make_pair
#define MT make_tuple
#define PB push_back
typedef long long  LL;
typedef unsigned long long ULL;
typedef pair<int,int > pii;
typedef pair<LL,LL> pll;
typedef pair<double,double > pdd;
typedef pair<double,int > pdi;
const int INF = 0x7fffffff;
const LL INFF = 0x7f7f7f7fffffffff;
const int MOD = 1e9+7;

#define debug(x) std::cerr << #x << " = " << (x) << std::endl
const int MAXM = 5e3+17;
const int MAXN = 1e5+17;
int main(int argc, char const *argv[])
{
	#ifdef GoodbyeMonkeyKing
    	freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    #endif
    vector<int > ans(10,-1),cg(10,0);
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i)
    {
    	string cmd;
    	int num;
    	cin>>cmd>>num;
    	bitset<10> temp(num);
    	switch(cmd[0])
    	{
    		case '|':
    		{
    			for (int i = 0; i < 10; ++i)
    				if(temp[i])
    					ans[i] = 1;
    			break;
    		}
    		case '&':
    		{
    			for (int i = 0; i < 10; ++i)
    				if(!temp[i])
    					ans[i] = 0;
    			break;
    		}
    		case '^':
    		{
    			for (int i = 0; i < 10; ++i)
    				if(temp[i])
    				{
    					if(ans[i]==-1)
    						cg[i] ^= 1;
    					else
    						ans[i] ^=1;
    				}
    			break;
    		}
    	}
    }
    // for (int i = 9; i > -1; --i)
    // {
    // 	cerr<<ans[i];
    // }
    // cerr<<endl;
    // for (int i = 9; i > -1; --i)
    // {
    // 	cerr<<cg[i];
    // }
    // cerr<<endl;
    bitset<10 > ad,r,xr;
	ad.set();
	for (int i = 0; i < 10; ++i)
	{
		if(ans[i]==-1)
			xr[i] = cg[i];
		else
		{
			if(ans[i]==1)
			{
				r[i] = 1;
			}
			else
			{
				ad[i] = 1;
			}
		}
	}
	cout<<3<<endl;
	cout<<"& "<<ad.to_ulong()<<endl;
	cout<<"| "<<r.to_ulong()<<endl;
	cout<<"^ "<<xr.to_ulong()<<endl;
    return 0;
}
// & 1 无用 0 置零
// | 1 置一 0 无用
// ^ 1 取反 0 无用


/* Farewell. */
#include <iostream>
#include <vector>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <set>
using namespace std;
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MP make_pair
#define MT make_tuple
#define PB push_back
typedef long long  LL;
typedef unsigned long long ULL;
typedef pair<int,int > pii;
typedef pair<LL,LL> pll;
typedef pair<double,double > pdd;
typedef pair<double,int > pdi;
const int INF = 0x7fffffff;
const LL INFF = 0x7f7f7f7fffffffff;
const int MOD = 1e9+7;

#define debug(x) std::cerr << #x << " = " << (x) << std::endl
const int MAXM = 5e3+17;
const int MAXN = 1e5+17;
struct dap
{
	int st,cg;
}a[10+17];
int main(int argc, char const *argv[])
{
	#ifdef GoodbyeMonkeyKing
    	freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    #endif
    for (int i = 0; i < 11; ++i)
    {
    	a[i].st = -1;
    	a[i].cg = 0;
    }
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i)
    {
    	string cmd;
    	int num;
    	cin>>cmd>>num;
    	bitset<10> temp(num);
    	//cerr<<temp<<endl;
    	switch(cmd[0])
    	{
    		case '|':
    		{
    			for (int i = 0; i < 10; ++i)
    				if(temp[i])
    					a[i].st = 1;
    			break;
    		}
    		case '&':
    		{
    			for (int i = 0; i < 10; ++i)
    				if(!temp[i])
    					a[i].st = 0;
    			break;
    		}
    		case '^':
    		{
    			for (int i = 0; i < 10; ++i)
    				if(temp[i])
    					a[i].cg ^= 1;
    			break;
    		}
    	}
    }
    bitset<10> ad,r,xr;
    ad.set();
    for (int i = 0; i < 10; ++i)
    {
    	if(a[i].st==1)
    		r[i] = 1;
    	else if(a[i].st==0)
    		ad[i] = 0;
    	if(a[i].cg==1)
    		xr[i] = 1;
    }
    //debug(ad);debug(r);debug(xr);
    ULL x,y,z;
    x = ad.to_ullong();
    y = r.to_ullong();
    z = xr.to_ulong();
    // debug(x);
    // debug(y);
    // debug(z);
    cout<<3<<endl;
    cout<<"^ "<<z<<endl;
    cout<<"& "<<x<<endl;
    cout<<"| "<<y<<endl;
    return 0;
}
// & 1 无用 0 置零
// | 1 置一 0 无用
// ^ 1 取反 0 无用


/* Farewell. */
#include <iostream>
#include <vector>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <set>
using namespace std;
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MP make_pair
#define MT make_tuple
#define PB push_back
typedef long long  LL;
typedef unsigned long long ULL;
typedef pair<int,int > pii;
typedef pair<LL,LL> pll;
typedef pair<double,double > pdd;
typedef pair<double,int > pdi;
const int INF = 0x7fffffff;
const LL INFF = 0x7f7f7f7fffffffff;
const int MOD = 1e9+7;

#define debug(x) std::cerr << #x << " = " << (x) << std::endl
const int MAXM = 5e3+17;
const int MAXN = 1e5+17;
struct dap
{
	int st,cg;
}a[10+17];
int main(int argc, char const *argv[])
{
	#ifdef GoodbyeMonkeyKing
    	freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    #endif
    for (int i = 0; i < 11; ++i)
    {
    	a[i].st = -1;
    	a[i].cg = 0;
    }
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i)
    {
    	string cmd;
    	int num;
    	cin>>cmd>>num;
    	bitset<10> temp(num);
    	//cerr<<temp<<endl;
    	switch(cmd[0])
    	{
    		case '|':
    		{
    			for (int i = 0; i < 10; ++i)
    				if(temp[i])
    					a[i].st = 1;
    			break;
    		}
    		case '&':
    		{
    			for (int i = 0; i < 10; ++i)
    				if(!temp[i])
    					a[i].st = 0;
    			break;
    		}
    		case '^':
    		{
    			for (int i = 0; i < 10; ++i)
    				if(temp[i])
    					a[i].cg ^= 1;
    			break;
    		}
    	}
    }
    bitset<10> ad,r,xr;
    ad.set();
    for (int i = 0; i < 10; ++i)
    {
    	if(a[i].st==1)
    		r[i] = 1;
    	else if(a[i].st==0)
    		ad[i] = 0;
    	if(a[i].cg==1)
    		xr[i] = 1;
    }
    //debug(ad);debug(r);debug(xr);
    ULL x,y,z;
    x = ad.to_ullong();
    y = r.to_ullong();
    z = xr.to_ulong();
    // debug(x);
    // debug(y);
    // debug(z);
    cout<<3<<endl;
    cout<<"| "<<y<<endl;
    cout<<"& "<<x<<endl;
    cout<<"^ "<<z<<endl;
    return 0;
}
// & 1 无用 0 置零
// | 1 置一 0 无用
// ^ 1 取反 0 无用


/* Farewell. */
#include <iostream>
#include <vector>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <set>
using namespace std;
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MP make_pair
#define MT make_tuple
#define PB push_back
typedef long long  LL;
typedef unsigned long long ULL;
typedef pair<int,int > pii;
typedef pair<LL,LL> pll;
typedef pair<double,double > pdd;
typedef pair<double,int > pdi;
const int INF = 0x7fffffff;
const LL INFF = 0x7f7f7f7fffffffff;
const int MOD = 1e9+7;

#define debug(x) std::cerr << #x << " = " << (x) << std::endl
const int MAXM = 5e3+17;
const int MAXN = 1e5+17;
struct dap
{
	int st,cg;
}a[10+17];
int main(int argc, char const *argv[])
{
	#ifdef GoodbyeMonkeyKing
    	freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    #endif
    for (int i = 0; i < 11; ++i)
    {
    	a[i].st = -1;
    	a[i].cg = 0;
    }
    int n;
    cin>>n;
    int chk = 123;
    for (int i = 0; i < n; ++i)
    {
    	string cmd;
    	int num;
    	cin>>cmd>>num;
    	bitset<10> temp(num);
    	//cerr<<temp<<endl;
    	switch(cmd[0])
    	{
    		case '|':
    		{
    			chk = chk | num;
    			for (int i = 0; i < 10; ++i)
    				if(temp[i])
    					a[i].st = 1;
    			break;
    		}
    		case '&':
    		{
    			chk = chk#
    			for (int i = 0; i < 10; ++i)
    				if(!temp[i])
    					a[i].st = 0;
    			break;
    		}
    		case '^':
    		{
    			chk = chk^num;
    			for (int i = 0; i < 10; ++i)
    				if(temp[i])
    					a[i].cg ^= 1;
    			break;
    		}
    	}
    }
    bitset<10> ad,r,xr;
    ad.set();
    for (int i = 0; i < 10; ++i)
    {
    	if(a[i].st==1)
    		r[i] = 1;
    	else if(a[i].st==0)
    		ad[i] = 0;
    	if(a[i].cg==1)
    		xr[i] = 1;
    }
    //debug(ad);debug(r);debug(xr);
    ULL x,y,z;
    x = ad.to_ullong();
    y = r.to_ullong();
    z = xr.to_ulong();
    // debug(x);
    // debug(y);
    // debug(z);
    if((123&x|y^z)==chk)
	{
		cout<<3<<endl;
		cout<<"& "<<x<<endl;
	    cout<<"| "<<y<<endl;
	    cout<<"^ "<<z<<endl;
	    return 0;
	}
	if((123|y&x^z)==chk)
	{
		cout<<3<<endl;
		cout<<"| "<<y<<endl;
		cout<<"& "<<x<<endl;
	    cout<<"^ "<<z<<endl;
	    return 0;
	}
	if((123^z|y&x)==chk)
	{
		cout<<3<<endl;
		cout<<"^ "<<z<<endl;
		cout<<"| "<<y<<endl;
		cout<<"& "<<x<<endl;
	    return 0;
	}
	if((123^z&x|y)==chk)
	{
		cout<<3<<endl;
		cout<<"^ "<<z<<endl;
		cout<<"& "<<x<<endl;
		cout<<"| "<<y<<endl;
	    return 0;
	}
    return 0;
}
// & 1 无用 0 置零
// | 1 置一 0 无用
// ^ 1 取反 0 无用


/* Farewell. */
#include <iostream>
#include <vector>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <set>
using namespace std;
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MP make_pair
#define MT make_tuple
#define PB push_back
typedef long long  LL;
typedef unsigned long long ULL;
typedef pair<int,int > pii;
typedef pair<LL,LL> pll;
typedef pair<double,double > pdd;
typedef pair<double,int > pdi;
const int INF = 0x7fffffff;
const LL INFF = 0x7f7f7f7fffffffff;
const int MOD = 1e9+7;

#define debug(x) std::cerr << #x << " = " << (x) << std::endl
const int MAXM = 5e3+17;
const int MAXN = 1e5+17;
struct dap
{
	int st,cg;
}a[10+17];
int main(int argc, char const *argv[])
{
	#ifdef GoodbyeMonkeyKing
    	freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    #endif
    for (int i = 0; i < 11; ++i)
    {
    	a[i].st = -1;
    	a[i].cg = 0;
    }
    int n;
    cin>>n;
    int chk = 123;
    for (int i = 0; i < n; ++i)
    {
    	string cmd;
    	int num;
    	cin>>cmd>>num;
    	bitset<10> temp(num);
    	cerr<<cmd<<"   ";debug(temp);
    	switch(cmd[0])
    	{
    		case '|':
    		{
    			chk = chk | num;
    			for (int i = 0; i < 10; ++i)
    				if(temp[i])
    					a[i].st = 1;
    			break;
    		}
    		case '&':
    		{
    			chk = chk#
    			for (int i = 0; i < 10; ++i)
    				if(!temp[i])
    					a[i].st = 0;
    			break;
    		}
    		case '^':
    		{
    			chk = chk^num;
    			for (int i = 0; i < 10; ++i)
    				if(temp[i])
    					a[i].cg ^= 1;
    			break;
    		}
    	}
    }
    for (int i = 9; i > -1; --i)
    {
    	debug(a[i].st);
    }
    bitset<10> ad,r,xr;
    ad.set();
    for (int i = 0; i < 10; ++i)
    {
    	if(a[i].st==1)
    		r[i] = 1;
    	else if(a[i].st==0)
    		ad[i] = 0;
    	if(a[i].cg==1)
    		xr[i] = 1;
    }
    ULL x,y,z;
    x = ad.to_ullong();
    y = r.to_ullong();
    z = xr.to_ulong();
    debug(ad);debug(r);debug(xr);
    debug(x);debug(y);debug(z);debug(chk);
    if((((123&x)|y)^z)==chk)
	{
		cout<<3<<endl;
		cout<<"& "<<x<<endl;
	    cout<<"| "<<y<<endl;
	    cout<<"^ "<<z<<endl;
	    return 0;
	}
	if((((123|y)&x)^z)==chk)
	{
		cout<<3<<endl;
		cout<<"| "<<y<<endl;
		cout<<"& "<<x<<endl;
	    cout<<"^ "<<z<<endl;
	    return 0;
	}
	if((((123^z)|y)&x)==chk)
	{
		cout<<3<<endl;
		cout<<"^ "<<z<<endl;
		cout<<"| "<<y<<endl;
		cout<<"& "<<x<<endl;
	    return 0;
	}
	if((((123^z)&x)|y)==chk)
	{
		cout<<3<<endl;
		cout<<"^ "<<z<<endl;
		cout<<"& "<<x<<endl;
		cout<<"| "<<y<<endl;
	    return 0;
	}
	if((((123&x)^z)|y)==chk)
	{
		cout<<3<<endl;
		cout<<"& "<<x<<endl;
		cout<<"^ "<<z<<endl;
		cout<<"| "<<y<<endl;
	    return 0;
	}
	if((((123|y)^z)&x)==chk)
	{
		cout<<3<<endl;
		cout<<"| "<<y<<endl;
		cout<<"^ "<<z<<endl;
		cout<<"& "<<x<<endl;
	    return 0;
	}
    return 0;
}
// & 1 无用 0 置零
// | 1 置一 0 无用
// ^ 1 取反 0 无用


/* Farewell. */
#include <iostream>
#include <vector>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <set>
using namespace std;
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MP make_pair
#define MT make_tuple
#define PB push_back
typedef long long  LL;
typedef unsigned long long ULL;
typedef pair<int,int > pii;
typedef pair<LL,LL> pll;
typedef pair<double,double > pdd;
typedef pair<double,int > pdi;
const int INF = 0x7fffffff;
const LL INFF = 0x7f7f7f7fffffffff;
const int MOD = 1e9+7;

#define debug(x) std::cerr << #x << " = " << (x) << std::endl
const int MAXM = 5e3+17;
const int MAXN = 1e5+17;
struct dap
{
	int st,cg;
}a[10+17];
int main(int argc, char const *argv[])
{
	#ifdef GoodbyeMonkeyKing
    	freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    #endif
    for (int i = 0; i < 11; ++i)
    {
    	a[i].st = -1;
    	a[i].cg = 0;
    }
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i)
    {
    	string cmd;
    	int num;
    	cin>>cmd>>num;
    	bitset<11+3> temp(num);
    	switch(cmd[0])
    	{
    		case '|':
    		{
    			for (int i = 0; i < 11; ++i)
    				if(temp[i])
    					a[i].st = 1;
    			break;
    		}
    		case '&':
    		{
    			for (int i = 0; i < 11; ++i)
    				if(!temp[i])
    					a[i].st = 0;
    			break;
    		}
    		case '^':
    		{
    			for (int i = 0; i < 11; ++i)
    				if(temp[i])
    					a[i].cg ^= 1;
    			break;
    		}
    	}
    }
    bitset<11> ad,r,xr;
    ad.set();
    for (int i = 0; i < 11; ++i)
    {
    	if(a[i].st==1)
    		r[i] = 1;
    	else if(a[i].st==0)
    		ad[i] = 0;
    	if(a[i].cg==1)
    		xr[i] = 1;
    }
    //debug(ad);debug(r);debug(xr);
    ULL x,y,z;
    x = ad.to_ullong();
    y = r.to_ullong();
    z = xr.to_ulong();
    // debug(x);
    // debug(y);
    // debug(z);
    cout<<3<<endl;
    cout<<"& "<<x<<endl;
    cout<<"| "<<y<<endl;
    cout<<"^ "<<z<<endl;
    return 0;
}
// & 1 无用 0 置零
// | 1 置一 0 无用
// ^ 1 取反 0 无用


/* Farewell. */
#include <iostream>
#include <vector>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <set>
using namespace std;
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MP make_pair
#define MT make_tuple
#define PB push_back
typedef long long  LL;
typedef unsigned long long ULL;
typedef pair<int,int > pii;
typedef pair<LL,LL> pll;
typedef pair<double,double > pdd;
typedef pair<double,int > pdi;
const int INF = 0x7fffffff;
const LL INFF = 0x7f7f7f7fffffffff;
const int MOD = 1e9+7;

#define debug(x) std::cerr << #x << " = " << (x) << std::endl
const int MAXM = 5e3+17;
const int MAXN = 1e5+17;
int main(int argc, char const *argv[])
{
	#ifdef GoodbyeMonkeyKing
    	freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    #endif
    vector<int > ans(10,-1),cg(10,0);
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i)
    {
    	string cmd;
    	int num;
    	cin>>cmd>>num;
    	bitset<10> temp(num);
    	switch(cmd[0])
    	{
    		case '|':
    		{
    			for (int i = 0; i < 10; ++i)
    				if(temp[i])
    					ans[i] = 1;
    			break;
    		}
    		case '&':
    		{
    			for (int i = 0; i < 10; ++i)
    				if(!temp[i])
    					ans[i] = 0;
    			break;
    		}
    		case '^':
    		{
    			for (int i = 0; i < 10; ++i)
    				if(temp[i])
    				{
    					if(ans[i]==-1)
    						cg[i] ^= 1;
    					else
    						ans[i] ^=1;
    				}
    			break;
    		}
    	}
    }
    // for (int i = 9; i > -1; --i)
    // {
    // 	cerr<<ans[i];
    // }
    // cerr<<endl;
    // for (int i = 9; i > -1; --i)
    // {
    // 	cerr<<cg[i];
    // }
    // cerr<<endl;
    bitset<10 > ad,r,xr;
	ad.set();
	for (int i = 0; i < 10; ++i)
	{
		if(ans[i]==-1)
			xr[i] = cg[i];
		else
		{
			if(ans[i]==1)
			{
				r[i] = 1;
			}
			else
			{
				ad[i] = 0;
			}
		}
	}
	cout<<3<<endl;
	cout<<"& "<<ad.to_ulong()<<endl;
	cout<<"| "<<r.to_ulong()<<endl;
	cout<<"^ "<<xr.to_ulong()<<endl;
    return 0;
}
// & 1 无用 0 置零
// | 1 置一 0 无用
// ^ 1 取反 0 无用


/* Farewell. */
#include <iostream>
#include <vector>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <set>
using namespace std;
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MP make_pair
#define MT make_tuple
#define PB push_back
typedef long long  LL;
typedef unsigned long long ULL;
typedef pair<int,int > pii;
typedef pair<LL,LL> pll;
typedef pair<double,double > pdd;
typedef pair<double,int > pdi;
const int INF = 0x7fffffff;
const LL INFF = 0x7f7f7f7fffffffff;
const int MOD = 1e9+7;

#define debug(x) std::cerr << #x << " = " << (x) << std::endl
const int MAXM = 5e3+17;
const int MAXN = 1e3+17+17;
int save[MAXN][MAXN];
int main(int argc, char const *argv[])
{
	#ifdef GoodbyeMonkeyKing
    	freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    #endif
    int n;
    cin>>n;
    int chk = 123;
    for (int i = 0; i < n; ++i)
    {
    	string cmd;
    	int num;
    	cin>>cmd>>num;
    	switch(cmd[0])
    	{
    		case '|':
    		{
    			chk = chk | num;
    			break;
    		}
    		case '&':
    		{
    			chk = chk#
    			break;
    		}
    		case '^':
    		{
    			chk = chk^num;
    			break;
    		}
    	}
    }
    for (int i = 0; i < 1024; ++i)
    {
    	save[i][0] = 123&i;
    	if(save[i][0]==chk)
    	{
    		cout<<1<<endl;
    		cout<<"& " <<i<<endl;
    		return 0;
    	}
    }
    for (int i = 0; i < 1024; ++i)
    {
    	for (int j = 0; j < 1024; ++j)
    	{
    		save[i][j] = save[i][j]|j;
	    	if(save[i][j]==chk)
	    	{
	    		cout<<2<<endl;
	    		cout<<"& " <<i<<endl;
	    		cout<<"| "<<j<<endl;
	    		return 0;
	    	}
    	}
    }
    return 0;
}
// & 1 无用 0 置零
// | 1 置一 0 无用
// ^ 1 取反 0 无用


/* Farewell. */
#include <iostream>
#include <vector>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <set>
using namespace std;
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MP make_pair
#define MT make_tuple
#define PB push_back
typedef long long  LL;
typedef unsigned long long ULL;
typedef pair<int,int > pii;
typedef pair<LL,LL> pll;
typedef pair<double,double > pdd;
typedef pair<double,int > pdi;
const int INF = 0x7fffffff;
const LL INFF = 0x7f7f7f7fffffffff;
const int MOD = 1e9+7;

#define debug(x) std::cerr << #x << " = " << (x) << std::endl
const int MAXM = 5e3+17;
const int MAXN = 1e5+17;
struct dap
{
	int st,cg;
}a[10+17];
int main(int argc, char const *argv[])
{
	#ifdef GoodbyeMonkeyKing
    	freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    #endif
    for (int i = 0; i < 11; ++i)
    {
    	a[i].st = -1;
    	a[i].cg = 0;
    }
    int n;
    cin>>n;
    int chk = 123;
    for (int i = 0; i < n; ++i)
    {
    	string cmd;
    	int num;
    	cin>>cmd>>num;
    	bitset<10> temp(num);
    	//cerr<<temp<<endl;
    	switch(cmd[0])
    	{
    		case '|':
    		{
    			chk = chk | num;
    			for (int i = 0; i < 10; ++i)
    				if(temp[i])
    					a[i].st = 1;
    			break;
    		}
    		case '&':
    		{
    			chk = chk#
    			for (int i = 0; i < 10; ++i)
    				if(!temp[i])
    					a[i].st = 0;
    			break;
    		}
    		case '^':
    		{
    			chk = chk^num;
    			for (int i = 0; i < 10; ++i)
    				if(temp[i])
    					a[i].cg ^= 1;
    			break;
    		}
    	}
    }
    bitset<10> ad,r,xr;
    ad.set();
    for (int i = 0; i < 10; ++i)
    {
    	if(a[i].st==1)
    		r[i] = 1;
    	else if(a[i].st==0)
    		ad[i] = 0;
    	if(a[i].cg==1)
    		xr[i] = 1;
    }
    //debug(ad);debug(r);debug(xr);
    ULL x,y,z;
    x = ad.to_ullong();
    y = r.to_ullong();
    z = xr.to_ulong();
    if((((123&x)|y)^z)==chk)
	{
		cout<<3<<endl;
		cout<<"& "<<x<<endl;
	    cout<<"| "<<y<<endl;
	    cout<<"^ "<<z<<endl;
	    return 0;
	}
	if((((123|y)&x)^z)==chk)
	{
		cout<<3<<endl;
		cout<<"| "<<y<<endl;
		cout<<"& "<<x<<endl;
	    cout<<"^ "<<z<<endl;
	    return 0;
	}
	if((((123^z)|y)&x)==chk)
	{
		cout<<3<<endl;
		cout<<"^ "<<z<<endl;
		cout<<"| "<<y<<endl;
		cout<<"& "<<x<<endl;
	    return 0;
	}
	if((((123^z)&x)|y)==chk)
	{
		cout<<3<<endl;
		cout<<"^ "<<z<<endl;
		cout<<"& "<<x<<endl;
		cout<<"| "<<y<<endl;
	    return 0;
	}
	if((((123&x)^z)|y)==chk)
	{
		cout<<3<<endl;
		cout<<"& "<<x<<endl;
		cout<<"^ "<<z<<endl;
		cout<<"| "<<y<<endl;
	    return 0;
	}
	if((((123|y)^z)&x)==chk)
	{
		cout<<3<<endl;
		cout<<"| "<<y<<endl;
		cout<<"^ "<<z<<endl;
		cout<<"& "<<x<<endl;
	    return 0;
	}
    return 0;
}
// & 1 无用 0 置零
// | 1 置一 0 无用
// ^ 1 取反 0 无用


/* Farewell. */
#include <iostream>
#include <vector>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <set>
using namespace std;
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MP make_pair
#define MT make_tuple
#define PB push_back
typedef long long  LL;
typedef unsigned long long ULL;
typedef pair<int,int > pii;
typedef pair<LL,LL> pll;
typedef pair<double,double > pdd;
typedef pair<double,int > pdi;
const int INF = 0x7fffffff;
const LL INFF = 0x7f7f7f7fffffffff;
const int MOD = 1e9+7;

#define debug(x) std::cerr << #x << " = " << (x) << std::endl
const int MAXM = 5e3+17;
const int MAXN = 1e5+17;
struct dap
{
	int st,cg;
}a[10+17];
int main(int argc, char const *argv[])
{
	#ifdef GoodbyeMonkeyKing
    	freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    #endif
    for (int i = 0; i < 11; ++i)
    {
    	a[i].st = -1;
    	a[i].cg = 0;
    }
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i)
    {
    	string cmd;
    	int num;
    	cin>>cmd>>num;
    	bitset<10> temp(num);
    	//cerr<<temp<<endl;
    	switch(cmd[0])
    	{
    		case '|':
    		{
    			for (int i = 0; i < 10; ++i)
    				if(temp[i])
    					a[i].st = 1;
    			break;
    		}
    		case '&':
    		{
    			for (int i = 0; i < 10; ++i)
    				if(!temp[i])
    					a[i].st = 0;
    			break;
    		}
    		case '^':
    		{
    			for (int i = 0; i < 10; ++i)
    				if(temp[i])
    					a[i].cg ^= 1;
    			break;
    		}
    	}
    }
    bitset<10> ad,r,xr;
    ad.set();
    for (int i = 0; i < 10; ++i)
    {
    	if(a[i].st==1)
    		r[i] = 1;
    	else if(a[i].st==0)
    		ad[i] = 0;
    	if(a[i].cg==1)
    		xr[i] = 1;
    }
    //debug(ad);debug(r);debug(xr);
    ULL x,y,z;
    x = ad.to_ullong();
    y = r.to_ullong();
    z = xr.to_ulong();
    // debug(x);
    // debug(y);
    // debug(z);
    cout<<3<<endl;
    cout<<"| "<<y<<endl;
    cout<<"^ "<<z<<endl;
    cout<<"& "<<x<<endl;
    return 0;
}
// & 1 无用 0 置零
// | 1 置一 0 无用
// ^ 1 取反 0 无用


/* Farewell. */
#include <iostream>
#include <vector>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <set>
using namespace std;
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MP make_pair
#define MT make_tuple
#define PB push_back
typedef long long  LL;
typedef unsigned long long ULL;
typedef pair<int,int > pii;
typedef pair<LL,LL> pll;
typedef pair<double,double > pdd;
typedef pair<double,int > pdi;
const int INF = 0x7fffffff;
const LL INFF = 0x7f7f7f7fffffffff;
const int MOD = 1e9+7;

#define debug(x) std::cerr << #x << " = " << (x) << std::endl
const int MAXM = 5e3+17;
const int MAXN = 1e5+17;
struct dap
{
	int st,cg;
}a[10+17];
int main(int argc, char const *argv[])
{
	#ifdef GoodbyeMonkeyKing
    	freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    #endif
    for (int i = 0; i < 11; ++i)
    {
    	a[i].st = -1;
    	a[i].cg = 0;
    }
    int n;
    cin>>n;
    for (int i = 0; i < n; ++i)
    {
    	string cmd;
    	int num;
    	cin>>cmd>>num;
    	bitset<11+3> temp(num);
    	switch(cmd[0])
    	{
    		case '|':
    		{
    			for (int i = 0; i < 11; ++i)
    				if(temp[i])
    					a[i].st = 1;
    			break;
    		}
    		case '&':
    		{
    			for (int i = 0; i < 11; ++i)
    				if(!temp[i])
    					a[i].st = 0;
    			break;
    		}
    		case '^':
    		{
    			for (int i = 0; i < 11; ++i)
    				if(temp[i])
    					a[i].cg ^= 1;
    			break;
    		}
    	}
    }
    bitset<10> ad,r,xr;
    ad.set();
    for (int i = 0; i < 10; ++i)
    {
    	if(a[i].st==1)
    		r[i] = 1;
    	else if(a[i].st==0)
    		ad[i] = 0;
    	if(a[i].cg==1)
    		xr[i] = 1;
    }
    //debug(ad);debug(r);debug(xr);
    ULL x,y,z;
    x = ad.to_ullong();
    y = r.to_ullong();
    z = xr.to_ulong();
    // debug(x);
    // debug(y);
    // debug(z);
    cout<<3<<endl;
    cout<<"& "<<x<<endl;
    cout<<"| "<<y<<endl;
    cout<<"^ "<<z<<endl;
    return 0;
}
// & 1 无用 0 置零
// | 1 置一 0 无用
// ^ 1 取反 0 无用


#include <bits/stdc++.h>

#define D(x) cout << #x << " = " << x << endl

using namespace std;

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

#define PB push_back

#define FASTCIN ios::sync_with_stdio(false)
#define FASTCOUT cin.tie(false)

int main()
{
    int a = 1023, b = 0, n, e;
    char op;

    cin >> n;

    while (n--)
    {
        cin >> op >> e;

        if (op == '|')
        {
            a |= e;
            b |= e;
        }
        else if (op == '&')
        {
            a &= e;
            b &= e;
        }
        else if (op == '^')
        {
            a ^= e;
            b ^= e;
        }

        //cout << a << endl;
        //cout << b << endl;
    }

    int ouxor = 0;
    int ou = 0;
    int exor = 0;
    e = 0;

    for (int i = 0; i < 10; i++)
    {
        int num = 1 << i;

        if ((a & num) && (b & num))
            ou |= num;
        else if ((b & num))
            exor |= num,
            e |= num;
        else if((a & num))
            e |= num;
        else if (!(a & num) && !(b & num))
            ouxor |= num;
    }
/*
    cout << a << endl;
    cout << b << endl;
*/
    int count = 0;

    count += ouxor ? 2 : 0;
    count += ou ? 1 : 0;
    count += exor ? 1 : 0;
    count += e ? 1 : 0;

    cout << count << endl;

    if (ouxor)
    {
        cout << "| " << ouxor << endl;
        cout << "^ " << ouxor << endl;
    }
    if (ou)
        cout << "| " << ou << endl;
    if (e)
    {
        cout << "& " << e << endl;

        if(exor)
            cout << "^ " << exor << endl;
    }
}


#include <bits/stdc++.h>

#define D(x) cout << #x << " = " << x << endl

using namespace std;

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

#define PB push_back

#define FASTCIN ios::sync_with_stdio(false)
#define FASTCOUT cin.tie(false)

int main()
{
    int a = 1023, b = 0, n, e;
    char op;

    cin >> n;

    while (n--)
    {
        cin >> op >> e;

        if (op == '|')
        {
            a |= e;
            b |= e;
        }
        else if (op == '&')
        {
            a &= e;
            b &= e;
        }
        else if (op == '^')
        {
            a ^= e;
            b ^= e;
        }

        //cout << a << endl;
        //cout << b << endl;
    }

    int ouxor = 0;
    int ou = 0;
    int exor = 0;

    for (int i = 0; i < 10; i++)
    {
        int num = 1 << i;

        if ((a & num) && (b & num))
            ou |= num;
        else if ((b & num))
            exor |= num;
        else if (!(a & num) && !(b & num))
            ouxor |= num;
    }

    if (ouxor)
    {
        cout << "| " << ouxor << endl;
        cout << "^ " << ouxor << endl;
    }
    if (ou)
        cout << "| " << ou << endl;
    if (exor)
    {
        cout << "^ " << exor << endl;
        cout << "| " << exor << endl;
    }

    if(!ouxor && !ou && !exor)
        cout << "0" << endl;
}


#include <bits/stdc++.h>

#define D(x) cout << #x << " = " << x << endl

using namespace std;

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

#define PB push_back

#define FASTCIN ios::sync_with_stdio(false)
#define FASTCOUT cin.tie(false)

int main()
{
    int a = 1023, b = 0, n, e;
    char op;

    cin >> n;

    while (n--)
    {
        cin >> op >> e;

        if (op == '|')
        {
            a |= e;
            b |= e;
        }
        else if (op == '&')
        {
            a &= e;
            b &= e;
        }
        else if (op == '^')
        {
            a ^= e;
            b ^= e;
        }

        //cout << a << endl;
        //cout << b << endl;
    }

    int ouxor = 0;
    int ou = 0;
    int exor = 0;
    e = 0;

    for (int i = 0; i < 10; i++)
    {
        int num = 1 << i;

        if ((a & num) && (b & num))
            ou |= num;
        else if ((b & num))
            exor |= num;
        else if (!(a & num) && !(b & num))
            ouxor |= num;
    }
    /*
    cout << a << endl;
    cout << b << endl;
*/
    int count = 0;

    count += ouxor ? 2 : 0;
    count += ou ? 1 : 0;
    count += exor? 1 : 0;

    cout << count << endl;

    if (ouxor)
    {
        cout << "| " << ouxor << endl;
        cout << "^ " << ouxor << endl;
    }
    if (ou)
        cout << "| " << ou << endl;
    if (exor)
        cout << "^ " << exor << endl;
}


#include <bits/stdc++.h>

#define D(x) cout << #x << " = " << x << endl

using namespace std;

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

#define PB push_back

#define FASTCIN ios::sync_with_stdio(false)
#define FASTCOUT cin.tie(false)

int main()
{
    int a = 1023, b = 0, n, e;
    char op;

    cin >> n;

    while (n--)
    {
        cin >> op >> e;

        if (op == '|')
        {
            a |= e;
            b |= e;
        }
        else if (op == '&')
        {
            a &= e;
            b &= e;
        }
        else if (op == '^')
        {
            a ^= e;
            b ^= e;
        }

        //cout << a << endl;
        //cout << b << endl;
    }

    int ouxor = 0;
    int ou = 0;
    int exor = 0;

    for (int i = 0; i < 10; i++)
    {
        int num = 1 << i;

        if ((a & num) && (b & num))
            ou |= num;
        else if ((b & num))
            exor |= num;
        else if (!(a & num) && !(b & num))
            ouxor |= num;
    }
    int count = 0;

    count += ouxor ? 2 : 0;
    count += ou ? 1 : 0;
    count += exor ? 2 : 0;

    cout << count << endl;

    if (ouxor)
    {
        cout << "| " << ouxor << endl;
        cout << "^ " << ouxor << endl;
    }
    if (ou)
        cout << "| " << ou << endl;
    if (exor)
    {
        cout << "& " << exor << endl;
        cout << "| " << exor << endl;
    }
}


#include <bits/stdc++.h>

#define D(x) cout << #x << " = " << x << endl

using namespace std;

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

#define PB push_back

#define FASTCIN ios::sync_with_stdio(false)
#define FASTCOUT cin.tie(false)

int main()
{
    int a = 1023, b = 0, n, e;
    char op;

    cin >> n;

    while (n--)
    {
        cin >> op >> e;

        if (op == '|')
        {
            a |= e;
            b |= e;
        }
        else if (op == '&')
        {
            a &= e;
            b &= e;
        }
        else if (op == '^')
        {
            a ^= e;
            b ^= e;
        }

        //cout << a << endl;
        //cout << b << endl;
    }

    int ouxor = 0;
    int ou = 0;
    int exor = 0;

    for (int i = 0; i < 10; i++)
    {
        int num = 1 << i;

        if ((a & num) && (b & num))
            ou |= num;
        else if ((b & num))
            exor |= num;
        else if (!(a & num) && !(b & num))
            ouxor |= num;
    }
    int count = 0;

    count += ouxor ? 2 : 0;
    count += ou ? 1 : 0;
    count += exor ? 2 : 0;

    cout << count << endl;

    if (ouxor)
    {
        cout << "| " << ouxor << endl;
        cout << "^ " << ouxor << endl;
    }
    if (ou)
        cout << "| " << ou << endl;
    if (exor)
    {
        cout << "^ " << exor << endl;
        cout << "| " << exor << endl;
    }
}


#include <bits/stdc++.h>

#define D(x) cout << #x << " = " << x << endl

using namespace std;

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

#define PB push_back

#define FASTCIN ios::sync_with_stdio(false)
#define FASTCOUT cin.tie(false)

int main()
{
    int a = 1023, b = 0, n, e;
    char op;

    cin >> n;

    while (n--)
    {
        cin >> op >> e;

        if (op == '|')
        {
            a |= e;
            b |= e;
        }
        else if (op == '&')
        {
            a &= e;
            b &= e;
        }
        else if (op == '^')
        {
            a ^= e;
            b ^= e;
        }

        //cout << a << endl;
        //cout << b << endl;
    }

    int ouxor = 0;
    int ou = 0;
    int exor = 0;

    for (int i = 0; i < 10; i++)
    {
        int num = 1 << i;

        if ((a & num) && (b & num))
            ou |= num;
        else if ((b & num))
            exor |= num;
        else if (!(a & num) && !(b & num))
            ouxor |= num;
    }
    int count = 0;

    count += ouxor ? 2 : 0;
    count += ou ? 1 : 0;
    count += exor ? 2 : 0;

    cout << count << endl;

    if (ouxor)
    {
        cout << "| " << ouxor << endl;
        cout << "^ " << ouxor << endl;
    }
    if (ou)
        cout << "| " << ou << endl;
    if (exor)
    {
        cout << "& " << exor << endl;
        cout << "^ " << exor << endl;
    }
}


#include <iostream>

int main()
{
	int n;
	std::cin >> n;
	int zero = 0, max = 1023;

	for (int i = 0; i < n; ++i)
	{
		char c;
		int x;
		std::cin >> c >> x;

		if (c == '|')
		{
			zero |= x;
			max |= x;
		}
		else if (c == '^')
		{
			zero ^= x;
			max ^= x;
		}
		else
		{
			zero &= x;
			max &= x;
		}
	}

	std::cout << "3\n";
	std::cout << "^ " << (max ^ zero) << "\n";
	std::cout << "| " << (max & zero) << "\n";
	std::cout << "& " << (max | zero) << "\n";
}


#include <iostream>

int main()
{
	int n;
	std::cin >> n;
	int zero = 0, max = 1023;

	for (int i = 0; i < n; ++i)
	{
		char c;
		int x;
		std::cin >> c >> x;

		if (c == '|')
		{
			zero |= x;
			max |= x;
		}
		else if (c == '^')
		{
			zero ^= x;
			max ^= x;
		}
		else
		{
			zero &= x;
			max &= x;
		}
	}

	std::cout << "2\n";
	std::cout << "| " << zero << "\n";
	std::cout << "^ " << (max ^ 1023);
}


#include <iostream>

int main()
{
	int n;
	std::cin >> n;
	int zero = 0, max = 1023;

	for (int i = 0; i < n; ++i)
	{
		char c;
		int x;
		std::cin >> c >> x;

		if (c == '|')
		{
			zero |= x;
			max |= x;
		}
		else if (c == '^')
		{
			zero ^= x;
			max ^= x;
		}
		else
		{
			zero &= x;
			max &= x;
		}
	}

	std::cout << "4\n";
	std::cout << "| " << 0 << "\n";
	std::cout << "^ " << (max ^ zero) << "\n";
	std::cout << "| " << (max & zero) << "\n";
	std::cout << "& " << (max | zero);
}


#include <iostream>

int main()
{
	int n;
	std::cin >> n;
	int zero = 0, max = 1023;

	for (int i = 0; i < n; ++i)
	{
		char c;
		int x;
		std::cin >> c >> x;

		if (c == '|')
		{
			zero |= x;
			max |= x;
		}
		else if (c == '^')
		{
			zero ^= x;
			max ^= x;
		}
		else
		{
			zero &= x;
			max &= x;
		}
	}

	std::cout << "3\n";
	std::cout << "| " << 0 << "\n";
	std::cout << "^ " << (max ^ zero) << "\n";
	std::cout << "| " << (max & zero) << "\n";
	std::cout << "& " << (max | zero);
}


#include <iostream>

int main()
{
	int n;
	std::cin >> n;
	int zero = 0, max = 1023;

	for (int i = 0; i < n; ++i)
	{
		char c;
		int x;
		std::cin >> c >> x;

		if (c == '|')
		{
			zero |= x;
			max |= x;
		}
		else if (c == '^')
		{
			zero ^= x;
			max ^= x;
		}
		else
		{
			zero &= x;
			max &= x;
		}
	}

	std::cout << "2\n";
	std::cout << "| " << zero << "\n";
	std::cout << "& " << max;
}


#include <iostream>

int main()
{
	int n;
	std::cin >> n;
	int zero = 0, max = 1023;

	for (int i = 0; i < n; ++i)
	{
		char c;
		int x;
		std::cin >> c >> x;

		if (c == '|')
		{
			zero |= x;
			max |= x;
		}
		else if (c == '^')
		{
			zero ^= x;
			max ^= x;
		}
		else
		{
			zero &= x;
			max &= x;
		}
	}

	std::cout << "2\n";
	std::cout << "& " << (zero ^ max) << "\n";
	std::cout << "^ " << zero;
}


#include <iostream>

int main()
{
	int n;
	std::cin >> n;
	int zero = 0, max = 1023;

	for (int i = 0; i < n; ++i)
	{
		char c;
		int x;
		std::cin >> c >> x;

		if (c == '|')
		{
			zero |= x;
			max |= x;
		}
		else if (c == '^')
		{
			zero ^= x;
			max ^= x;
		}
		else
		{
			zero &= x;
			max &= x;
		}
	}

	std::cout << "3\n";
	std::cout << "| " << zero << "\n";
	std::cout << "| " << (max ^ 1023) << "\n";
	std::cout << "^ " << (max ^ 1023);
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define V vector
#define MP make_pair
#define all(v)  ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define clr(v, d) memset(v, d, sizeof(v))
#define sf(x) scanf("%d", &x)
#define sf2(x, y) scanf("%d %d", &x, &y)
#define sf3(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define sfll(x) scanf("%I64d", &x)
#define sfll2(x, y) scanf("%I64d %I64d", &x, &y)
#define sfll3(x, y, z) scanf("%I64d %I64d %I64d", &x, &y, &z)
typedef long long ll;
int dx[]{1, -1, 0, 0, 1, -1, 1, -1};
int dy[]{0, 0, 1, -1, 1, -1, -1, 1};
ll suf(ll x) { return (x * (x + 1)) / 2; }
V<V<int > > adj;
const ll mod = 1e9 + 7, oo = 1e9 + 10, MAX = 2005;
int n, m, in[MAX][MAX], g[MAX][25], T[MAX], L[MAX];
long long pref[MAX] , w[MAX][MAX];

struct UnionFind{
	vector<int> rank, F;
	int comp;
	UnionFind(int n){
		rank = vector<int>(n);
		F = vector<int>(n);
		comp = n;
		for (int i = 0; i < n; i++)
			F[i] = i;
	}
	int find_set(int x){
		if (x == F[x]) return x;
		return F[x] = find_set(F[x]);
	}
	void link(int x, int y){
		if (rank[x] > rank[y]) swap(x, y);
		if (rank[x] == rank[y]) rank[y]++;
		F[x] = y;
	}
	bool union_set(int x, int y){
		x = find_set(x), y = find_set(y);
		if (x == y) return 0;
		link(x, y);
		comp--;
		return 1;
	}
};
void dfs(int nd, ll sum, int lst , int po){
	for (int i = 0; i < adj[nd].size(); i++){
		int ch = adj[nd][i];
		if (ch == lst) continue;
		w[ch][po] = w[po][ch] = sum + (ll)in[nd][ch];
		dfs(ch, sum + (ll)in[nd][ch], nd, po);
	}
}

int main()
{

	while (cin >> n){
		priority_queue<pair<int, pair<int, int> >, V<pair<int, pair<int, int>  > >, greater<pair<int, pair<int, int> > > > pq;
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				sf(in[i][j]);
				if (j > i)
					pq.push(MP(in[i][j], MP(i, j)));
			}
		}
		adj.resize(n);
		UnionFind me(n);
		while (pq.empty() == 0){
			pair<int, pair<int, int> > p = pq.top();
			pq.pop();
			if (me.union_set(p.second.first, p.second.second)){
				adj[p.second.first].push_back(p.second.second);
				adj[p.second.second].push_back(p.second.first);
			}
		}
		for (int i = 0; i < n; i++)
			dfs(i, 0, -1, i);
		bool ok = 1;
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++)if(i != j){
				ok &= (in[i][j] == w[i][j] && w[i][j] > 0) && (in[j][i] == w[i][j] && w[i][j] > 0);
				if (!ok) break;
			}
		}
		for (int i = 0; i < n; i++)
			ok &= in[i][i] == 0;
		if (ok) cout << "YES" << endl;
		else cout << "NO" << endl;
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define V vector
#define MP make_pair
#define all(v)  ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define clr(v, d) memset(v, d, sizeof(v))
#define sf(x) scanf("%d", &x)
#define sf2(x, y) scanf("%d %d", &x, &y)
#define sf3(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define sfll(x) scanf("%I64d", &x)
#define sfll2(x, y) scanf("%I64d %I64d", &x, &y)
#define sfll3(x, y, z) scanf("%I64d %I64d %I64d", &x, &y, &z)
typedef long long ll;
int dx[]{1, -1, 0, 0, 1, -1, 1, -1};
int dy[]{0, 0, 1, -1, 1, -1, -1, 1};
ll suf(ll x) { return (x * (x + 1)) / 2; }
V<V<int> > adj;
//V<V<int > > adj2;
const ll mod = 1e9 + 7, oo = 1e9 + 10, MAX = 2005;
int n, m , g[MAX][12] ,dis[MAX][12], in[MAX][MAX] , T[MAX] , L[MAX] , vs[MAX] ,cmp[MAX][MAX] ,cur  = 0;
bool done[MAX];

bool iscon(int nd , int dis){
	cur++;
	queue<int>q;
	q.push(nd);
	vs[nd] = cur;
	while (q.empty() == false){
		int p = q.front();
		q.pop();
		if (p == dis) return 1;
		for (int i = 0; i < adj[p].size(); i++){
			if (vs[adj[p][i]] == cur)continue;
			q.push(adj[p][i]);
		}
	}
	return 0;
}

void dfs(int nd, int lst, int l){
	L[nd] = l;
	T[nd] = lst;
	if (vs[nd] == cur) return;
	vs[nd] = cur;
	for (int i = 0; i < adj[nd].size(); i++){
		if (lst == adj[nd][i]) continue;
		dfs(adj[nd][i], nd, l + 1);
	}
}
void built(){
	clr(g, -1);
	for (int i = 0; i < n; i++){
		g[i][0] = T[i];
		dis[i][0] = in[i][T[i]];
	}
	for (int j = 1; j < 12; j++){
		for (int i = 0; i < n; i++){
			if (g[i][j - 1] != -1){
				g[i][j] = g[g[i][j - 1]][j - 1];
				dis[i][j] = dis[g[i][j - 1]][j - 1] + dis[i][j - 1];
			}
		}
	}
}

int get(int x, int y){
	int sum = 0;
	if (L[x] < L[y]) swap(x, y);
	for (int j = 11; j >= 0; j--){
		if (L[x] - (1 << j) >= L[y]){
			sum += dis[x][j];
			x = g[x][j];
		}
	}
	if (x == y) return sum;
	for (int j = 11; j >= 0; j--){
		if (g[x][j] != -1 && g[x][j] != g[y][j]){
			sum += dis[x][j];
			sum += dis[y][j];
			x = g[x][j], y = g[y][j];
		}
	}
	return sum + in[x][T[x]] + in[y][T[y]];
}
int main()
{

	while (cin >> n){
		adj.resize(n);
		V<pair<int, pair<int, int> > > p;
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				sf(in[i][j]);
				if (i != j)
				p.push_back(MP(in[i][j], MP(i, j)));
			}
		}
		sort(all(p));
		for (int i = 0; i < p.size(); i++){
			cur++;
			if (iscon(p[i].second.first, p[i].second.second) == 0){
				adj[p[i].second.first].push_back(p[i].second.second);
				adj[p[i].second.second].push_back(p[i].second.first);
			}
		}
		cur++;
		dfs(0, -1, 0);
		built();
		for (int i = 0; i < n; i++){
			for (int j = i + 1; j < n; j++){
				cmp[i][j] = cmp[j][i] = get(i, j);
			}
		}
		bool ok = 1;
		for (int i = 0; i < n && ok; i++){
			for (int j = 0; j < n&&ok; j++){
				if (cmp[i][j] != in[i][j] || (i != j) && cmp[i][j] == 0)
					ok = 0;
			}
		}
		if (ok) cout << "YES" << endl;
		else cout << "NO" << endl;
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define V vector
#define MP make_pair
#define all(v)  ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define clr(v, d) memset(v, d, sizeof(v))
#define sf(x) scanf("%d", &x)
#define sf2(x, y) scanf("%d %d", &x, &y)
#define sf3(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define sfll(x) scanf("%I64d", &x)
#define sfll2(x, y) scanf("%I64d %I64d", &x, &y)
#define sfll3(x, y, z) scanf("%I64d %I64d %I64d", &x, &y, &z)
typedef long long ll;
int dx[]{1, -1, 0, 0, 1, -1, 1, -1};
int dy[]{0, 0, 1, -1, 1, -1, -1, 1};
ll suf(ll x) { return (x * (x + 1)) / 2; }
V<V<int> > adj;
//V<V<int > > adj2;
const ll mod = 1e9 + 7, oo = 1e9 + 10, MAX = 2005;
int n, m , g[MAX][12] ,dis[MAX][12], in[MAX][MAX] , T[MAX] , L[MAX] , vs[MAX] ,cmp[MAX][MAX] ,cur  = 0;
bool done[MAX];

bool iscon(int nd , int dis , int lst = -1 ){
	if (nd == dis) return 1;
	for (int i = 0; i < adj[nd].size(); i++){
		if (lst == adj[nd][i]) continue;
		if (iscon(adj[nd][i], dis , nd))
			return 1;
	}
	return 0;
}

void dfs(int nd, int lst, int l){
	L[nd] = l;
	T[nd] = lst;
	for (int i = 0; i < adj[nd].size(); i++){
		if (lst == adj[nd][i]) continue;
		dfs(adj[nd][i], nd, l + 1);
	}
}
void built(){
	clr(g, -1);
	for (int i = 0; i < n; i++){
		g[i][0] = T[i];
		dis[i][0] = in[i][T[i]];
	}
	for (int j = 1; j < 12; j++){
		for (int i = 0; i < n; i++){
			if (g[i][j - 1] != -1){
				g[i][j] = g[g[i][j - 1]][j - 1];
				dis[i][j] = dis[g[i][j - 1]][j - 1] + dis[i][j - 1];
			}
		}
	}
}

int get(int x, int y){
	int sum = 0;
	if (L[x] < L[y]) swap(x, y);
	for (int j = 11; j >= 0; j--){
		if (L[x] - (1 << j) >= L[y]){
			sum += dis[x][j];
			x = g[x][j];
		}
	}
	if (x == y) return sum;
	for (int j = 11; j >= 0; j--){
		if (g[x][j] != g[y][j]){
			sum += dis[x][j];
			sum += dis[y][j];
			x = g[x][j], y = g[y][j];
		}
	}
	return sum + in[x][T[x]] + in[y][T[y]];
}
int main()
{

	while (cin >> n){
		adj.resize(n);
		V<pair<int, pair<int, int> > > p;
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				sf(in[i][j]);
				if (i != j)
				p.push_back(MP(in[i][j], MP(i, j)));
			}
		}
		sort(all(p));
		for (int i = 0; i < p.size(); i++){
			cur++;
			if (iscon(p[i].second.first, p[i].second.second) == 0){
				adj[p[i].second.first].push_back(p[i].second.second);
				adj[p[i].second.second].push_back(p[i].second.first);
			}
		}
		dfs(0, -1, 0);
		built();
		for (int i = 0; i < n; i++){
			for (int j = i + 1; j < n; j++){
				cmp[i][j] = cmp[j][i] = get(i, j);
			}
		}
		bool ok = 1;
		for (int i = 0; i < n && ok; i++){
			for (int j = 0; j < n&&ok; j++){
				if (cmp[i][j] != in[i][j] || (i != j) && cmp[i][j] == 0)
					ok = 0;
			}
		}
		if (ok) cout << "YES" << endl;
		else cout << "NO" << endl;
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define V vector
#define MP make_pair
#define all(v)  ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define clr(v, d) memset(v, d, sizeof(v))
#define sf(x) scanf("%d", &x)
#define sf2(x, y) scanf("%d %d", &x, &y)
#define sf3(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define sfll(x) scanf("%I64d", &x)
#define sfll2(x, y) scanf("%I64d %I64d", &x, &y)
#define sfll3(x, y, z) scanf("%I64d %I64d %I64d", &x, &y, &z)
typedef long long ll;
int dx[]{1, -1, 0, 0, 1, -1, 1, -1};
int dy[]{0, 0, 1, -1, 1, -1, -1, 1};
ll suf(ll x) { return (x * (x + 1)) / 2; }
V<V<int > > adj;
const ll mod = 1e9 + 7, oo = 1e9 + 10, MAX = 2005;
int n, m , in[MAX][MAX] , pref[MAX] , g[MAX][25] , T[MAX] , L[MAX];

struct UnionFind{
	vector<int> rank, F;
	int comp;
	UnionFind(int n){
		rank = vector<int>(n);
		F = vector<int>(n);
		comp = n;
		for (int i = 0; i < n; i++)
			F[i] = i;
	}
	int find_set(int x){
		if (x == F[x]) return x;
		return F[x] = find_set(F[x]);
	}
	void link(int x, int y){
		if (rank[x] > rank[y]) swap(x, y);
		if (rank[x] == rank[y]) rank[y]++;
		F[x] = y;
	}
	bool union_set(int x, int y){
		x = find_set(x), y = find_set(y);
		if (x == y) return 0;
		link(x, y);
		comp--;
		return 1;
	}
};
void dfs(int nd, int sum, int l, int lst){
	pref[nd] = sum, L[nd] = l, T[nd] = lst;
	for (int i = 0; i < adj[nd].size(); i++){
		int ch = adj[nd][i];
		if (ch == lst) continue;
		dfs(ch, sum + in[nd][ch], l + 1 , nd);
	}
}

void built(){
	clr(g, -1);
	for (int i = 0; i < n; i++)
		g[i][0] = T[i];

	for (int j = 1; j < 25; j++){
		for (int i = 0; i < n; i++){
			if (g[i][j - 1] != -1)
				g[i][j] = g[g[i][j - 1]][j - 1];
		}
	}
}
int LCA(int x, int y){
	if (L[x] < L[y]) swap(x, y);
	for (int i = 25; i >= 0; i--){
		if (L[x] - (1 << i) >= L[y])
			x = g[x][i];
	}
	if (x == y) return x;
	for (int i = 25; i >= 0; i--){
		if (g[x][i] != -1 && g[x][i] != g[y][i])
			x = g[x][i], y = g[y][i];
	}
	return T[x];
}
int main()
{

	while (cin >> n){
		priority_queue<pair<int, pair<int, int> >, V<pair<int, pair<int, int>  > >, greater<pair<int, pair<int, int> > > > pq;
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				sf(in[i][j]);
				if (j > i)
					pq.push(MP(in[i][j], MP(i, j)));
			}
		}
		adj.resize(n);
		UnionFind me(n);
		while (pq.empty() == 0){
			pair<int, pair<int, int> > p = pq.top();
			pq.pop();
			if (me.union_set(p.second.first, p.second.second)){
				adj[p.second.first].push_back(p.second.second);
				adj[p.second.second].push_back(p.second.first);
			}
		}
		dfs(0, 0, 0, -1);
		built();
		bool ok = 1;
		for (int i = 0; i < n; i++){
			for (int j = i + 1; j < n; j++){
				int lca = LCA(i, j);
				int now = pref[i] + pref[j] - pref[lca];
				ok &= (in[i][j] == now && now > 0) && (in[j][i] == now && now > 0);
				if (!ok) break;
			}
		}
		for (int i = 0; i < n; i++)
			ok &= in[i][i] == 0;
		if (ok) cout << "YES" << endl;
		else cout << "NO" << endl;
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define V vector
#define MP make_pair
#define all(v)  ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define clr(v, d) memset(v, d, sizeof(v))
#define sf(x) scanf("%d", &x)
#define sf2(x, y) scanf("%d %d", &x, &y)
#define sf3(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define sfll(x) scanf("%I64d", &x)
#define sfll2(x, y) scanf("%I64d %I64d", &x, &y)
#define sfll3(x, y, z) scanf("%I64d %I64d %I64d", &x, &y, &z)
typedef long long ll;
int dx[]{1, -1, 0, 0, 1, -1, 1, -1};
int dy[]{0, 0, 1, -1, 1, -1, -1, 1};
ll suf(ll x) { return (x * (x + 1)) / 2; }
V<V<int > > adj;
const ll mod = 1e9 + 7, oo = 1e9 + 10, MAX = 2005;
int n, m, in[MAX][MAX], g[MAX][25], T[MAX], L[MAX];
long long pref[MAX];

struct UnionFind{
	vector<int> rank, F;
	int comp;
	UnionFind(int n){
		rank = vector<int>(n);
		F = vector<int>(n);
		comp = n;
		for (int i = 0; i < n; i++)
			F[i] = i;
	}
	int find_set(int x){
		if (x == F[x]) return x;
		return F[x] = find_set(F[x]);
	}
	void link(int x, int y){
		if (rank[x] > rank[y]) swap(x, y);
		if (rank[x] == rank[y]) rank[y]++;
		F[x] = y;
	}
	bool union_set(int x, int y){
		x = find_set(x), y = find_set(y);
		if (x == y) return 0;
		link(x, y);
		comp--;
		return 1;
	}
};
void dfs(int nd, ll sum, int l, int lst){
	pref[nd] = sum, L[nd] = l, T[nd] = lst;
	for (int i = 0; i < adj[nd].size(); i++){
		int ch = adj[nd][i];
		if (ch == lst) continue;
		dfs(ch, sum + (ll) in[nd][ch], l + 1 , nd);
	}
}

void built(){
	clr(g, -1);
	for (int i = 0; i < n; i++)
		g[i][0] = T[i];

	for (int j = 1; j < 25; j++){
		for (int i = 0; i < n; i++){
			if (g[i][j - 1] != -1)
				g[i][j] = g[g[i][j - 1]][j - 1];
		}
	}
}
int LCA(int x, int y){
	if (L[x] < L[y]) swap(x, y);
	for (int i = 25; i >= 0; i--){
		if (L[x] - (1 << i) >= L[y])
			x = g[x][i];
	}
	if (x == y) return x;
	for (int i = 25; i >= 0; i--){
		if (g[x][i] != -1 && g[x][i] != g[y][i])
			x = g[x][i], y = g[y][i];
	}
	return T[x];
}
int main()
{

	while (cin >> n){
		priority_queue<pair<int, pair<int, int> >, V<pair<int, pair<int, int>  > >, greater<pair<int, pair<int, int> > > > pq;
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				sf(in[i][j]);
				if (j > i)
					pq.push(MP(in[i][j], MP(i, j)));
			}
		}
		adj.resize(n);
		UnionFind me(n);
		while (pq.empty() == 0){
			pair<int, pair<int, int> > p = pq.top();
			pq.pop();
			if (me.union_set(p.second.first, p.second.second)){
				adj[p.second.first].push_back(p.second.second);
				adj[p.second.second].push_back(p.second.first);
			}
		}
		dfs(0, 0, 0, -1);
		built();
		bool ok = 1;
		for (int i = 0; i < n; i++){
			for (int j = i + 1; j < n; j++){
				int lca = LCA(i, j);
				ll now = pref[i] + pref[j] - pref[lca];
				ok &= (in[i][j] == now && now > 0) && (in[j][i] == now && now > 0);
				if (!ok) break;
			}
		}
		for (int i = 0; i < n; i++)
			ok &= in[i][i] == 0;
		if (ok) cout << "YES" << endl;
		else cout << "NO" << endl;
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define V vector
#define MP make_pair
#define all(v)  ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define clr(v, d) memset(v, d, sizeof(v))
#define sf(x) scanf("%d", &x)
#define sf2(x, y) scanf("%d %d", &x, &y)
#define sf3(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define sfll(x) scanf("%I64d", &x)
#define sfll2(x, y) scanf("%I64d %I64d", &x, &y)
#define sfll3(x, y, z) scanf("%I64d %I64d %I64d", &x, &y, &z)
typedef long long ll;
int dx[]{1, -1, 0, 0, 1, -1, 1, -1};
int dy[]{0, 0, 1, -1, 1, -1, -1, 1};
ll suf(ll x) { return (x * (x + 1)) / 2; }
V<V<int> > adj;
//V<V<int > > adj2;
const ll mod = 1e9 + 7, oo = 1e9 + 10, MAX = 2005;
int n, m , g[MAX][12] ,dis[MAX][12], in[MAX][MAX] , T[MAX] , L[MAX] , vs[MAX] ,cmp[MAX][MAX] , cur  = 0;
bool done[MAX] , vbf[MAX];

void dfs(int nd, int lst, int l){
	L[nd] = l;
	T[nd] = lst;
	if (vs[nd] == cur) return;
	vs[nd] = cur;
	for (int i = 0; i < adj[nd].size(); i++){
		if (lst == adj[nd][i]) continue;
		dfs(adj[nd][i], nd, l + 1);
	}
}
void built(){
	clr(g, -1);
	for (int i = 0; i < n; i++){
		g[i][0] = T[i];
		dis[i][0] = in[i][T[i]];
	}
	for (int j = 1; j < 12; j++){
		for (int i = 0; i < n; i++){
			if (g[i][j - 1] != -1){
				g[i][j] = g[g[i][j - 1]][j - 1];
				dis[i][j] = dis[g[i][j - 1]][j - 1] + dis[i][j - 1];
			}
		}
	}
}

int get(int x, int y){
	int sum = 0;
	if (L[x] < L[y]) swap(x, y);
	for (int j = 11; j >= 0; j--){
		if (L[x] - (1 << j) >= L[y]){
			sum += dis[x][j];
			x = g[x][j];
		}
	}
	if (x == y) return sum;
	for (int j = 11; j >= 0; j--){
		if (g[x][j] != -1 && g[x][j] != g[y][j]){
			sum += dis[x][j];
			sum += dis[y][j];
			x = g[x][j], y = g[y][j];
		}
	}
	return sum + in[x][T[x]] + in[y][T[y]];
}
int main()
{

	while (cin >> n){
		adj.resize(n);
		V<pair<int, pair<int, int> > > p;
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				sf(in[i][j]);
				if (j > i)
					p.push_back(MP(in[i][j], MP(i, j)));
			}
		}
		sort(all(p));
		for (int i = 0; i < p.size(); i++){
			cur++;
			if (vbf[p[i].second.first]== 1 && vbf[p[i].second.second] == 1) continue;
			adj[p[i].second.first].push_back(p[i].second.second);
			adj[p[i].second.second].push_back(p[i].second.first);
			vbf[p[i].second.first] = vbf[p[i].second.second] = 1;
		}
		cur++;
		dfs(0, -1, 0);
		built();
		for (int i = 0; i < n; i++){
			for (int j = i + 1; j < n; j++){
				cmp[i][j] = cmp[j][i] = get(i, j);
			}
		}
		bool ok = 1;
		for (int i = 0; i < n && ok; i++){
			for (int j = 0; j < n&&ok; j++){
				if (cmp[i][j] != in[i][j] || (i != j) && cmp[i][j] == 0)
					ok = 0;
			}
		}
		if (ok) cout << "YES" << endl;
		else cout << "NO" << endl;
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define V vector
#define MP make_pair
#define all(v)  ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define clr(v, d) memset(v, d, sizeof(v))
#define sf(x) scanf("%d", &x)
#define sf2(x, y) scanf("%d %d", &x, &y)
#define sf3(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define sfll(x) scanf("%I64d", &x)
#define sfll2(x, y) scanf("%I64d %I64d", &x, &y)
#define sfll3(x, y, z) scanf("%I64d %I64d %I64d", &x, &y, &z)
typedef long long ll;
int dx[]{1, -1, 0, 0, 1, -1, 1, -1};
int dy[]{0, 0, 1, -1, 1, -1, -1, 1};
ll suf(ll x) { return (x * (x + 1)) / 2; }
V<V<int > > adj;
const ll mod = 1e9 + 7, oo = 1e9 + 10, MAX = 2005;
int n, m , in[MAX][MAX] , pref[MAX] , g[MAX][12] , T[MAX] , L[MAX];

struct UnionFind{
	vector<int> rank, F;
	int comp;
	UnionFind(int n){
		rank = vector<int>(n);
		F = vector<int>(n);
		comp = n;
		for (int i = 0; i < n; i++)
			F[i] = i;
	}
	int find_set(int x){
		if (x == F[x]) return x;
		return F[x] = find_set(F[x]);
	}
	void link(int x, int y){
		if (rank[x] > rank[y]) swap(x, y);
		if (rank[x] == rank[y]) rank[y]++;
		F[x] = y;
	}
	bool union_set(int x, int y){
		x = find_set(x), y = find_set(y);
		if (x == y) return 0;
		link(x, y);
		comp--;
		return 1;
	}
};
void dfs(int nd, int sum, int l, int lst){
	pref[nd] = sum, L[nd] = l, T[nd] = lst;
	for (int i = 0; i < adj[nd].size(); i++){
		int ch = adj[nd][i];
		if (ch == lst) continue;
		dfs(ch, sum + in[nd][ch], l + 1 , nd);
	}
}

void built(){
	clr(g, -1);
	for (int i = 0; i < n; i++)
		g[i][0] = T[i];

	for (int j = 1; j < 12; j++){
		for (int i = 0; i < n; i++){
			if (g[i][j - 1] != -1)
				g[i][j] = g[g[i][j - 1]][j - 1];
		}
	}
}
int LCA(int x, int y){
	if (L[x] < L[y]) swap(x, y);
	for (int i = 11; i >= 0; i--){
		if (L[x] - (1 << i) >= L[y])
			x = g[x][i];
	}
	if (x == y) return x;
	for (int i = 11; i >= 0; i--){
		if (g[x][i] != -1 && g[x][i] != g[y][i])
			x = g[x][i], y = g[y][i];
	}
	return T[x];
}
int main()
{

	while (cin >> n){
		priority_queue<pair<int, pair<int, int> >, V<pair<int, pair<int, int>  > >, greater<pair<int, pair<int, int> > > > pq;
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				sf(in[i][j]);
				if (j > i)
					pq.push(MP(in[i][j], MP(i, j)));
			}
		}
		adj.resize(n);
		UnionFind me(n);
		while (pq.empty() == 0){
			pair<int, pair<int, int> > p = pq.top();
			pq.pop();
			if (me.union_set(p.second.first, p.second.second)){
				adj[p.second.first].push_back(p.second.second);
				adj[p.second.second].push_back(p.second.first);
			}
		}
		dfs(0, 0, 0, -1);
		built();
		bool ok = 1;
		for (int i = 0; i < n; i++){
			for (int j = i + 1; j < n; j++){
				int lca = LCA(i, j);
				int now = pref[i] + pref[j] - pref[lca];
				ok &= (in[i][j] == now && now > 0) && (in[j][i] == now && now > 0);
				if (!ok) break;
			}
		}
		for (int i = 0; i < n; i++)
			ok &= in[i][i] == 0;
		if (ok) cout << "YES" << endl;
		else cout << "NO" << endl;
	}

	return 0;
}


#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#include<bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define ll long long
const int OO = 0x3f3f3f3f, N = 2e5 + 5,mod = 1e9 + 7;

ll arr[2005][2005];
vector<int> parent;

void make_set(int v) {
    parent[v] = v;
}

int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        parent[b] = a;

    }
}

struct Edge {
    int u, v;
    ll weight;
    bool operator<(Edge const& other) {
        return weight < other.weight;
    }
};
vector<ll>dep,vis;
vector< vector<pair<ll,ll>>> gg;
int *cost;
int w[2000][2000];
void DFS(int u, int p){
    for (int i = 0; i < gg[u].size();++i)
    if (gg[u][i].first != p){
        cost[gg[u][i].first] = cost[u] + gg[u][i].second;
        DFS(gg[u][i].first, u);
    }
}

                                   /***  بسم الله الرحمن الرحيم😁  ***/
int main() {
        fast

 int n;cin>>n;
    vector<Edge>g;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++){
            cin>>arr[i][j];
            g.push_back({i,j,arr[i][j]});
        }
    for(int i=0;i<n;i++)
        if(arr[i][i]){cout<<"NO";return 0;}

    parent.resize(n);
    //rank.resize(n);
    for (int i = 0; i < n; i++)make_set(i);

    sort(g.begin(), g.end());
    gg.resize(n);
    for (Edge t : g) {
        if (find_set(t.u) != find_set(t.v)) {
            gg[t.u].push_back({t.v,t.weight});
            gg[t.v].push_back({t.u,t.weight});
            union_sets(t.u, t.v);
        }
    }

    for (int i = 0; i < n; ++i){
        cost = w[i];
        cost[i] = 0;
        DFS(i, -1);
    }
    for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
    if (w[i][j] != arr[i][j]){
        puts("NO");
        return 0;
    }
    puts("YES");

}


#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#include<bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define ll long long
const int OO = 0x3f3f3f3f, N = 2e5 + 5,mod = 1e9 + 7;

ll arr[2005][2005];
vector<int> parent;

void make_set(int v) {
    parent[v] = v;
}

int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        parent[b] = a;

    }
}

struct Edge {
    int u, v;
    ll weight;
    bool operator<(Edge const& other) {
        return weight < other.weight;
    }
};
vector<ll>dep,vis;
vector< vector<pair<ll,ll>>> gg;
int *cost;
int w[2000][2000];
void DFS(int u, int p){
    for (int i = 0; i < gg[u].size();++i)
    if (gg[u][i].first != p){
        cost[gg[u][i].first] = cost[u] + gg[u][i].second;
        DFS(gg[u][i].first, u);
    }
}

                                   /***  بسم الله الرحمن الرحيم😁  ***/
int main() {
        fast

 int n;cin>>n;
    vector<Edge>g;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++){
            cin>>arr[i][j];
            if(i==j&&arr[i][j]){cout<<"NO";return 0;}
            if(i!=j&&!arr[i][j]){cout<<"NO";return 0;}
            g.push_back({i,j,arr[i][j]});
        }

    parent.resize(n);
    //rank.resize(n);
    for (int i = 0; i < n; i++)make_set(i);

    sort(g.begin(), g.end());
    gg.resize(n);
    for (Edge t : g) {
        if (find_set(t.u) != find_set(t.v)) {
            gg[t.u].push_back({t.v,t.weight});
            gg[t.v].push_back({t.u,t.weight});
            union_sets(t.u, t.v);
        }
    }

    for (int i = 0; i < n; ++i){
        cost = w[i];
        cost[i] = 0;
        DFS(i, -1);
    }
    for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
    if (w[i][j] != arr[i][j]){
        puts("NO");
        return 0;
    }
    puts("YES");

}


#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#include<bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define ll long long
const int OO = 0x3f3f3f3f, N = 2e5 + 5,mod = 1e9 + 7;

ll arr[2005][2005];
vector<int> parent;

void make_set(int v) {
    parent[v] = v;
}

int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        parent[b] = a;

    }
}

struct Edge {
    int u, v;
    ll weight;
    bool operator<(Edge const& other) {
        return weight < other.weight;
    }
};
vector<ll>dep,vis;
vector< vector<pair<ll,ll>>> gg;
void BFS(int u , int n){
    dep=vector<ll>(n,-1);
    vis=vector<ll>(n,0);
    queue<pair<ll,ll>>q;
    q.push({u,0});
    dep[u]=0;
    vis[u]=1;
    while(!q.empty()){
        pair<int,ll>p=q.front(); q.pop();
        for(auto t : gg[p.first]){
            if(!vis[t.first]){
                vis[t.first]=1;
                dep[t.first]=p.second+t.second;
                q.push(t);
            }
        }

    }

}

                                   /***  بسم الله الرحمن الرحيم😁  ***/
int main() {
        fast
 // read 9:01 probblem i finish  9:08 Why 5 trips ?!
 // start 9:23  depug😪
 // start in G 9:28
 int n;cin>>n;
    vector<Edge>g;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++){
            cin>>arr[i][j];
            g.push_back({i,j,arr[i][j]});
        }
    for(int i=0;i<n;i++)
        if(arr[i][i]){cout<<"NO";return 0;}

    vector<Edge> result;
    parent.resize(n);
    //rank.resize(n);
    for (int i = 0; i < n; i++)make_set(i);

    sort(g.begin(), g.end());

    for (Edge e : g) {
        if (find_set(e.u) != find_set(e.v)) {

            result.push_back(e);
            union_sets(e.u, e.v);
        }
    }
    gg.resize(n);
    for(auto t : result){
        gg[t.u].push_back({t.v,t.weight});
        gg[t.v].push_back({t.u,t.weight});
    }
    for(int i=0;i<n;i++){
        BFS(i,n);
        for(int j=0;j<n;j++){

            if(arr[i][j]!=dep[j] || (i!=j&&arr[i][j]==0) ){cout<<"NO";return 0;}
        }

    }
    cout<<"YES\n";

}


#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#include<bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define ll long long
const int OO = 0x3f3f3f3f, N = 2e5 + 5,mod = 1e9 + 7;

int arr[2005][2005];
vector<int> parent;

void make_set(int v) {
    parent[v] = v;
}

int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        parent[b] = a;

    }
}

struct Edge {
    int u, v, weight;
    bool operator<(Edge const& other) {
        return weight < other.weight;
    }
};
vector<int>dep,vis;
vector< vector<pair<int,int>>> gg;
void BFS(int u , int n){
    dep=vector<int>(n,-1);
    vis=vector<int>(n,0);
    queue<pair<int,int>>q;
    q.push({u,0});
    dep[u]=0;vis[u]=1;
    while(!q.empty()){
        pair<int,int>p=q.front(); q.pop();
        for(auto t : gg[p.first]){
            //cout<<t.first<<" "<<t.second<<endl;
            if(!vis[t.first]){
                vis[t.first]=1;
                dep[t.first]=p.second+t.second;
                q.push(t);
            }
        }

    }

}

                                   /***  بسم الله الرحمن الرحيم😁  ***/
int main() {
        fast
 // read 9:01 probblem i finish  9:08 Why 5 trips ?!
 // start 9:23  depug😪
 // start in G 9:28
 int n;cin>>n;
    vector<Edge>g;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++){
            cin>>arr[i][j];
            g.push_back({i,j,arr[i][j]});
        }
    for(int i=0;i<n;i++)
        if(arr[i][i]){cout<<"NO";return 0;}

    vector<Edge> result;
    parent.resize(n);
    //rank.resize(n);
    for (int i = 0; i < n; i++)make_set(i);

    sort(g.begin(), g.end());

    for (Edge e : g) {
        if (find_set(e.u) != find_set(e.v)) {

            result.push_back(e);
            union_sets(e.u, e.v);
        }
    }
    gg.resize(n);
    for(auto t : result){
        gg[t.u].push_back({t.v,t.weight});
        gg[t.v].push_back({t.u,t.weight});
    }
    for(int i=0;i<n;i++){
        BFS(i,n);
        for(int j=0;j<n;j++){

            if(arr[i][j]!=dep[j] || (i!=j&&arr[i][j]==0) ){cout<<"NO";return 0;}
        }

    }
    cout<<"YES\n";

}


#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#include<bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define ll long long
const int OO = 0x3f3f3f3f, N = 2e5 + 5,mod = 1e9 + 7;

ll arr[2005][2005];
vector<int> parent;

void make_set(int v) {
    parent[v] = v;
}

int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        parent[b] = a;

    }
}

struct Edge {
    int u, v;
    ll weight;
    bool operator<(Edge const& other) {
        return weight < other.weight;
    }
};
vector<ll>dep,vis;
vector< vector<pair<ll,ll>>> gg;
void BFS(int u , int n){
    dep=vector<ll>(n,0);
    vis=vector<ll>(n,0);
    queue<pair<ll,ll>>q;
    q.push({u,0});
    dep[u]=0;
    vis[u]=1;
    while(!q.empty()){
        pair<int,ll>p=q.front(); q.pop();
        for(auto t : gg[p.first]){
            if(!vis[t.first]){
                vis[t.first]=1;
                dep[t.first]=p.second+t.second;
                q.push(t);
            }
        }

    }

}

                                   /***  بسم الله الرحمن الرحيم😁  ***/
int main() {
        fast
 // read 9:01 probblem i finish  9:08 Why 5 trips ?!
 // start 9:23  depug😪
 // start in G 9:28
 int n;cin>>n;
    vector<Edge>g;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++){
            cin>>arr[i][j];
            g.push_back({i,j,arr[i][j]});
        }
    for(int i=0;i<n;i++)
        if(arr[i][i]){cout<<"NO";return 0;}

    parent.resize(n);
    //rank.resize(n);
    for (int i = 0; i < n; i++)make_set(i);

    sort(g.begin(), g.end());
    gg.resize(n);
    for (Edge t : g) {
        if (find_set(t.u) != find_set(t.v)) {
            gg[t.u].push_back({t.v,t.weight});
            gg[t.v].push_back({t.u,t.weight});
            union_sets(t.u, t.v);
        }
    }

    for(int i=0;i<n;i++){
        BFS(i,n);
        for(int j=0;j<n;j++){
            if(arr[i][j]!=dep[j] || (i!=j&&arr[i][j]==0) ){cout<<"NO";return 0;}
        }

    }
    cout<<"YES\n";

}


//  RAKSHIT KADAM
 #include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
 #warning !!!check the size of arrayss!!!

 #define ll long long
 #define int long long
 #define MOD  1000000007
 #define newMOD  998244353
 #define MAX 200006
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define endl "\n"
 #define x first
 #define y second
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define INF 1000000000000000005
 #define vi vector<ll>
 #define PI 3.14159265

using namespace std;
//int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;                                                  return (y%2 == 0)? p : (x * p) % m;}

//ll modInverse(int a, int m){int g = gcd(a, m); { return power(a, m-2, m);}}
//ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
void solve()
{
    ll a[2005][2005]={0};
    ll n;cin>>n;
    for(ll i=1;i<=n;i++)for(ll j=1;j<=n;j++)cin>>a[i][j];
    for(ll i=1;i<=n;i++)
    {
        if(a[i][i]){cout<<"NO"<<endl;return;} ll h=1;
        for(ll j=1;j<=n;j++)
        {
            if(a[i][j]!=a[j][i]){cout<<"NO"<<endl;return;}
            if(i!=j && a[i][h]>a[i][j])h=j;
        }
        for(ll j=1;j<=n;j++)
        {

            if(abs(a[i][j]-a[h][j])!=a[i][h]){cout<<"NO"<<endl;return;}
        }
    }
    cout<<"YES"<<endl;
}
signed main()
{
    Need_for_speed(activated);
//       satisfy
//       {
//           solve();
//       }
//
  solve();
//

    return 0;}


//  RAKSHIT KADAM
 #include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
 #warning !!!check the size of arrayss!!!

 #define ll long long
 #define int long long
 #define MOD  1000000007
 #define newMOD  998244353
 #define MAX 200006
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define endl "\n"
 #define x first
 #define y second
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define INF 1000000000000000005
 #define vi vector<ll>
 #define PI 3.14159265

using namespace std;
//int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;                                                  return (y%2 == 0)? p : (x * p) % m;}

//ll modInverse(int a, int m){int g = gcd(a, m); { return power(a, m-2, m);}}
//ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
void solve()
{
    ll a[2005][2005]={0};
    ll n;cin>>n;
    for(ll i=1;i<=n;i++)for(ll j=1;j<=n;j++)cin>>a[i][j];
    for(ll i=1;i<=n;i++)
    {
        if(a[i][i]){cout<<"NO"<<endl;return;} ll h=1;
        for(ll j=1;j<=n;j++)
        {
            if(a[i][j]!=a[j][i]||!a[i][j]){cout<<"NO"<<endl;return;}
            if(i!=j && a[i][h]>a[i][j])h=j;
        }
        for(ll j=1;j<=n;j++)
        {

            if(abs(a[i][j]-a[h][j])!=a[i][h]){cout<<"NO"<<endl;return;}
        }
    }
    cout<<"YES"<<endl;
}
signed main()
{
    Need_for_speed(activated);
//       satisfy
//       {
//           solve();
//       }
//
  solve();
//

    return 0;}


//  RAKSHIT KADAM
 #include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
 #warning !!!check the size of arrayss!!!

 #define ll long long
 #define int long long
 #define MOD  1000000007
 #define newMOD  998244353
 #define MAX 200006
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define endl "\n"
 #define x first
 #define y second
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define INF 1000000000000000005
 #define vi vector<ll>
 #define PI 3.14159265

using namespace std;
//int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;                                                  return (y%2 == 0)? p : (x * p) % m;}

//ll modInverse(int a, int m){int g = gcd(a, m); { return power(a, m-2, m);}}
//ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
void solve()
{
    ll a[2005][2005]={0};
    ll n;cin>>n;
    for(ll i=1;i<=n;i++)for(ll j=1;j<=n;j++)cin>>a[i][j];
    for(ll i=1;i<=n;i++)
    {
        if(a[i][i]){cout<<"NO"<<endl;return;} ll h=1;
        for(ll j=1;j<=n;j++)
        {
            if(a[i][j]!=a[j][i]||(!a[i][j]&&i!=j)){cout<<"NO"<<endl;return;}
            if(i!=j && a[i][h]>a[i][j])h=j;
        }
        for(ll j=1;j<=n;j++)
        {

            if(abs(a[i][j]-a[h][j])!=a[i][h]){cout<<"NO"<<endl;return;}
        }
    }
    cout<<"YES"<<endl;
}
signed main()
{
    Need_for_speed(activated);
//       satisfy
//       {
//           solve();
//       }
//
  solve();
//

    return 0;}


//  RAKSHIT KADAM
 #include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
 #warning !!!check the size of arrayss!!!

 #define ll long long
 #define int long long
 #define MOD  1000000007
 #define newMOD  998244353
 #define MAX 200006
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define endl "\n"
 #define x first
 #define y second
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define INF 1000000000000000005
 #define vi vector<ll>
 #define PI 3.14159265

using namespace std;
//int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;                                                  return (y%2 == 0)? p : (x * p) % m;}

//ll modInverse(int a, int m){int g = gcd(a, m); { return power(a, m-2, m);}}
//ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
void solve()
{
    ll a[2005][2005]={0};
    ll n;cin>>n;
    for(ll i=1;i<=n;i++)for(ll j=1;j<=n;j++)cin>>a[i][j];
    for(ll i=1;i<=n;i++)
    {
        if(a[i][i]){cout<<"NO"<<endl;return;} ll h=i;
        for(ll j=1;j<=n;j++)
        {
            if(a[i][j]!=a[j][i]){cout<<"NO"<<endl;return;}
            if(i!=j && a[i][h]>a[i][j])h=j;
        }
        for(ll j=1;j<=n;j++)
        {

            if(abs(a[i][j]-a[h][j])!=a[i][h]){cout<<"NO"<<endl;return;}
        }
    }
    cout<<"YES"<<endl;
}
signed main()
{
    Need_for_speed(activated);
//       satisfy
//       {
//           solve();
//       }
//
  solve();
//

    return 0;}


//  RAKSHIT KADAM
 #include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
 #warning !!!check the size of arrayss!!!

 #define ll long long
 #define int long long
 #define MOD  1000000007
 #define newMOD  998244353
 #define MAX 200006
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define endl "\n"
 #define x first
 #define y second
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define INF 1000000000000000005
 #define vi vector<ll>
 #define PI 3.14159265

using namespace std;
//int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;                                                  return (y%2 == 0)? p : (x * p) % m;}

//ll modInverse(int a, int m){int g = gcd(a, m); { return power(a, m-2, m);}}
//ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
void solve()
{
    ll a[2005][2005]={0};
    ll n;cin>>n;
    for(ll i=1;i<=n;i++)for(ll j=1;j<=n;j++)cin>>a[i][j];
    for(ll i=1;i<=n;i++)
    {
        if(a[i][i]!=0){cout<<"NO"<<endl;return;} ll h=1;
        for(ll j=1;j<=n;j++)
        {
            if(a[i][j]!=a[j][i]){cout<<"NO"<<endl;return;}
            if(i!=j && a[i][h]>a[i][j])h=j;
        }
        for(ll j=1;j<=n;j++)
        {
            if(i==j)continue;
            if(a[i][j]!=a[i][h]+a[h][j]){cout<<"NO"<<endl;return;}
        }
    }
    cout<<"YES"<<endl;
}
signed main()
{
    Need_for_speed(activated);
//       satisfy
//       {
//           solve();
//       }
//
  solve();
//

    return 0;}


#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#define mp make_pair

using namespace std;

ifstream in("inverse_the_problem.in");
ofstream out("inverse_the_problem.out");

const int Nmax = 2000;

int l;
vector<int> A[Nmax];
vector<int> dad(Nmax);
vector<int> viz(Nmax);
vector<vector<int>> d(Nmax, vector<int>(Nmax));
vector<vector<int>> init(Nmax, vector<int>(Nmax));
vector<vector<int>> cost(Nmax, vector<int>(Nmax));

struct nod
{
    int x;
    int y;
    int c;
}v[Nmax * Nmax];

bool cmp (nod a, nod b)
{
    return a.c < b.c;
}

int Find (int x)
{
    if (dad[x] == x) return x;
    return dad[x] = Find (dad[x]);
}

void Union (int x, int y)
{
    dad[x] = y;
}

void DFS (int x, int cnt, int dist)
{
    viz[x] = l;

    for (auto i = 0; i < A[x].size(); i++)
    {
        int w = A[x][i];

        if (viz[w] == 1 - l)
        {
            d[cnt][w] = dist + cost[x][w];
            int rez = d[cnt][w];
            DFS(w, cnt, d[cnt][w]);
        }
    }
}

int main()
{
    int n, nr = 0;
    cin >> n;

    for (int i = 1; i <= n; i++)
    {
        dad[i] = i;

        for (int j = 1; j <= n; j++)
        {
            int c;
            cin >> init[i][j];
            c = init[i][j];

            nr++;
            v[nr].x = i;
            v[nr].y = j;
            v[nr].c = c;
        }
    }

    sort (v + 1, v + n * n + 1, cmp);

    for (int i = 1; i <= n * n; i++)
    {
        int x = v[i].x;
        int y = v[i].y;
        int c = v[i].c;

        int xx = Find(x);
        int yy = Find(y);

        if (xx != yy)
        {
            Union(xx, yy);

            A[x].push_back(y);
            A[y].push_back(x);

            cost[x][y] = c;
            cost[y][x] = c;

            if (c == 0)
            {
                cout << "NO";
                return 0;
            }
        }
    }

    for (int i = 1; i <= n; i++)
    {
        l = 1 - l;
        DFS(i, i, 0);
    }

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
        {
            if (d[i][j] != init[i][j])
            {
                cout << "NO";
                return 0;
            }
        }

    cout << "YES";
    return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <queue>

using namespace std;

ifstream in("inverse_the_problem.in");
ofstream out("inverse_the_problem.out");

const int Nmax = 2000;

int l;
int dad[Nmax], viz[Nmax];
int cost[Nmax][Nmax], v[Nmax][Nmax], d[Nmax][Nmax];
bool OK = true;

struct Nod
{
    int x;
    int y;
    int c;
};

struct comp
{
    bool operator()(Nod X, Nod Y)
    {
        return X.c > Y.c;
    }
};

priority_queue <Nod,  vector<Nod>, comp> Q;
vector <int> A[Nmax];

int Find (int x)
{
    if (dad[x] == x) return x;
    return dad[x] = Find(dad[x]);
}

void Union (int x, int y)
{
    dad[x] = y;
}

void DFS (int x, int cnt)
{
    if (OK == true)
    {
        viz[x] = l;

        for (auto i = 0; i < A[x].size(); i++)
        {
            int w = A[x][i];

            if (viz[w] == 1 - l)
            {
                d[cnt][w] = d[cnt][x] + cost[x][w];

                if (v[cnt][w] != d[cnt][w])
                {
                    OK = false;
                    return;
                }

                DFS(w, cnt);
            }
        }
    }
}

int main()
{
    int n;
    cin >> n;

    for (int i = 1; i <= n; i++)
    {
        if (v[i - 1][i - 1] != 0)
        {
            cout << "NO";
            return 0;
        }
        dad[i] = i;
            for (int j = 1; j <= n; j++)
        {
            cin >> v[i][j];

            int c = v[i][j];
            Nod nod;

            nod.x = i;
            nod.y = j;
            nod.c = c;

            Q.push(nod);
        }
    }

    if (v[n][n] != 0)
    {
        cout << "NO";
        return 0;
    }

    while (!Q.empty())
    {
        int x = Q.top().x;
        int y = Q.top().y;
        int c = Q.top().c;

        int xx = Find(x);
        int yy = Find(y);

        if (xx != yy)
        {
            Union(xx, yy);

            A[x].push_back(y);
            A[y].push_back(x);

            cost[x][y] = c;
            cost[y][x] = c;

            if (c == 0)
            {
                cout << "NO";
                return 0;
            }
        }

        Q.pop();
    }

    for (int i = 1; i <= n; i++)
    {
        l = 1 - l;
        DFS(i, i);

        if (OK == false)
        {
            cout << "NO";
            return 0;
        }
    }

    cout << "YES";
    return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#define mp make_pair

using namespace std;

ifstream in("inverse_the_problem.in");
ofstream out("inverse_the_problem.out");

const int Nmax = 2000;

int dad[Nmax];
int cost[Nmax][Nmax], v[Nmax][Nmax];
bool OK = true;

struct Nod
{
    int x;
    int y;
    int c;
};

struct comp
{
    bool operator()(Nod X, Nod Y)
    {
        return X.c > Y.c;
    }
};

priority_queue <Nod,  vector<Nod>, comp> Q;
vector <int> A[Nmax];

int Find (int x)
{
    if (dad[x] == x) return x;
    return dad[x] = Find(dad[x]);
}

void Union (int x, int y)
{
    dad[x] = y;
}

void DFS (int x, int cnt, vector<int> viz, vector<int> d)
{
    if (OK == true)
    {
        viz[x] = 1;

        for (auto i = 0; i < A[x].size(); i++)
        {
            int w = A[x][i];

            if (viz[w] == 0)
            {
                d[w] = d[x] + cost[x][w];

                if (v[cnt][w] != d[w])
                {
                    OK = false;
                    return;
                }

                DFS(w, cnt, viz, d);
            }
        }
    }
}

int main()
{
    int n;
    cin >> n;

    for (int i = 1; i <= n; i++)
    {
        if (v[i - 1][i - 1] != 0)
        {
            cout << "NO";
            return 0;
        }

        dad[i] = i;
            for (int j = 1; j <= n; j++)
        {
            cin >> v[i][j];

            int c = v[i][j];
            Nod nod;

            nod.x = i;
            nod.y = j;
            nod.c = c;

            Q.push(nod);
        }
    }

    if (v[n][n] != 0)
    {
        cout << "NO";
        return 0;
    }

    while (!Q.empty())
    {
        int x = Q.top().x;
        int y = Q.top().y;
        int c = Q.top().c;

        int xx = Find(x);
        int yy = Find(y);

        if (xx != yy)
        {
            Union(xx, yy);

            A[x].push_back(y);
            A[y].push_back(x);

            cost[x][y] = c;
            cost[y][x] = c;

            if (c == 0)
            {
                cout << "NO";
                return 0;
            }
        }

        Q.pop();
    }

    for (int i = 1; i <= n; i++)
    {
        vector <int> viz(Nmax), d(Nmax);
        DFS(i, i, viz, d);

        if (OK == false)
        {
            cout << "NO";
            return 0;
        }
    }

    cout << "YES";
    return 0;
}


#include <iostream>
#include <vector>
#include <queue>

using namespace std;

const int Nmax = 2000;

int i, l;
int dad[Nmax], viz[Nmax];
int cost[Nmax][Nmax], v[Nmax][Nmax], d[Nmax][Nmax];

struct Nod
{
    int x;
    int y;
    int c;
};

struct comp
{
    bool operator()(Nod X, Nod Y)
    {
        return X.c > Y.c;
    }
};

priority_queue <Nod,  vector<Nod>, comp> Q;
vector <int> A[Nmax];

int Find (int x)
{
    if (dad[x] == x) return x;
    return dad[x] = Find(dad[x]);
}

void Union (int x, int y)
{
    dad[x] = y;
}

void DFS (int x)
{

    viz[x] = l;
    for (auto j = 0; j < A[x].size(); j++)
    {
        int w = A[x][j];
        if (viz[w] == 1 - l)
        {
            d[i][w] = d[i][x] + cost[x][w];
            DFS(w);
        }
    }
}

int main()
{
    int n;
    cin >> n;

    for (int i = 1; i <= n; i++)
    {
        dad[i] = i;
            for (int j = 1; j <= n; j++)
        {
            cin >> v[i][j];

            int c = v[i][j];
            Nod nod;

            nod.x = i;
            nod.y = j;
            nod.c = c;

            Q.push(nod);
        }
    }

    while (!Q.empty())
    {
        int x = Q.top().x;
        int y = Q.top().y;
        int c = Q.top().c;

        int xx = Find(x);
        int yy = Find(y);

        if (xx != yy)
        {
            Union(xx, yy);

            A[x].push_back(y);
            A[y].push_back(x);

            cost[x][y] = c;
            cost[y][x] = c;

            if (c == 0)
            {
                cout << "NO";
                return 0;
            }
        }

        Q.pop();
    }

    for (i = 1; i <= n; i++)
    {
        l = 1 - l;
        DFS(i);
    }

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
        {
            if (d[i][j] != v[i][j])
            {
                cout << "NO";
                return 0;
            }
        }

    cout << "YES";
    return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <queue>

using namespace std;

ifstream in("inverse_the_problem.in");
ofstream out("inverse_the_problem.out");

const int Nmax = 2000;

int i;
int dad[Nmax];
int cost[Nmax][Nmax], v[Nmax][Nmax];
bool OK = true;

struct Nod
{
    int x;
    int y;
    int c;
};

struct comp
{
    bool operator()(Nod X, Nod Y)
    {
        return X.c > Y.c;
    }
};

priority_queue <Nod,  vector<Nod>, comp> Q;
vector <int> A[Nmax], viz(Nmax), d(Nmax);

int Find (int x)
{
    if (dad[x] == x) return x;
    return dad[x] = Find(dad[x]);
}

void Union (int x, int y)
{
    dad[x] = y;
}

void DFS (int x)
{
    if (OK == true)
    {
        viz[x] = 1;

        for (auto j = 0; j < A[x].size(); j++)
        {
            int w = A[x][j];

            if (viz[w] == 0)
            {
                d[w] = d[x] + cost[x][w];

                if (v[i][w] != d[w])
                {
                    OK = false;
                    return;
                }

                DFS(w);
            }
        }
    }
}

int main()
{
    int n;
    cin >> n;

    for (i = 1; i <= n; i++)
    {
        if (v[i - 1][i - 1] != 0)
        {
            cout << "NO";
            return 0;
        }

        dad[i] = i;
            for (int j = 1; j <= n; j++)
        {
            cin >> v[i][j];

            int c = v[i][j];
            Nod nod;

            nod.x = i;
            nod.y = j;
            nod.c = c;

            Q.push(nod);
        }
    }

    if (v[n][n] != 0)
    {
        cout << "NO";
        return 0;
    }

    while (!Q.empty())
    {
        int x = Q.top().x;
        int y = Q.top().y;
        int c = Q.top().c;

        int xx = Find(x);
        int yy = Find(y);

        if (xx != yy)
        {
            Union(xx, yy);

            A[x].push_back(y);
            A[y].push_back(x);

            cost[x][y] = c;
            cost[y][x] = c;

            if (c == 0)
            {
                cout << "NO";
                return 0;
            }
        }

        Q.pop();
    }

    for (i = 1; i <= n; i++)
    {
        DFS(i);

        viz.clear();
        d.clear();

        if (OK == false)
        {
            cout << "NO";
            return 0;
        }
    }

    cout << "YES";
    return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
#define mp make_pair

using namespace std;

ifstream in("inverse_the_problem.in");
ofstream out("inverse_the_problem.out");

const int Nmax = 2000;

int dad[Nmax], viz[Nmax], d[Nmax];
int cost[Nmax][Nmax], v[Nmax][Nmax];
bool OK;

struct Nod
{
    int x;
    int y;
    int c;
};

struct comp
{
    bool operator()(Nod X, Nod Y)
    {
        return X.c > Y.c;
    }
};

priority_queue <Nod,  vector<Nod>, comp> Q;
vector <int> A[Nmax];

int Find (int x)
{
    if (dad[x] == x) return x;
    return dad[x] = Find(dad[x]);
}

void Union (int x, int y)
{
    dad[x] = y;
}

void DFS (int x, int cnt)
{
    if (OK == true)
    {
        viz[x] = 1;

        for (auto i = 0; i < A[x].size(); i++)
        {
            int w = A[x][i];

            if (viz[w] == 0)
            {
                d[w] = d[x] + cost[x][w];

                if (v[cnt][w] != d[w])
                {
                    OK = false;
                    return;
                }

                DFS(w, cnt);
            }
        }
    }
}

int main()
{
    int n;
    cin >> n;

    for (int i = 1; i <= n; i++)
    {
        dad[i] = i;
            for (int j = 1; j <= n; j++)
        {
            cin >> v[i][j];

            int c = v[i][j];
            Nod nod;

            nod.x = i;
            nod.y = j;
            nod.c = c;

            Q.push(nod);
        }
    }

   /* while (!Q.empty())
    {
        out << Q.top().x << ' ' << Q.top().y << ' ' << Q.top().c << '\n';
        Q.pop();
    }*/

    while (!Q.empty())
    {
        int x = Q.top().x;
        int y = Q.top().y;
        int c = Q.top().c;

        int xx = Find(x);
        int yy = Find(y);

        if (xx != yy)
        {
            Union(xx, yy);

            A[x].push_back(y);
            A[y].push_back(x);

            cost[x][y] = c;
            cost[y][x] = c;

            if (c == 0)
            {
                cout << "NO";
                return 0;
            }
        }

        Q.pop();
    }

    for (int i = 1; i <= n; i++)
    {
        OK = true;
        DFS(i, i);

        OK = OK;

        for (int j = 1; j <= n; j++)
            viz[j] = 0, d[j] = 0;

        if (OK == false)
        {
            cout << "NO";
            return 0;
        }
    }

    for (int i = 1; i <= n; i++)
        if (v[i][i] != 0)
        {
            cout << "NO";
            return 0;
        }

    cout << "YES";
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#define mp make_pair

using namespace std;

const int Nmax = 2000;

vector<pair<int, int>> A[Nmax];

struct nod
{
    int x;
    int y;
    int c;
}v[Nmax * Nmax];

bool cmp (nod a, nod b)
{
    return a.c < b.c;
}

int Find (int x, vector<int>&dad)
{
    if (dad[x] == x) return x;
    return dad[x] = Find (dad[x], dad);
}

void Union (int x, int y, vector<int>&dad)
{
    dad[x] = y;
}

void DFS (int x, int cnt, int &l, bool &OK, vector<int>&viz, vector<vector<int>>&d, vector<vector<int>>&init)
{
    viz[x] = l;

    for (auto i = 0; i < A[x].size(); i++)
    {
        int w = A[x][i].first;
        int q = A[x][i].second;

        if (viz[w] == 1 - l)
        {
            d[cnt][w] = d[cnt][x] + q;
            if (d[cnt][w] != init[cnt][w])
                OK = false;

            DFS(w, cnt, l, OK, viz, d, init);
        }
    }
}

int main()
{
    bool OK = true;
    int n, l = 0, nr = 0;
    vector<int> viz(Nmax);
    vector<int> dad(Nmax);
    vector<vector<int>> d(Nmax, vector<int>(Nmax));
    vector<vector<int>> init(Nmax, vector<int>(Nmax));

    cin >> n;

    for (int i = 1; i <= n; i++)
    {
        dad[i] = i;

        for (int j = 1; j <= n; j++)
        {
            cin >> init[i][j];
            int c = init[i][j];

            nr++;
            v[nr].x = i;
            v[nr].y = j;
            v[nr].c = c;
        }
    }

    sort (v + 1, v + n * n + 1, cmp);

    for (int i = 1; i <= n * n; i++)
    {
        int x = v[i].x;
        int y = v[i].y;
        int c = v[i].c;

        int xx = Find(x, dad);
        int yy = Find(y, dad);

        if (xx != yy)
        {
            Union(xx, yy, dad);

            A[x].push_back(mp(y, c));
            A[y].push_back(mp(x, c));

            if (c == 0)
            {
                cout << "NO";
                return 0;
            }
        }
    }

    for (int i = 1; i <= n; i++)
    {
        l = 1 - l;
        DFS(i, i, l, OK, viz, d, init);

        if (OK == false)
        {
            cout << "NO";
            return 0;
        }
    }

    cout << "YES";
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#define mp make_pair

using namespace std;

const int Nmax = 2005;

vector<pair<int, int>> A[Nmax];

struct nod
{
    int x;
    int y;
    int c;
}v[Nmax * Nmax];

bool cmp (nod a, nod b)
{
    return a.c < b.c;
}

int Find (int x, vector<int>&dad)
{
    if (dad[x] == x) return x;
    return dad[x] = Find (dad[x], dad);
}

void Union (int x, int y, vector<int>&dad)
{
    dad[x] = y;
}

void DFS (int x, int cnt, int &l, vector<int>&viz, vector<vector<int>>&d)
{
    viz[x] = l;

    for (auto i = 0; i < A[x].size(); i++)
    {
        int w = A[x][i].first;
        int q = A[x][i].second;

        if (viz[w] == 1 - l)
        {
            d[cnt][w] = d[cnt][x] + q;
            DFS(w, cnt, l, viz, d);
        }
    }
}

int main()
{
    int n, l = 0, nr = 0;
    vector<int> viz(Nmax);
    vector<int> dad(Nmax);
    vector<vector<int>> d(Nmax, vector<int>(Nmax));
    vector<vector<int>> init(Nmax, vector<int>(Nmax));

    cin.sync_with_stdio(false);
    cin >> n;

    for (int i = 1; i <= n; i++)
    {
        dad[i] = i;

        for (int j = 1; j <= n; j++)
        {
            cin >> init[i][j];
            int c = init[i][j];

            nr++;
            v[nr].x = i;
            v[nr].y = j;
            v[nr].c = c;
        }
    }

    sort (v + 1, v + n * n + 1, cmp);

    for (int i = 1; i <= n * n; i++)
    {
        int x = v[i].x;
        int y = v[i].y;
        int c = v[i].c;

        int xx = Find(x, dad);
        int yy = Find(y, dad);

        if (xx != yy)
        {
            Union(xx, yy, dad);

            A[x].push_back(mp(y, c));
            A[y].push_back(mp(x, c));

            if (c == 0)
            {
                cout << "NO";
                return 0;
            }
        }
    }

    for (int i = 1; i <= n; i++)
    {
        l = 1 - l;
        DFS(i, i, l, viz, d);
    }

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
        {
            if (d[i][j] != init[i][j])
            {
                cout << "NO";
                return 0;
            }
        }

    cout << "YES";
    return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
#define mp make_pair

using namespace std;

ifstream in("inverse_the_problem.in");
ofstream out("inverse_the_problem.out");

const int Nmax = 2000;

int n, c, x, y, z, xx, yy;
int dad[Nmax];
int cost[Nmax][Nmax];
bool OK;

struct Nod
{
    int x;
    int y;
    int c;
};

struct comp
{
    bool operator()(Nod X, Nod Y)
    {
        return X.c > Y.c;
    }
};

int Find (int x)
{
    if (dad[x] == x) return x;
    return dad[x] = Find(dad[x]);
}

void Union (int x, int y)
{
    dad[x] = y;
}

priority_queue <Nod,  vector<Nod>, comp> Q;

vector <int> A[Nmax];

int main()
{
    cin >> n;

    for (int i = 1; i <= n; i++)
    {
        dad[i] = i;
            for (int j = 1; j <= n; j++)
        {
            cin >> c;
            Nod nod;

            nod.x = i;
            nod.y = j;
            nod.c = c;

            Q.push(nod);
        }
    }

   /* while (!Q.empty())
    {
        out << Q.top().x << ' ' << Q.top().y << ' ' << Q.top().c << '\n';
        Q.pop();
    }*/

    while (!Q.empty())
    {
        x = Q.top().x;
        y = Q.top().y;
        c = Q.top().c;

        xx = Find(x);
        yy = Find(y);

        if (xx != yy)
        {
            Union(xx, yy);

            A[x].push_back(y);
            A[y].push_back(x);

            cost[x][y] = c;
            cost[y][x] = c;

            if (c == 0)
            {
                cout << "NO";
                return 0;
            }
        }

        else

        {
            OK = false;
            for (auto i = 0; i < A[x].size(); i++)
            {
                int w = A[x][i];
                if (cost[x][w] + cost[w][y] == c)
                {
                    OK = true;
                    break;
                }
            }

            if (x == y)
            {
                if (c == 0)
                    OK = true;
                else
                    OK = false;
            }

            if (OK == false)
            {
                cout << "NO";
                return 0;
            }
        }

        Q.pop();
    }

    cout << "YES";
    return 0;
}