alexjercan/bugnet huggingface dataset:
Problem p02557 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

int N;
const int MAX_N = 200005;
int as[MAX_N];
int ac[MAX_N], bcc[MAX_N];
std::vector<std::pair<int, int>> bccc;

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    int v;
    scanf("%d", &v);
    as[i] = v;
    ac[v]++;
  }
  for (int i = 0; i < N; ++i) {
    int v;
    scanf("%d", &v);
    bcc[v]++;
  }
  for (int i = 0; i < MAX_N; ++i) {
    if (bcc[i])
      bccc.push_back({i, bcc[i]});
  }
  bool doable = true;
  for (auto &kv : bccc) {
    if (kv.second + ac[kv.first] > N) {
      doable = false;
      break;
    }
  }
  if (!doable) {
    printf("No\\n");
    return 0;
  }
  printf("Yes\\n");
  std::vector<int> ans;
  auto eng = std::default_random_engine(12432);
  while (1) {
    auto bc = bccc;
    std::shuffle(bc.begin(), bc.end(), eng);
    auto iter = bc.begin();
    ans.clear();
    int idx = 0;
    while (bc.size()) {
      int to_remove = -1;
      if (iter->first == as[idx]) {
        iter++;
        if (bc.size() == 1)
          break;
        if (iter == bc.end())
          iter = bc.begin();
      }
      while (as[idx] != iter->first) {
        idx++;
        iter->second--;
        ans.push_back(iter->first);
        if (iter->second == 0) {
          to_remove = iter->first;
          break;
        }
      }
      if (to_remove >= 0) {
        std::swap(*iter, *(--bc.end()));
        bc.pop_back();
        iter = bc.begin();
      }
    }
    if (ans.size() == N)
      break;
  }
  for (int i : ans)
    printf("%d ", i);
  printf("\\n");
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

int N;
const int MAX_N = 200005;
int as[MAX_N];
int ac[MAX_N], bcc[MAX_N];
std::vector<std::pair<int, int>> bccc;

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    int v;
    scanf("%d", &v);
    as[i] = v;
    ac[v]++;
  }
  for (int i = 0; i < N; ++i) {
    int v;
    scanf("%d", &v);
    bcc[v]++;
  }
  for (int i = 0; i < MAX_N; ++i) {
    if (bcc[i])
      bccc.push_back({i, bcc[i]});
  }
  bool doable = true;
  for (auto &kv : bccc) {
    if (kv.second + ac[kv.first] > N) {
      doable = false;
      break;
    }
  }
  if (!doable) {
    printf("No\\n");
    return 0;
  }
  printf("Yes\\n");
  std::vector<int> ans;
  while (1) {
    auto bc = bccc;
    std::shuffle(bc.begin(), bc.end(), std::default_random_engine(12432));
    auto iter = bc.begin();
    ans.clear();
    int idx = 0;
    while (bc.size()) {
      int to_remove = -1;
      if (iter->first == as[idx]) {
        iter++;
        if (bc.size() == 1)
          break;
        if (iter == bc.end())
          iter = bc.begin();
      }
      while (as[idx] != iter->first) {
        idx++;
        iter->second--;
        ans.push_back(iter->first);
        if (iter->second == 0) {
          to_remove = iter->first;
          break;
        }
      }
      if (to_remove >= 0) {
        std::swap(*iter, *(--bc.end()));
        bc.pop_back();
        iter = bc.begin();
      }
    }
    if (ans.size() == N)
      break;
  }
  for (int i : ans)
    printf("%d ", i);
  printf("\\n");
}
Problem p02557 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

