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

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

#define ll long long
#define ld long double
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define For(i, a, b) for (long long int i = (a); i <= (b); i++)
#define Forr(i, a, b) for (long long int i = (a); i >= (b); i--)
#define F_OR(i, a, b, s)                                                       \\
  for (int i = (a); (s) > 0 ? i < (b) : i > (b); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto &x : a)
const int MOD = 1e9 + 7;
const ll dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const ll dxx[8] = {-1, -1, 0, 1, 1, 1, 0, -1},
         dyy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vt<int> a(n), b(n);
  vt<int> xplusy, xminusy, yminusx;
  FOR(n) {
    cin >> a[i] >> b[i];
    xplusy.pb(a[i] + b[i]);
    xminusy.pb(a[i] - b[i]);
    yminusx.pb(b[i] - a[i]);
  }
  sort(all(xplusy));
  sort(all(xminusy));
  sort(all(yminusx));
  int ans = xplusy.back() - xplusy[0];
  ans = max(ans, xminusy.back() + yminusx.back());
  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

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

#define ll long long
#define ld long double
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
const int MOD = 1e9 + 7;
const ll dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const ll dxx[8] = {-1, -1, 0, 1, 1, 1, 0, -1},
         dyy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
#define For(i, a, b) for (long long int i = (a); i <= (b); i++)
#define Forr(i, a, b) for (long long int i = (a); i >= (b); i--)
#define F_OR(i, a, b, s)                                                       \\
  for (int i = (a); (s) > 0 ? i < (b) : i > (b); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto &x : a)

