prithivMLmods/Coder-Stat huggingface dataset:
Problem p02556 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
const int dem = 2;
const long long INF = 1e18;
struct Point {
  long long x[dem];
} p[maxn];
int n;
long long minx[1 << dem], maxx[1 << dem];
long long solve() {
  int tmp = (1 << dem);
  for (int i = 0; i < tmp; i++) {
    minx[i] = INF;
    maxx[i] = -INF;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < tmp; j++) {
      int t = j;
      long long s = 0;
      for (int k = 0; k < dem; k++) {
        if (t & 1)
          s += p[i].x[k];
        else
          s -= p[i].x[k];
        t >>= 1;
      }
      if (maxx[j] < s)
        maxx[j] = s;
      if (minx[j] > s)
        minx[j] = s;
    }
  }
  long long ans = -INF;
  for (int i = 0; i < tmp; i++) {
    if (maxx[i] - minx[i] > ans)
      ans = maxx[i] - minx[i];
  }
  return ans;
}
int main() {
  while (scanf("%d", &n) != EOF) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < dem; j++) {
        scanf("%lld", &p[i].x[j]);
      }
    }
    printf("%lld\n", solve());
    return 0;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10;
const int dem = 2;
const long long INF = 1e18;
struct Point {
  long long x[dem];
} p[maxn];
int n;
long long minx[1 << dem], maxx[1 << dem];
long long solve() {
  int tmp = (1 << dem);
  for (int i = 0; i < tmp; i++) {
    minx[i] = INF;
    maxx[i] = -INF;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < tmp; j++) {
      int t = j;
      long long s = 0;
      for (int k = 0; k < dem; k++) {
        if (t & 1)
          s += p[i].x[k];
        else
          s -= p[i].x[k];
        t >>= 1;
      }
      if (maxx[j] < s)
        maxx[j] = s;
      if (minx[j] > s)
        minx[j] = s;
    }
  }
  long long ans = -INF;
  for (int i = 0; i < tmp; i++) {
    if (maxx[i] - minx[i] > ans)
      ans = maxx[i] - minx[i];
  }
  return ans;
}
int main() {
  while (scanf("%d", &n) != EOF) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < dem; j++) {
        scanf("%lld", &p[i].x[j]);
      }
    }
    printf("%lld\n", solve());
    return 0;
  }
}
Problem p02556 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 100;
struct Node {
  ll x, y;
  ll num1, num2;
} p[N];

ll n;
bool cmp1(const Node &a, const Node &b) { return a.num1 < b.num1; }
bool cmp2(const Node &a, const Node &b) { return a.num2 < b.num2; }
int main() {
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    cin >> p[i].x >> p[i].y;
    p[i].num1 = p[i].x - p[i].y;
    p[i].num2 = p[i].x + p[i].y;
  }
  ll ans = 0;
  sort(p + 1, p + n + 1, cmp1);
  ans = max(ans, p[n].num1 - p[1].num1);
  sort(p + 1, p + n + 1, cmp2);
  ans = max(ans, p[n].num2 - p[1].num2);
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 100;
struct Node {
  ll x, y;
  ll num1, num2;
} p[N];

ll n;
bool cmp1(const Node &a, const Node &b) { return a.num1 < b.num1; }
bool cmp2(const Node &a, const Node &b) { return a.num2 < b.num2; }
int main() {
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    cin >> p[i].x >> p[i].y;
    p[i].num1 = p[i].x - p[i].y;
    p[i].num2 = p[i].x + p[i].y;
  }
  ll ans = 0;
  sort(p + 1, p + n + 1, cmp1);
  ans = max(ans, p[n].num1 - p[1].num1);
  sort(p + 1, p + n + 1, cmp2);
  ans = max(ans, p[n].num2 - p[1].num2);
  cout << ans << endl;
  return 0;
}
Problem p02556 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair

using namespace std;

typedef long long ll;

const int nax = 1e5 + 5;
int xx[nax];
int yy[nax];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    xx[i] = a + b;
    yy[i] = b - a;
  }
  sort(xx, xx + n);
  sort(yy, yy + n);
  cout << max(abs(xx[0] - xx[n - 1]), abs(yy[0] - yy[n - 1]));
}


Fixed submission:
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair

using namespace std;

typedef long long ll;

