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

#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
using P = pair<pair<int, int>, pair<int, int>>;
signed main() {
  int N;
  cin >> N;
  map<int, int> mp, mp1, mp2;
  vector<int> A(N), B(N);
  for (int &i : A) {
    cin >> i;
    mp[i]++;
    mp1[i]++;
  }
  for (int &i : B) {
    cin >> i;
    mp[i]++;
    mp2[i]++;
  }
  vector<P> C;
  for (pair<int, int> p : mp)
    C.push_back({{p.s, p.f}, {mp1[p.f], mp2[p.f]}});
  sort(C.rbegin(), C.rend());
  if (C[0].f.f > N) {
    puts("No");
    return 0;
  }
  puts("Yes");
  vector<pair<int, int>> D(N);
  for (int i = 0; i < N; i++)
    D[i].f = D[i].s = -1;
  int n = 0;
  for (P &p : C) {
    for (int i = 0; i < p.s.f; i++) {
      if (i + n == N) {
        p.s.f -= i;
        goto home;
      }
      D[n + i].f = p.f.s;
    }
    n += p.s.f;
    p.s.f = 0;
    for (int i = 0; i < p.s.s; i++) {
      if (i + n == N) {
        p.s.s -= i;
        goto home;
      }
      D[n + i].s = p.f.s;
    }
    n += p.s.s;
    p.s.s = 0;
  }
home:;
  n = 0;
  for (P p : C) {
    int m = 0;
    for (; m < p.s.f && n < N; n++) {
      if (D[n].f == -1)
        D[n].f = p.f.s, m++;
    }
  }
  n = 0;
  for (P p : C) {
    int m = 0;
    for (; m < p.s.s && n < N; n++) {
      if (D[n].s == -1)
        D[n].s = p.f.s, m++;
    }
  }
  sort(D.begin(), D.end());
  for (int i = 0; i < N; i++)
    cout << D[i].s << (i == N - 1 ? '\\n' : ' ');
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
using P = pair<pair<int, int>, pair<int, int>>;
signed main() {
  int N;
  cin >> N;
  map<int, int> mp, mp1, mp2;
  vector<int> A(N), B(N);
  for (int &i : A) {
    cin >> i;
    mp[i]++;
    mp1[i]++;
  }
  for (int &i : B) {
    cin >> i;
    mp[i]++;
    mp2[i]++;
  }
  vector<P> C;
  for (pair<int, int> p : mp)
    C.push_back({{p.s, p.f}, {mp1[p.f], mp2[p.f]}});
  sort(C.rbegin(), C.rend());
  if (C[0].f.f > N) {
    puts("No");
    return 0;
  }
  puts("Yes");
  vector<pair<int, int>> D(N);
  for (int i = 0; i < N; i++)
    D[i].f = D[i].s = -1;
  int n = 0;
  for (P &p : C) {
    for (int i = 0; i < p.s.f; i++) {
      if (i + n == N) {
        p.s.f -= i;
        goto home;
      }
      D[n + i].f = p.f.s;
    }
    n += p.s.f;
    p.s.f = 0;
    for (int i = 0; i < p.s.s; i++) {
      if (i + n == N) {
        p.s.f -= i;
        goto home;
      }
      D[n + i].s = p.f.s;
    }
    n += p.s.s;
    p.s.s = 0;
  }
home:;
  n = 0;
  for (P p : C) {
    int m = 0;
    for (; m < p.s.f; n++) {
      if (D[n].f == -1)
        D[n].f = p.f.s, m++;
    }
  }
  n = 0;
  for (P p : C) {
    int m = 0;
    for (; m < p.s.s; n++) {
      if (D[n].s == -1)
        D[n].s = p.f.s, m++;
    }
  }
  sort(D.begin(), D.end());
  for (int i = 0; i < N; i++)
    cout << D[i].s << (i == N - 1 ? '\\n' : ' ');
}
Problem p02557 (C++) — buggy submission, verdict: Time Limit Exceeded

// #include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
ll n, m, ans;
ll a[200005], b[200005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[n - i + 1];
  }
  ll l = 1;
  for (int i = 1; i <= n; i++) {
    if (a[i] != b[i])
      continue;
    while (!(a[i] == b[i] && a[i] != a[l] && b[i] != b[l])) {
      l++;
      if (l > n) {
        cout << "No";
        // system("pause");
        return 0;
      }
    }
    swap(b[l], b[i]);
  }
  cout << "Yes\\n";
  for (int i = 1; i <= n; i++)
    cout << b[i] << " ";
  // system("pause");
  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] << " ";
    }
  }
  system("pause");
  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++)
