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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b)                                                           \
  for (register int i = (a), i##_end_ = (b); i <= i##_end_; ++i)
#define drep(i, a, b)                                                          \
  for (register int i = (a), i##_end_ = (b); i >= i##_end_; --i)
#define clear(a, b) memset((a), (b), sizeof(a))
typedef long long LL;
int read() {
  int x = 0, flag = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      flag = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + (ch - 0x30);
    ch = getchar();
  }
  return flag * x;
}

LL a, b;
int sign(LL a) { return (a >= 0); }
void gdata() { exit(998244353); }
int main() {
#ifdef Qrsikno
  freopen("k.in", "r", stdin);
  freopen("k.out", "w", stdout);
#endif
  cin >> a >> b;
  if (a == b)
    puts("0");
  else if (a == 0)
    printf("%lld\n", (b < 0) + abs(b));
  else if (b == 0)
    printf("%lld\n", (a > 0) + abs(a));
  else if (a * b < 0) {
    if (abs(a) == abs(b))
      printf("1\n");
    else
      printf("%lld\n", 1 + abs(abs(b) - abs(a)));
  } else {
    if (a < 0)
      printf("%lld\n", 2 + abs(abs(b) - abs(a))), gdata();
    else
      printf("%lld\n", abs(abs(b) - abs(a)));
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b)                                                           \
  for (register int i = (a), i##_end_ = (b); i <= i##_end_; ++i)
#define drep(i, a, b)                                                          \
  for (register int i = (a), i##_end_ = (b); i >= i##_end_; --i)
#define clear(a, b) memset((a), (b), sizeof(a))
typedef long long LL;
int read() {
  int x = 0, flag = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-')
      flag = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + (ch - 0x30);
    ch = getchar();
  }
  return flag * x;
}

LL a, b;
int sign(LL a) { return (a >= 0); }
void gdata() { exit(998244353); }
int main() {
#ifdef Qrsikno
  freopen("k.in", "r", stdin);
  freopen("k.out", "w", stdout);
#endif
  cin >> a >> b;
  if (a == b)
    puts("0");
  else if (a == 0)
    printf("%lld\n", (b < 0) + abs(b));
  else if (b == 0)
    printf("%lld\n", (a > 0) + abs(a));
  else if (a * b < 0) {
    if (abs(a) == abs(b))
      printf("1\n");
    else
      printf("%lld\n", 1 + abs(abs(b) - abs(a)));
  } else {
    if (a < 0)
      if (abs(a) < abs(b))
        printf("%lld\n", 2 + abs(abs(b) - abs(a)));
      else
        printf("%lld\n", abs(abs(a) - abs(b)));
    else if (a > b)
      printf("%lld\n", 2 + abs(abs(b) - abs(a)));
    else
      printf("%lld\n", abs(abs(b) - abs(a)));
  }
  return 0;
}
Problem p03838 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <cmath>

// using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
// typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
// #define rep(i, n) for (ll i = 0; i < (n); ++i)
// #define sz(x) ll(x.size())
typedef pair<int, int> P;
// typedef pair<ll, int> P;
// typedef pair<ll, ll> P;
// const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
// const ll INF = (1ll << 31) - 1;
// const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
// const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
// typedef pair<int, int> P;
// typedef pair<double, double> P;

bool contain(set<string> &s, string a) { return s.find(a) != s.end(); }

// ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
// ofstream outfile("log.txt");
// outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0')
// << rank << endl;
//  std::cout << std::bitset<8>(9);
const int mod = 1000000007;
typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;

int main() {
  ll x, y;
  cin >> x >> y;

  ll count = 0;
  if (abs(x) > abs(y)) {
    if (x > 0) {
      count++;
      x = -x;
    }
  } else {
    if (x < 0) {
      count++;
      x = -x;
    }
  }

  ll diff = abs(abs(x) - abs(y));
  count += diff;
  x += count;
  if (x != y) {
    count++;
    x = -x;
  }
  assert(x == y);
  cout << count << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#include <cmath>

// using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
// typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
// #define rep(i, n) for (ll i = 0; i < (n); ++i)
// #define sz(x) ll(x.size())
typedef pair<int, int> P;
// typedef pair<ll, int> P;
// typedef pair<ll, ll> P;
// const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
// const ll INF = (1ll << 31) - 1;
// const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
// const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
// typedef pair<int, int> P;
// typedef pair<double, double> P;

bool contain(set<string> &s, string a) { return s.find(a) != s.end(); }

// ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
// ofstream outfile("log.txt");
// outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0')
// << rank << endl;
//  std::cout << std::bitset<8>(9);
const int mod = 1000000007;
typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;

int main() {
  ll x, y;
  cin >> x >> y;

  ll count = 0;
  if (abs(x) > abs(y)) {
    if (x > 0) {
      count++;
      x = -x;
    }
  } else {
    if (x < 0) {
      count++;
      x = -x;
    }
  }

  ll diff = abs(abs(x) - abs(y));
  count += diff;
  x += diff;
  if (x != y) {
    count++;
    x = -x;
  }
  assert(x == y);
  cout << count << endl;
}
Problem p03838 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long x, y;
  cin >> x >> y;
  long ans = 0;
  int tmp;
  while (x != y) {
    tmp = 0;
    if (x == -y) {
      ans += 1;
      x = -x;
    } else {
      if (x > 0)
        tmp += 1;
      if (y > 0)
        tmp += 2;
      if (abs(x) > abs(y))
        tmp += 4;

      switch (tmp) {
      case 1:
      case 3:
      case 4:
      case 6:
        ans += abs(abs(x) - abs(y));
        x += abs(abs(x) - abs(y));
        break;
      case 0:
      case 2:
      case 5:
      case 7:
        ans++;
        x = -x;
        break;
      }
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long x, y;
  cin >> x >> y;
  long ans = 0;
  int tmp;
  while (x != y) {
    tmp = 0;
    if (x == -y) {
      ans += 1;
      x = -x;
    } else if (x == 0) {
      x++;
      ans++;
    } else {
      if (x > 0)
        tmp += 1;
      if (y > 0)
        tmp += 2;
      if (abs(x) > abs(y))
        tmp += 4;

      switch (tmp) {
      case 1:
      case 3:
      case 4:
      case 6:
        ans += abs(abs(x) - abs(y));
        x += abs(abs(x) - abs(y));
        break;
      case 0:
      case 2:
      case 5:
      case 7:
        ans++;
        x = -x;
        break;
      }
    }
  }
  cout << ans << endl;
}
Problem p03838 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

typedef pair<ll, ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

vector<int> G[100005];
std::vector<P> tree[100010];

int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

ll i, j, k;
ll n, m;
ll a[100005], b[100005];
ll ans = 0;

int main() {
  cin >> n >> m;
  if (n * m > 0) {
    if (m > n)
      ans = m - n;
    else
      ans = n - m + 2;
  } else if (n * m < 0) {
    ans = abs(abs(m) - abs(n)) + 1;
  } else {
    for (i = 0; i <= 1000000; i++) {
      for (j = 0; j <= 10000; j++) {
        ans += i + j;
        ans %= mod;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

typedef pair<ll, ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

vector<int> G[100005];
std::vector<P> tree[100010];

int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

ll i, j, k;
ll n, m;
ll a[100005], b[100005];
ll ans = 0;

int main() {
  cin >> n >> m;
  if (n * m > 0) {
    if (m > n)
      ans = m - n;
    else
      ans = n - m + 2;
  } else if (n * m < 0) {
    ans = abs(abs(m) - abs(n)) + 1;
  } else {
    if (n == 0 && m > 0)
      ans = m;
    else if (n == 0 && m < 0)
      ans = 1 - m;
    else if (m == 0 && n > 0)
      ans = 1 + n;
    else
      ans = -1 * n;
  }
  cout << ans << endl;
  return 0;
}
Problem p03838 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

class question {
public:
  int x, y;

  void ans() {
    cin >> x >> y;
    int sgnx = x / abs(x), sgny = y / abs(y);
    int res = abs(abs(x) - abs(y));
    if (x < y) {
      if (sgnx * sgny < 0)
        res++;
    } else {
      res++;
      if (sgnx * sgny > 0)
        res++;
    }
    cout << res << "\n";
  }
};

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

  question q;
  q.ans();

  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

class question {
public:
  int x, y;

  void ans() {
    cin >> x >> y;
    int sgnx = x / max(abs(x), 1), sgny = y / max(abs(y), 1);
    int res = abs(abs(x) - abs(y));
    if (x < y) {
      if (sgnx * sgny < 0)
        res++;
    } else {
      res++;
      if (sgnx * sgny > 0)
        res++;
    }
    cout << res << "\n";
  }
};

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

  question q;
  q.ans();

  return 0;
}
Problem p03838 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

bool balance(int x, int y) {
  return ((x >= 0) && (y >= 0)) || ((x < 0) && (y < 0));
}

bool isminus(int x) { return x < 0; }
bool isplus(int x) { return x >= 0; }

int solve(int x, int y, int step) {
  if (x == y)
    return step;
  if (isplus(x) && isplus(y)) { // + && +
    if (x > y)
      return solve(-x, y, step + 1);
    if (x < y)
      return solve(x + (y - x), y, step + (y - x));
  } else if (isplus(x) && isminus(y)) { // + && -
    if (x >= abs(y))
      return solve(-x, y, step + 1);
    return solve(x + (abs(y) - x), y, step + (abs(y) - x));
  } else if (isminus(x) && isplus(y)) { // - && +
    if (abs(x) > y)
      return solve(x + 1, y, step + 1);
    if (abs(x) > y)
      return solve(x + (abs(x) - y), y, step + (abs(x) - y));
    return solve(-x, y, step + 1);
  } else if (isminus(x) && isminus(y)) {
    if (x < y)
      return solve(x + (y - x), y, step + (y - x));
    if (x > y)
      return solve(-x, y, step + 1);
  }
}

int main() {
  int x, y, ans;
  cin >> x >> y;
  cout << solve(x, y, 0) << endl;
}


Fixed submission:
#include <iostream>
using namespace std;

bool balance(int x, int y) {
  return ((x >= 0) && (y >= 0)) || ((x < 0) && (y < 0));
}

bool isminus(int x) { return x < 0; }
bool isplus(int x) { return x >= 0; }

int solve(int x, int y, int step) {
  if (x == y)
    return step;
  if (isplus(x) && isplus(y)) { // + && +
    if (x > y)
      return solve(-x, y, step + 1);
    if (x < y)
      return solve(x + (y - x), y, step + (y - x));
  } else if (isplus(x) && isminus(y)) { // + && -
    if (x >= abs(y))
      return solve(-x, y, step + 1);
    return solve(x + (abs(y) - x), y, step + (abs(y) - x));
  } else if (isminus(x) && isplus(y)) { // - && +
    if (abs(x) > y)
      return solve(x + (abs(x) - y), y, step + (abs(x) - y));
    return solve(-x, y, step + 1);
  } else if (isminus(x) && isminus(y)) {
    if (x < y)
      return solve(x + (y - x), y, step + (y - x));
    if (x > y)
      return solve(-x, y, step + 1);
  }
}

int main() {
  int x, y, ans;
  cin >> x >> y;
  cout << solve(x, y, 0) << endl;
}
Problem p03838 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>
using namespace std;
int main() {
  long long x, y;
  cin >> x >> y;
  long long ans = 0;
  if (abs(x) < abs(y)) {
    if (x < 0) {
      ans++;
      x = -x;
    }
    ans += abs(y) - abs(x);
    x += abs(y) - abs(x);
  }
  if (abs(x) > abs(y)) {
    if (x > 0) {
      ans++;
      x = -x;
    }
    ans += abs(x) - abs(y);
    x += abs(x) - abs(y);
  }
  if (abs(x) / x != abs(y) / y)
    ans++;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <cmath>
#include <iostream>
using namespace std;
int main() {
  long long x, y;
  cin >> x >> y;
  long long ans = 0;
  if (abs(x) < abs(y)) {
    if (x < 0) {
      ans++;
      x = -x;
    }
    ans += abs(y) - abs(x);
    x += abs(y) - abs(x);
  }
  if (abs(x) > abs(y)) {
    if (x > 0) {
      ans++;
      x = -x;
    }
    ans += abs(x) - abs(y);
    x += abs(x) - abs(y);
  }
  if (x * y < 0)
    ans++;
  cout << ans << endl;
  return 0;
}
Problem p03838 (C++)

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using LL = long long;
using ULL = unsigned long long;

int solve2(int x, int y) {
  if (x > y)
    return solve2(x, -y) + 1; // x <= y
  if (y <= 0 || 0 <= x)
    return y - x; // x < 0 && 0 < y
  if (-x <= y)
    return solve2(-x, y) + 1; // y < -x
  return solve2(x, -y) + 1;
}

void solve() {
  int x, y;
  cin >> x >> y;
  cout << solve2(x, y) << endl;
}

int main() {

  solve();

  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using LL = long long;
using ULL = unsigned long long;

int solve2(int x, int y) {
  if (x > y) {
    if (-x < y)
      return solve2(-x, y) + 1;
    return solve2(x, -y) + 1;
  } // x <= y
  if (y <= 0 || 0 <= x)
    return y - x; // x < 0 && 0 < y
  if (-x <= y)
    return solve2(-x, y) + 1; // y < -x
  return solve2(x, -y) + 1;
}

void solve() {
  int x, y;
  cin >> x >> y;
  cout << solve2(x, y) << endl;
}

int main() {

  solve();

  return 0;
}
Problem p03838 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int solve(int x, int y) {
  if (x <= y && (y > 0 && x > 0 || y < 0 && x < 0)) {
    return y - x;
  } else if (-x <= y) {
    return solve(-x, y) + 1;
  } else {
    return solve(x, -y) + 1;
  }
}

int main() {
  int x, y;
  cin >> x >> y;
  cout << solve(x, y);
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;

int solve(int x, int y) {
  if (x <= y && (y >= 0 && x >= 0 || y <= 0 && x <= 0)) {
    return y - x;
  } else if (-x <= y) {
    return solve(-x, y) + 1;
  } else {
    return solve(x, -y) + 1;
  }
}

int main() {
  int x, y;
  cin >> x >> y;
  cout << solve(x, y);
  return 0;
}
Problem p03838 (Python)

Buggy submission (status: Runtime Error):
def main():
    x, y = map(int, input().split())
    A = abs(abs(x) - abs(y))

    if x * y > 0:
        if x < y:
            B = 0
        else:
            B = 2
    elif x == 0:
        if x < y:
            B = 0
        else:
            B = 1
    elif y == 0:
        if x < y:
            B = 0
        else:
            B = 1

    print(A + B)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    x, y = map(int, input().split())
    A = abs(abs(x) - abs(y))

    if x * y > 0:
        if x < y:
            B = 0
        else:
            B = 2
    elif x == 0:
        if x < y:
            B = 0
        else:
            B = 1
    elif y == 0:
        if x < y:
            B = 0
        else:
            B = 1
    else:
        B = 1

    print(A + B)


if __name__ == "__main__":
    main()
Problem p03838 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#define MAX_INT 100005
using namespace std;

// 入力
long X, Y;

int main() {

  ios::sync_with_stdio(false);

  cin >> X >> Y;
  int a = 0, b = 0;

  // 絶対値を一致させる
  while (abs(X) != abs(Y)) {
    if (abs(abs(X + 1) - abs(Y)) < abs(abs(X) - abs(Y))) {
      // +1 で絶対値の差が縮む間は +1
      a++;
      X++;
    } else {
      b++;
      X = -X;
    }
  }

  // 符号を一致させる
  if (X != Y) {
    b++;
  }

  cout << a + b << "\n";
}


Fixed submission:
#include <algorithm>
#include <iostream>
#define MAX_INT 100005
using namespace std;

// 入力
long X, Y;

int main() {

  ios::sync_with_stdio(false);

  cin >> X >> Y;
  int a = 0, b = 0;

  // 絶対値を一致させる
  while (abs(X) != abs(Y)) {
    if (abs(abs(X + 1) - abs(Y)) < abs(abs(X) - abs(Y))) {
      // +1 で絶対値の差が縮むまで +1
      int diff = abs(abs(X) - abs(Y));
      a += diff;
      X += diff;
    } else {
      b++;
      X = -X;
    }
  }

  // 符号を一致させる
  if (X != Y) {
    b++;
  }

  cout << a + b << "\n";
}
Problem p03838 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all_map(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define ALL(a) (a).begin(), (a).end()

int main() {
  ll x, y;
  cin >> x >> y;
  ll ans = abs(abs(x) - abs(y));
  if (x / abs(x) != y / abs(y))
    ans++;
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all_map(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define ALL(a) (a).begin(), (a).end()

int main() {
  ll x, y;
  cin >> x >> y;
  ll ans = abs(abs(x) - abs(y));
  if (x > y) {
    if (x < 0 || y > 0)
      ans += 2;
    else
      ans++;
  } else if (ans != y - x)
    ans++;
  cout << ans << endl;
}
Problem p03838 (Python)

Buggy submission (status: Runtime Error):
def main():
    x, y = map(int, input().split())

    if 0 <= x <= y or x <= y <= 0:
        ans = abs(abs(x) - abs(y))

    elif x < 0 < y or y < 0 < x:
        ans = abs(abs(x) - abs(y)) + 1

    elif y < x < 0 or 0 < y < x:
        ans = abs(abs(x) - abs(y)) + 2

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    x, y = map(int, input().split())

    if 0 <= x <= y or x <= y <= 0:
        ans = abs(abs(x) - abs(y))

    elif x <= 0 <= y or y <= 0 <= x:
        ans = abs(abs(x) - abs(y)) + 1

    elif y < x < 0 or 0 < y < x:
        ans = abs(abs(x) - abs(y)) + 2

    print(ans)


if __name__ == "__main__":
    main()
Problem p03838 (C++)

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

using namespace std;

const int inf = 2000000000;

int culc(int x, int y) {
  if (x >= 0 && abs(y) < x) {
    return inf;
  }
  if (x >= 0) {
    if (y > 0) {
      return y - x;
    }
    return -y - x + 1;
  }
  if (y > 0) {
    if (x <= -y) {
      return -y - x + 1;
    }
    return y - x;
  }
  if (y < x) {
    return inf;
  }
  return y - x;
}

int main() {
  int x, y;
  cin >> x >> y;
  int res = min(culc(x, y), culc(-x, y) + 1);
  return res;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

const int inf = 2000000000;

int culc(int x, int y) {
  if (x >= 0 && abs(y) < x) {
    return inf;
  }
  if (x >= 0) {
    if (y > 0) {
      return y - x;
    }
    return -y - x + 1;
  }
  if (y > 0) {
    if (x <= -y) {
      return -y - x + 1;
    }
    return y - x;
  }
  if (y < x) {
    return inf;
  }
  return y - x;
}

int main() {
  int x, y;
  cin >> x >> y;
  int res = min(culc(x, y), culc(-x, y) + 1);
  cout << res << endl;
}
Problem p03839 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 5005
// #define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template <class T> void read(T &res) {
  res = 0;
  T f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
  }
  res *= f;
}
template <class T> void out(T x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x >= 10) {
    out(x / 10);
  }
  putchar('0' + x % 10);
}
int N, K;
int64 pre[MAXN], suf[MAXN], a[MAXN], sum[MAXN];
void Solve() {
  read(N);
  read(K);

  for (int i = 1; i <= N; ++i) {
    read(a[i]);
    sum[i] = sum[i - 1] + a[i];
    pre[i] = pre[i - 1];
    if (a[i] > 0)
      pre[i] = pre[i] + a[i];
  }
  for (int i = N; i >= 1; --i) {
    suf[i] = suf[i + 1];
    if (a[i] > 0)
      suf[i] = suf[i] + a[i];
  }
  int64 ans = 0;
  for (int i = 1; i <= N; ++i) {
    int r = i + K - 1;
    if (r > N)
      break;
    int64 all = pre[i - 1] + suf[r + 1];
    if (sum[r] - sum[i - 1] > 0)
      all += sum[r] - sum[i - 1];
    ans = max(ans, all);
  }
  out(ans);
  enter;
}
int main() {
#ifdef ivorysi
  freopen("f1.in", "r", stdin);
#endif
  Solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
// #define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template <class T> void read(T &res) {
  res = 0;
  T f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
  }
  res *= f;
}
template <class T> void out(T x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x >= 10) {
    out(x / 10);
  }
  putchar('0' + x % 10);
}
int N, K;
int64 pre[MAXN], suf[MAXN], a[MAXN], sum[MAXN];
void Solve() {
  read(N);
  read(K);

  for (int i = 1; i <= N; ++i) {
    read(a[i]);
    sum[i] = sum[i - 1] + a[i];
    pre[i] = pre[i - 1];
    if (a[i] > 0)
      pre[i] = pre[i] + a[i];
  }
  for (int i = N; i >= 1; --i) {
    suf[i] = suf[i + 1];
    if (a[i] > 0)
      suf[i] = suf[i] + a[i];
  }
  int64 ans = 0;
  for (int i = 1; i <= N; ++i) {
    int r = i + K - 1;
    if (r > N)
      break;
    int64 all = pre[i - 1] + suf[r + 1];
    if (sum[r] - sum[i - 1] > 0)
      all += sum[r] - sum[i - 1];
    ans = max(ans, all);
  }
  out(ans);
  enter;
}
int main() {
#ifdef ivorysi
  freopen("f1.in", "r", stdin);
#endif
  Solve();
  return 0;
}
Problem p03839 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int N, K, s;
ll sum, ans, a;

int main() {
  cin >> N >> K;
  vector<ll> T, S;
  for (int i = 0; i < N; i++) {
    cin >> a;
    T.push_back(T.back() + a);
    S.push_back(S.back() + max(0LL, a));
  }

  for (int i = K; i <= N; i++) {
    ans = max((S[N] - S[i]) + S[i - K] + max(0LL, T[i] - T[i - K]), ans);
  }

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int N, K, s;
ll sum, ans, a;

int main() {
  cin >> N >> K;
  vector<ll> T, S;
  T.push_back(0);
  S.push_back(0);
  for (int i = 0; i < N; i++) {
    cin >> a;
    T.push_back(T.back() + a);
    S.push_back(S.back() + max(0LL, a));
  }

  for (int i = K; i <= N; i++) {
    ans = max((S[N] - S[i]) + S[i - K] + max(0LL, T[i] - T[i - K]), ans);
  }

  cout << ans << endl;
}
Problem p03839 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("trapv")
#include <bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using vi = vector<int>;
using ll = long long;
const int maxn = 2020, mod = 924844033;
ll n, k, a[maxn], b[maxn], c[maxn];
ll ans = 0;
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++)
    b[i] = max(a[i], 0ll) + b[i - 1];
  for (int i = n; i; i--)
    c[i] = max(a[i], 0ll) + c[i + 1];
  for (int i = 1; i <= n; i++)
    a[i] += a[i - 1];
  for (int i = k; i <= n; i++) {
    ll t = max(0ll, a[i] - a[i - k]);
    t += b[i - k] + c[i + 1];
    ans = max(ans, t);
  }
  cout << ans;
}


Fixed submission:
#pragma GCC optimize("trapv")
#include <bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using vi = vector<int>;
using ll = long long;
const int maxn = 1 << 20, mod = 924844033;
ll n, k, a[maxn], b[maxn], c[maxn];
ll ans = 0;
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++)
    b[i] = max(a[i], 0ll) + b[i - 1];
  for (int i = n; i; i--)
    c[i] = max(a[i], 0ll) + c[i + 1];
  for (int i = 1; i <= n; i++)
    a[i] += a[i - 1];
  for (int i = k; i <= n; i++) {
    ll t = max(0ll, a[i] - a[i - k]);
    t += b[i - k] + c[i + 1];
    ans = max(ans, t);
  }
  cout << ans;
}
Problem p03840 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int, int> pii;
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

const int N = 7;

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  // freopen("in.txt", "r", stdin);
  vl a(N);
  rep(i, 0, sz(a)) { cin >> a[i]; }
  ll ret = a[1];
  ll x = min(a[0], min(a[3], a[4]));
  rep(i, 0, x + 1) {
    ll loc = a[1] + 3 * i;
    loc += ((a[0] - i) / 2) * 2;
    loc += ((a[3] - i) / 2) * 2;
    loc += ((a[4] - i) / 2) * 2;
    ret = max(ret, loc);
  }
  cout << ret << '\n';
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int, int> pii;
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

const int N = 7;

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  // freopen("in.txt", "r", stdin);
  vl a(N);
  rep(i, 0, sz(a)) { cin >> a[i]; }
  ll ret = a[1];
  ll x = min(a[0], min(a[3], a[4]));
  ll y = a[0] % 2 + a[3] % 2 + a[4] % 2;
  if (y >= 2) {
    x = min(1LL, x);
  } else {
    x = 0;
  }
  rep(i, 0, x + 1) {
    ll loc = a[1] + 3 * i;
    loc += ((a[0] - i) / 2) * 2;
    loc += ((a[3] - i) / 2) * 2;
    loc += ((a[4] - i) / 2) * 2;
    ret = max(ret, loc);
  }
  cout << ret << '\n';
  return 0;
}
Problem p03840 (C++)

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

long long a, b, c, d, e, f, g;

int main() {
  cin >> a >> b >> c >> d >> e >> f;
  long long res = 0;
  for (int i = 0; i <= min({a, d, e}); ++i)
    res = max(res, 3 * i + 2 * ((a - i) / 2 + (d - i) / 2 + (e - i) / 2) + b);
  cout << res << endl;
  return 0;
}


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

long long a, b, c, d, e, f, g;

int main() {
  cin >> a >> b >> c >> d >> e >> f;
  long long res = b;
  for (int i = 0; i <= min({a, d, e, 4LL}); ++i)
    res = max(res, 3 * i + 2 * ((a - i) / 2 + (d - i) / 2 + (e - i) / 2) + b);
  cout << res << endl;
  return 0;
}
Problem p03840 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  long long a[7] = {0, 0, 0, 0, 0, 0, 0};
  for (int i = 0; i < 7; i++)
    cin >> a[i];
  long long cnt = a[1];
  long long cnt2 = 0;
  for (int i = 0; i <= min(a[0], min(a[3], a[4])); i++) {
    long long ret1 = 3 * i;
    long long ret2 = 2 * ((a[0] - i) / 2);
    long long ret3 = 2 * ((a[3] - i) / 2);
    long long ret4 = 2 * ((a[4] - i) / 2);
    cnt2 = max(cnt2, ret1 + ret2 + ret3 + ret4);
  }
  cout << cnt + cnt2 << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  long long a[7] = {0, 0, 0, 0, 0, 0, 0};
  for (int i = 0; i < 7; i++)
    cin >> a[i];
  long long cnt = a[1];
  long long cnt2 = 0;
  for (int i = 0; i <= min(20000000LL, min(a[0], min(a[3], a[4]))); i++) {
    long long ret1 = 3 * i;
    long long ret2 = 2 * ((a[0] - i) / 2);
    long long ret3 = 2 * ((a[3] - i) / 2);
    long long ret4 = 2 * ((a[4] - i) / 2);
    cnt2 = max(cnt2, ret1 + ret2 + ret3 + ret4);
  }
  cout << cnt + cnt2 << endl;
  return 0;
}
Problem p03840 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

int main() {
  vector<ll> vs(7);
  for (int i = 0; i < 7; i++) {
    cin >> vs[i];
  }

  ll k = 2 * vs[1];
  vector<int> is = {0, 3, 4};
  for (int i : is) {
    ll num = vs[i] <= 2 ? 0 : vs[i] % 2 == 0 ? vs[i] - 2 : vs[i] - 1;
    k += 2 * num;
  }

  vector<int> table = {0, 0, 4, 0, 0, 4, 4, 4, 8, 0, 0, 4, 0, 6,
                       6, 4, 6, 8, 4, 0, 8, 4, 6, 8, 8, 8, 12};
  int index = 9 * vs[0] + 3 * vs[3] + vs[4];
  k += table[index];
  cout << k / 2 << endl;
}


Fixed submission:
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

int main() {
  vector<ll> vs(7);
  for (int i = 0; i < 7; i++) {
    cin >> vs[i];
  }

  ll k = 2 * vs[1];
  vector<int> is = {0, 3, 4};
  for (int i : is) {
    ll num = vs[i] <= 2 ? 0 : vs[i] % 2 == 0 ? vs[i] - 2 : vs[i] - 1;
    k += 2 * num;
    vs[i] -= num;
  }

  vector<int> table = {0, 0, 4, 0, 0, 4, 4, 4, 8, 0, 0, 4, 0, 6,
                       6, 4, 6, 8, 4, 0, 8, 4, 6, 8, 8, 8, 12};
  int index = 9 * vs[0] + 3 * vs[3] + vs[4];
  k += table[index];
  cout << k / 2 << endl;
}
Problem p03840 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock() / CLOCKS_PER_SEC
signed main() {
#ifdef HOME
  freopen("input.txt", "r", stdin);
#else
#define endl '\n'
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#endif
  int ai, ao, at, aj, al, as, az;
  cin >> ai >> ao >> at >> aj >> al >> as >> az;

  int ans = 0;
  for (int i = 0;; ++i) {
    ans = max(ans, (ai / 2) * 2 + ao * 1 + (aj / 2) * 2 + (al / 2) * 2 + i * 3);
    if (!ai || !aj || !al) {
      break;
    }
    --ai;
    --aj;
    --al;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock() / CLOCKS_PER_SEC
signed main() {
#ifdef HOME
  freopen("input.txt", "r", stdin);
#else
#define endl '\n'
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#endif
  int ai, ao, at, aj, al, as, az;
  cin >> ai >> ao >> at >> aj >> al >> as >> az;

  int ans = 0;
  for (int i = 0; i < 1000 * 1000; ++i) {
    ans = max(ans, (ai / 2) * 2 + ao * 1 + (aj / 2) * 2 + (al / 2) * 2 + i * 3);
    if (!ai || !aj || !al) {
      break;
    }
    --ai;
    --aj;
    --al;
  }
  cout << ans << endl;
}
Problem p03840 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
vector<string> split(const string &str, char sep) {
  std::vector<std::string> v;
  auto first = str.begin();
  while (first != str.end()) {
    auto last = first;
    while (last != str.end() && *last != sep)
      ++last;
    v.push_back(std::string(first, last));
    if (last != str.end())
      ++last;
    first = last;
  }
  return v;
}
long long ai, ao, at, aj, al, as, az;
long long ans;
int main() {
  cin >> ai >> ao >> at >> aj >> al >> as >> az;
  ans = ao;
  int x = min({ai, aj, al});
  rep(i, x + 1) {
    ans = max(ans, ao + i * 3 + ((ai - i) / 2) * 2 + ((aj - i) / 2) * 2 +
                       ((al - i) / 2) * 2);
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
vector<string> split(const string &str, char sep) {
  std::vector<std::string> v;
  auto first = str.begin();
  while (first != str.end()) {
    auto last = first;
    while (last != str.end() && *last != sep)
      ++last;
    v.push_back(std::string(first, last));
    if (last != str.end())
      ++last;
    first = last;
  }
  return v;
}
long long ai, ao, at, aj, al, as, az;
long long ans;
int main() {
  cin >> ai >> ao >> at >> aj >> al >> as >> az;
  ans = ao;
  int x = min({ai, aj, al});
  rep(i, min(10, x + 1)) {
    ans = max(ans, ao + i * 3 + ((ai - i) / 2) * 2 + ((aj - i) / 2) * 2 +
                       ((al - i) / 2) * 2);
  }
  cout << ans << endl;
  return 0;
}
Problem p03840 (C++)

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

long long a[7];
int main() {
  for (int i = 0; i < 7; i++) {
    cin >> a[i];
  }

  long long m = min(min(a[0], a[3]), a[4]);
  /*
  a[0] -= m;
  a[3] -= m;
  a[4] -= m;
  */

  long long ans = 0;
  for (int i = 0; i <= m; i++) {
    ans = max(ans, 3 * i + (a[0] - i) / 2 * 2 + (a[3] - i) / 2 * 2 +
                       (a[4] - i) / 2 * 2);
  }

  cout << ans + a[1] << endl;
}


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

long long a[7];
int main() {
  for (int i = 0; i < 7; i++) {
    cin >> a[i];
  }

  long long m = min(min(a[0], a[3]), a[4]);
  /*
  a[0] -= m;
  a[3] -= m;
  a[4] -= m;
  */

  long long ans = 0;
  for (int i = 0; i <= min(m, 100ll); i++) {
    ans = max(ans, 3 * i + (a[0] - i) / 2 * 2 + (a[3] - i) / 2 * 2 +
                       (a[4] - i) / 2 * 2);
  }

  cout << ans + a[1] << endl;
}
Problem p03840 (C++)

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

typedef long long ll;
const int N = 7;

ll cnt[N], ans;

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  for (int i = 0; i < N; i++)
    cin >> cnt[i];
  ans += 2 * cnt[1];
  cnt[1] = 0;

  ll maxi = 0;
  for (int i = 0; i <= min({cnt[0], cnt[3], cnt[4]}); i++) {
    ll X = 6 * i;

    X += 4 * ((cnt[3] - i) / 2);

    X += 4 * ((cnt[4] - i) / 2);

    X += 4 * ((cnt[0] - i) / 2);

    maxi = max(maxi, X);
  }

  cout << (ans + maxi) / 2;
}


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

typedef long long ll;
const int N = 7;

ll cnt[N], ans;

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  for (int i = 0; i < N; i++)
    cin >> cnt[i];
  ans += 2 * cnt[1];
  cnt[1] = 0;

  ll maxi = 0;
  for (int i = 0; i <= min({1LL, cnt[0], cnt[3], cnt[4]}); i++) {
    ll X = 6 * i;

    X += 4 * ((cnt[3] - i) / 2);

    X += 4 * ((cnt[4] - i) / 2);

    X += 4 * ((cnt[0] - i) / 2);

    maxi = max(maxi, X);
  }

  cout << (ans + maxi) / 2;
}
Problem p03841 (C++)

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

vector<int> ans;
P c[500];
signed main() {
  int a;
  cin >> a;
  for (int b = 0; b < a; b++) {
    int d;
    cin >> d;
    d--;
    c[b] = {d, b};
  }
  sort(c, c + a);
  int count[500]{};
  for (int b = 0; b < a * a; b++) {
    bool S = false;
    for (int d = 0; d < a; d++) {
      if (c[d].first == b) {
        if (count[c[d].second] == c[d].second) {
          ans.push_back(c[d].second + 1);
          count[c[d].second]++;
          S = true;
        } else {
          puts("No");
          return 0;
        }
      }
    }
    if (S)
      continue;
    for (int d = 0; d < a; d++) {
      if (count[c[d].second] < c[d].second) {
        ans.push_back(c[d].second + 1);
        count[c[d].second]++;
        S = true;
        break;
      }
    }
    if (S)
      continue;
    for (int d = 0; d < a; d++) {
      if (c[d].first < b && count[c[d].second] < a) {
        ans.push_back(c[d].second + 1);
        count[c[d].second]++;
        S = true;
        break;
      }
    }
  }
  puts("Yes");
  for (int b = 0; b < a * a; b++) {
    if (b)
      cout << " ";
    cout << ans[b];
  }
  cout << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define P pair<int, int>
using namespace std;

vector<int> ans;
P c[500];
signed main() {
  int a;
  cin >> a;
  for (int b = 0; b < a; b++) {
    int d;
    cin >> d;
    d--;
    c[b] = {d, b};
  }
  sort(c, c + a);
  int count[500]{};
  for (int b = 0; b < a * a; b++) {
    bool S = false;
    for (int d = 0; d < a; d++) {
      if (c[d].first == b) {
        if (count[c[d].second] == c[d].second) {
          ans.push_back(c[d].second + 1);
          count[c[d].second]++;
          S = true;
        } else {
          puts("No");
          return 0;
        }
      }
    }
    if (S)
      continue;
    for (int d = 0; d < a; d++) {
      if (count[c[d].second] < c[d].second) {
        ans.push_back(c[d].second + 1);
        count[c[d].second]++;
        S = true;
        break;
      }
    }
    if (S)
      continue;
    for (int d = 0; d < a; d++) {
      if (c[d].first < b && count[c[d].second] < a) {
        ans.push_back(c[d].second + 1);
        count[c[d].second]++;
        S = true;
        break;
      }
    }
  }
  if (ans.size() != a * a) {
    puts("No");
    return 0;
  }
  puts("Yes");
  for (int b = 0; b < a * a; b++) {
    if (b)
      cout << " ";
    cout << ans[b];
  }
  cout << endl;
}
Problem p03841 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int N = 510;
typedef pair<int, int> pii;
int gi() {
  int x = 0, o = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-')
    ch = getchar();
  if (ch == '-')
    o = -1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
int n, ans[N], lim[N], rem[N];
pii a[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    a[i].fi = lim[i] = gi(), a[i].se = i;
  sort(a + 1, a + n + 1);
  int p = 1;
  for (int i = 1; i <= n; i++) {
    ans[a[i].fi] = a[i].se;
    for (int j = 1; j <= a[i].se - 1; j++) {
      while (ans[p])
        p++;
      ans[p] = a[i].se;
      p++;
    }
    if (p - 1 > a[i].fi)
      return puts("No"), 0;
  }
  for (int i = 1; i <= n; i++)
    rem[i] = n - i;
  for (int i = p; i <= n * n; i++) {
    if (ans[i])
      continue;
    for (int j = 1; j <= n; j++)
      if (rem[j] && lim[j] < i) {
        ans[i] = j;
        rem[j]--;
        break;
      }
    if (!ans[i])
      return puts("No"), 0;
  }
  puts("Yes");
  for (int i = 1; i <= n * n; i++)
    printf("%d ", ans[i]);
  return 0;
}
// orzgzy
// 鸡贼明年进队超稳


Fixed submission:
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int N = 3e5 + 10;
typedef pair<int, int> pii;
int gi() {
  int x = 0, o = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-')
    ch = getchar();
  if (ch == '-')
    o = -1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
int n, ans[N], lim[N], rem[N];
pii a[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    a[i].fi = lim[i] = gi(), a[i].se = i;
  sort(a + 1, a + n + 1);
  int p = 1;
  for (int i = 1; i <= n; i++) {
    ans[a[i].fi] = a[i].se;
    for (int j = 1; j <= a[i].se - 1; j++) {
      while (ans[p])
        p++;
      ans[p] = a[i].se;
      p++;
    }
    if (p - 1 > a[i].fi)
      return puts("No"), 0;
  }
  for (int i = 1; i <= n; i++)
    rem[i] = n - i;
  for (int i = p; i <= n * n; i++) {
    if (ans[i])
      continue;
    for (int j = 1; j <= n; j++)
      if (rem[j] && lim[j] < i) {
        ans[i] = j;
        rem[j]--;
        break;
      }
    if (!ans[i])
      return puts("No"), 0;
  }
  puts("Yes");
  for (int i = 1; i <= n * n; i++)
    printf("%d ", ans[i]);
  return 0;
}
// orzgzy
// 鸡贼明年进队超稳
Problem p03841 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a, b) (a > b ? a = b : a)
#define cmax(a, b) (a < b ? a = b : a)
#define mem(a, k) memset(a, k, sizeof(a))
#define lop(i, s, t) for (int i = s; i < (t); ++i)
#define rep(i, s, t) for (int i = s; i <= (t); ++i)
#define dec(i, s, t) for (int i = s; i >= (t); --i)
#define fore(i, v)                                                             \
  for (int i = g[v], d = es[i].d; i; i = es[i].nxt, d = es[i].d)
using namespace std;

typedef long long ll;

#define Pr(f, ...) fprintf(stderr, f, ##__VA_ARGS__), fflush(stderr)

const int N = 505, M = N * N;

struct P {
  int x, c;
} a[N];
bool operator<(const P &a, const P &b) { return a.x < b.x; }

int fail, n, cnt[N], q[N], h, t, res[N];

int main(int argc, char *argv[]) {
#ifdef CURIOUSCAT
  // freopen("dat.in","r",stdin);
  // freopen("my.out","w",stdout);
#endif
  scanf("%d", &n);
  rep(i, 1, n) {
    scanf("%d", &a[i].x);
    a[i].c = i;
  }
  sort(a + 1, a + n + 1);
  int p = n;
  dec(i, n, 1) {
    lop(k, 0, n - a[i].c) q[t++] = a[i].c;
    cnt[a[i].c] = n;
  }
  dec(i, n * n, 1) {
    if (p && i == a[p].x) {
      if (cnt[a[p].c] != a[p].c)
        fail = true;
      res[i] = a[p].c;
      lop(k, 1, a[p].c) q[t++] = a[p].c;
      --p;
    } else {
      if (h == t)
        fail = true;
      res[i] = q[h++];
      --cnt[res[i]];
    }
  }
  puts(fail ? "No" : "Yes");
  if (!fail)
    rep(i, 1, n * n) printf("%d ", res[i]);
  puts("");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a, b) (a > b ? a = b : a)
#define cmax(a, b) (a < b ? a = b : a)
#define mem(a, k) memset(a, k, sizeof(a))
#define lop(i, s, t) for (int i = s; i < (t); ++i)
#define rep(i, s, t) for (int i = s; i <= (t); ++i)
#define dec(i, s, t) for (int i = s; i >= (t); --i)
#define fore(i, v)                                                             \
  for (int i = g[v], d = es[i].d; i; i = es[i].nxt, d = es[i].d)
using namespace std;

typedef long long ll;

#define Pr(f, ...) fprintf(stderr, f, ##__VA_ARGS__), fflush(stderr)

const int N = 505, M = N * N;

struct P {
  int x, c;
} a[N];
bool operator<(const P &a, const P &b) { return a.x < b.x; }

int fail, n, cnt[N], q[M], h, t, res[M];

int main(int argc, char *argv[]) {
#ifdef CURIOUSCAT
  // freopen("dat.in","r",stdin);
  // freopen("my.out","w",stdout);
#endif
  scanf("%d", &n);
  rep(i, 1, n) {
    scanf("%d", &a[i].x);
    a[i].c = i;
  }
  sort(a + 1, a + n + 1);
  int p = n;
  dec(i, n, 1) {
    lop(k, 0, n - a[i].c) q[t++] = a[i].c;
    cnt[a[i].c] = n;
  }
  dec(i, n * n, 1) {
    if (p && i == a[p].x) {
      if (cnt[a[p].c] != a[p].c)
        fail = true;
      res[i] = a[p].c;
      lop(k, 1, a[p].c) q[t++] = a[p].c;
      --p;
    } else {
      if (h == t)
        fail = true;
      res[i] = q[h++];
      --cnt[res[i]];
    }
  }
  puts(fail ? "No" : "Yes");
  if (!fail)
    rep(i, 1, n * n) printf("%d ", res[i]);
  puts("");
  return 0;
}
Problem p03841 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <array>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using i64 = int64_t;
int n;
vector<int> x;
int main() {
  cin >> n;
  x.resize(n + 1);
  vector<int> res(n * n);
  for (int i = 1; i <= n; ++i) {
    cin >> x[i];
    res[x[i] - 1] = i;
  }
  if (n == 1) {
    cout << "Yes\n1\n";
    return 0;
  }
  vector<pair<int, int>> ps;
  for (int i = 1; i <= n; ++i) {
    ps.emplace_back(x[i], i);
  }
  sort(begin(ps), end(ps));
  bool f = false;
  for (int i = 0, j = 0, k = -1; i < n * n; ++i) {
    while (j == 0) {
      k++;
      if (k == n) {
        k = 0;
        f = true;
      }
      if (!f)
        j = ps[k].second - 1;
      else
        j = n - ps[k].second;
    }
    cerr << k << endl;
    if (res[i] == 0) {
      res[i] = ps[k].second;
      --j;
    }
    for (int y : res)
      cerr << y << ' ';
    cerr << endl;
  }
  for (int i = 1; i <= n; ++i) {
    int cnt = 0;
    for (int j = x[i] - 1; j >= 0; --j) {
      cnt += res[j] == i;
    }
    cerr << i << ' ' << cnt << endl;
    if (cnt != i) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
  for (int y : res)
    cout << y << ' ';
  cout << '\n';
  return 0;
}

Fixed submission:
#include <algorithm>
#include <array>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using i64 = int64_t;
int n;
vector<int> x;
int main() {
  cin >> n;
  x.resize(n + 1);
  vector<int> res(n * n);
  for (int i = 1; i <= n; ++i) {
    cin >> x[i];
    res[x[i] - 1] = i;
  }
  if (n == 1) {
    cout << "Yes\n1\n";
    return 0;
  }
  vector<pair<int, int>> ps;
  for (int i = 1; i <= n; ++i) {
    ps.emplace_back(x[i], i);
  }
  sort(begin(ps), end(ps));
  bool f = false;
  for (int i = 0, j = 0, k = -1; i < n * n; ++i) {
    while (j == 0) {
      k++;
      if (k == n) {
        k = 0;
        f = true;
      }
      if (!f)
        j = ps[k].second - 1;
      else
        j = n - ps[k].second;
    }
    cerr << k << endl;
    if (res[i] == 0) {
      res[i] = ps[k].second;
      --j;
    }
  }
  for (int i = 1; i <= n; ++i) {
    int cnt = 0;
    for (int j = x[i] - 1; j >= 0; --j) {
      cnt += res[j] == i;
    }
    cerr << i << ' ' << cnt << endl;
    if (cnt != i) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
  for (int y : res)
    cout << y << ' ';
  cout << '\n';
  return 0;
}