#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
//#include <stack>
#include <cstring>
#include <cassert>

using namespace std;

#ifdef LOCAL_DEBUG
#include <local_debug.h>
#define DEBUG(...) DBG2::print(#__VA_ARGS__, __LINE__, __VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

string validate_answer(VI A, VI B, VI answer) {
   if (SZ(A) != SZ(B))
      return "Invalid size";
   REP(i, SZ(A)) {
      if (A[i] == answer[i])
         return "Element at position " + to_string(i) + " matches";
   }
   sort(answer.begin(), answer.end());
   if (answer != B)
      return "Answer is not a permutation of B";
   return "OK";
}

string validate_answer2(VI A, VI B, VI answer, VI expected) {
   if (answer.empty() != expected.empty()) {
      if (answer.empty())
         return "Failed to find valid answer";
      else
         return "Found answer when there is none";
   }
   if (answer.empty() == expected.empty())
      return "OK";
   if (SZ(A) != SZ(B))
      return "Invalid size";
   const int N = SZ(A);
   REP(i, N) {
      if (!(1 <= answer[i] && answer[i] <= N))
         return "Element at position " + to_string(i) + " is out of range";
      if (A[i] == answer[i])
         return "Element at position " + to_string(i) + " matches";
   }
   sort(answer.begin(), answer.end());
   if (answer != B)
      return "Answer is not a permutation of B";
   return "OK";
}

namespace GR {

typedef pair<int,int> II;

// https://atcoder.jp/contests/abc178/submissions/16702070
VI solve(int N, const VI& A, const VI& B) {
   vector<int> freq(N+1), freq_in_B(N+1);
   for (int x : A)
      ++freq[x];
   for (int x : B) {
      ++freq[x];
      ++freq_in_B[x];
   }

   FOR(x, 1, N)
      if (freq[x] > N)
         return {};
   
   set< II, greater<II> > S;
   FOR(b, 1, N)
      if (freq_in_B[b] > 0)
         S.emplace(freq[b], b);

   VI res(N);
   for (int n = N-1; n >= 0; --n) {
      assert(!S.empty());
      if (SZ(S) == 1) {
         int cnt, b;
         tie(cnt, b) = *S.begin();
         assert(cnt == n+1);
         assert(b != A[n]);
         for (; n >= 0; --n)
            res[n] = b;
         return res;
      }

      int a = A[n];
      auto max_it = S.begin();
      auto max2_it = next(max_it);
      int b = max_it->second;
      if (b == a) {
         // use max2
         b = max2_it->second;
         S.erase(max2_it);
      }
      else
         S.erase(max_it);

      res[n] = b;

      if (freq_in_B[a] > 0)
         S.erase({freq[a], a});
      --freq[a];
      if (freq_in_B[a] > 0)
         S.emplace(freq[a], a);

      --freq[b];
      --freq_in_B[b];
      if (freq_in_B[b] > 0)
         S.emplace(freq[b], b);

   }

   return res;
}

}

namespace BF {

VI solve(int N, const VI& A, VI B) {
   do {
      bool ok = true;
      REP(i, N)
         if (A[i] == B[i]) {
            ok = false;
            break;
         }
      if (ok) {
         return B;
      }
   } while (next_permutation(B.begin(), B.end()));
   return {};
}

}


void print_test(int N, VI A, VI B) {
   cerr << N << endl;
   for (int x : A)
      cerr << x << ' ';
   cerr << endl;
   for (int x : B)
      cerr << x << ' ';
   cerr << endl;
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   int N;
   VI A, B;
   if (argc > 1) {
      srand( atoi(argv[1]) );

      FOR(tc, 1, 10000) {
      // cerr << "Test #" << tc << endl;
         N = 1 + rand() % 11;
         A = VI(N);
         REP(i, N)
            A[i] = 1 + rand() % N;
         sort(A.begin(), A.end());
         B = VI(N);
         REP(i, N)
            B[i] = 1 + rand() % N;
         sort(B.begin(), B.end());

      // print_test(N, A, B);

         VI resBF = BF::solve(N, A, B);
         VI resGR = GR::solve(N, A, B);
         
         string verdict = validate_answer2(A, B, resGR, resBF);
         if (verdict != "OK") {
            cerr << "Failed test #" << tc << endl;
            cerr << "Verdict: " << verdict << endl;
            cerr << "Your answer:";
            for (int x : resGR) cerr << ' ' << x;
            cerr << endl;
            cerr << "Expected answer:";
            for (int x : resBF) cerr << ' ' << x;
            cerr << endl;
            print_test(N, A, B);
            break;
         }
      }
   }
   else {
      cin >> N;

      A = VI(N);
      REP(i, N)
         cin >> A[i];

      B = VI(N);
      REP(i, N)
         cin >> B[i];

      VI res = GR::solve(N, A, B);
      if (res.empty())
         cout << "No\n";
      else {
         cout << "Yes\n";
         for (int x : res)
            cout << x << ' ';
         cout << '\n';
      }
   }

   return 0;
}


Measured memory_bytes: 16232