const int nax = 2e5 + 5;
int xx[nax];
int yy[nax];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    xx[i] = a + b;
    yy[i] = b - a;
  }
  sort(xx, xx + n);
  sort(yy, yy + n);
  cout << max(abs(xx[0] - xx[n - 1]), abs(yy[0] - yy[n - 1]));
}
Problem p02556 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>

using namespace std;

const int maxn = 100000 + 10;
const int dem = 2; // 维数
const double INF = (1e200);

struct Point {
  double x[dem];
} p[maxn];

int n;
double minx[1 << dem], maxx[1 << dem];

long long solve() {
  int tmp = 1 << dem;

  for (int i = 0; i < tmp; i++) {
    minx[i] = INF;
    maxx[i] = -INF;
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < tmp; j++) {
      int t = j;
      double s = 0;
      for (int k = 0; k < dem; k++) {
        if (t & 1)
          s += p[i].x[k];
        else
          s -= p[i].x[k];
        t >>= 1;
      }
      if (maxx[j] < s)
        maxx[j] = s;
      if (minx[j] > s)
        minx[j] = s;
    }
  }

  double ans = -INF;
  for (int i = 0; i < tmp; i++) {
    if (maxx[i] - minx[i] > ans)
      ans = maxx[i] - minx[i];
  }

  return ans;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < dem; j++) {
      scanf("%lf", &p[i].x[j]);
    }
  }
  cout << solve() << endl;
  return 0;
}


Fixed submission:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>

using namespace std;

const int maxn = 400000 + 10;
const int dem = 2; // 维数
const double INF = (1e200);

struct Point {
  double x[dem];
} p[maxn];

int n;
double minx[1 << dem], maxx[1 << dem];

long long solve() {
  int tmp = 1 << dem;

  for (int i = 0; i < tmp; i++) {
    minx[i] = INF;
    maxx[i] = -INF;
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < tmp; j++) {
      int t = j;
      double s = 0;
      for (int k = 0; k < dem; k++) {
        if (t & 1)
          s += p[i].x[k];
        else
          s -= p[i].x[k];
        t >>= 1;
      }
      if (maxx[j] < s)
        maxx[j] = s;
      if (minx[j] > s)
        minx[j] = s;
    }
  }

  double ans = -INF;
  for (int i = 0; i < tmp; i++) {
    if (maxx[i] - minx[i] > ans)
      ans = maxx[i] - minx[i];
  }

  return ans;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < dem; j++) {
      scanf("%lf", &p[i].x[j]);
    }
  }
  cout << solve() << endl;
  return 0;
}
Problem p02556 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

const int mod = 1e9;
int main() {
  int N;
  scanf("%d", &N);

  int Max1 = mod * -1, Min1 = mod;
  int Max0 = mod * -1, Min0 = mod;
  for (int i = 1; i <= N; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);

    Max1 = max(Max1, x + y);
    Min1 = min(Min1, x + y);
    Max0 = max(Max0, x - y);
    Min0 = min(Min0, x - y);
  }
  int ans = max((Max1 - Min1), (Max0 - Min0));
  return printf("%d", ans);
}

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

const int mod = 1e9;
int main() {
  int N;
  scanf("%d", &N);

  int Max1 = mod * -1, Min1 = mod;
  int Max0 = mod * -1, Min0 = mod;
  for (int i = 1; i <= N; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);

    Max1 = max(Max1, x + y);
    Min1 = min(Min1, x + y);
    Max0 = max(Max0, x - y);
    Min0 = min(Min0, x - y);
  }
  int ans = max((Max1 - Min1), (Max0 - Min0));
  return printf("%d", ans), 0;
}
Problem p02556 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  vector<int> x(n);
  vector<int> y(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }
  vector<int> rect(4, 0);
  for (int i = 0; i < n; i++) {
    if (x[i] + y[i] > x[rect[0]] + y[rect[0]]) {
      rect[0] = i;
    }
    if (x[i] - y[i] > x[rect[1]] - y[rect[1]]) {
      rect[1] = i;
    }
    if (y[i] - x[i] > y[rect[2]] - x[rect[2]]) {
      rect[2] = i;
    }
    if (x[i] + y[i] < x[rect[3]] + y[rect[3]]) {
      rect[3] = i;
    }
  }
  cout << max(abs(x[rect[0]] - x[rect[3]]) + abs(y[rect[0]] - y[rect[3]]),
              abs(x[rect[1]] - x[rect[2]]) + abs(y[rect[1]] - y[rect[2]]))
       << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  vector<int> y(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }
  vector<int> rect(4, 0);
  for (int i = 0; i < n; i++) {
    if (x[i] + y[i] > x[rect[0]] + y[rect[0]]) {
      rect[0] = i;
    }
    if (x[i] - y[i] > x[rect[1]] - y[rect[1]]) {
      rect[1] = i;
    }
    if (y[i] - x[i] > y[rect[2]] - x[rect[2]]) {
      rect[2] = i;
    }
    if (x[i] + y[i] < x[rect[3]] + y[rect[3]]) {
      rect[3] = i;
    }
  }
  cout << max(abs(x[rect[0]] - x[rect[3]]) + abs(y[rect[0]] - y[rect[3]]),
              abs(x[rect[1]] - x[rect[2]]) + abs(y[rect[1]] - y[rect[2]]))
       << endl;
}
Problem p02556 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define sync                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)
#define input(arr, n)                                                          \
  for (ll i1 = 0; i1 < n; i1++)                                                \
  cin >> arr[i1]
