alexjercan/bugnet huggingface dataset:
Problem p02557 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

const int N = 2000000 + 10;

// struct Node {
//     int pos, v;
//     bool operator < (const Node &tmp) const { return v < tmp.v; }
// }a[N], b[N];

int a[N], b[N], c[N], n;

int check() {
  unordered_map<int, int> ump1, ump2;
  for (int i = 1; i <= n; i++)
    ump1[a[i]]++;
  for (int i = 1; i <= n; i++)
    ump2[b[i]]++;
  int res = 0;
  for (auto x : ump1) {
    if (ump2.count(x.first)) {
      if (min(x.second, ump2[x.first]) > n / 2) {
        return -1;
      }
      res = max(res, max(x.second, ump2[x.first]));
    }
  }
  return res;
}

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    scanf("%d", a + i);
  for (int i = 1; i <= n; i++)
    scanf("%d", b + i);
  unordered_map<int, pair<int, int>> ump1, ump2;
  for (int i = 1; i <= n; i++) {
    if (ump1.count(a[i]))
      ump1[a[i]].second = i;
    else
      ump1[a[i]] = {i, i};
  }
  for (int i = 1; i <= n; i++) {
    if (ump2.count(b[i]))
      ump2[b[i]].second = i;
    else
      ump2[b[i]] = {i, i};
  }
  int L = 0, R = 2 * n;
  for (auto x : ump1) {
    int val = x.first;
    if (ump2.count(val)) {
      int l1 = ump1[val].first, r1 = ump1[val].second;
      int l2 = ump2[val].first, r2 = ump2[val].second;
      L = max(L, r1 - l2 + 1);
      R = min(R, l1 + n - r2 - 1);
    }
  }
  if (L <= R) {
    cout << "Yes\\n";
    int dx = L;
    for (int i = 1; i <= n; i++)
      c[(i + dx - 1) % n + 1] = b[i];
    for (int i = 1; i <= n; i++)
      cout << c[i] << ' ';
  } else {
    cout << "No\\n";
  }
#ifndef ONLINE_JUDGE
  system("pause");
#endif
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const int N = 2000000 + 10;

// struct Node {
//     int pos, v;
//     bool operator < (const Node &tmp) const { return v < tmp.v; }
// }a[N], b[N];

int a[N], b[N], c[N], n;

int check() {
  unordered_map<int, int> ump1, ump2;
  for (int i = 1; i <= n; i++)
    ump1[a[i]]++;
  for (int i = 1; i <= n; i++)
    ump2[b[i]]++;
  int res = 0;
  for (auto x : ump1) {
    if (ump2.count(x.first)) {
      if (min(x.second, ump2[x.first]) > n / 2) {
        return -1;
      }
      res = max(res, max(x.second, ump2[x.first]));
    }
  }
  return res;
}

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    scanf("%d", a + i);
  multiset<int> st;
  for (int i = 1; i <= n; i++) {
    scanf("%d", b + i);
    st.insert(b[i]);
    st.insert(b[i] + 1000000);
  }
  int res = check();
  if (res != -1) {
    cout << "Yes\\n";
    for (int i = 1; i <= n; i++) {
      auto it = st.upper_bound(a[i]);
      if (*it == a[i] + 1000000)
        it = st.upper_bound(a[i] + 1000000);
      if (*it >= 1000000) {
        cout << (*it - 1000000) << ' ';
        st.erase(st.lower_bound(*it - 1000000));
        st.erase(it);
      } else {
        cout << (*it) << ' ';
        st.erase(st.lower_bound(*it + 1000000));
        st.erase(it);
      }
    }
  } else {
    cout << "No\\n";
  }

#ifndef ONLINE_JUDGE
  system("pause");