ll solve(vt<pair<int, int>> arr) {
  ll ans = 0;
  int n = sz(arr);
  For(i, 0, n - 2) {
    For(j, i + 1, n - 1) {
      ans = max(ans, (ll)(abs(arr[i].first - arr[j].first) +
                          abs(arr[i].second - arr[j].second)));
    }
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vt<pair<int, int>> arr(n);
  For(i, 0, n - 1) cin >> arr[i].first >> arr[i].second;
  cout << solve(arr);
  return 0;
}
Problem p02557 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int read() {
  int w = 0, f = 1;
  char c = ' ';
  while (c < '0' || c > '9')
    c = getchar(), f = c == '-' ? -1 : f;
  while (c >= '0' && c <= '9')
    w = w * 10 + c - 48, c = getchar();
  return w * f;
}
int n;
int a[N], b[N];
int ca[N], cb[N];
signed main() {
  n = read();
  for (int i = 1; i <= n; i++)
    a[i] = read(), ca[a[i]]++;
  for (int i = 1; i <= n; i++)
    b[i] = read(), cb[b[i]]++;
  for (int i = 1; i <= n; i++)
    if (ca[i] + cb[i] > n)
      return printf("No\\n"), 0;
  reverse(b + 1, b + n + 1);
  vector<int> t;
  int cnt = 0, val = 0, len = 0;
  for (int i = 1; i <= n; i++) {
    if (b[i] == a[i]) {
      cnt++;
      val = b[i];
      t.push_back(i);
    }
  }
  len = cnt;
  vector<int> s;
  for (int i = 1; i <= n; i++) {
    if (a[i] == b[i])
      continue;
    if (cnt == 0)
      break;
    if (a[i] != val && b[i] != val) {
      s.push_back(i);
      cnt--;
    }
  }
  for (int i = 0; i < len; i++) {
    swap(b[s[i]], b[t[i]]);
  }
  printf("Yes\\n");
  for (int i = 1; i <= n; i++)
    printf("%d ", b[i]);
  printf("\\n");
  return 0;
}


Error: -6
e93afab6-7944-4b25-b79d-1bb5e82670df.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02557/C++/s972812424.cpp:33: int main(): Assertion `st.size() == 1' failed.


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int read() {
  int w = 0, f = 1;
  char c = ' ';
  while (c < '0' || c > '9')
    c = getchar(), f = c == '-' ? -1 : f;
  while (c >= '0' && c <= '9')
    w = w * 10 + c - 48, c = getchar();
  return w * f;
}
int n;
int a[N], b[N];
int ca[N], cb[N];
signed main() {
  n = read();
  for (int i = 1; i <= n; i++)
    a[i] = read(), ca[a[i]]++;
  for (int i = 1; i <= n; i++)
    b[i] = read(), cb[b[i]]++;
  for (int i = 1; i <= n; i++)
    if (ca[i] + cb[i] > n)
      return printf("No\\n"), 0;
  reverse(b + 1, b + n + 1);
  vector<int> t;
  int cnt = 0, val = 0, len = 0;
  set<int> st;
  for (int i = 1; i <= n; i++) {
    if (b[i] == a[i]) {
      cnt++;
      val = b[i];
      t.push_back(i);
      st.insert(a[i]);
    }
  }
  assert(st.size() == 1);
  len = cnt;
  vector<int> s;
  for (int i = 1; i <= n; i++) {
    if (a[i] == b[i])
      continue;
    if (cnt == 0)
      break;
    if (a[i] != val && b[i] != val) {
      s.push_back(i);
      cnt--;
    }
  }
  for (int i = 0; i < len; i++) {
    swap(b[s[i]], b[t[i]]);
  }
  printf("Yes\\n");
  for (int i = 1; i <= n; i++)
    printf("%d ", b[i]);
  printf("\\n");
  return 0;
}
Problem p02557 (C++) — buggy submission, verdict: Runtime Error

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

template <typename T> void out(T x) {
  cout << x << endl;
  exit(0);
}
#define watch(x) cout << (#x) << " is " << (x) << endl

using ll = long long;

const ll mod = 1e9 + 7;
const int maxn = 1e6 + 5;

int n;
int a[maxn];
int b[maxn];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  cin >> 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);

  int val = -1;
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      val = a[i];
      break;
    }
  }

  int l = n;
  int r = -1;

  for (int i = 0; i < n; i++) {
    if (a[i] == val && b[i] == val) {
      l = i;
      break;
    }
  }

  for (int i = n - 1; i >= 0; i--) {
    if (a[i] == val && b[i] == val) {
      r = i;
      break;
    }
  }

  for (int i = 0; i < n && l <= r; i++) {
    if (a[i] != val && b[i] != val) {
      swap(b[l++], b[i]);
    }
  }

  if (l <= r)
    out("No");

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

  return 0;
}


Error: WA

Fixed submission:

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

template <typename T> void out(T x) {
  cout << x << endl;
  exit(0);
}
#define watch(x) cout << (#x) << " is " << (x) << endl

using ll = long long;

const ll mod = 1e9 + 7;
const int maxn = 3e5;

int n;
int a[maxn], b[maxn];
int f[maxn], g[maxn];

vector<pair<int, int>> ival[maxn];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    f[a[i]]++;
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    g[b[i]]++;
  }

  // for (int i=0; i<maxn; i++) {
  // 	if (2*f[i]>n && 2*g[i]>n) out("No");
  // }

  for (int i = 0; i < n;) {
    int j = i;
    while (j < n && a[i] == a[j])
      j++;
    ival[a[i]].push_back({i, j - 1});
    i = j;
  }
  for (int i = 0; i < n;) {
    int j = i;
    while (j < n && b[i] == b[j])
      j++;
    ival[b[i]].push_back({i, j - 1});
    i = j;
  }

  int hi = 0;

  for (int i = 0; i < maxn; i++) {
    if (ival[i].empty())
      continue;
    assert((int)ival[i].size() == 2);

    pair<int, int> p = ival[i].front();
    pair<int, int> q = ival[i].back();
    int cur = q.second - p.first + 1;
    hi = max(hi, cur);
  }

  std::rotate(b, b + hi, b + n);

  // cerr<<"hi: "<<hi<<endl;
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i])
      out("No");
  }

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

//
// Created by bytedance on 2020/4/10.
//

#include <bits/stdc++.h>
// #include <fstream>

using namespace std;
const int maxn = 2e5 + 5;

int a[maxn];
int b[maxn];

int main() {
  int n;
  scanf("%d", &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);
  int l = 0, r = n - 1;
  while (l < n && a[l] != b[l])
    l++;
  while (r >= 0 && a[r] != b[r])
    r--;
  int tl = l, tr = r;
  for (int i = 0; i < tl && l <= r; i++) {
    if (b[i] != a[l] && a[i] != b[l]) {
      swap(b[i], b[l]);
      l++;
    } else {
      break;
    }
  }
  for (int i = n - 1; i > tr && l <= r; i--) {
    if (b[i] != a[r] && a[i] != b[r]) {
      swap(b[i], b[r]);
      r--;
    } else {
      break;
    }
  }
  if (l <= r) {
    printf("No\\n");
  } else {
    printf("Yes\\n");
    for (int i = 0; i < n; i++) {
      printf("%d%c", b[i], i == n - 1 ? '\\n' : ' ');
    }
  }
  return 0;
}

Error: WA

Fixed submission:

//
// Created by bytedance on 2020/4/10.
//

#include <bits/stdc++.h>
// #include <fstream>

using namespace std;
const int maxn = 2e5 + 5;

int a[maxn];
int b[maxn];

int main() {
  int n;
  scanf("%d", &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);
  int l = 0, r = n - 1;
  while (l < n && a[l] != b[l])
    l++;
  while (r >= 0 && a[r] != b[r])
    r--;
  int tl = l, tr = r;
  for (int i = 0; i < tl && l <= r; i++) {
    if (b[i] != a[l] && a[i] != b[l]) {
      swap(b[i], b[l]);
      l++;
    }
    //        else {
    //            break;
    //        }
  }
  for (int i = n - 1; i > tr && l <= r; i++) {
    if (b[i] != a[r] && a[i] != b[r]) {
      swap(b[i], b[r]);
      r--;
    }
    //        else {
    //            break;
    //        }
  }
  if (l <= r) {
    printf("No\\n");
  } else {
    printf("Yes\\n");
    for (int i = 0; i < n; i++) {
      printf("%d%c", b[i], i == n - 1 ? '\\n' : ' ');
    }
  }
  return 0;
}
Problem p02557 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;
  map<int, int> MA, MB;
  vector<int> A(N), B(N);
  rep(i, N) {
    cin >> A[i];
    MA[A[i]]++;
  }
  rep(i, N) {
    cin >> B[i];
    MB[B[i]]++;
  }
  for (auto [k, v] : MA) {
    if (MB.count(k) > 0) {
      if (N - MB[k] < v) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  for (auto [k, v] : MB) {
    if (MA.count(k) > 0) {
      if (N - MA[k] < v) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  int j = 0, prev = -1;
  rep(i, N) {
    if (A[i] != prev)
      j = 0;
    if (A[i] == B[i]) {
      for (; j < N; j++)
        if (A[i] != A[j] && B[j] != A[i])
          break;
      swap(B[i], B[j]);
    }
    prev = A[i];
  }

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


Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  map<int, int> MA, MB;
  vector<int> A(N), B(N);
  rep(i, N) {
    cin >> A[i];
    MA[A[i]]++;
  }
  rep(i, N) {
    cin >> B[i];
    MB[B[i]]++;
  }
  for (auto [k, v] : MA) {
    if (MB.count(k) > 0) {
      if (N - MB[k] < v) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  for (auto [k, v] : MB) {
    if (MA.count(k) > 0) {
      if (N - MA[k] < v) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  rep(i, N) {
    if (A[i] == B[i]) {
      int j = i + 1;
      if (j >= N)
        j = 0;
      while (B[i] == B[j]) {
        j++;
        if (j >= N)
          j = 0;
      }
      swap(B[i], B[j]);
    }
  }
  cout << "Yes" << endl;
  rep(i, N) {
    cout << B[i];
    if (i != N - 1)
      cout << " ";
  }
  cout << endl;
}
Problem p02557 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>

using namespace std;

const int N = 2 * 1e5;

int n, x[N], y[N];

bool cmp(int a, int b) { return a > b; }

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &y[i]);
  }
  sort(y, y + n, cmp);
  int flag = 0;
  for (int i = 0; i < n; i++) {
    if (x[i] == y[i]) {
      flag = i;
      break;
    }
  }
  while (x[flag] == y[flag]) {
    for (int i = 0; i < n; i++) {
      if (x[i] != x[flag] && y[i] != x[flag]) {
        swap(y[i], y[flag]);
        flag++;
        break;
      }
      if (i == n - 1) {
        printf("No");
        return 0;
      }
    }
  }
  printf("Yes\\n");
  for (int i = 0; i < n; i++) {
    printf("%d ", y[i]);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int n, a[1000000], b[1000000];
int f = 0;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int j = n; j >= 1; j--)
    cin >> b[j];
  for (int i = 1; i <= n; i++) {
    if (a[i] == b[i]) {
      f++;
      int l = lower_bound(b + i + 1, b + 1 + n, a[i] + 1) - b;
      for (int j = i; j <= n; j++) {
        if (a[i] != b[j]) {
          swap(b[i], b[j]);
          f--;
          break;
        }
      }
    }
  }

  if (f)
    cout << "No";
  else {
    puts("Yes");
    for (int i = 1; i <= n; i++) {
      cout << b[i];
      if (i < n)
        cout << " ";
    }
  }
  // system("pause");
  return 0;
}
Problem p02557 (C++) — buggy submission, verdict: Runtime Error


#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;

const int MAXN = int(2e5 + 4);

long long seqa[MAXN];
long long seqb[MAXN];

int temp = 0;
int swap(int a, int b) {
  temp = a;
  a = b;
  b = temp;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> seqa[i];
  for (int i = 0; i < n; i++)
    cin >> seqb[i];

  reverse(seqb, seqb + n);

  int com = -1;
  int len = n;
  int re = -1;
  for (int i = 0; i < n; i++) {
    if (com == -1 && seqa[i] == seqb[i]) {
      com = seqa[i];
      len = i;
      re = i;
    } else if (com != -1 && seqa[i] == seqb[i]) {
      re = i;
    }
  }

  for (int i = 0; i < n; i++) {
    if (com != seqa[i] && com != seqb[i] && len <= re) {

      swap(seqb[i], seqb[len]);
      len++;
    }
  }

  if (len <= re) {
    printf("No\\n");
  } else {
    printf("Yes\\n");
    for (int i = 0; i < n; i++) {
      printf("%d ", seqb[i]);
    }
  }
  // system("pause");
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline int read() {
  int _s = 0, _f = 1, _q = getchar();
  while (_q < 48 || _q > 57) {
    if (_q == '-')
      _f = -1;
    _q = getchar();
  }
  while (_q > 47 && _q < 58)
    _s = (_s << 3) + (_s << 1) + _q ^ 48, _q = getchar();
  return _s * _f;
}
const int M = 200050;
int ca[M], cb[M], a[M], b[M], n, ia, ib, t, na[M], nb[M], ma, mb;
int main() {
  n = read();
  for (int i = 0; i < n; i++) {
    a[i] = read(), ca[a[i]]++, ma = max(ma, ca[a[i]]);
    if (ca[a[i]] == 1)
      na[ia++] = a[i];
  }
  for (int i = 0; i < n; i++) {
    b[i] = read(), cb[b[i]]++, mb = max(mb, cb[b[i]]);
    if (cb[b[i]] == 1)
      nb[ib++] = b[i];
  }
  if (max(ma, mb) * 2 > n) {
    cout << "No\\n";
    return 0;
  }
  int j;
  cout << "Yes\\n";
  for (int i = 0; i < ia; i++) {
    j = ib - 1;
    while (ca[na[i]]) {
      if (nb[j] == na[i])
        j = (j - 1 + j) % ib;
      while (min(ca[na[i]], cb[nb[j]]) > 0) {
        cout << nb[j] << ' ';
        ca[na[i]]--, cb[nb[j]]--;
      }
      j--;
    }
  }
  return 0;
}
Problem p02557 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, k, a[N], f[N], b[N], F, le, ri, l, r;
int main() {
  cin >> n;
  for (k = 1; k <= n; k++) {
    cin >> a[k];
    f[a[k]]++;
  }
  for (k = 1; k <= n; k++) {
    cin >> b[k];
    f[b[k]]++;
    if (f[b[k]] > n) {
      F = 1;
    }
  }
  if (F)
    cout << "No" << endl;
  else {
    reverse(b + 1, b + n + 1);
    for (k = 1; k <= n; k++) {
      if (a[k] == b[k])
        F = a[k];
    }

    if (F) {
      l = n;
      for (k = 1; k <= n; k++) {
        if (a[k] == F)
          l = min(l, k);
        if (b[k] == F)
          l = min(l, k);
      }
      le = 1;
      ri = n;
      for (k = 1; k <= n; k++) {
        if (b[k] == F && a[k] == F) {
          if (le < l) {
            swap(b[k], b[le]);
            le++;
          } else {
            swap(b[k], b[ri]);
            ri--;
          }
        }
      }
    }
    cout << "Yes" << endl;
    for (k = 1; k <= n; k++) {
      cout << b[k] << " ";
    }
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, k, a[N], f[N], b[N], F, le, ri, l, r;
int main() {
  cin >> n;
  for (k = 1; k <= n; k++) {
    cin >> a[k];
    f[a[k]]++;
  }
  for (k = 1; k <= n; k++) {
    cin >> b[k];
    f[b[k]]++;
    if (f[b[k]] > n) {
      F = 1;
    }
  }
  if (F)
    cout << "No" << endl;
  else {
    reverse(b + 1, b + n + 1);
    for (k = 1; k <= n; k++) {
      if (a[k] == b[k])
        F = a[k];
    }

    if (F) {
      l = n;
      for (k = 1; k <= n; k++) {
        if (a[k] == F)
          l = min(l, k);
        if (b[k] == F)
          l = min(l, k);
      }
      le = 1;
      ri = n;
      for (k = 1; k <= n; k++) {
        if (b[k] == F && a[k] == F) {
          if (le < l) {
            swap(b[k], b[le]);
            le++;
          } else {
            swap(b[k], b[ri]);
            ri--;
          }
        }
      }
    }
    cout << "Yes" << endl;
    for (k = 1; k <= n; k++) {
      cout << b[k] << " ";
    }
  }
}
Problem p02557 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define endl '\\n'

const int max_n = 2e5 + 5;

int n, co;
int seen[max_n];
int a[max_n], b[max_n];
int A[max_n], B[max_n];
int L[max_n], R[max_n];

int r() {
  int x = (rand() % 1000) * 1000 + rand() % 1000;
  return x % n;
}

bool FindMatch(int i) {
  for (int j = 0; j < 2000; j++) {
    int foo = r();
    if (a[i] != b[foo] && seen[foo] != co) {
      seen[foo] = co;
      if (R[foo] < 0 || FindMatch(R[foo])) {
        L[i] = foo;
        R[foo] = i;
        return true;
      }
    }
  }
  return false;
}

int BipartiteMatching() {
  memset(L, -1, sizeof L);
  memset(R, -1, sizeof R);
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      L[i] = R[i] = i;
    }
  }
  for (int i = 0; i < n; i++) {
    if (L[i] == -1) {
      co = i + n;
      if (!FindMatch(i))
        return 0;
    }
  }
  return 1;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  srand(time(NULL));

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

  for (int i = 1; i < max_n; i++) {
    if (B[i] > n - A[i]) {
      cout << "No" << endl;
      return 0;
    }
  }

  reverse(b, b + n);
  if (BipartiteMatching()) {
    cout << "Yes" << endl;
    for (int i = 0; i < n; i++) {
      cout << b[L[i]] << " ";
    }
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

// Oh damn, cann't you see I'm fine?

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

#define endl '\\n'

const int max_n = 2e5 + 5;

int n, co;
int seen[max_n];
int a[max_n], b[max_n];
int A[max_n], B[max_n];
int L[max_n], R[max_n];

int r() {
  int x = (rand() % 1000) * 1000 + rand() % 1000;
  return x % n;
}

bool FindMatch(int i) {
  for (int j = 0; j < 2000; j++) {
    int foo = r();
    if (a[i] != b[foo] && seen[foo] != co) {
      seen[foo] = co;
      if (R[foo] < 0 || FindMatch(R[foo])) {
        L[i] = foo;
        R[foo] = i;
        return true;
      }
    }
  }
  return false;
}

int BipartiteMatching() {
  memset(L, -1, sizeof L);
  memset(R, -1, sizeof R);
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      L[i] = R[i] = i;
    }
  }
  for (int i = 0; i < n; i++) {
    if (L[i] == -1) {
      co = i + n;
      if (!FindMatch(i))
        return 0;
    }
  }
  return 1;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  srand(time(NULL));

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

  for (int i = 1; i < max_n; i++) {
    if (B[i] > n - A[i]) {
      cout << "No" << endl;
      return 0;
    }
  }

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

#include <bits/stdc++.h>

/*
#pragma GCC optimize("-Ofast")
//#pragma GCC optimize("trapv")
#pragma GCC
target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")*/

#define I inline void
#define S struct
#define vi vector<int>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;
using ll = long long;
using ld = long double;

const int N = 2e5 + 7, mod = 1e9 + 7;
const int inf = N;
// How interesting!

int n;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

vector<int> a(N, 0), b(N, 0);
int occ[N], occ2[N];
int mx1, mx2;

int ans[N];

I check() {
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      return;
    }
  }
  cout << "Yes\\n";
  for (int i = 0; i < n; i++)
    cout << b[i] << " ";
  exit(0);
}

I shift(vector<int> &aux, int x) {
  vector<int> tmp(n, 0);
  for (int i = 0; i < n; i++) {
    tmp[(i + x + n) % n] = aux[i];
  }
  for (int i = 0; i < n; i++) {
    aux[i] = tmp[i];
  }
}

I make(int x) {
  shift(b, x);
  check();
  shift(b, -x);
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  srand(time(0));
  // freopen("in.in" , "r" , stdin) ;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mx1 = max(mx1, ++occ[a[i]]);
  }

  for (int i = 0; i < n; i++) {
    cin >> b[i];
    mx2 = max(mx2, ++occ2[b[i]]);
  }
  make(mx1);
  make(mx2);
  make(n - mx1);
  make(n - mx2);
  for (int i = 0; i < 1000000 / n; i++) {
    int x = rng() % n;
    make(x);
  }
  cout << "No";
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

/*
#pragma GCC optimize("-Ofast")
//#pragma GCC optimize("trapv")
#pragma GCC
target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")*/

#define I inline void
#define S struct
#define vi vector<int>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e5 + 7, mod = 1e9 + 7;
const int inf = N;
// How interesting!

int n;

vector<int> a(N, 0), b(N, 0);
int occ[N], occ2[N];
int mx1, mx2;

int ans[N];

I check() {
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      return;
    }
  }
  cout << "Yes\\n";
  for (int i = 0; i < n; i++)
    cout << b[i] << " ";
  exit(0);
}

I shift(vector<int> &aux, int x) {
  vector<int> tmp(n, 0);
  for (int i = 0; i < n; i++) {
    tmp[(i + x + n) % n] = aux[i];
  }
  for (int i = 0; i < n; i++) {
    aux[i] = tmp[i];
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // freopen("in.in" , "r" , stdin) ;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mx1 = max(mx1, ++occ[a[i]]);
  }

  for (int i = 0; i < n; i++) {
    cin >> b[i];
    mx2 = max(mx2, ++occ2[b[i]]);
  }

  shift(b, mx1);
  check();
  shift(b, -mx1);
  shift(b, n - mx2);
  check();

  cout << "No";

  return 0;
}