#define mod 1000000007
#define F first
#define S second
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")

using namespace __gnu_pbds;
#define ordered_set                                                            \
  tree<ll, null_type, less_equal<ll>, rb_tree_tag,                             \
       tree_order_statistics_node_update> // s.order_of_key(val)
                                          // *s.find_by_order(ind)
using namespace std;

const int N = 1e6 + 5;
int main() {
  sync;
  ll n;
  cin >> n;
  vector<pair<ll, ll>> v(n);
  for (ll i = 0; i < n; i++)
    cin >> v[i].F >> v[i].S;
  ll ans = 0;
  for (ll i = 0; i < n; i++)
    for (ll j = 0; j < n; j++)
      ans = max(ans, abs(v[i].F - v[j].F) + abs(v[i].S - v[j].S));
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define sync                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)
#define input(arr, n)                                                          \
  for (ll i1 = 0; i1 < n; i1++)                                                \
  cin >> arr[i1]
#define mod 1000000007
#define F first
#define S second
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")

using namespace __gnu_pbds;
#define ordered_set                                                            \
  tree<ll, null_type, less_equal<ll>, rb_tree_tag,                             \
       tree_order_statistics_node_update> // s.order_of_key(val)
                                          // *s.find_by_order(ind)
using namespace std;

const int N = 1e6 + 5;
int main() {
  sync;
  ll n;
  cin >> n;
  vector<pair<ll, ll>> v(n);
  for (ll i = 0; i < n; i++)
    cin >> v[i].F >> v[i].S;
  ll ans = 0, minm = 1e18, maxm = -1e18;
  for (ll i = 0; i < n; i++) {
    minm = min(minm, v[i].F + v[i].S);
    maxm = max(maxm, v[i].F + v[i].S);
  }
  ans = maxm - minm;
  minm = 1e18, maxm = -1e18;
  for (ll i = 0; i < n; i++) {
    minm = min(minm, v[i].F - v[i].S);
    maxm = max(maxm, v[i].F - v[i].S);
  }
  ans = max(ans, maxm - minm);
  cout << ans;
}
Problem p02556 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define pii pair<int, int>

int N;
int X[100010], Y[100010];

signed main() {
  cin >> N;
  rep(i, N) {
    int x, y;
    cin >> x >> y;
    X[i] = x + y;
    Y[i] = x - y;
  }

  sort(X, X + N);
  sort(Y, Y + N);

  cout << max(X[N - 1] - X[0], Y[N - 1] - Y[0]) << endl;

  return 0;
}


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

#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define pii pair<int, int>

int N;
int X[200010], Y[200010];

signed main() {
  cin >> N;
  rep(i, N) {
    int x, y;
    cin >> x >> y;
    X[i] = x + y;
    Y[i] = x - y;
  }

  sort(X, X + N);
  sort(Y, Y + N);

  cout << max(X[N - 1] - X[0], Y[N - 1] - Y[0]) << endl;

  return 0;
}
Problem p02556 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;
const int N = 100005;
const double INF = 1e100;

int a[N][3];
int n;