#endif
  return 0;
}
Problem p02557 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define LL __int128
#define ll long long
#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define scl(a) scanf("%lld", &a)
#define scl2(a, b) scanf("%lld%lld", &a, &b)
#define ss(a) scanf("%s", a)
#define mem(a, b) memset(a, b, sizeof(a))
#define ios                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define PII pair<int, int>
using namespace std;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
int a[maxn], b[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++)
    cin >> b[i];
  reverse(b + 1, b + n + 1);
  int ok = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] != b[i])
      continue;
    int f = 0;
    for (int j = 1; j <= n; j++) {
      if (a[i] != b[j] && a[j] != b[i]) {
        f = 1;
        swap(b[i], b[j]);
        break;
      }
    }
    if (!f) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i <= n; i++) {
    if (i != 1)
      cout << " ";
    cout << b[i];
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define LL __int128
#define ll long long
#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define scl(a) scanf("%lld", &a)
#define scl2(a, b) scanf("%lld%lld", &a, &b)
#define ss(a) scanf("%s", a)
#define mem(a, b) memset(a, b, sizeof(a))
#define ios                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define PII pair<int, int>
using namespace std;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
int a[maxn], b[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++)
    cin >> b[i];
  reverse(b + 1, b + n + 1);
  int ok = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] != b[i])
      continue;
    int f = 0;
    for (int j = 1; j <= n; j++) {
      if (a[i] != b[j] && a[j] != b[i]) {
        f = 1;
        swap(b[i], b[j]);
        break;
      }
    }
    if (!f) {
      ok = 1;
      break;
    }
  }
  if (ok)
    cout << "No" << endl;
  else {
    cout << "Yes" << endl;
    for (int i = 1; i <= n; i++) {
      if (i != 1)
        cout << " ";
      cout << b[i];
    }
    cout << endl;
  }
  return 0;
}
Problem p02557 (C++) — buggy submission, verdict: Runtime Error

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

int main(void) {
  int N;
  cin >> N;
  int A[N];
  vector<int> cnt(N + 1);
  int maxcnt = 1;
  rep(i, N) {
    cin >> A[i];
    cnt[A[i]]++;
  }
  int B[N];
  rep(i, N) {
    cin >> B[N - 1 - i];
    cnt[B[N - 1 - i]]++;
  }
  sort(cnt.begin(), cnt.end());
  maxcnt = cnt[N];

  if (maxcnt > N) {
    cout << "No" << endl;
    return 0;
  }

  int j = 0;
  rep(i, N) {
    while (A[i] == B[i]) {
      swap(B[i], B[j]);
      j++;
    }
  }
  j = N - 1;
  rep(i, N) {
    while (A[i] == B[i]) {
      swap(B[i], B[j]);
      j--;
    }
  }

  cout << "Yes" << endl;
  rep(i, N) cout << B[i] << " ";
  cout << endl;

  return 0;
}


Error: WA

Fixed submission:

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

