#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<ll,ll> Pair;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}

ll solve1(VL& g, VL& b){
    int ng = g.size(), nb = b.size(), pos = 0;
    ll ret = LINF;
    REP(i,nb){
        while(pos<ng-1 && abs(b[i]-g[pos]) > abs(b[i]-g[pos+1])) pos++;
        chmin(ret, abs(b[i]-g[pos]));
    }
    return ret;
}

VL f(VL& b, VL& v){
    int n = b.size(), m = v.size(), pos = 0;
    VL ret(n);
    REP(i,n){
        while(pos<m-1 && abs(v[pos]-b[i]) > abs(v[pos+1]-b[i])) pos++;
        ret[i] = abs(v[pos]-b[i]);
    }
    return ret;
}

ll solve2(VL& r, VL& g, VL& b){
    int n = b.size(), nr = r.size(), ng = g.size();

    if(n==0) return LINF;

    VL dr = f(b,r), dg = f(b,g);
    VI pr(n), pg(n); REP(i,n) pr[i] = pg[i] = i;
    auto cr = [&](int i, int j){return dr[i]<dr[j];};
    auto cg = [&](int i, int j){return dg[i]<dg[j];};
    sort(ALL(pr), cr); sort(ALL(pg), cg);

    ll ret = LINF;
    if(pr[0] != pg[0]) chmin(ret, dr[pr[0]] + dg[pg[0]]);
    else chmin(ret, min(dr[pr[0]]+dg[pg[1]], dr[pr[1]]+dg[pg[0]]));
    return ret;
}

void Main(){
    int N; cin >> N;
    int M = N<<1, nr=0, ng=0, nb=0;
    VL r,g,b; vector<char> c(M);
    REP(i,M){
        ll a; char c;
        cin >> a >> c;
        if(c=='R') nr++, r.push_back(a);
        else if(c=='G') ng++, g.push_back(a);
        else nb++, b.push_back(a);
    }

    if(nr%2 + ng%2 + nb%2 == 0){
        cout << 0 << en;
        return;
    }

    SORT(r); SORT(g); SORT(b);
    if(nr%2 == 0) swap(r,b);
    else if(ng%2 == 0) swap(g,b);

    ll ans = solve1(r,g);
    chmin(ans, solve2(r,g,b));
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    while(t--) Main();
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD int(1e9+7)
#define INF int(1e9+7)
#define LINF ll(1e18+7)
#define PI acos(-1)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define P pair<ll,ll>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

int n;
int Mat[550][550];

int main(){
  cin>>n;
  rep(i,n)rep(j,n) cin>>Mat[i][j];
  vector<int> a(n),b(n);
  a[0]=0;
  b[0]=Mat[0][0]-a[0];
  bool ok=1;
  rep(i,n) a[i]=Mat[i][0]-b[0];
  rep(j,n) b[j]=Mat[0][j]-a[0];
  rep(i,n)rep(j,n){
    if(a[i]+b[j]!=Mat[i][j]) ok=0;
  }
  int amin=INT_MAX, bmin=INT_MAX;
  rep(i,n) chmin(amin,a[i]);
  rep(i,n) chmin(bmin,b[i]);
  if(amin<0 && bmin<0) ok=0;
  else if(amin<0){
    rep(i,n) a[i]+=abs(amin);
    rep(i,n){
      b[i]-=abs(amin);
      if(b[i]<0) ok=0;
    }
  }else if(bmin<0){
    rep(i,n) b[i]+=abs(bmin);
    rep(i,n){
      a[i]-=abs(bmin);
      if(a[i]<0) ok=0;
    }
  }
  if(ok){
    cout<<"Yes"<<endl;
    rep(i,n) cout<<a[i]<<" "; cout<<endl;
    rep(i,n) cout<<b[i]<<" "; cout<<endl;
  }else{
    cout<<"No"<<endl;
  }
}