Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define mkp make_pair
#define fi first
#define se second
int n,a[200004],ans[200004];
set<pii>pq;
map<int,int>mp,mp1;
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++){
		cin>>ans[i];
		mp[ans[i]]++,mp[a[i]]++;
		mp1[ans[i]]++;
	}
	for(map<int,int>::iterator it=mp1.begin();it!=mp1.end();it++)pq.insert(mkp(-mp[it->first],it->first));
	for(int i=0;i<n;i++){
		if(pq.empty())return 0; 
		pii O=(*pq.begin());
		pq.erase(pq.begin());
		if(O.se!=a[i]){
			ans[i]=O.se;
			O.fi++;
		}else{
			if(pq.empty()){puts("No");return 0;}
			O=(*pq.begin());
			pq.erase(pq.begin());
			pq.insert(mkp(-mp[a[i]],a[i]));
			ans[i]=O.se;
			O.fi++;
		}
		mp1[O.se]--;
		if(mp1[O.se]>0)pq.insert(O);
		if(mp1.find(a[i])!=mp1.end()&&mp1[a[i]]>0){
			if(pq.find(-mp[a[i]],a[i])==pq.end())return 0;
			pq.erase(pq.find(mkp(-mp[a[i]],a[i])));
			mp[a[i]]--;
			pq.insert(mkp(-mp[a[i]],a[i]));
		}
	}
	puts("Yes");
	for(int i=0;i<n;i++)cout<<ans[i]<<" ";
}

Compiler output:
a.cc: In function 'int main()':
a.cc:37:35: error: no matching function for call to 'std::set<std::pair<int, int> >::find(std::map<int, int>::mapped_type, int&)'
   37 |                         if(pq.find(-mp[a[i]],a[i])==pq.end())return 0;
      |                            ~~~~~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/set:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:158,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_set.h:806:9: note: candidate: 'template<class _Kt> decltype (std::set<_Key, _Compare, _Alloc>::iterator{((std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_find_tr(__x)}) std::set<_Key, _Compare, _Alloc>::find(const _Kt&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >]'
  806 |         find(const _Kt& __x)
      |         ^~~~
/usr/include/c++/14/bits/stl_set.h:806:9: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_set.h:812:9: note: candidate: 'template<class _Kt> decltype (std::set<_Key, _Compare, _Alloc>::const_iterator{((const std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_find_tr(__x)}) std::set<_Key, _Compare, _Alloc>::find(const _Kt&) const [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >]'
  812 |         find(const _Kt& __x) const
      |         ^~~~
/usr/include/c++/14/bits/stl_set.h:812:9: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_set.h:796:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::find(const key_type&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator; key_type = std::pair<int, int>]'
  796 |       find(const key_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_set.h:796:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_set.h:800:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::const_iterator std::set<_Key, _Compare, _Alloc>::find(const key_type&) const [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; const_iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator; key_type = std::pair<int, int>]'
  800 |       find(const key_type& __x) const
      |       ^~~~
/usr/include/c++/14/bits/stl_set.h:800:7: note:   candidate expects 1 argument, 2 provided