int main() {
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < 2; j++)
        scanf("%d", &a[i][j]);
    int ans = 0, mi, mx, t;
    for (int s = 1; s < (1 << 2); s++) {
      mi = INF;
      mx = -INF;
      for (int i = 0; i < n; i++) {
        t = 0;
        for (int j = 0; j < 2; j++) {
          if ((1 << j) & s)
            t += a[i][j];
          else
            t -= a[i][j];
        }
        mi = min(mi, t);
        mx = max(mx, t);
      }
      ans = max(ans, mx - mi);
    }
    printf("%d\n", ans);
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;
const int N = 200005;
const double INF = 1e100;

int a[N][3];
int n;

int main() {
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < 2; j++)
        scanf("%d", &a[i][j]);
    int ans = 0, mi, mx, t;
    for (int s = 1; s < (1 << 2); s++) {
      mi = INF;
      mx = -INF;
      for (int i = 0; i < n; i++) {
        t = 0;
        for (int j = 0; j < 2; j++) {
          if ((1 << j) & s)
            t += a[i][j];
          else
            t -= a[i][j];
        }
        mi = min(mi, t);
        mx = max(mx, t);
      }
      ans = max(ans, mx - mi);
    }
    printf("%d\n", ans);
  }
  return 0;
}
Problem p02556 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define INF 9999999999999
#define D 2      // 空间维数
#define M 100005 // 坐标个数
struct Point {
  int x[D];
} pt[M];
int dis[1 << D][M], minx[1 << D], maxx[1 << D];

// 去掉绝对值后有2^D种可能
void Get(int N) // 取得所有点在指定状态（S）下的“本点有效距离”
{
  int tot = (1 << D);
  for (int s = 0; s < tot; s++) // 遍历所有维数正负状态
  {
    int coe[D];
    for (int i = 0; i < D; i++) // 设定当前状态的具体正负参数
      if (s & (1 << i))
        coe[i] = -1.0;
      else
        coe[i] = 1.0;

    for (int i = 0; i < N;
         i++) // 遍历所有点，确定每个点在当前状态下的“本点有效距离”
    {
      dis[s][i] = 0.0;
      for (int j = 0; j < D; j++)
        dis[s][i] = dis[s][i] + coe[j] * pt[i].x[j];
    }
  }
}
// 取每种可能中的最大差距
void Solve(int N) {
  int tot = (1 << D);
  int tmp, ans;
  for (int s = 0; s < tot; s++) {
    minx[s] = INF;
    maxx[s] = -INF;
    for (int i = 0; i < N; i++) {
      if (minx[s] > dis[s][i])
        minx[s] = dis[s][i];
      if (maxx[s] < dis[s][i])
        maxx[s] = dis[s][i];
    }
  }
  ans = 0;
  for (int s = 0; s < tot; s++) {
    tmp = maxx[s] - minx[s];
    if (tmp > ans)
      ans = tmp;
  }

  cout << ans << endl;
}

int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    for (int i = 0; i < n; i++)
      cin >> pt[i].x[0] >> pt[i].x[1];
    Get(n);
    Solve(n);
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define INF 9999999999999
#define D 2      // 空间维数
#define M 200005 // 坐标个数
struct Point {
  int x[D];
} pt[M];
int dis[1 << D][M], minx[1 << D], maxx[1 << D];

// 去掉绝对值后有2^D种可能
void Get(int N) // 取得所有点在指定状态（S）下的“本点有效距离”
{
  int tot = (1 << D);
  for (int s = 0; s < tot; s++) // 遍历所有维数正负状态
  {
    int coe[D];
    for (int i = 0; i < D; i++) // 设定当前状态的具体正负参数
      if (s & (1 << i))
        coe[i] = -1.0;
      else
        coe[i] = 1.0;

    for (int i = 0; i < N;
         i++) // 遍历所有点，确定每个点在当前状态下的“本点有效距离”
    {
      dis[s][i] = 0.0;
      for (int j = 0; j < D; j++)
        dis[s][i] = dis[s][i] + coe[j] * pt[i].x[j];
    }
  }
}
// 取每种可能中的最大差距
void Solve(int N) {
  int tot = (1 << D);
  int tmp, ans;
  for (int s = 0; s < tot; s++) {
    minx[s] = INF;
    maxx[s] = -INF;
    for (int i = 0; i < N; i++) {
      if (minx[s] > dis[s][i])
        minx[s] = dis[s][i];
      if (maxx[s] < dis[s][i])
        maxx[s] = dis[s][i];
    }
  }
  ans = 0;
  for (int s = 0; s < tot; s++) {
    tmp = maxx[s] - minx[s];
    if (tmp > ans)
      ans = tmp;
  }

  cout << ans << endl;
}