int N;
const int MAX_N = 200005;
int as[MAX_N];
int ac[MAX_N], bcc[MAX_N];
std::vector<std::pair<int, int>> bccc;

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    int v;
    scanf("%d", &v);
    as[i] = v;
    ac[v]++;
  }
  for (int i = 0; i < N; ++i) {
    int v;
    scanf("%d", &v);
    bcc[v]++;
  }
  for (int i = 0; i < MAX_N; ++i) {
    if (bcc[i])
      bccc.push_back({i, bcc[i]});
  }
  bool doable = true;
  for (auto &kv : bccc) {
    if (kv.second + ac[kv.first] > N) {
      doable = false;
      break;
    }
  }
  if (!doable) {
    printf("No\\n");
    return 0;
  }
  printf("Yes\\n");
  std::vector<int> ans;
  while (1) {
    auto bc = bccc;
    std::random_shuffle(bc.begin(), bc.end());
    auto iter = bc.begin();
    ans.clear();
    int idx = 0;
    while (bc.size()) {
      int to_remove = -1;
      if (iter->first == as[idx]) {
        iter++;
        if (bc.size() == 1)
          break;
        if (iter == bc.end())
          iter = bc.begin();
      }
      while (as[idx] != iter->first) {
        idx++;
        iter->second--;
        ans.push_back(iter->first);
        if (iter->second == 0) {
          to_remove = iter->first;
          break;
        }
      }
      if (to_remove >= 0) {
        std::swap(*iter, *(--bc.end()));
        bc.pop_back();
        iter = bc.begin();
      }
    }
    if (ans.size() == N)
      break;
  }
  for (int i : ans)
    printf("%d ", i);
  printf("\\n");
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

int N;
const int MAX_N = 200005;
int as[MAX_N];
int ac[MAX_N], bcc[MAX_N];
std::vector<std::pair<int, int>> bccc;

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    int v;
    scanf("%d", &v);
    as[i] = v;
    ac[v]++;
  }
  for (int i = 0; i < N; ++i) {
    int v;
    scanf("%d", &v);
    bcc[v]++;
  }
  for (int i = 0; i < MAX_N; ++i) {
    if (bcc[i])
      bccc.push_back({i, bcc[i]});
  }
  bool doable = true;
  for (auto &kv : bccc) {
    if (kv.second + ac[kv.first] > N) {
      doable = false;
      break;
    }
  }
  if (!doable) {
    printf("No\\n");
    return 0;
  }
  printf("Yes\\n");
  int idx = 0;
  std::vector<int> ans;
  while (1) {
    auto bc = bccc;
    std::random_shuffle(bc.begin(), bc.end());
    auto iter = bc.begin();
    ans.clear();
    while (bc.size()) {
      int to_remove = -1;
      if (iter->first == as[idx]) {
        iter++;
        if (bc.size() == 1)
          break;
        if (iter == bc.end())
          iter = bc.begin();
      }
      while (as[idx] != iter->first) {
        idx++;
        iter->second--;
        ans.push_back(iter->first);
        if (iter->second == 0) {
          to_remove = iter->first;
          break;
        }
      }
      if (to_remove >= 0) {
        std::swap(*iter, *(--bc.end()));
        bc.pop_back();
        iter = bc.begin();
      }
    }
    if (ans.size() == N)
      break;
  }
  for (int i : ans)
    printf("%d ", i);
  printf("\\n");
}
Problem p02557 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;