#define rep1(i, n) for (int i = 1; i <= (int)n; i++)
#define sp(n) cout << fixed << setprecision(n)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;
using namespace std;
int main(void) {
  ll n;
  cin >> n;
  vector<ll> a(n), b(n);
  map<ll, ll> mp;
  rep(i, n) {
    cin >> a[i];
    mp[a[i]]++;
  }
  rep(i, n) {
    cin >> b[i];
    mp[b[i]]++;
  }

  for (auto &p : mp) {
    if (p.second > n) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  ll buf = -1, j = 0;
  rep(i, n) {
    if (buf != a[i])
      j = 0;
    if (a[i] == b[i]) {
      for (; j < n; j++) {
        if (b[i] != a[j] && b[j] != a[i]) {
          swap(b[i], b[j]);
          break;
        }
      }
    }
    buf = a[i];
  }
  rep(i, n) cout << b[i] << " ";
  cout << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep1(i, n) for (int i = 1; i <= (int)n; i++)
#define sp(n) cout << fixed << setprecision(n)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
typedef long long ll;
using namespace std;
int main(void) {
  ll n;
  cin >> n;
  vector<ll> a(n), b(n);
  map<ll, ll> mp;
  rep(i, n) {
    cin >> a[i];
    mp[a[i]]++;
  }
  rep(i, n) {
    cin >> b[i];
    mp[b[i]]++;
  }

  for (auto &p : mp) {
    if (p.second > n) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  vector<ll> c;
  rep(i, n) {
    if (a[i] == b[i]) {
      rep(j, n) {
        if (b[i] != a[j] && b[j] != a[i]) {
          swap(b[i], b[j]);
          break;
        }
      }
    }
  }
  rep(i, n) cout << b[i] << " ";
  cout << endl;
}
Problem p02557 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <utility>
#include <vector>
#define M_PI 3.14159265358979323846264338327950288
#define oo 998244353
#define maxN 200007
using namespace std;

int a[maxN], b[maxN];
bool cmp(int &a, int &b) { return a > b; }

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n;
  cin >> n;

  for (int i = 1; i <= n; ++i)
    cin >> a[i];
  for (int i = 1; i <= n; ++i)
    cin >> b[i];
  sort(b + 1, b + n + 1, cmp);

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

  for (int i = n; i >= 1; --i) {
    if (a[i] == b[i]) {
      right = i;
      break;
    }
  }

  bool to_right = false;
  int left_correct = 1, right_correct = n;
  for (int i = left; i <= right; ++i) {
    if (b[left_correct] == b[i] || a[left_correct] == b[i])
      to_right = true;
    if (!to_right) {
      swap(b[left_correct], b[i]);
      ++left_correct;
    } else {
      swap(b[right_correct], b[i]);
      --right_correct;
    }
  }

  for (int i = 1; i <= n; ++i) {
    if (b[i] == a[i]) {
      puts("No");
      return 0;
    }
  }

  puts("Yes");
  for (int i = 1; i <= n; ++i)
    cout << b[i] << " ";

  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <utility>
#include <vector>
#define oo 1000000007
#define maxN 200007
using namespace std;

int a[maxN], b[maxN];

int main() {

  int n;
  cin >> n;

  multiset<int> stA;
  multiset<int> stB;
  multiset<int> st;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    stA.insert(a[i]);
  }
  for (int i = 1; i <= n; ++i) {
    cin >> b[i];
    if (stA.find(b[i]) != stA.end()) {
      st.insert(b[i]);
      stA.erase(stA.find(b[i]));
    } else
      stB.insert(b[i]);
  }

  for (int i = 1; i <= n; ++i) {
    auto it = st.upper_bound(a[i]);
    if (it != st.end()) {
      b[i] = *it;
      st.erase(it);
    } else {
      if (st.size() && *st.begin() != a[i]) {
        it = st.begin();
        b[i] = *it;
        st.erase(it);
      } else {
        auto it2 = stB.upper_bound(a[i]);
        if (it2 != stB.end()) {
          b[i] = *it2;
          stB.erase(it2);
        } else {
          it2 = stB.begin();
          b[i] = *it2;
          stB.erase(it2);
        }
      }
    }
  }

  for (int i = 1; i <= n; ++i) {
    if (b[i] == a[i]) {
      puts("No");
      return 0;
    }
  }

  puts("Yes");
  for (int i = 1; i <= n; ++i)
    cout << b[i] << " ";

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

#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
signed main() {
  int n;
  cin >> n;
  int a[n], b[n];
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[n - 1 - i];
  int x = 0, y = n - 1;
  rep(i, n) {
    if (a[i] == b[i]) {
      if (x < n && b[x] != a[i] && a[x] != b[i])
        swap(b[i], b[x++]);
      else if (0 <= y && b[y] != a[i] && a[y] != b[i])
        swap(b[i], b[y--]);
      else {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << '\\n';
  rep(i, n) cout << b[i] << " ";
}


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 <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
signed main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[n - i];
  int x = 0, y = n - 1;
  rep(i, n) {
    if (a[i] == b[i]) {
      if (x < n && b[x] != a[i] && a[x] != b[i])
        swap(b[i], b[x++]);
      else if (0 <= y && b[y] != a[i] && a[y] != b[i])
        swap(b[i], b[y--]);
      else {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << '\\n';
  rep(i, n) cout << b[i] << " ";
}
Problem p02557 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define maxn 200086

using namespace std;

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

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++)
    scanf("%d", &b[i]);
  reverse(b + 1, b + 1 + n);
  int l = n, r = 1;
  for (int i = 1; i <= n; i++) {
    if (a[i] == b[i])
      l = min(l, i), r = max(r, i);
  }
  for (int i = 1; i <= n && l <= r; i++) {
    if (a[i] != a[l] && b[i] != a[l])
      swap(b[i], b[l++]);
  }
  if (l <= r)
    return printf("No"), 0;
  puts("Yes");
  for (int i = 1; i <= n; i++)
    printf("%d ", b[i]);
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define maxn 200086

using namespace std;

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

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++)
    scanf("%d", &b[i]);
  reverse(b + 1, b + 1 + n);
  int l = n, r = 1;
  for (int i = 1; i <= n; i++) {
    if (a[i] == b[i])
      l = min(l, i), r = max(r, i);
  }
  for (int i = 1; i <= n && l <= r; i++) {
    if (a[i] != a[l] && b[i] != a[l])
      swap(b[i], b[l++]);
  }
  if (l <= r)
    return printf("No");
  puts("Yes");
  for (int i = 1; i <= n; i++)
    printf("%d ", b[i]);
}
Problem p02557 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD = 1000000007;
const long long INF = 1LL << 60;

void YN(bool x) {
  if (x)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

int main() {
  bool finish = true;
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N, 0), D(N, 0);
  rep(i, N) {
    cin >> A.at(i);
    C.at(A.at(i) - 1)++;
  }
  rep(i, N) {
    cin >> B.at(i);
    D.at(B.at(i) - 1)++;
  }
  rep(i, N) {
    if (C.at(i) + D.at(i) > N)
      finish = false;
  }
  YN(finish);
  if (finish) {
    reverse(B.begin(), B.end());
    int k = 0;
    rep(i, N) {
      if (A.at(i) == B.at(i)) {
        k = 0;
        while (A.at(i) == B.at(k) || A.at(i) == A.at(k)) {
          k++;
          if (k == N)
            k = 0;
        }
        swap(B.at(i), B.at(k));
      }
    }
    rep(i, N) {
      if (i == N - 1)
        cout << B.at(i) << endl;
      else
        cout << B.at(i) << ' ';
    }
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD = 1000000007;
const long long INF = 1LL << 60;

void YN(bool x) {
  if (x)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

int main() {
  bool finish = true;
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N, 0), D(N, 0);
  rep(i, N) {
    cin >> A.at(i);
    C.at(A.at(i) - 1)++;
  }
  rep(i, N) {
    cin >> B.at(i);
    D.at(B.at(i) - 1)++;
  }
  rep(i, N) {
    if (C.at(i) + D.at(i) > N)
      finish = false;
  }
  YN(finish);
  if (finish) {
    reverse(B.begin(), B.end());
    int k = 0;
    rep(i, N) {
      if (A.at(i) == B.at(i)) {
        k = i;
        // if(i>0&&B.at(i)!=B.at(i-1))k=i;
        while (A.at(i) == B.at(k) || A.at(k) == B.at(i)) {
          k++;
          if (k == N)
            k = 0;
        }
        swap(B.at(i), B.at(k));
        // k--;
      }
      if (i < N - 1)
        cout << B.at(i) << ' ';
      else
        cout << B.at(i);
    }
  }
}
Problem p02557 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n), d(n), e(n);
  rep(i, n) {
    c[i] = 0;
    d[i] = -1;
    e[i] = -1;
  }
  rep(i, n) {
    cin >> a[i];
    c[a[i] - 1] += 1;
    d[a[i] - 1] = i;
  }
  rep(i, n) {
    cin >> b[i];
    c[b[i] - 1] += 1;
    if (e[b[i] - 1] == -1)
      e[b[i] - 1] = i;
  }
  rep(i, n) {
    if (c[i] > n) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  int maxDelta = 0;
  rep(i, n) {
    int Delta = d[i] - e[i] + 1;
    if (d[i] == -1 || e[i] == -1)
      Delta = 0;
    if (maxDelta < Delta) {
      maxDelta = Delta;
    }
  }

  rep(i, n) {
    if (i == n - 1)
      cout << b[(i + n - maxDelta) % n] << endl;
    else
      cout << b[(i + n - maxDelta) % n] << " ";
  }

  return 0;
}
/*
 */


Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n + 1);
  rep(i, n + 1) c[i] = 0;
  rep(i, n) {
    cin >> a[i];
    c[a[i]] += 1;
  }
  rep(i, n) {
    cin >> b[i];
    c[b[i]] += 1;
  }
  rep(i, n + 1) {
    if (c[i] > n) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  queue<P> que;
  rep(i, n + 1) c[i] = 0;
  rep(i, n) { c[b[i]] += 1; }
  rep(i, n + 1) {
    if (c[i] > 0) {
      que.push(make_pair(i, c[i]));
    }
  }

  rep(i, n) {
    while (que.front().first == a[i]) {
      que.push(que.front());
      que.pop();
    }
    b[i] = que.front().first;
    que.front().second -= 1;
    if (que.front().second == 0) {
      que.pop();
    }
  }

  rep(i, n) { cout << b[i] << " "; }
  cout << endl;

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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define mems(p) memset(p, -1, sizeof(p))
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define nl "\\n"

const int mxN = 1e5;
const ll MOD = 1e9 + 7;

void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
  fast();
  int n, tmp;
  cin >> n;
  vector<int> ctra(n + 1, 0), ctrb(n + 1, 0);
  vector<int> a(n), b(n);
  vector<int> ans(n, 0);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ctra[a[i]]++;
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
    ctrb[b[i]]++;
  }
  for (int i = 1; i <= n; ++i) {
    int common = min(ctra[i], ctrb[i]);
    if (common + max(ctra[i], ctrb[i]) > n) {
      cout << "No\\n";
      return 0;
    }
  }
  cout << "Yes\\n";
  int lb = 0, rb = n - 1;
  while (lb <= rb) {
    int mb = (lb + rb) / 2;
    // start frm mb
    int ctr = 0;
    bool fail = false;
    for (int i = mb; i < mb + n; ++i) {
      int idx = i;
      if (idx >= n)
        idx -= n;
      if (b[ctr] == a[idx]) {
        fail = true;
        if (idx >= mb) {
          lb = mb + 1;
        } else {
          rb = mb - 1;
        }
        break;
      }
      ans[idx] = b[ctr];
      ++ctr;
    }
    if (!fail) {
      for (int i = 0; i < n; ++i) {
        cout << ans[i] << " ";
      }
      cout << nl;
      return 0;
    }
  }
  cout << "fail?\\n";
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define mems(p) memset(p, -1, sizeof(p))
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define nl "\\n"

const int mxN = 1e5;
const ll MOD = 1e9 + 7;

void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
  fast();
  int n, tmp;
  cin >> n;
  vector<int> ctra(n + 1, 0), ctrb(n + 1, 0);
  vector<int> a(n);
  vector<int> ans(n, 0);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ctra[a[i]]++;
  }
  for (int i = 0; i < n; ++i) {
    cin >> tmp;
    ctrb[tmp]++;
  }
  int ptr = 0;
  for (int i = 1; i <= n; ++i) {
    int common = min(ctra[i], ctrb[i]);
    if (common + max(ctra[i], ctrb[i]) > n) {
      cout << "No\\n";
      return 0;
    }
    int ctr = ctrb[i];
    while (ctr > 0) {
      while (a[ptr] == i || ans[ptr]) {
        ++ptr;
        if (ptr >= n)
          ptr = 0;
      }
      ans[ptr] = i;
      --ctr;
    }
  }
  cout << "Yes\\n";
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << " ";
  }
  cout << nl;
}
Problem p02557 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define SZ(a) ((int)(a).size())
typedef long long int64;
int main() {
#ifdef LOCAL
  freopen(".a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);
  int n;
  cin >> n;
  vector<int> A(n), B(n), C(3 * n);
  for (auto &i : A)
    cin >> i;
  for (auto &i : B)
    cin >> i;
  for (int i = 0; i < n; ++i) {
    int l = lower_bound(B.begin(), B.end(), A[i]) - B.begin();
    if (l == n || B[l] != A[i])
      continue;
    int r = upper_bound(B.begin(), B.end(), A[i]) - B.begin() - 1;
    if (i <= l) {
      C[l - i]++;
      C[r - i + 1]--;
    } else if (i > r) {
      C[n - i + l]++;
      C[n - i + r + 1]--;
    } else {
      C[0]++;
      C[r - i + 1]--;
      C[n - i + l]++;
    }
  }
  for (int i = 1; i < n; ++i)
    C[i] += C[i - 1];
  for (int i = 0; i < n; ++i)
    if (C[i] == 0) {
      cout << "Yes\\n";
      for (int j = 0; j < n; ++j)
        cout << B[(i + j) % n] << " ";
      cout << "\\n";
      return 0;
    }
  cout << "No";

  return 0;
}
// 2020.09.13 21:03:42


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define SZ(a) ((int)(a).size())
typedef long long int64;
int main() {
#ifdef LOCAL
  freopen(".a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);
  int n;
  cin >> n;
  vector<int> A(n), B(n), C(3 * n);
  for (auto &i : A)
    cin >> i;
  for (auto &i : B)
    cin >> i;
  for (int i = 0; i < n; ++i) {
    int l = lower_bound(B.begin(), B.end(), A[i]) - B.begin();
    if (l == n || B[l] != A[i])
      continue;
    int r = upper_bound(B.begin(), B.end(), A[i]) - B.begin() - 1;
    if (i <= l) {
      C[i - l]++;
      C[r - i + 1]--;
    } else if (i > r) {
      C[n - i + l]++;
      C[n - i + r + 1]--;
    } else {
      C[0]++;
      C[r - i + 1]--;
      C[n - i + l]++;
    }
  }
  for (int i = 1; i < n; ++i)
    C[i] += C[i - 1];
  for (int i = 0; i < n; ++i)
    if (C[i] == 0) {
      cout << "Yes\\n";
      for (int j = 0; j < n; ++j)
        cout << B[(i + j) % n] << " ";
      cout << "\\n";
      return 0;
    }
  cout << "No";

  return 0;
}
// 2020.09.13 21:03:42
Problem p02557 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

const string YES = "Yes";

const string NO = "No";

void solve(int N, vector<int> A, vector<int> B) {
  vector<int> cnt_A(N + 1), cnt_B(N + 1);
  for (int i = 0; i < N; i++) {
    cnt_A.at(A.at(i))++;
    cnt_B.at(B.at(i))++;
  }
  for (int i = 1; i <= N; i++) {
    if (cnt_A.at(i) + cnt_B.at(i) > N) {
      cout << NO << endl;
      return;
    }
  }
  cout << YES << endl;
  vector<int> C(N + 1), D(N + 1);
  for (int i = 1; i <= N; i++) {
    C.at(i) = C.at(i - 1) + cnt_A.at(i);
    D.at(i) = D.at(i - 1) + cnt_B.at(i);
  }
  int x = 0;
  for (int i = 1; i <= N; i++) {
    x = max(x, C.at(i) - D.at(i - 1));
  }
  for (int i = 0; i < N - 1; i++) {
    cout << B.at((i - x + N) % N) << " ";
  }
  cout << B.at((N - 1 - x + N) % N) << endl;
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    cin >> B.at(i);
  }
  solve(N, move(A), move(B));
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const string YES = "Yes";

const string NO = "No";

void solve(int N, vector<int> A, vector<int> B) {
  vector<int> cnt_A(N + 1), cnt_B(N + 1);
  for (int i = 0; i < N; i++) {
    cnt_A.at(A.at(i))++;
    cnt_B.at(B.at(i))++;
  }
  for (int i = 1; i <= N; i++) {
    if (cnt_A.at(i) + cnt_B.at(i) > N) {
      cout << NO << endl;
      return;
    }
  }
  cout << YES << endl;
  vector<int> C(N + 1), D(N + 1);
  for (int i = 1; i <= N; i++) {
    C.at(i) = C.at(i - 1) + cnt_A.at(i);
    D.at(i) = D.at(i - 1) + cnt_B.at(i);
  }
  int x = 0;
  for (int i = 1; i <= N; i++) {
    x = max(x, C.at(i) - D.at(i - 1));
  }
  for (int i = 0; i < N - 1; i++) {
    cout << B.at((i - x + N) % N) << " ";
  }
  cout << B.at((N - 1 - x) % N) << endl;
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    cin >> B.at(i);
  }
  solve(N, move(A), move(B));
  return 0;
}