int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    for (int i = 0; i < n; i++)
      cin >> pt[i].x[0] >> pt[i].x[1];
    Get(n);
    Solve(n);
  }
  return 0;
}
Problem p02556 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ar array<int, 2>
#define inf 1000000000000000000
int mod = 1e9 + 7;
int min(int a, int b) { return (a < b) ? a : b; }
int max(int a, int b) { return (a > b) ? a : b; }
int fp(int a, int b) {
  if (b == 0)
    return 1;
  int x = fp(a, b / 2);
  x = (x * x) % mod;
  if (b & 1)
    x = (x * a) % mod;
  return x;
}

const int N = 2e5 + 5;

void solve() {
  int n, x, y;
  cin >> n;
  vector<int> tmp(1ll << 2, -inf);
  int ans = -inf;
  for (int i = 1; i <= n; i++) {
    cin >> x >> y;
    for (int j = 0; j < (1ll << 2); j++) {
      if (tmp[i] == -inf)
        break;
      int z = tmp[j];
      if (j & 1)
        z -= y;
      else
        z += y;
      if ((j >> 1) & 1)
        z -= x;
      else
        z += x;
      ans = max(ans, z);
    }

    for (int j = 0; j < (1ll << 2); j++) {
      int z = 0;
      if (j & 1)
        z += y;
      else
        z -= y;
      if ((j >> 1) & 1)
        z += x;
      else
        z -= x;
      tmp[j] = max(tmp[j], z);
      // cout<<tmp[j]<<endl;
    }
  }
  cout << ans << endl;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(time(0));
  int t = 1;
  // cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ar array<int, 2>
#define inf 1000000000000000000
int mod = 1e9 + 7;
int min(int a, int b) { return (a < b) ? a : b; }
int max(int a, int b) { return (a > b) ? a : b; }
int fp(int a, int b) {
  if (b == 0)
    return 1;
  int x = fp(a, b / 2);
  x = (x * x) % mod;
  if (b & 1)
    x = (x * a) % mod;
  return x;
}

const int N = 2e5 + 5;

void solve() {
  int n, x, y;
  cin >> n;
  vector<int> tmp(1ll << 2, -inf);
  int ans = -inf;
  for (int i = 1; i <= n; i++) {
    cin >> x >> y;
    for (int j = 0; j < (1ll << 2); j++) {
      if (tmp[j] == -inf)
        break;
      int z = tmp[j];
      if (j & 1)
        z -= y;
      else
        z += y;
      if ((j >> 1) & 1)
        z -= x;
      else
        z += x;
      ans = max(ans, z);
    }

    for (int j = 0; j < (1ll << 2); j++) {
      int z = 0;
      if (j & 1)
        z += y;
      else
        z -= y;
      if ((j >> 1) & 1)
        z += x;
      else
        z -= x;
      tmp[j] = max(tmp[j], z);
      // cout<<tmp[j]<<endl;
    }
  }
  cout << ans << endl;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(time(0));
  int t = 1;
  // cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
}
Problem p02556 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#ifdef _MSC_VER
#define GC getchar
#else
#define GC getchar_unlocked
#endif
int input() {
  int x = 0;
  char c;
  bool minus = false;
  for (;;) {
    c = GC();
    if (c == '-') {
      minus = true;
      continue;
    }
    if (c == ' ' || c == '\n')
      if (minus)
        return -x;
      else
        return x;
    x = 10 * x + c - '0';
  }
}
void fix() {
  char c;
  for (;;) {
    c = GC();
    if (c == -1 || c != ' ' && c != '\n')
      break;
  }
  if (c != -1)
    ungetc(c, stdin);
}
int main() {
  int N, i, j, k, d;
  int a[6];
  int m[32];
  int M[32];
  for (i = 0; i < 32; i++) {
    m[i] = 1000000000;
    M[i] = -1000000000;
  }
  scanf("%d %d", &N, &d);
  fix();
  for (i = 0; i < N; i++) {
    for (j = 0; j < d; j++)
      a[j] = input(); //,fix();
    for (j = 0; j < 1 << (d - 1); j++) {
      int x = a[0];
      for (k = 0; k < d - 1; k++)
        if (j & (1 << k))
          x += a[k + 1];
        else
          x -= a[k + 1];
      if (m[j] > x)
        m[j] = x;
      if (M[j] < x)
        M[j] = x;
    }
  }
  int ans = 0;
  for (i = 0; i < 1 << (d - 1); i++)
    if (ans < M[i] - m[i])
      ans = M[i] - m[i];
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <cstdio>
#ifdef _MSC_VER
#define GC getchar
#else
#define GC getchar_unlocked
#endif
int input() {
  int x = 0;
  char c;
  bool minus = false;
  for (;;) {
    c = GC();
    if (c == '-') {
      minus = true;
      continue;
    }
    if (c == ' ' || c == '\n')
      if (minus)
        return -x;
      else
        return x;
    x = 10 * x + c - '0';
  }
}
void fix() {
  char c;
  for (;;) {
    c = GC();
    if (c == -1 || c != ' ' && c != '\n')
      break;
  }
  if (c != -1)
    ungetc(c, stdin);
}
int main() {
  int N, i, j, k, d;
  int a[6];
  int m[32];
  int M[32];
  for (i = 0; i < 32; i++) {
    m[i] = 1000000000;
    M[i] = -1000000000;
  }
  scanf("%d", &N);
  d = 2;
  fix();
  for (i = 0; i < N; i++) {
    for (j = 0; j < d; j++)
      a[j] = input(); //,fix();
    for (j = 0; j < 1 << (d - 1); j++) {
      int x = a[0];
      for (k = 0; k < d - 1; k++)
        if (j & (1 << k))
          x += a[k + 1];
        else
          x -= a[k + 1];
      if (m[j] > x)
        m[j] = x;
      if (M[j] < x)
        M[j] = x;
    }
  }
  int ans = 0;
  for (i = 0; i < 1 << (d - 1); i++)
    if (ans < M[i] - m[i])
      ans = M[i] - m[i];
  printf("%d\n", ans);
  return 0;
}
Problem p02557 (C++)

Buggy submission (status: 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");
  puts("Yes");
  for (int i = 1; i <= n; i++)
    printf("%d ", b[i]);
}

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"), 0;
  puts("Yes");
  for (int i = 1; i <= n; i++)
    printf("%d ", b[i]);
}
Problem p02557 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#pragma GCC optimization("O3")

#define endl '\n'
#define pb push_back
#define fr first
#define sc second
#define ll long long int
#define ld long double
#define bit(idx) idx & (-idx)
#define bin(x, a) bitset<a>(x)
#define all(A) A.begin(), A.end()
#define de(x) cout << #x << " = " << x << endl;
#define row vector<ll>
#define matrix vector<row>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
/// find_by_order(x) -> x-th element in the set
/// order_of_key(x)  -> how many elements are smaller than x
/// insert(x) -> inserts x into the set

int main() {
  /// ios_base::sync_with_stdio(false); cin.tie(NULL);
  ll n;
  cin >> n;
  vector<ll> A(n), B(n), cnt(n + 2);
  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++) {
    ++cnt[A[i]];
    ++cnt[B[i]];
  }
  for (int i = 1; i <= n; i++) {
    if (cnt[i] > n) {
      cout << "No\n";
      return 0;
    }
  }
  reverse(all(B));
  int L = 0, R = n - 1;
  for (int i = 0; i < n; i++) {
    if (A[i] == B[i]) {
      if (B[L] != A[i] && A[L] != A[i]) {
        swap(B[L], B[i]);
        --L;
      } else {
        swap(B[R], B[i]);
        --R;
      }
    }
  }
  cout << "Yes\n";
  for (auto x : B)
    cout << x << " ";
  cout << endl;
}
/**

*/

Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#pragma GCC optimization("O3")

