#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(...) fprintf(stderr, ##__VA_ARGS__)
#else
#define endl "\n"
#define debug(...) void(0)
#endif
using LL = long long;
int n, deg[100010], m;
basic_string<int> g[100010];
vector<int> toposort(int op) {
// op == -1 min
// op == 1 max
priority_queue<int> q;
vector<int> ret;
for (int i = 1; i <= n; i++) deg[i] = 0;
for (int i = 1; i <= n; i++) for (int v : g[i]) deg[v] += 1;
for (int i = 1; i <= n; i++) if (!deg[i]) q.push(i * op);
while (!q.empty()) {
int u = q.top() * op; q.pop();
ret.push_back(u);
for (int v : g[u]) if (--deg[v] == 0) q.push(v * op);
}
return ret;
}
vector<int> a, b;
void solvea(int l, int r) {
if (l >= r) return ;
int lst = a[l], pre = l, llst = -1;
for (int i = l + 1; i < r; i++) {
if (lst > a[i]) {
if (llst == -1 || llst < a[i]) g[lst] += a[i], llst = a[i];
}
else solvea(pre + 1, i), lst = a[i], pre = i, llst = -1;
}
solvea(pre + 1, r);
}
void solveb(int l, int r) {
if (l >= r) return ;
int lst = b[l], pre = l, llst = -1;
for (int i = l + 1; i < r; i++) {
if (lst < b[i]) {
if (llst == -1 || llst > b[i]) g[lst] += b[i], llst = b[i];
} else solveb(pre + 1, i), lst = b[i], pre = i, llst = -1;
}
solveb(pre + 1, r);
}
int main() {
#ifndef LOCAL
cin.tie(nullptr)->sync_with_stdio(false);
#endif
cin >> n;
a.resize(n);
b.resize(n);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
solvea(0, n);
solveb(0, n);
#ifdef LOCAL
for (int i = 1; i <= n; i++) for (int v : g[i]) cout << i << " " << v << endl;
#endif
if (toposort(-1) == a && toposort(+1) == b) {
cout << "Yes" << endl;
for (int i = 1; i <= n; i++) {
auto bg = begin(g[i]), ed = end(g[i]);
sort(bg, ed), g[i].erase(unique(bg, ed), ed);
m += (int)g[i].size();
}
cout << m << endl;
for (int i = 1; i <= n; i++) for (int v : g[i]) cout << i << " " << v << endl;
} else {
cout << "No" << endl;
}
return 0;
}