#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define pii pair<int, int>
void bad() {
cout << "NO" << '\n';
exit(0);
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef CB
freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
int N;
cin >> N;
vector<int> X(N), Y(N), Z(N);
for (int i = 0; i < N; i++) {
cin >> X[i];
}
for (int i = 0; i < N; i++) {
cin >> Y[i];
}
for (int i = 0; i < N; i++) {
cin >> Z[i];
}
map<tuple<int, int, int>, int> s;
for (int i = 0; i < N; i++) {
s[{X[i], Y[i], Z[i]}] = i;
}
map<pii, vector<int>> xy, yz, zx;
for (int i = 0; i < N; i++) {
xy[{X[i], Y[i]}].push_back(Z[i]);
yz[{Y[i], Z[i]}].push_back(X[i]);
zx[{Z[i], X[i]}].push_back(Y[i]);
}
for (auto& [p, v] : xy) {
sort(v.begin(), v.end());
}
for (auto& [p, v] : yz) {
sort(v.begin(), v.end());
}
for (auto& [p, v] : zx) {
sort(v.begin(), v.end());
}
// same line
for (int i = 0; i < N; i++) {
vector<pair<vector<int>&, int>> a = {
{xy[{X[i], Y[i]}], Z[i]},
{yz[{Y[i], Z[i]}], X[i]},
{zx[{Z[i], X[i]}], Y[i]},
};
for (auto [v, x] : a) {
auto t = lower_bound(v.begin(), v.end(), x);
if (t != v.begin()) {
if (*prev(t) != *t - 1) {
bad();
}
}
if (next(t) != v.end()) {
if (*next(t) != *t + 1) {
bad();
}
}
}
}
// same plane
map<int, map<int, pii>> xp, yp, zp;
for (int i = 0; i < N; i++) {
xp[X[i]][Y[i]];
yp[Y[i]][Z[i]];
zp[Z[i]][X[i]];
}
for (auto& [x, m] : xp) {
pii a = {INT_MAX, INT_MIN};
for (auto t = m.begin(); t != m.end(); t++) {
t->second = a;
a.first = min(a.first, xy[{x, t->first}].front());
a.second = max(a.second, xy[{x, t->first}].back());
}
}
for (auto& [y, m] : yp) {
pii a = {INT_MAX, INT_MIN};
for (auto t = m.begin(); t != m.end(); t++) {
t->second = a;
a.first = min(a.first, yz[{y, t->first}].front());
a.second = max(a.second, yz[{y, t->first}].back());
}
}
for (auto& [z, m] : zp) {
pii a = {INT_MAX, INT_MIN};
for (auto t = m.begin(); t != m.end(); t++) {
t->second = a;
a.first = min(a.first, zx[{z, t->first}].front());
a.second = max(a.second, zx[{z, t->first}].back());
}
}
map<int, map<int, pii>> xs, ys, zs;
for (int i = 0; i < N; i++) {
xs[X[i]][Y[i]];
ys[Y[i]][Z[i]];
zs[Z[i]][X[i]];
}
for (auto& [x, m] : xs) {
pii a = {INT_MAX, INT_MIN};
for (auto t = m.rbegin(); t != m.rend(); t++) {
t->second = a;
a.first = min(a.first, xy[{x, t->first}].front());
a.second = max(a.second, xy[{x, t->first}].back());
}
}
for (auto& [y, m] : ys) {
pii a = {INT_MAX, INT_MIN};
for (auto t = m.rbegin(); t != m.rend(); t++) {
t->second = a;
a.first = min(a.first, yz[{y, t->first}].front());
a.second = max(a.second, yz[{y, t->first}].back());
}
}
for (auto& [z, m] : zs) {
pii a = {INT_MAX, INT_MIN};
for (auto t = m.rbegin(); t != m.rend(); t++) {
t->second = a;
a.first = min(a.first, zx[{z, t->first}].front());
a.second = max(a.second, zx[{z, t->first}].back());
}
}
for (int i = 0; i < N; i++) {
if (xp[X[i]][Y[i]].first < Z[i]) {
if (!s.count({X[i], Y[i] - 1, Z[i]}) && !s.count({X[i], Y[i], Z[i] - 1})) {
bad();
}
}
if (xp[X[i]][Y[i]].second > Z[i]) {
if (!s.count({X[i], Y[i] - 1, Z[i]}) && !s.count({X[i], Y[i], Z[i] + 1})) {
bad();
}
}
if (xs[X[i]][Y[i]].first < Z[i]) {
if (!s.count({X[i], Y[i] + 1, Z[i]}) && !s.count({X[i], Y[i], Z[i] - 1})) {
bad();
}
}
if (xs[X[i]][Y[i]].second > Z[i]) {
if (!s.count({X[i], Y[i] + 1, Z[i]}) && !s.count({X[i], Y[i], Z[i] + 1})) {
bad();
}
}
if (yp[Y[i]][Z[i]].first < X[i]) {
if (!s.count({X[i] - 1, Y[i], Z[i]}) && !s.count({X[i], Y[i], Z[i] - 1})) {
bad();
}
}
if (yp[Y[i]][Z[i]].second > X[i]) {
if (!s.count({X[i] + 1, Y[i], Z[i]}) && !s.count({X[i], Y[i], Z[i] - 1})) {
bad();
}
}
if (ys[Y[i]][Z[i]].first < X[i]) {
if (!s.count({X[i] - 1, Y[i], Z[i]}) && !s.count({X[i], Y[i], Z[i] + 1})) {
bad();
}
}
if (ys[Y[i]][Z[i]].second > X[i]) {
if (!s.count({X[i] + 1, Y[i], Z[i]}) && !s.count({X[i], Y[i], Z[i] + 1})) {
bad();
}
}
if (zp[Z[i]][X[i]].first < Y[i]) {
if (!s.count({X[i] - 1, Y[i], Z[i]}) && !s.count({X[i], Y[i] - 1, Z[i]})) {
bad();
}
}
if (zp[Z[i]][X[i]].second > Y[i]) {
if (!s.count({X[i] - 1, Y[i], Z[i]}) && !s.count({X[i], Y[i] + 1, Z[i]})) {
bad();
}
}
if (zs[Z[i]][X[i]].first < Y[i]) {
if (!s.count({X[i] + 1, Y[i], Z[i]}) && !s.count({X[i], Y[i] - 1, Z[i]})) {
bad();
}
}
if (zs[Z[i]][X[i]].second > Y[i]) {
if (!s.count({X[i] + 1, Y[i], Z[i]}) && !s.count({X[i], Y[i] + 1, Z[i]})) {
bad();
}
}
}
// check connectivity
vector<int> v(N);
auto dfs = [&](auto dfs, int i) {
if (v[i]) {
return;
}
v[i] = true;
if (s.count({X[i] + 1, Y[i], Z[i]})) {
dfs(dfs, s[{X[i] + 1, Y[i], Z[i]}]);
}
if (s.count({X[i] - 1, Y[i], Z[i]})) {
dfs(dfs, s[{X[i] - 1, Y[i], Z[i]}]);
}
if (s.count({X[i], Y[i] + 1, Z[i]})) {
dfs(dfs, s[{X[i], Y[i] + 1, Z[i]}]);
}
if (s.count({X[i], Y[i] - 1, Z[i]})) {
dfs(dfs, s[{X[i], Y[i] - 1, Z[i]}]);
}
if (s.count({X[i], Y[i], Z[i] + 1})) {
dfs(dfs, s[{X[i], Y[i], Z[i] + 1}]);
}
if (s.count({X[i], Y[i], Z[i] - 1})) {
dfs(dfs, s[{X[i], Y[i], Z[i] - 1}]);
}
};
dfs(dfs, 0);
if (count(v.begin(), v.end(), true) != N) {
bad();
}
cout << "YES" << '\n';
return 0;
}