Language: C++

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <array>
#include <cassert>
#include <utility>
#include <vector>
// #include <atcoder/all>

template <class InputIterator>
std::ostream& range_output(std::ostream& os_arg, InputIterator first_arg, InputIterator last_arg){ if(first_arg != last_arg){ do{ os_arg << *(first_arg++); if(first_arg == last_arg) break; os_arg << ' '; } while(true); }  return os_arg; }
template <class Tp> std::ostream& operator << (std::ostream& os_arg, const std::vector<Tp>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class Tp, std::size_t Size> std::ostream& operator << (std::ostream& os_arg, const std::array<Tp, Size>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class S, class T> std::ostream& operator << (std::ostream& os_arg, const std::pair<S, T>& pair_arg){ return os_arg << '(' << pair_arg.first << ", " << pair_arg.second << ')'; }

#ifndef ONLINE_JUDGE
    template <typename Head> void dump_out(Head head_arg){ std::cerr << head_arg << '\n'; }
    template <typename Head, typename... Tail>
    void dump_out(Head head_arg, Tail... tail_args){ std::cerr << head_arg << ", "; dump_out(tail_args...); }
    #define dump(...) do { std::cerr << "[in line " << __LINE__ << "] " << #__VA_ARGS__ << " : "; dump_out(__VA_ARGS__); } while(false)
#else
    #define dump(...) (void(0))
#endif


constexpr int mod = 1'000'000'007;

int main(void){
    std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); 
    std::cout << std::fixed << std::setprecision(16);

    int n; std::cin >> n;
    std::vector<int> A(n); for(auto& itr : A) std::cin >> itr;
    std::vector<int> B(n); for(auto& itr : B) std::cin >> itr;
    std::vector<int> Cntr(n + 1, 0); 
    for(const auto& itr : A) ++Cntr[itr]; for(const auto& itr : B) ++Cntr[itr];
    for(const auto& itr : Cntr) if(itr > n){ std::cout << "No\n"; return 0; }

    std::fill(Cntr.begin(), Cntr.end(), 0);

    const auto F = [&](int l, int r, int k){
        const int a = (l > k) ? l - k : 0;
        ++Cntr[a]; --Cntr[r + 1];
    };
    const auto action = [&](int la, int ra, int lb, int rb){
        la -= lb; ra -= lb + 1; rb -= lb + 1;
        if(la < 0 and ra >= 0){ F(la + n, n - 1); F(0, ra, rb); }
        else{
            if(la < 0) F(la + n, ra + n, rb);
            else F(la, ra, rb);
        }
    };

    for(int v = 1, la = 0, lb = 0; v <= n; ++v){
        int ra = la, rb = lb;
        while(ra < n and A[ra] == v) ++ra;
        while(rb < n and B[rb] == v) ++rb;
        if(la == ra or lb == rb){ la = ra; lb = rb; continue; }
        action(la, ra, lb, rb); la = ra; lb = rb;
    }
    for(int i = 0; i + 1 <= n; ++i) Cntr[i + 1] += Cntr[i];
    int shift = -1;
    for(int i = 0; i < n; ++i) if(Cntr[i] == 0){ shift = i; break; }
    if(shift == -1){ return 1; }
    std::cout << "Yes\n";
    for(int i = shift, cntr = 0; cntr < n; ++cntr){
        if(cntr) std::cout << ' ';
        std::cout << B[i]; ++i; if(i == n) i = 0;
    }

    return 0;
}

Compiler output:
a.cc: In lambda function:
a.cc:47:34: error: no match for call to '(const main()::<lambda(int, int, int)>) (int, int)'
   47 |         if(la < 0 and ra >= 0){ F(la + n, n - 1); F(0, ra, rb); }
      |                                 ~^~~~~~~~~~~~~~~
a.cc:41:20: note: candidate: 'main()::<lambda(int, int, int)>'
   41 |     const auto F = [&](int l, int r, int k){
      |                    ^
a.cc:41:20: note:   candidate expects 3 arguments, 2 provided