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

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

int32_t n, *a, *b;

void swap(int32_t *x, int32_t *y) {
  int32_t t = *x;
  *x = *y;
  *y = t;
}

int32_t main() {
  scanf("%d", &n);
  a = (int32_t *)malloc(n * sizeof(int32_t));
  b = (int32_t *)malloc(n * sizeof(int32_t));

  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  for (int i = 0; i < n; i++)
    scanf("%d", &b[n - i - 1]);

  bool bad = false;
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      bool ok = false;
      for (int j = 0; j < n; j++) {
        if (a[i] != b[j] && a[j] != b[i]) {
          swap(&b[i], &b[j]);
          ok = true;
          break;
        }
      }

      if (!ok) {
        bad = true;
        break;
      }
    }
  }

  if (bad) {
    puts("No");
    exit(0);
  }

  puts("Yes");
  for (int i = 0; i < n; i++)
    printf("%d ", b[i]);
  puts("");
  return 0;
}


Error: -6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)


Fixed submission:

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

int32_t n, *a, *b;

void swap(int32_t *x, int32_t *y) {
  int32_t t = *x;
  *x = *y;
  *y = t;
}

int32_t main() {
  scanf("%d", &n);
  a = (int32_t *)malloc(n * sizeof(int32_t));
  b = (int32_t *)malloc(n * sizeof(int32_t));

  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  for (int i = 0; i < n; i++)
    scanf("%d", &b[n - i]);

  bool bad = false;
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      bool ok = false;
      for (int j = 0; j < n; j++) {
        if (a[i] != b[j] && a[j] != b[i]) {
          swap(&b[i], &b[j]);
          ok = true;
          break;
        }
      }

      if (!ok) {
        bad = true;
        break;
      }
    }
  }

  if (bad) {
    puts("No");
    exit(0);
  }

  puts("Yes");
  for (int i = 0; i < n; i++)
    printf("%d ", b[i]);
  puts("");
  return 0;
}
Problem p02557 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

template <class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
  ll N;
  cin >> N;
  vl A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  vl B(N);
  for (int i = 0; i < N; ++i) {
    cin >> B[i];
  }

  int j = 0;
  ll bef = -1;
  for (int i = 0; i < N; ++i) {
    if (A[i] != bef)
      j = 0;
    if (A[i] == B[i]) {
      bool isNG = true;
      for (; j < N; ++j) {
        if (A[j] != B[i] && B[j] != A[i]) {
          swap(B[i], B[j]);
          isNG = false;
          break;
        }
      }
      if (isNG) {
        cout << "No" << endl;
        return 0;
      }
    }
    bef = A[i];
  }

  cout << "Yes" << endl;
  for (int i = 0; i < N; ++i) {
    cout << B[i] << " ";
  }
  cout << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

template <class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
  ll N;
  cin >> N;
  vl A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  vl B(N);
  for (int i = 0; i < N; ++i) {
    cin >> B[i];
  }

  for (int i = 0; i < N; ++i) {
    if (A[i] == B[i]) {
      bool isNG = true;
      for (int j = 0; j < N; ++j) {
        if (A[j] != B[i] && B[j] != A[i]) {
          swap(B[i], B[j]);
          isNG = false;
          break;
        }
      }
      if (isNG) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;
  for (int i = 0; i < N; ++i) {
    cout << B[i] << " ";
  }
  cout << endl;
}
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, 0);
  vector<int> A2(N, 0);
  vector<int> B(N, 0);
  int x;
  for (int i = 0; i < N; i++) {
    cin >> x;
    A.at(x - 1)++;
    A2.at(i) = x;
  }
  for (int i = 0; i < N; i++) {
    cin >> x;
    B.at(x - 1)++;
  }

  int m = 0;
  int n = 0;
  for (int i = 0; i < N; i++) {
    if (m < A.at(i) + B.at(i)) {
      m = A.at(i) + B.at(i);
      n = i;
    }
  }

  if (m > N) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;

    vector<int> B2(N, 0);

    int x = 0;
    for (int i = 0; i <= n; i++) {
      x += A.at(i);
    }
    int x2 = x - 1;
    if (x == N) {
      x = 0;
    }

    for (int i = 0; i < N; i++) {
      while (B.at(n) == 0) {
        n++;
        if (n == N) {
          n = 0;
        }
      }
      B2.at(x) = n + 1;
      B.at(n)--;
      x++;
      if (x == N) {
        x = 0;
      }
    }

    int z;
    bool check = true;
    while (check) {
      check = false;
      for (int i = 0; i < N; i++) {
        if (A2.at(i) == B2.at(i)) {
          if (x2 == -1) {
            x2 = N - 1;
          }
          check = true;
          z = B2.at(x2);
          B2.at(x2) = B2.at(i);
          B2.at(i) = z;
          x2--;
        }
      }
    }

    for (int i = 0; i < N; i++) {
      cout << B2.at(i);
      if (i < N - 1) {
        cout << ' ';
      } else {
        cout << endl;
      }
    }
  }

  return 0;
}

