#line 1 "main_c.cpp"
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */

using i64=std::int_fast64_t;
using u64=std::uint_fast64_t;
 
#define rep(i, a, b) for (i64 i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, u64 b,Num id=1) {
  if(b==0)return id;
  Num x = id;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  i64 n;

  std::cin>>n;

  std::vector<i64> pe(2*n,-1);

  std::vector<bool> dp(n+1,false);
  dp[0]=true;

  rep(i,0,n){
    i64 a,b;
    std::cin>>a>>b;
    if(a!=-1){
      a--;
      if(pe[a]!=-1){
        std::cout<<"No\n";
        return 0;
      }
      pe[a]=i;
    }
    if(b!=-1){
      b--;
      if(pe[b]!=-1){
        std::cout<<"No\n";
        return 0;
      }
      pe[b]=i+n;
    }
  }

  rep(i,1,n+1){
    rep(j,0,i){
      i64 len=i-j;
      bool val=dp[j];
      rep(k,2*j,2*j+len){
        if(pe[k]==-1){
          if(pe[k+len]!=-1&&pe[k+len]<n)val=false;
        }else{
          if(pe[k] >=n) val=false;
          if((pe[k+len]!=-1)&&(pe[k+len]!=pe[k]+n))val=false;
        }
      }
      if(val)dp[i]=true;
    }
  }

  debug(pe);
  debug(dp);

  if(dp[n])std::cout<<"Yes\n";
  else std::cout<<"No\n";
  
  return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> pii;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fo(i,a,b) for(ll i = a; i<=b;i+=1)
// #define Vector vector
#define rf(i,a,b)  for(ll i=a;i>=b;i--)
#define vll vector<ll>
#define sz(a) ll(a.size())
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front 
#define MAXN 100010
#define MOD 1000000007
#define mod 998244353
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define debug(x) cout << '>' << #x << ':' << x << " ";
#define nl '\n'
#define MS(x,y) fill_n(*x, sizeof x / sizeof **x, y);
#define mem(x,y) memset(x,y,sizeof(x));
#define INF 1000000000000000000
#define int long long int
#define IO                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);

void solve(){
    int n;
    cin >> n;
    vll a(n);
    f(i, 0, n){
        cin >> a[i];
    }
    sort(all(a));
    int aage = n-1;
    int sum = 0;
    f(i, 0, n){
        int piche = n - aage - 1;
        sum += piche*a[i]-aage*a[i];
        aage--;
    }

    cout << sum << nl;
    return ;
}
main()
{
    IO;
    int T = 1;
    // cin >> T;
    for(int c=1; c <= T; c++){
        solve();
        // cout<<"Case #"<<c<<": ";
    }
    return 0;
}