#define endl '\n'
#define pb push_back
#define fr first
#define sc second
#define ll long long int
#define ld long double
#define bit(idx) idx & (-idx)
#define bin(x, a) bitset<a>(x)
#define all(A) A.begin(), A.end()
#define de(x) cout << #x << " = " << x << endl;
#define row vector<ll>
#define matrix vector<row>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
/// find_by_order(x) -> x-th element in the set
/// order_of_key(x)  -> how many elements are smaller than x
/// insert(x) -> inserts x into the set

int main() {
  /// ios_base::sync_with_stdio(false); cin.tie(NULL);
  ll n;
  cin >> n;
  vector<ll> A(n), B(n), cnt(n + 2);
  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++) {
    ++cnt[A[i]];
    ++cnt[B[i]];
  }
  for (int i = 1; i <= n; i++) {
    if (cnt[i] > n) {
      cout << "No\n";
      return 0;
    }
  }
  reverse(all(B));
  int L = 0, R = n - 1;
  for (int i = 0; i < n; i++) {
    if (A[i] == B[i]) {
      if (B[L] != A[i] && A[L] != A[i]) {
        swap(B[L], B[i]);
        ++L;
      } else {
        swap(B[R], B[i]);
        --R;
      }
    }
  }
  cout << "Yes\n";
  for (auto x : B)
    cout << x << " ";
  cout << endl;
}
/**

*/
Problem p02557 (C++)