Error: 0

Fixed submission:

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

int main() {

  int N;
  cin >> N;

  vector<int> A(N, 0);
  vector<int> A2(N, 0);
  vector<int> B(N, 0);
  int x;
  for (int i = 0; i < N; i++) {
    cin >> x;
    A.at(x - 1)++;
    A2.at(i) = x;
  }
  for (int i = 0; i < N; i++) {
    cin >> x;
    B.at(x - 1)++;
  }

  int m = 0;
  int n = 0;
  for (int i = 0; i < N; i++) {
    if (m < A.at(i) + B.at(i)) {
      m = A.at(i) + B.at(i);
      n = i;
    }
  }

  if (m > N) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;

    vector<int> B2(N, 0);

    int x = 0;
    for (int i = 0; i <= n; i++) {
      x += A.at(i);
    }
    int x2 = x - 1;
    if (x == N) {
      x = 0;
    }

    for (int i = 0; i < N; i++) {
      while (B.at(n) == 0) {
        n++;
        if (n == N) {
          n = 0;
        }
      }
      B2.at(x) = n + 1;
      B.at(n)--;
      x++;
      if (x == N) {
        x = 0;
      }
    }

    int z;
    bool check = true;
    while (check) {
      check = false;
      for (int i = 0; i < N; i++) {
        if (A2.at(i) == B2.at(i)) {
          check = true;
          z = B2.at(x2);
          B2.at(x2) = B2.at(i);
          B2.at(i) = z;
          x2--;
          if (x2 == -1) {
            x2 = N - 1;
          }
        }
      }
    }

    for (int i = 0; i < N; i++) {
      cout << B2.at(i);
      if (i < N - 1) {
        cout << ' ';
      } else {
        cout << endl;
      }
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\\n"

const i64 timeLimit = 1900;

unsigned long xor128() {
  static unsigned long x = 123456789, y = 362436069, z = 521288629,
                       w = 88675123;
  unsigned long t = (x ^ (x << 11));
  x = y;
  y = z;
  z = w;
  return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

int main() {
  i64 N;
  cin >> N;
  vector<i64> A(N), B(N);
  for (i64 i = 0; i < N; i++)
    cin >> A[i];
  for (i64 i = 0; i < N; i++)
    cin >> B[i];
  reverse(B.begin(), B.end());
  i64 cnt = 0;
  for (i64 i = 0; i < N; i++)
    if (A[i] == B[i])
      cnt++;
  chrono::system_clock::time_point start = chrono::system_clock::now();
  while (chrono::duration_cast<chrono::microseconds>(
             chrono::system_clock::now() - start)
                 .count() /
             1000 <
         timeLimit) {
    i64 x = xor128() % N, y = xor128() % N;
    if (A[x] == B[y] || A[y] == B[x])
      continue;
    if (A[x] == B[x])
      cnt--;
    if (A[y] == B[y])
      cnt--;
    swap(B[x], B[y]);
    if (cnt == 0) {
      cout << "Yes" << endl;
      for (i64 i = 0; i < N; i++)
        cout << B[i] << " "[i + 1 == N];
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\\n"

const i64 timeLimit = 1950;

unsigned long xor128() {
  static unsigned long x = 123456789, y = 362436069, z = 521288629,
                       w = 88675123;
  unsigned long t = (x ^ (x << 11));
  x = y;
  y = z;
  z = w;
  return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

int main() {
  i64 N;
  cin >> N;
  vector<i64> A(N), B(N);
  for (i64 i = 0; i < N; i++)
    cin >> A[i];
  for (i64 i = 0; i < N; i++)
    cin >> B[i];
  reverse(B.begin(), B.end());
  i64 cnt = 0;
  for (i64 i = 0; i < N; i++)
    if (A[i] == B[i])
      cnt++;
  chrono::system_clock::time_point start = chrono::system_clock::now();
  while (chrono::duration_cast<chrono::microseconds>(
             chrono::system_clock::now() - start)
                 .count() /
             1000 <
         timeLimit) {
    i64 x = xor128() % N, y = xor128() % N;
    if (A[x] == B[y] || A[y] == B[x])
      continue;
    if (A[x] == B[x])
      cnt--;
    if (A[y] == B[y])
      cnt--;
    swap(B[x], B[y]);
    if (cnt == 0) {
      cout << "Yes" << endl;
      for (i64 i = 0; i < N; i++)
        cout << B[i] << " "[i + 1 == N];
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}
Problem p02557 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define vll vector<int>
#define pii pair<int, int>
#define pb push_back
#define sz(v) (int)(v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(), (v).end()
#define rep(i, a, b) for (int i = a; i < b; ++i)
using namespace std;

#define M 100010

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  vector<pii> a(n);
  int b[n], c[n], ans[n];
  map<int, int> mp;
  vll id[n + 1];
  rep(i, 0, n) cin >> c[i], mp[c[i]]++, id[c[i]].pb(i);
  set<pii> s;
  for (auto p : mp)
    s.insert({p.se, p.fi});
  int i = n - 1;
  while (i >= 0) {
    auto it = s.begin();
    pii p = *it;
    s.erase(it);
    int x = p.se;
    rep(k, 0, p.fi) a[i].fi = x, a[i].se = id[x].back(), id[x].pop_back(), i--;
  }

  // rep(i,0,n)cout<<a[i].fi<<" ";cout<<"\\n";
  mp.clear(), s.clear();
  rep(i, 0, n) cin >> b[i], mp[b[i]]++;
  for (auto p : mp)
    s.insert({p.se, -p.fi});
  rep(i, 0, n) ans[i] = -1;
  bool ok = 1;
  rep(i, 0, n) {
    int x = a[i].fi, j = a[i].se;
    auto it = s.end();
    it--;
    pii p = *it;
    p.se = -p.se;
    if (p.se != x) {
      s.erase(it);
      if (p.fi > 1)
        s.insert({p.fi - 1, -p.se});
      ans[j] = p.se;
    } else {
      if (s.size() == 1) {
        ok = 0;
        break;
      }
      it--, p = *it, s.erase(it), p.se = -p.se;
      if (p.fi > 1)
        s.insert({p.fi - 1, -p.se});
      ans[j] = p.se;
    }
  }
  if (!ok) {
    rep(i, 0, n / 2 + 1) if (i + n / 2 < n) swap(b[i], b[i + n / 2]);
    rep(i, 0, n) if (b[i] == c[i]) {
      cout << "No";
      return 0;
    }
    cout << "Yes\\n";
    rep(i, 0, n) cout << b[i] << " ";
    return 0;
  }
  cout << "Yes\\n";
  rep(i, 0, n) cout << ans[i] << " ";

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define vll vector<int>
#define pii pair<int, int>
#define pb push_back
#define sz(v) (int)(v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(), (v).end()
#define rep(i, a, b) for (int i = a; i < b; ++i)
using namespace std;

#define M 100010

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  int a[n], b[n];
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n) cin >> b[i];
  int i = 0;
  while (i < n) {
    if (a[i] == b[i]) {
      for (int j = 0; j < n; ++j) {
        if (a[i] != b[j] and a[j] != b[i]) {
          swap(b[i], b[j]);
          break;
        }
      }
      if (a[i] == b[i]) {
        cout << "No";
        return 0;
      }
    }
    ++i;
  }
  cout << "Yes\\n";
  rep(i, 0, n) cout << b[i] << " ";

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

#include <bits/stdc++.h>
// #include<atcoder/all>

using namespace std;
// using namespace atcoder;

int main() {
  int N;
  cin >> N;

  int A[N];
  int B[N];

  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }

  int j = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] == B[i]) {
      for (int c = 0; c < N; j++, c++) {
        if (A[i] != B[j] && A[j] != B[i]) {
          swap(B[i], B[j]);
          break;
        }
        if (j == N - 1)
          j = -1;
      }
      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: TLE

Fixed submission:

#include <bits/stdc++.h>
// #include<atcoder/all>

using namespace std;
// using namespace atcoder;

int main() {
  int N;
  cin >> N;

  int A[N];
  int B[N];

  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }

  for (int i = 0; i < N; i++) {
    if (A[i] == B[i]) {
      for (int j = 0; 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;
}
Problem p02557 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"

using namespace std;
using ll = long long;
int a[200005], b[200005];
int main() {
#ifdef LOCAL
  freopen("in1.txt", "r", stdin);
  freopen("out1.txt", "w", stdout);
#endif
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", &b[i]);
  }
  int q = 0, w = n - 1;
  bool ok = true;
  reverse(b, b + n);
  for (int i = 0; i < n; ++i) {
    if (a[i] != b[i])
      continue;
    if (a[q] != b[i] and a[i] != b[q]) {
      swap(b[q], b[i]);
      q++;
    } else if (a[w] != b[i] and a[i] != b[w]) {
      swap(b[w], b[i]);
      w--;
    } else {
      ok = false;
      break;
    }
  }

  if (ok) {
    cout << "Yes\\n";
    for (int i = 0; i < n; ++i) {
      printf("%d ", b[i]);
    }
  } else {
    cout << "No\\n";
  }

  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"

using namespace std;
using ll = long long;
int a[200005], b[200005];
int main() {
#ifdef LOCAL
  freopen("in1.txt", "r", stdin);
  freopen("out1.txt", "w", stdout);
#endif
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", &b[i]);
  }
  reverse(b, b + n);
  for (int i = 0; i < n; ++i) {
    if (a[i] != b[i])
      continue;
    for (int j = 0; j < n; ++j) {
      if (j != i and a[i] != b[j] and a[j] != b[i]) {
        swap(b[i], b[j]);
        break;
      }
    }
  }
  bool ok = true;
  for (int i = 0; i < n; ++i) {
    if (a[i] == b[i]) {
      ok = false;
      break;
    }
  }
  if (ok) {
    cout << "Yes\\n";
    for (int i = 0; i < n; ++i) {
      printf("%d ", b[i]);
    }
  } else {
    cout << "No\\n";
  }

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

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

int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int &it : a)
    cin >> it;
  for (int &it : b)
    cin >> it;
  reverse(b.begin(), b.end());
  int target = -1;
  vector<int> to_swap, cand;
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      target = a[i];
      to_swap.push_back(i);
    }
  }
  if (target != -1) {
    for (int i = 0; i < n; i++) {
      if (a[i] != target && b[i] != target) {
        cand.push_back(i);
      }
    }
    if (cand.size() < to_swap.size()) {
      cout << "No\\n";
      return 0;
    }
    for (int i = 0; i < (int)to_swap.size(); i++) {
      swap(b[to_swap[i]], b[cand[i]]);
    }
  }
  cout << "Yes\\n";
  for (int i = 0; i < n; i++)
    cout << b[i] << " \\n"[i == n - 1];
  return 0;
}

Error: TLE

Fixed submission:

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

#ifdef _LOCAL_DEBUG
#define en_if typename enable_if<sizeof x<T>(0) == 4, ostream &>::type
namespace dbg {
template <class T> char x(...);
template <class T> auto x(T *v) -> decltype(v->size(), 0);
template <class T> auto x(T *v) -> decltype(v->c_str(), "");
template <class T> en_if operator<<(ostream &os, const T &v) {
  os << "[";
  const char *sep = "";
  for (const auto &x : v)
    os << sep << x, sep = ", ";
  return os << "]";
}
template <class F, class S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T> void print(const char *n, T e) {
  cerr << "[" << n << ": " << e << "]\\n";
}
template <class Head, class... Tail>
void print(const char *n, Head h, Tail... t) {
  cerr << "[";
  while (*n != ',')
    cerr << *n++;
  cerr << ": " << h << "] ";
  print(n + 2, t...);
}
} // namespace dbg
#define debug(...) dbg::print(#__VA_ARGS__, __VA_ARGS__);
#else
#define debug(...)
#endif

int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  int n;
  cin >> n;
  vector<array<int, 2>> a(n + 1, {-1, -1});
  vector<int> b(n);
  for (int i = 0, x; i < n; i++) {
    cin >> x;
    if (a[x][0] == -1)
      a[x][0] = i;
    a[x][1] = i;
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  // debug(a, b);
  bitset<200000> vis;
  // vector<bool> vis(n);
  vector<int> mp(n, -1), mq(n, -1);
  function<bool(int)> dfs = [&](int x) -> bool {
    vis[x] = 1;
    // debug(x, b[x]);
    for (int i = 0; i < n; i++) {
      if (i != x && (i < a[b[x]][0] || i > a[b[x]][1])) {
        if (mq[i] == -1 || (!vis[mq[i]] && dfs(mq[i]))) {
          mq[i] = x;
          mp[x] = i;
          return 1;
        }
      }
    }
    return 0;
  };
  int match = 0;
  for (int i = 0; i < n; i++) {
    // fill(vis.begin(), vis.end(), false);
    vis.reset();
    if (dfs(i))
      match++;
  }
  debug(match, mq, mp);
  if (match != n) {
    cout << "No\\n";
  } else {
    cout << "Yes\\n";
    for (int i = 0; i < n; i++) {
      cout << b[mq[i]] << ' ';
    }
    cout << '\\n';
  }
  return 0;
}
Problem p02557 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>

bool check(std::vector<int> a, std::vector<int> b) {
  bool ret = true;
  for (std::size_t i = 0; i < a.size(); i++)
    ret &= (a[i] != b[i]);
  return ret;
}

void answer(bool ans, std::vector<int> a) {
  std::cout << (ans ? "Yes" : "No") << '\\n';
  if (ans)
    for (int e : a)
      std::cout << e << '\\n';
}

int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; i++)
    std::cin >> a[i];
  for (int i = 0; i < n; i++) {
    std::cin >> b[i];
    c[i] = b[i];
  }

  std::reverse(b.begin(), b.end());
  std::rotate(c.begin(), c.begin() + (n / 2), c.end());

  if (check(a, b))
    answer(true, b);
  else if (check(a, c))
    answer(true, c);
  else
    answer(false, a);
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

bool check(std::vector<int> a, std::vector<int> b) {
  bool ret = true;
  for (int i = 0; i < a.size(); i++)
    ret &= (a[i] != b[i]);
  return ret;
}

void answer(bool ans, std::vector<int> a) {
  std::cout << (ans ? "Yes" : "No") << '\\n';
  if (ans)
    for (int e : a)
      std::cout << e << '\\n';
}

int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; i++)
    std::cin >> a[i];
  for (int i = 0; i < n; i++) {
    std::cin >> b[i];
    c[i] = b[i];
  }

  std::reverse(b.begin(), b.end());
  std::rotate(c.begin(), c.begin() + (n / 2), b.end());

  if (check(a, b))
    answer(true, b);
  else if (check(a, c))
    answer(true, c);
  else
    answer(false, a);
  return 0;
}
Problem p02557 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
struct __fastio__ {
  __fastio__() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  }
} __fast_io__;
template <class T, class U> bool chmin(T &a, const U &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U> bool chmax(T &a, const U &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n), b(n), ans;
  for (int &e : a) {
    std::cin >> e;
  }
  for (int &e : b) {
    std::cin >> e;
  }

  const int s = (n >> 1);
  for (int i = s; i < n; i++)
    ans.push_back(b[i]);
  for (int i = 0; i < s; i++)
    ans.push_back(b[i]);

  bool ok = true;
  for (int i = 0; i < n; i++) {
    ok &= (a[i] != ans[i]);
  }

  if (ok) {
    std::cout << "Yes" << '\\n';
    for (int i = 0; i < n; i++) {
      std::cout << ans[i] << " \\n"[i + 1 == n];
    }
  } else {
    std::reverse(b.begin(), b.end());
    bool flag = true;
    for (int i = 0; i < n; i++) {
      flag &= (a[i] != b[i]);
    }
    if (flag) {
      std::cout << "Yes" << '\\n';
      for (int i = 0; i < n; i++) {
        std::cout << b[i] << " \\n"[i + 1 == n];
      }
    } else {
      std::cout << "No" << '\\n';
    }
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
struct __fastio__ {
  __fastio__() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  }
} __fast_io__;
template <class T, class U> bool chmin(T &a, const U &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U> bool chmax(T &a, const U &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n), b(n), ans;
  for (int &e : a) {
    std::cin >> e;
    e--;
  }
  for (int &e : b) {
    std::cin >> e;
    e--;
  }

  {
    std::vector<int> c(n, 0), d(n, 0);
    for (int &e : a)
      c[e]++;
    for (int &e : b)
      d[e]++;
    for (int i = 0; i < n; i++) {
      int value = std::min(c[i], d[i]);
      if (value * 2 > n) {
        assert(false);
      }
    }
  }
  std::cout << "No" << '\\n';
}