int main() {
  ll n;
  cin >> n;
  ll a[n], b[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> b[i];
  reverse(b, b + n);
  ll j = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      for (; j < n; j++) {
        if (a[i] != b[j] && a[j] != b[i]) {
          swap(b[i], b[j]);
          break;
        }
      }
      if (a[i] == b[i]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  for (int i = 0; i < n; i++)
    cout << b[i] << " ";
  cout << endl;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
const ll M = 400001;
ll a[M], b[M], acnt[M], bcnt[M], ans[M];
tuple<ll, ll, ll> sumcnt[M];

int main() {
  ll n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    acnt[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    bcnt[b[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    sumcnt[i] = {acnt[i] + bcnt[i], bcnt[i], i};
    if (get<0>(sumcnt[i]) > n) {
      cout << "No" << endl;
      return 0;
    }
  }
  sort(sumcnt, sumcnt + M);
  reverse(sumcnt, sumcnt + M);
  priority_queue<tuple<ll, ll, ll>> pq;
  for (int i = 0; i < M; i++)
    if (get<1>(sumcnt[i]) > 0)
      pq.push(sumcnt[i]);
  for (int i = 1; i <= n; i++) {
    tuple<ll, ll, ll> x = pq.top();
    pq.pop();
    //    cout<<get<0>(x)<<get<1>(x)<<get<2>(x)<<endl;
    if (get<2>(x) != a[i]) {
      ans[i] = get<2>(x);
      get<1>(x)--;
      get<0>(x)--;
      if (get<1>(x) > 0)
        pq.push(x);
    } else {
      tuple<ll, ll, ll> y = pq.top();
      pq.pop();
      ans[i] = get<2>(y);
      get<1>(y)--;
      get<0>(y)--;
      if (get<1>(y) > 0)
        pq.push(y);
      pq.push(x);
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i <= n; i++)
    cout << ans[i] << " ";
  cout << endl;
}
Problem p02557 (C++) — buggy submission, verdict: Runtime Error

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i, a) for (auto &i : a)
inline int in() {
  int x;
  scanf("%lld", &x);
  return x;
}
int32_t main() {
  int n = in();
  vector<int> a(n), b(n);
  for (int &i : a)
    i = in();
  for (int &i : b)
    i = in();
  reverse(all(b));
  int c = -1;
  for (int i = 0; i < n; i++)
    if (a[i] == b[i]) {
      c = a[i];
      break;
    }
  int l = 0, r = -1;
  for (int i = 0; i < n; i++) {
    if (b[i] == c and a[i] == c) {
      l = i;
      break;
    }
  }
  for (int i = n - 1; i >= 0; i--)
    if (b[i] == c and a[i] == c) {
      r = i;
      break;
    }

  for (int i = 0; i < n; i++) {
    if (a[i] != c and b[i] != c and l <= r) {
      swap(b[i], b[l]);
      l++;
    }
  }
  if (l <= r) {
    puts("No");
    return 0;
  }
  puts("Yes");
  for (int i : b)
    cout << i << " ";
}


Error: WA

Fixed submission:


#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i, a) for (auto &i : a)
inline int in() {
  int x;
  scanf("%lld", &x);
  return x;
}
const int N = 2e5 + 4;
int fa[N], fb[N], a[N], b[N];
int32_t main() {
  int n = in();

  set<int> have;
  for (int i = 1; i <= n; i++) {
    a[i] = in();
    fa[a[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    b[i] = in();
    fb[b[i]]++;
    have.insert(b[i]);
  }

  vector<int> ans;
  for (int i : have) {
    if (i == a[1])
      continue;
    for (int j = 0; j < fb[i]; j++)
      ans.push_back(i);
  }
  // for(int j=0;j<fb[a[1]];j++)ans.push_back(a[1]);

  bool ok = 1;
  // for(int i:ans)cout<<i<<" ";cout<<"\\n";
  for (int i = 1; i <= n; i++)
    ok &= (ans[i - 1] != a[i]);
  if (!ok)
    puts("No");
  else {
    puts("Yes");
    for (int i : ans)
      cout << i << " ";
  }
}
Problem p02557 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
// using namespace atcoder;

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  map<int, int> ANum, BNum;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    ANum[A[i]]++;
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
    BNum[B[i]]++;
  }
  for (int i = 0; i <= N; i++) {
    if (ANum.find(i) == ANum.end() || BNum.find(i) == BNum.end())
      continue;
    if (ANum[i] + BNum[i] > N) {
      cout << "No" << endl;
      return 0;
    }
  }
  int j = 0, bef = -1;
  for (int i = 0; i < N; i++) {
    if (bef != A[i])
      j = 0;
    if (A[i] == B[i]) {
      while (j < N) {
        if (A[j] != A[i] && B[j] != A[i]) {
          swap(B[i], B[j]);
          break;
        }
        j++;
      }
    }
    bef = A[i];
  }
  cout << "Yes" << endl;
  for (int b : B)
    cout << b << " ";
  cout << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
// using namespace atcoder;

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  map<int, int> ANum, BNum;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    ANum[A[i]]++;
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
    BNum[B[i]]++;
  }
  for (int i = 0; i < N; i++) {
    if (ANum.find(i) == ANum.end() || BNum.find(i) == BNum.end())
      continue;
    if (ANum[i] + BNum[i] > N) {
      cout << "No" << endl;
      return 0;
    }
  }
  int j = 0, bef = -1;
  for (int i = 0; i < N; i++) {
    if (bef != A[i])
      j = 0;
    if (A[i] == B[i]) {
      while (A[i] == B[j] || B[i] == A[j]) {
        j++;
        if (j >= N)
          j = 0;
      }
      swap(B[i], B[j]);
    }
    bef = A[i];
  }
  cout << "Yes" << endl;
  for (int b : B)
    cout << b << " ";
  cout << endl;
}
Problem p02557 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char c = getchar();
  int res = 0;
  while (!isdigit(c))
    c = getchar();
  while (isdigit(c)) {
    res = (c & 15) + (res << 1) + (res << 3);
    c = getchar();
  }
  return res;
}
int n, *a, *b;
int main() {
  n = read();
  a = new int[n];
  b = new int[n + 1];
  pair<int, int> *bound = new pair<int, int>[n + 1];
  for (int i = 0; i <= n; i++)
    bound[i] = make_pair(-1, -1);
  for (int i = 0, cur = 0; i < n; i++) {
    a[i] = read();
    if (cur != a[i]) {
      bound[cur].second = i - 1;
      bound[a[i]].first = i;
      cur = a[i];
    }
  }
  bound[a[n - 1]].second = n - 1;
  for (int i = 0; i < n; i++)
    b[i] = read();
  int *off = new int[n + 3];
  off[0] = 0;
  off++;
  for (int i = 0; i <= n + 1; i++)
    off[i] = 0;
  for (int i = 0, l, r; i < n; i++) {
    l = bound[b[i]].first;
    r = bound[b[i]].second;
    if (l != -1 && r != -1) {
      if (i < l) {
        off[l - i]--;
        off[r - i + 1]++;
      } else if (i > r) {
        off[n + l - i]--;
        off[n + r - i + 1]++;
      } else {
        off[0]--;
        off[r - i + 1]++;
        off[n + l - i]--;
      }
    }
  }
  for (int i = 0; i < n; i++)
    off[i] += off[i - 1];
  int res = -1;
  for (int i = 0; i < n; i++) {
    if (off[i] == 0) {
      res = i;
      break;
    }
  }
  if (res == -1) {
    printf("No");
  } else {
    printf("Yes\\n");
    for (int i = n; i < n << 1; i++) {
      printf("%d ", b[(i - res) % n]);
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int a[200001], b[200001];

int main()

{
  int n, i, j;
  bool f;
  f = true;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (i = 1; i <= n; i++) {
    cin >> b[i];
  }
  for (i = 1; i <= n; i++) {
    if (a[i] == b[i]) {
      for (j = 1; j <= n; j++) {
        if (a[i] != b[j] && a[j] != b[i]) {
          swap(b[i], b[j]);
          break;
        }
      }
    }
    if (a[i] == b[i]) {
      cout << "No";
      f = false;
      break;
    }
  }
  if (f == true) {
    cout << "Yes" << endl;
    for (i = 1; i <= n; i++) {
      cout << b[i] << " ";
    }
  }

  return 0;
}
Problem p02557 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

signed main() {
  int n;
  cin >> n;

  vector<int> a(n), b(n);
  vector<int> cnt(n + 1);
  rep(i, n) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  rep(i, n) {
    cin >> b[i];
    cnt[b[i]]++;
  }

  reverse(b.begin(), b.end());
  rep(i, n + 1) {
    if (cnt[i] > n) {
      cout << "No" << '\\n';
      return 0;
    }
  }
  int x = 0;
  int k = 0;
  vector<int> overlap;
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      x = a[i];
      overlap.push_back(i);
      k++;
    }
  }
  vector<int> idx;
  for (int i = 0; i < n; i++) {
    if (a[i] != x && b[i] != x) {
      idx.push_back(i);
    }
  }

  for (int i = 0; i < k; i++) {
    swap(b[overlap[i]], b[idx[i]]);
  }

  cout << "Yes" << '\\n';
  for (auto it : b)
    cout << it << " ";
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

signed main() {
  int n;
  cin >> n;

  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];

  reverse(b.begin(), b.end());
  bool ok = true;
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      for (int j = i + 1; j <= n; j++) {
        if (j == n) {
          ok = false;
          break;
        }
        if (a[i] != b[j]) {
          swap(b[i], b[j]);
          break;
        }
      }
      if (!ok)
        break;
    }
  }

  if (ok) {
    cout << "Yes" << '\\n';
    for (auto it : b)
      cout << it << " ";
    cout << '\\n';
  } else {
    cout << "No" << '\\n';
  }
}
Problem p02557 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
using ll = long long;

const int N = 2e5 + 5;
int cnta[N], cntb[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int ar[n], br[n];
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    cnta[ar[i]]++;
  }
  for (int i = 0; i < n; i++) {
    cin >> br[i];
    cntb[br[i]]++;
  }
  for (int i = 0; i < N; i++) {
    if (cnta[i]) {
      if (n - cntb[i] < cnta[i]) {
        cout << "No" << '\\n';
        exit(0);
      }
    }
  }
  reverse(br, br + n);
  vector<int> sama, beda;
  int val_sama = -1;
  for (int i = 0; i < n; i++) {
    if (ar[i] == br[i]) {
      val_sama = ar[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (ar[i] == br[i])
      sama.pb(i);
    else if (ar[i] != val_sama && br[i] != val_sama)
      beda.pb(i);
  }
  assert(sama.size() <= beda.size());
  for (int i = 0; i < sama.size(); i++) {
    swap(br[sama[i]], br[beda[i]]);
  }
  cout << "Yes" << '\\n';
  for (int i = 0; i < n; i++) {
    cout << br[i];
    if (i == n - 1)
      cout << '\\n';
    else
      cout << ' ';
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
using ll = long long;

const int N = 2e5 + 5;
int cnta[N], cntb[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int ar[n], br[n];
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    cnta[ar[i]]++;
  }
  multiset<int> sb;
  for (int i = 0; i < n; i++) {
    cin >> br[i];
    cntb[br[i]]++;
    sb.insert(br[i]);
  }
  for (int i = 0; i < N; i++) {
    if (cnta[i]) {
      if (n - cntb[i] < cnta[i]) {
        cout << "No" << '\\n';
        exit(0);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    auto fr = sb.begin();
    auto bac = sb.rbegin();
    assert(*fr != ar[i] || *bac != ar[i]);
    if (*fr != ar[i]) {
      br[i] = *fr;
    } else {
      br[i] = *bac;
    }
    sb.erase(sb.find(br[i]));
  }
  cout << "Yes" << '\\n';
  for (int i = 0; i < n; i++) {
    cout << br[i];
    if (i == n - 1)
      cout << '\\n';
    else
      cout << ' ';
  }
  return 0;
}
Problem p02557 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

// Template START
#define endl "\\n"
#define async                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define int long long int
#define all(y) y.begin(), y.end()
#define present(x, y) (x.find(y) != x.end())
const int mod = (int)1e9 + 7;
template <class T> auto matrix(int r, int c, T v) {
  return vector<vector<T>>(r, vector<T>(c, v));
}
template <class T> auto matrix(int o1, int o2, int o3, T v) {
  return vector<vector<vector<T>>>(o1, vector<vector<T>>(o2, vector<T>(o3, v)));
}
#define v vector
// Template END

int power(int x, int n) {
  if (n == 0)
    return 1;
  else if (n & 1)
    return (x * power((x * x) % mod, n / 2)) % mod;
  return power((x * x) % mod, n / 2) % mod;
}

signed main() {
  int n;
  cin >> n;
  v<int> a(n), b(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> b[i];
  int prev = -1, j = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] != prev)
      j = 0;
    if (a[i] == b[i]) {
      for (; j < n; j++) {
        if (a[i] != b[j] && a[j] != b[i]) {
          swap(b[i], b[j]);
          break;
        }
      }
      if (a[i] == b[i]) {
        cout << "No";
        return 0;
      }
    }
    prev = a[i];
  }
  cout << "Yes" << endl;
  for (int i = 0; i < n; i++)
    cout << b[i] << " ";
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

// Template START
#define endl "\\n"
#define async                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define int long long int
#define all(y) y.begin(), y.end()
#define present(x, y) (x.find(y) != x.end())
const int mod = (int)1e9 + 7;
template <class T> auto matrix(int r, int c, T v) {
  return vector<vector<T>>(r, vector<T>(c, v));
}
template <class T> auto matrix(int o1, int o2, int o3, T v) {
  return vector<vector<vector<T>>>(o1, vector<vector<T>>(o2, vector<T>(o3, v)));
}
#define v vector
// Template END

int power(int x, int n) {
  if (n == 0)
    return 1;
  else if (n & 1)
    return (x * power((x * x) % mod, n / 2)) % mod;
  return power((x * x) % mod, n / 2) % mod;
}

signed main() {
  int n;
  cin >> n;
  v<int> a(n), b(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> b[i];
  int prev = -1, j = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      if (a[i] == prev)
        j = 0;
      for (; j < n; j++) {
        if (a[i] != b[j] && a[j] != b[i]) {
          swap(b[i], b[j]);
          break;
        }
      }
      if (a[i] == b[i]) {
        cout << "No";
        return 0;
      }
    }
    prev = a[i];
  }
  cout << "Yes" << endl;
  for (int i = 0; i < n; i++)
    cout << b[i] << " ";
  return 0;
}