int main(void) {
  int N;
  cin >> N;
  int A[N];
  vector<int> cnt(N + 1);
  rep(i, N) {
    cin >> A[i];
    cnt[A[i]]++;
  }
  vector<int> v(N + 1);
  rep(i, N) {
    int b;
    cin >> b;
    cnt[b]++;
    v[b]++;
  }
  sort(cnt.begin(), cnt.end());
  if (cnt[N] > N) {
    cout << "No" << endl;
    return 0;
  }

  int h = N;
  int ans[N];
  rep(i, N) {
    while (v[h] == 0)
      h--;
    if (h != A[i]) {
      ans[i] = h;
      v[h]--;
    } else {
      int k = h - 1;
      while (v[k] == 0)
        k--;
      ans[i] = k;
      v[k]--;
    }
  }

  cout << "Yes" << endl;
  rep(i, N) cout << ans[i] << " ";
  cout << endl;

  return 0;
}
Problem p02557 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  map<int, int> ma, mb;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    ma[A[i]]++;
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
    mb[B[i]]++;
  }
  for (auto v : mb) {
    int t = v.second + ma[v.first];
    if (t > N) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  vector<int> right(200100, 0), left(200100, -1);
  for (int i = 0; i < N - 1; i++) {
    if (A[i] != A[i + 1])
      right[A[i]] = i + 1;
  }
  if (right[A[N - 1]] == 0)
    right[A[N - 1]] = N;
  int ha = 1e9, ind = 0;
  for (int i = 0; i < N; i++) {
    if (left[B[i]] == -1) {
      left[B[i]] = N + i;
      if (ha > left[B[i]] - right[B[i]]) {
        ha = left[B[i]] - right[B[i]];
        ind = N - ha;
      }
    }
  }
  vector<int> ans(N);
  for (int i = 0; i < N; i++) {
    ans[(ind + i) % N] = B[i];
  }
  for (int i = 0; i < N; i++) {
    if (i != N - 1)
      cout << ans[i] << ' ';
    else
      cout << ans[i] << endl;
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  map<int, int> ma, mb;
  vector<int> cnt[200010];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    cnt[A[i]].push_back(i);
    ma[A[i]]++;
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
    mb[B[i]]++;
  }
  for (auto v : mb) {
    int t = v.second + ma[v.first];
    if (t > N) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  vector<int> right(200100, 0), left(200100, -1);
  for (int i = 0; i < N - 1; i++) {
    if (A[i] != A[i + 1])
      right[A[i]] = i + 1;
  }
  if (right[A[N - 1]] == 0)
    right[A[N - 1]] = N;
  int ha = 1e9, ind = 0;
  for (int i = 0; i < N; i++) {
    if (left[B[i]] == -1) {
      left[B[i]] = N + i;
      if (ha > left[B[i]] - right[B[i]]) {
        ha = left[B[i] - right[B[i]]];
        ind = right[B[i]];
      }
    }
  }
  vector<int> ans(N);
  for (int i = 0; i < N; i++) {
    ans[(ind + i) % N] = B[i];
  }
  for (int i = 0; i < N; i++) {
    if (i != N - 1)
      cout << ans[i] << ' ';
    else
      cout << ans[i] << endl;
  }
}
Problem p02557 (C++) — buggy submission, verdict: Runtime Error

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

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> b[i];

  reverse(b.begin(), b.end());

  vector<int> visited(n);
  int k = -1;
  int want = 0;
  vector<int> eq;
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      eq.push_back(i);
      k = a[i];
      visited[i] = 1;
      want++;
    }
  }

  //    for (auto e:eq) cout<<e<<" ";
  //    cout<<endl;

  vector<int> avail;
  int can = 0;
  for (int i = 0; i < n; i++) {
    if (!visited[i]) {
      if (a[i] != k and b[i] != k) {
        avail.push_back(i);
        can++;
      }
    }
  }

  //    for (auto e:avail) cout<<e<<" ";
  //    cout<<endl;

  if (can >= want) {
    for (int i = 0; i < (int)eq.size(); i++) {
      swap(b[avail[i]], b[eq[i]]);
    }
    cout << "Yes" << endl;
    for (int i = 0; i < n; i++) {
      cout << b[i] << " ";
    }
    cout << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Error: WA

Fixed submission:

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

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> b[i];

  reverse(b.begin(), b.end());

  vector<int> visited(n);
  int k = -1;
  int want = 0;
  vector<int> eq;
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      eq.push_back(i);
      k = a[i];
      visited[i] = 1;
      want++;
    }
  }

  //    for (auto e:eq) cout<<e<<" ";
  //    cout<<endl;

  vector<int> avail;
  int can = 0;
  for (int i = 0; i < n; i++) {
    if (!visited[i]) {
      if (a[i] != k and b[i] != k) {
        avail.push_back(i);
        can++;
      }
    }
  }

  //    for (auto e:avail) cout<<e<<" ";
  //    cout<<endl;

  for (int i = 0; i < (int)eq.size(); i++) {
    swap(b[avail[i]], b[eq[i]]);
  }

  cout << (can >= want ? "Yes" : "No") << endl;

  if (can >= want) {
    for (int i = 0; i < n; i++) {
      cout << b[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
Problem p02557 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define pb push_back
#define ld long double
#define int long long

mt19937 rnd(51);

const int MOD = 1e9 + 7;

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<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 l = 0, r = n - 1;
  reverse(b.begin(), b.end());
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      if (b[l] != a[i] && a[l] != b[i]) {
        swap(b[l++], b[i]);
      } else {
        swap(b[r--], b[i]);
      }
    }
  }
  bool x = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i])
      x = 0;
  }
  if (x) {
    cout << "Yes\\n";
    for (auto to : b) {
      cout << to << " ";
    }
  } else {
    cout << "No";
  }
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define pb push_back
#define ld long double
#define int long long

