#include <bits/stdc++.h>
 
using namespace std;
 
#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(NULL); cout.tie(NULL);}
#define f first
#define s second
#define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());}
typedef long long ll;
typedef long double lld;
typedef unsigned long long ull;
 
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
	cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
	cin >> p.first;
	return cin >> p.second;
}
 
mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(61378913);
/* usage - just do rng() */
 
void usaco(string filename) {
  // #pragma message("be careful, freopen may be wrong")
	freopen((filename + ".in").c_str(), "r", stdin);
	freopen((filename + ".out").c_str(), "w", stdout);
}
 
const lld pi = 3.14159265358979323846;
const ll mod = 1000000007;
// const ll mod = 998244353;
// ll mod;
 
 
 
ll n, m, k, q, l, r, x, y, z;
const ll template_array_size = 1e6 + 1389;
ll a[template_array_size];
ll b[template_array_size];
ll c[template_array_size];
string s, t;
ll ans = 0;
 
 
 
void solve(int tc = 0) {
	cin >> n;
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (ll i = 0; i < n; i++) {
		cin >> b[i];
	}
	
	reverse(b, b + n);
	
	ll lpt = 0, rpt = n - 1;
	
	for (ll i = 0; i < n; i++) {
		if (a[i] == b[i]) {
			if (b[lpt] != b[i] && a[lpt] != b[i]) {
				swap(b[i], b[lpt]);
				++lpt;
			} else if (b[rpt] != b[i] && a[rpt] != b[i]) {
				swap(b[i], b[rpt]);
				--rpt;
			} else {
				cout << "No\n";
				return;
			}
		}
	}
	
	for (ll i = 0; i < n; i++) {
		if (a[i] == b[i]) {
			cout << "No\n";
			return;
		}
	}
	
	cout << "Yes\n";
	for (ll i = 0; i < n; i++) {
		cout << b[i] << " ";
	}
	cout << '\n';
}
 
int main() {
	#ifdef galen_colin_local
		auto begin = std::chrono::high_resolution_clock::now();
	#endif
	
	send help
 
	#ifndef galen_colin_local
		// usaco("moop");
	#endif
	
	// usaco("cowland");
	
	// freopen("tc.cpp", "r", stdin);
 
	int tc = 1;
	// cin >> tc;
	for (int t = 0; t < tc; t++) solve(t);
	
	#ifdef galen_colin_local
		auto end = std::chrono::high_resolution_clock::now();
		cout << setprecision(4) << fixed;
		// cout << "Execution time: " << std::chrono::duration_cast<std::chrono::duration<double>>(end - begin).count() << " seconds" << endl;
	#endif
} 
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#include<math.h>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;
double const PI = 3.1415926535;

struct edge{	
	ll from;  long long to; long long cost;
	bool operator<(const edge& rhs) const {
		return cost > rhs.cost;
	}
};

ll const MAX_UF = 200005;
ll parent[MAX_UF];
ll rk[MAX_UF];


void init(ll n) {
	for (ll i = 1; i <= n; i++) {
		parent[i] = i;
		rk[i] = 1;
	}
}

ll find(ll x) {
	if (parent[x] == x) {
		return x;
	}
	parent[x] = find(parent[x]);
	return parent[x];
}

bool same(ll x, ll y) {
	return find(x) == find(y);
}

void unite(ll x, ll y) {
	if (!same(x, y)) {
		x = parent[x];
		y = parent[y];
		if (rk[x] < rk[y]) {
			parent[x] = y;
		}
		else {
			parent[y] = x;
			if (rk[x] == rk[y]) {
				rk[x]++;
			}
		}
	}
}


ll const MAX_seg = 800005; //4倍に取っておく
ll segtree[MAX_seg];
ll mintree[MAX_seg];

//演算
ll op(ll x, ll y) {
	return min(x, y);
}
//init valueの変更を忘れない
ll const INIT_VALUE = 1e17;
ll n_ = 1;

void init_seg(ll n) {
	while (n_ <= n) {
		n_ *= 2;
	}
	REP(i, 1, n_ * 2) {
		segtree[i] = INIT_VALUE;
	}
	REP(i, n_ , n_ * 2) {
		mintree[i] = i - n_;
	}
	REP(i, 1, n_ - 1) {
		mintree[i] = mintree[i * 2];
	}
}

//k番目をxでupdate
void update(ll k, ll x) {
	k += n_;
	segtree[k] = x;
	while (k >= 1) {
		k /= 2;
		segtree[k] = op(segtree[k * 2], segtree[k * 2 + 1]);
		if (segtree[k * 2] > segtree[k * 2 + 1]) {
			mintree[k] = mintree[k * 2 + 1];
		}
		else {
			mintree[k] = mintree[k * 2];
		}
	}
}

ll val_o(ll a, ll b, ll k, ll l, ll r,ll& g) {
	if (a <= l && r <= b) {
		g = mintree[k];
		return segtree[k];
	}
	else if (r <= a || b <= l) {
		//ここの値注意
		return INIT_VALUE;
		g = mintree[k];
	}
	else {
		ll g1 = 0; ll g2 = 0;
		ll x1 = val_o(a, b, k * 2, l, (l + r) / 2, g1);
		ll x2 = val_o(a, b, k * 2 + 1, (l + r) / 2, r, g2);
		if (x1 > x2) {
			g = g2;
		}else{
			g = g1;
		}
		return op(x1, x2);
	}

}

//[a,b)のvalueを求める
ll val(ll a, ll b, ll& g) {
	return val_o(a, b, 1, 0, n_, g);
}

ll const MAX = 2e5;
ll n, d;
ll a[MAX];
ll ord[MAX];

bool orders(ll x, ll y) {
	return a[x] < a[y];
}

ll bignumber = 5e16;

priority_queue<edge> pq;

void makegraph(ll type) {
	init_seg(n);
	REP(i, 1, n) {
		ll cur = ord[i];
		if (i > 1) {
			ll min_i = 0;
			ll min_a;
			if (type == 1) {
				min_a = val(cur + 1, n + 1, min_i);
			}
			else {
				min_a = val(1, cur, min_i);
			}
		//	cout << type << " " << cur << " " << min_a << endl;
			if (min_a <= bignumber) {
				ll c;
				if (type == 1) {
					c = min_a - d * cur + a[cur];
				}
				else {
					c = min_a + d * cur + a[cur];
				}
				pq.push({ min_i,cur,c });
			}
		}
		ll t = a[cur] + type * cur * d;
		update(cur, t);
	//	cout << "?" << cur << " " << t << endl;
	}
}

int main() {
	cin >> n >> d;
	REP(i, 1, n) {
		cin >> a[i];
	}
	REP(i, 1, n) {
		ord[i] = i;
	}
	SORT_O(ord, n, orders);
	makegraph(1);
	makegraph(-1);
	ll ans = 0;
	init(n);
	while (!pq.empty()) {
		edge cur = pq.top();
		pq.pop();
		//cout << "!" << cur.cost << endl;
		if (!same(cur.from, cur.to)) {
			ans += cur.cost;
			unite(cur.from, cur.to);
		}
	}
	cout << ans << endl;
}