Buggy submission (status: Time Limit Exceeded):
#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;
}


Fixed submission:
#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;
}
Problem p02557 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  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];
  reverse(B.begin(), B.end());
  for (int i = 0; i < N; i++) {
    if (A[i] == B[i]) {
      int now = N, now2 = N;
      for (int j = i + 1; j < N; j++) {
        if (A[i] != B[j])
          now2 = min(now2, j);
        if (A[i] != B[j] && A[i] != A[j]) {
          now = j;
          break;
        }
      }
      int old = now;
      now = -1;
      for (int j = i - 1; j >= 0; j--)
        if (A[i] != B[j] && A[i] != A[j]) {
          now = j;
          break;
        }
      if (!(now + 1 + N - old < now2 - i)) {
        for (int j = i; j < now2; j++) {
          if (j - i < N - old)
            swap(B[j], B[old + j - i]);
          else
            swap(B[j], B[now - (j - i)]);
        }
      } else {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  for (int i = 0; i < N; i++) {
    cout << B[i] << ((i + 1 == N) ? "\n" : " ");
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  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];
  reverse(B.begin(), B.end());
  for (int i = 0; i < N; i++) {
    if (A[i] == B[i]) {
      int now = N, now2 = N;
      for (int j = i + 1; j < N; j++) {
        if (A[i] != B[j])
          now2 = min(now2, j);
        if (A[i] != B[j] && A[i] != A[j]) {
          now = j;
          break;
        }
      }
      int old = now;
      now = -1;
      for (int j = i - 1; j >= 0; j--)
        if (A[i] != B[j] && A[i] != A[j]) {
          now = j;
          break;
        }
      if (!(now + 1 + N - old < now2 - i)) {
        for (int j = i; j < now2; j++) {
          if (j - i < N - old)
            swap(B[j], B[old + j - i]);
          else
            swap(B[j], B[now - (j - i) + (N - old)]);
        }
      } else {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  for (int i = 0; i < N; i++) {
    cout << B[i] << ((i + 1 == N) ? "\n" : " ");
  }
}
Problem p02557 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define mem(a, x) memset(a, x, sizeof(a));
#define ft                                                                     \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
int main() {
  ft int t, i, j, n, m, l, r;
  cin >> n;
  int a[n + 1], b[n + 1], c[n + 1];
  mem(c, 0);
  for (i = 0; i < n; i++) {
    cin >> a[i];
    c[a[i]]++;
  }
  for (i = 0; i < n; i++) {
    cin >> b[i];
    c[b[i]]++;
  }
  for (i = 1; i <= n; i++) {
    if (c[i] > n) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
  for (i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      for (j = 0; j < n; j++) {
        if (b[j] != a[i] && b[i] != a[j]) {
          swap(b[i], b[j]);
          break;
        }
      }
    }
  }
  for (i = 0; i < n; i++) {
    cout << b[i] << " ";
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define mem(a, x) memset(a, x, sizeof(a));
#define ft                                                                     \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
int main() {
  ft int t, i, j, n, m, l, r;
  cin >> n;
  int a[n + 1], b[n + 1], c[n + 1];
  mem(c, 0);
  for (i = 0; i < n; i++) {
    cin >> a[i];
    c[a[i]]++;
  }
  for (i = 0; i < n; i++) {
    cin >> b[i];
    c[b[i]]++;
  }
  for (i = 1; i <= n; i++) {
    if (c[i] > n) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
  reverse(b, b + n);
  for (i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      for (j = 0; j < n; j++) {
        if (b[j] != a[i] && b[i] != a[j]) {
          swap(b[i], b[j]);
          break;
        }
      }
    }
  }
  for (i = 0; i < n; i++) {
    cout << b[i] << " ";
  }
  return 0;
}
Problem p02557 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

void Main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
  }
  for (int i = 0; i < n; i++) {
    cin >> b[n - 1 - i];
    m[b[i]]++;
  }
  for (auto i : m) {
    if (i.second > n) {
      cout << "No" << endl;
      return;
    }
  }
  cout << "Yes" << endl;
  for (int i = 0; i < n; i++) {
    while (a[i] == b[i]) {
      int r = rand() % n;
      if (a[r] != b[i] && b[r] != b[i]) {
        swap(b[i], b[r]);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (i != 0)
      cout << " ";
    cout << b[i];
  }
  cout << endl;
}

int main(int argc, char **argv) {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  Main();
  return 0;
}


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

void Main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
  }
  for (int i = 0; i < n; i++) {
    cin >> b[n - 1 - i];
    m[b[n - 1 - i]]++;
  }
  for (auto i : m) {
    if (i.second > n) {
      cout << "No" << endl;
      return;
    }
  }
  cout << "Yes" << endl;
  for (int i = 0; i < n; i++) {
    while (a[i] == b[i]) {
      int r = rand() % n;
      if (a[r] != b[i] && b[r] != b[i]) {
        swap(b[i], b[r]);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (i != 0)
      cout << " ";
    cout << b[i];
  }
  cout << endl;
}

int main(int argc, char **argv) {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  Main();
  return 0;
}
Problem p02557 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define PI 3.141592653589793238462
using namespace std;
typedef long long ll;
typedef long double db;
ll a[200005], b[200005], p[200005];
int main() {
  ll n;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    cin >> a[i];
    p[a[i]]++;
  }
  for (ll i = 1; i <= n; i++) {
    cin >> b[i];
    p[b[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    if (p[i] > n) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i <= n; i++) {
    if (a[i] == b[i]) {
      for (int j = 1; j <= n; j++) {
        if (b[j] != a[i] && b[i] != a[j]) {
          swap(b[i], b[j]);
          break;
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << b[i] << " ";
  }
  cout << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define PI 3.141592653589793238462
using namespace std;
typedef long long ll;
typedef long double db;
ll a[200005], b[200005], p[200005];
int main() {
  ll n;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    cin >> a[i];
    p[a[i]]++;
  }
  for (ll i = 1; i <= n; i++) {
    cin >> b[i];
    p[b[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    if (p[i] > n) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  reverse(b + 1, b + 1 + n);
  for (int i = 1; i <= n; i++) {
    if (a[i] == b[i]) {
      for (int j = 1; j <= n; j++) {
        if (b[j] != a[i] && b[i] != a[j]) {
          swap(b[i], b[j]);
          break;
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << b[i] << " ";
  }
  cout << endl;
}
Problem p02557 (C++)

Buggy submission (status: 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]);

  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;
}


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 - 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;
}
Problem p02557 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <iostream>
using namespace std;

#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define deb(x) cout << #x << " " << x << endl;

typedef long long int ll;

int main() {

  IOS

      int n;
  cin >> n;

  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];

  bool swapped = true;

  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      swapped = false;

      for (int j = 0; j < n; j++) {
        if (b[i] == b[j])
          continue;

        if (a[j] == b[i])
          continue;

        if (a[i] == b[j])
          continue;

        swap(b[i], b[j]);
        swapped = true;
        break;
      }

      if (!swapped)
        break;
    }
  }

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

  } else
    cout << "No";

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;

#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define deb(x) cout << #x << " " << x << endl;

typedef long long int ll;

int main() {

  IOS

      int n;
  cin >> n;

  int a[n], b[n];

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

  for (int i = n - 1; i >= 0; i--)
    cin >> b[i];

  bool swapped = true;

  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      swapped = false;

      for (int j = 0; j < n; j++) {
        if (b[i] == b[j])
          continue;

        if (a[j] == b[i])
          continue;

        if (a[i] == b[j])
          continue;

        swap(b[i], b[j]);
        swapped = true;
        break;
      }

      if (!swapped)
        break;
    }
  }

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

  } else
    cout << "No";

  return 0;
}
Problem p02557 (C++)

Buggy submission (status: Runtime Error):
#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] << " ";
    }
  }
}

Fixed submission:
#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] << " ";
    }
  }
}
Problem p02557 (C++)

Buggy submission (status: 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[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


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[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
Problem p02557 (C++)

Buggy submission (status: 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) << 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;
}


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) % 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;
}