mt19937 rnd(51);

const int MOD = 1e9 + 7;

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<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 l = 0, r = 0;
  reverse(b.begin(), b.end());
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      if (b[l] != a[i] && a[l] != b[i]) {
        swap(b[l++], b[i]);
      } else {
        swap(b[r--], b[i]);
      }
    }
  }
  bool x = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i])
      x = 0;
  }
  if (x) {
    cout << "Yes\\n";
    for (auto to : b) {
      cout << to << " ";
    }
  } else {
    cout << "No";
  }
  return 0;
}
Problem p02557 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  vector<int> bkt(N + 1, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    bkt[A[i]]++;
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
    bkt[B[i]]++;
  }

  for (int i = 1; i <= N; i++) {
    if (bkt[i] > N) {
      cout << "No\\n";
      return 0;
    }
  }
  vector<int> ami(N + 1, 1e9), ama(N + 1, -1), bmi(N + 1, 1e9), bma(N + 1, -1);
  for (int i = 0; i < N; i++) {
    ami[A[i]] = min(ami[A[i]], i);
    ama[A[i]] = max(ama[A[i]], i);
    bmi[B[i]] = min(bmi[B[i]], i);
    bma[B[i]] = max(bma[B[i]], i);
  }
  vector<int> imos(N, 0);
  for (int i = 0; i <= N; i++) {
    if (ama[i] >= 0 && bma[i] >= 0) {
      int st = (ami[i] - bma[i] + N) % N;
      int en = (ama[i] - bmi[i] + N + 1) % N;
      imos[st]++;
      imos[en]--;
      if (en < st)
        imos[0]++;
    }
  }
  for (int i = 1; i < N; i++) {
    imos[i] += imos[i - 1];
  }
  cout << "Yes\\n";
  for (int i = 0; i < N; i++) {
    if (imos[i] == 0) {
      for (int j = 0; j < N; j++) {
        cout << B[(j - i + N) % N];
        if (j < N - 1)
          cout << " ";
        else
          cout << "\\n";
      }
      return 0;
    }
  }
}


Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  vector<int> bkt(N + 1, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    bkt[A[i]]++;
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
    bkt[B[i]]++;
  }

  for (int i = 1; i <= N; i++) {
    if (bkt[i] > N) {
      cout << "No\\n";
      return 0;
    }
  }
  queue<int> q;
  for (int i = 0; i < N; i++) {
    q.push(B[i]);
  }
  cout << "Yes\\n";
  int pos = 0;
  if (A[0] > B[0] && A[0] < B[N - 1]) {
    while (q.front() < A[0]) {
      int n = q.front();
      q.pop();
      q.push(n);
    }
  }
  while (!q.empty()) {
    int n = q.front();
    q.pop();
    if (A[pos] != n) {
      cout << n;
      pos++;
      if (pos == N) {
        cout << "\\n";
        break;
      } else {
        cout << " ";
      }
    } else {
      q.push(n);
    }
  }
}
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++)
#define irep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
using namespace std;
using ll = long long;
using PL = pair<ll, ll>;
using P = pair<int, int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007; // = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> A(N), B(N);
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];
  vector<int> ca(N + 1, 0), cb(N + 1, 0);
  rep(i, N) {
    ca[A[i]]++;
    cb[B[i]]++;
  }
  rep(i, N) {
    if (ca[i + 1] + cb[i + 1] > N) {
      cout << "No" << '\\n';
      return 0;
    }
  }

  rep(i, N) {
    ca[i + 1] += ca[i];
    cb[i + 1] += cb[i];
  }
  int ma = -1;
  rep(i, N) ma = max(ma, ca[i + 1] - cb[i]);

  cout << "Yes" << '\\n';
  rep(i, N) cout << B[(i - ma + N) % N] << ' ';
  cout << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define irep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
