#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";
   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";
}

namespace GR {

// https://codeforces.com/blog/entry/82566?#comment-695378
VI solve(int N, const VI& A, VI B) {
   multiset<int> MS(B.begin(), B.end());

   reverse(B.begin(), B.end());
   int first_common_pos = -1, last_common_pos = -1;
   REP(i, N) {
      if (A[i] == B[i]) {
         if (first_common_pos < 0)
            first_common_pos = i;
         last_common_pos = i;
      }
   }

   if (first_common_pos < 0)
      return B;

   int common_element = A[first_common_pos];
   queue<int> others;
   REP(i, N)
      if (A[i] != common_element && B[i] != common_element)
         others.push(i);

   FOR(i, first_common_pos, last_common_pos) {
      if (others.empty())
         return {};
      int j = others.front();
      others.pop();
      swap(B[i], B[j]);
   }

   return B;
}

}

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() % 8;
         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: 15800