using namespace std;
using ll = long long;
using PL = pair<ll, ll>;
using P = pair<int, int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007; // = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> A(N), B(N);
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];

  vector<int> ca(N + 1, 0), cb(N + 1, 0);
  rep(i, N) {
    ca[A[i]]++;
    cb[B[i]]++;
  }

  bool flag = true;
  rep(i, N) {
    if (ca[i + 1] + cb[i + 1] > N) {
      flag = false;
      break;
    }
  }
  if (!flag) {
    cout << "No" << '\\n';
    return 0;
  }

  // possible
  vector<int> ans(N, -1);
  vector<P> aa(N), bb(N);
  rep(i, N) {
    if (ca[i + 1] > 0)
      aa[i] = make_pair(ca[i + 1], i + 1);
    if (cb[i + 1] > 0)
      bb[i] = make_pair(cb[i + 1], i + 1);
  }

  sort(aa.begin(), aa.end(), greater<P>());
  sort(bb.begin(), bb.end(), greater<P>());

  int b = 0;
  for (P &p : aa) {
    int idx = lower_bound(A.begin(), A.end(), p.second) - A.begin();
    while (idx < N && A[idx] == p.second) {
      while (bb[b].second == p.second || bb[b].first == 0) {
        ++b;
        if (b >= (int)bb.size())
          b = 0;
      }
      while (idx < N && A[idx] == p.second && bb[b].first > 0) {
        ans[idx] = bb[b].second;
        ++idx;
        --bb[b].first;
      }
    }
  }
  cout << "Yes" << '\\n';
  rep(i, N) cout << ans[i] << ' ';
  cout << '\\n';
  return 0;
}
Problem p02557 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define LL __int128
#define ll long long
#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define scl(a) scanf("%lld", &a)
#define scl2(a, b) scanf("%lld%lld", &a, &b)
#define ss(a) scanf("%s", a)
#define mem(a, b) memset(a, b, sizeof(a))
#define ios                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define PII pair<int, int>
using namespace std;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
int a[maxn], b[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++)
    cin >> b[i];
  reverse(b + 1, b + n + 1);
  bool ok = false;
  for (int i = 1; i <= n; i++) {
    if (a[i] != b[i])
      continue;
    bool f = false;
    for (int j = 1; j <= n; j++) {
      if (a[i] != b[j] && a[j] != b[i]) {
        f = true;
        swap(b[i], b[j]);
        break;
      }
    }
    if (!f) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  for (int i = 1; i <= n; i++) {
    if (i != 1)
      cout << " ";
    cout << b[i];
  }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define LL __int128
#define ll long long
#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define scl(a) scanf("%lld", &a)
#define scl2(a, b) scanf("%lld%lld", &a, &b)
#define ss(a) scanf("%s", a)
#define mem(a, b) memset(a, b, sizeof(a))
#define ios                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define PII pair<int, int>
using namespace std;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
int a[maxn], b[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++)
    cin >> b[i];
  reverse(b + 1, b + n + 1);
  bool ok = false;
  for (int i = 1; i <= n; i++) {
    if (a[i] != b[i])
      continue;
    bool f = false;
    for (int j = 1; j <= n; j++) {
      if (a[i] != b[j] && a[j] != b[i]) {
        f = true;
        swap(b[i], b[j]);
        break;
      }
    }
    if (!f) {
      ok = true;
      break;
    }
  }
  if (ok)
    cout << "No" << endl;
  else {
    cout << "Yes" << endl;
    for (int i = 1; i <= n; i++) {
      if (i != 1)
        cout << " ";
      cout << b[i];
    }
    cout << endl;
  }
  return 0;
}