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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<int, int> P;
int main() {
  int n;
  while (cin >> n, n) {
    set<P> SET;
    vector<P> point;
    FOR(i, 0, n) {
      int y, x;
      cin >> y >> x;
      SET.insert(P(y, x));
      point.push_back(P(y, x));
    }
    int ans = 0;
    FOR(i, 0, n) {
      int y = point[i].first;
      int x = point[i].second;
      FOR(j, 0, n) {
        if (i == j)
          continue;
        int yy = point[j].first;
        int xx = point[j].second;

        int dy = yy - y;
        int dx = xx - x;
        if (dy >= 0) {
          int Y = yy - dx;
          int X = xx + dy;
          if (SET.count(P(Y, X)) == 0)
            continue;

          Y = Y - dy;
          X = X - dx;
          if (SET.count(P(Y, X)) == 0)
            continue;

          Y = Y + dx;
          X = X - dy;

          if (y == Y && x == X) {
            ans = max(ans, dy * dy + dx * dx);
          }
        }
      }
    }
    cout << ans << '\\n';
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<int, int> P;
bool isp[5050][5050];
vector<P> point;
int main() {
  int n;
  while (cin >> n, n) {
    CLR(isp);
    FOR(i, 0, n) {
      int y, x;
      cin >> y >> x;
      isp[y][x] = true;
      point.push_back(P(y, x));
    }
    int ans = 0;
    FOR(i, 0, n) {
      int y = point[i].first;
      int x = point[i].second;
      FOR(j, 0, n) {
        if (i == j)
          continue;
        int yy = point[j].first;
        int xx = point[j].second;

        int dy = yy - y;
        int dx = xx - x;

        if (dy >= 0 && dx >= 0) {
          int Y = yy - dx;
          int X = xx + dy;
          if (Y > 5000 || X > 5000 || !isp[Y][X])
            continue;

          Y = Y - dy;
          X = X - dx;
          if (Y > 5000 || X > 5000 || !isp[Y][X])
            continue;

          Y = Y + dx;
          X = X - dy;

          if (y == Y && x == X) {
            ans = max(ans, (dy + dx) * (dy + dx) - dy * dx * 2);
          }
        }
      }
    }
    cout << ans << '\\n';
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;

int n, x[3001], y[3001], dx, dy, ans;
bool xy[5001][5001];

void solve(int x1, int y1, int x2, int y2) {
  if (x1 == x2) {
    ans = max(ans, dy * dy);
  } else if (y1 == y2) {
    ans = max(ans, dx * dx);
  } else {
    if (dx < 0) {
      dx = -dx;
    }
    if (dy < 0) {
      dy = -dy;
    }
    ans = max(ans, (dy + dx) * (dy + dx) - (dy * dx) * 2);
  }

  return;
}

int main() {
  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }

    for (int i = 0; i < n; i++) {
      cin >> x[i] >> y[i];
      xy[x[i]][y[i]] = 1;
    }

    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        dx = x[i] - x[j];
        dy = y[i] - y[j];

        if (x[i] + dy < 5001 && x[j] + dy < 5001 && x[i] + dy >= 0 &&
            x[j] + dy >= 0 && y[i] - dx < 5001 && y[j] - dx < 5001 &&
            y[i] - dx >= 0 && y[j] - dx >= 0) {
          if (xy[x[i] + dy][y[i] - dx] == 1 && xy[x[j] + dy][y[j] - dx] == 1) {
            solve(x[i], y[i], x[j], y[j]);
          }
        }
        if (x[i] - dy < 5001 && x[j] - dy < 5001 && x[i] - dy >= 0 &&
            x[j] - dy >= 0 && y[i] + dx < 5001 && y[j] + dx < 5001 &&
            y[i] + dx >= 0 && y[j] + dx >= 0) {
          if (xy[x[i] - dy][y[i] + dx] == 1 && xy[x[j] - dy][y[j] + dx] == 1) {
            solve(x[i], y[i], x[j], y[j]);
          }
        }
      }
    }

    cout << ans << endl;

    memset(xy, false, sizeof xy);
    ans = 0;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;

int n, x[3001], y[3001], dx, dy, ans = 0;
bool xy[5001][5001];

void solve(int x1, int y1, int x2, int y2, int dx, int dy) {
  if (x1 == x2) {
    ans = max(ans, dy * dy);
  } else if (y1 == y2) {
    ans = max(ans, dx * dx);
  } else {
    if (dx < 0) {
      dx = -dx;
    }
    if (dy < 0) {
      dy = -dy;
    }
    ans = max(ans, (dy + dx) * (dy + dx) - (dy * dx) * 2);
  }

  return;
}

int main() {
  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }

    for (int i = 0; i < n; i++) {
      cin >> x[i] >> y[i];
      xy[x[i]][y[i]] = 1;
    }

    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        int dx = x[i] - x[j], dy = y[i] - y[j];

        if (x[i] >= -dy && x[j] >= -dy && y[i] >= dx && y[j] >= dx) {
          if (xy[x[i] + dy][y[i] - dx] == 1 && xy[x[j] + dy][y[j] - dx] == 1) {
            solve(x[i], y[i], x[j], y[j], dx, dy);
          }
        }
        if (x[i] >= dy && x[j] >= dy && y[i] >= -dx && y[j] >= -dx) {
          if (xy[x[i] - dy][y[i] + dx] == 1 && xy[x[j] - dy][y[j] + dx] == 1) {
            solve(x[i], y[i], x[j], y[j], dx, dy);
          }
        }
      }
    }

    cout << ans << endl;
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bits //stdc++.h>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
struct P {
  int x, y;
};
bool operator<(P a, P b) {
  if (a.x < b.x)
    return true;
  else if (a.x > b.x)
    return false;
  else {
    if (a.y < b.y)
      return true;
    else
      return false;
  }
}
bool operator>(P a, P b) {
  if (a.x < b.x)
    return false;
  else if (a.x > b.x)
    return true;
  else {
    if (a.y < b.y)
      return false;
    else
      return true;
  }
}
bool operator==(P a, P b) { return a.x == b.x && a.y == b.y; }
int main() {
  int n;
  while (cin >> n && n != 0) {
    P a[3000];
    for (int i = 0; i < n; i++) {
      cin >> a[i].x >> a[i].y;
    }
    int sum = 0;
    sort(a, a + n);
    for (int i = 0; i < n; i++) {
      int x1 = a[i].x, y1 = a[i].y;
      for (int j = 0; j < n; j++) {
        if (i != j && a[j].x >= x1 && a[j].y >= y1) {
          int x2 = a[j].x, y2 = a[j].y;
          int x3 = x2 - x1, y3 = y2 - y1;
          int x4 = x2 - y3, y4 = y2 + x3;
          P b = {x4, y4};
          int s = lower_bound(a, a + n, b) - a;
          if (!(s < n && a[s] == b))
            continue;
          int x5 = (x4 - x3), y5 = (y4 - y3);
          s = 0;
          b = {x5, y5};
          s = lower_bound(a, a + n, b) - a;
          if (!(s < n && a[s] == b))
            continue;
          int sum2 = ((x2 - x5) * (y4 - y1));
          sum2 -= ((x3 * y3) * 2);
          sum = max(sum, sum2);
        }
      }
    }
    cout << sum << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits //stdc++.h>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
struct P {
  int x, y;
};
int main() {
  int n;
  while (cin >> n && n != 0) {
    P a[3000];
    for (int i = 0; i < n; i++) {
      cin >> a[i].x >> a[i].y;
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
      int x1 = a[i].x, y1 = a[i].y;
      for (int j = 0; j < n; j++) {
        if (i != j && a[j].x >= x1 && a[j].y >= y1) {
          int x2 = a[j].x, y2 = a[j].y;
          int x3 = x2 - x1, y3 = y2 - y1;
          int x4 = x2 - y3, y4 = y2 + x3;
          bool f1 = true;
          for (int j = 0; j < n; j++) {
            if (a[j].x == x4 && a[j].y == y4) {
              f1 = false;
              break;
            }
          }
          if (f1 == true)
            continue;
          int x5 = (x4 - x3), y5 = (y4 - y3);
          bool f2 = true;
          for (int j = 0; j < n; j++) {
            if (a[j].x == x5 && a[j].y == y5) {
              f2 = false;
              break;
            }
          }
          if (f2 == true)
            continue;
          int sum2 = ((x2 - x5) * (y4 - y1));
          sum2 -= ((x3 * y3) * 2);
          sum = max(sum, sum2);
        }
      }
    }
    cout << sum << endl;
  }
}
Problem p00441 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <map>
#include <set>
#include <stdio.h>
#include <string.h>
using namespace std;
int main() {
  while (1) {
    int n, max = 0;
    int points[3000][2];
    set<pair<int, int>> fields;

    scanf("%d", &n);
    if (n == 0) {
      return 0;
    }
    for (int i = 0; i < n; i++) {
      int xi, yi;
      scanf("%d%d", &xi, &yi);
      points[i][0] = xi;
      points[i][1] = yi;
      fields.insert(make_pair(xi, yi));
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i == j)
          continue;
        int xdis = points[i][0] - points[j][0];
        int ydis = points[i][1] - points[j][1];
        if (points[j][0] + ydis < 0 || points[j][0] + ydis > 5000)
          continue;
        if (points[j][1] - xdis < 0 || points[j][1] - xdis > 5000)
          continue;
        if (points[i][0] + ydis < 0 || points[i][0] + ydis > 5000)
          continue;
        if (points[i][1] - xdis < 0 || points[i][1] - xdis > 5000)
          continue;
        if (fields.find(make_pair(points[j][0] + ydis, points[j][1] - xdis)) ==
            fields.end())
          continue;
        if (fields.find(make_pair(points[i][0] + ydis, points[i][1] - xdis)) ==
            fields.end())
          continue;
        if (max < xdis * xdis + ydis * ydis) {
          max = xdis * xdis + ydis * ydis;
        }
      }
    }
    printf("%d\\n", max);
  }
}

Error: MLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#define max(a, b) (a > b ? a : b)
using namespace std;
vector<pair<int, int>> points;
vector<int> table[5001];
bool Check(int x, int y) {
  return (0 <= x && x <= 5000 && 0 <= y && y <= 5000) ? (bool)table[x][y]
                                                      : false;
}
int main() {
  int a;
  while (scanf("%d", &a), a) {
    memset(table, 0, sizeof(table));
    points.clear();
    for (int i = 0; i <= 5000; i++) {
      for (int j = 0; j <= 5000; j++)
        table[i].push_back(0);
    }
    while (a--) {
      int j, k;
      scanf("%d%d", &j, &k);
      points.push_back(make_pair(j, k));
      table[j][k] = 1;
    }
    int res = 0;
    for (int i = 0; (unsigned)i < points.size(); i++) {
      for (int j = 0; (unsigned)j < points.size(); j++) {
        if (i == j)
          continue;
        int x1 = points[i].first, x2 = points[j].first, y1 = points[i].second,
            y2 = points[j].second;
        int dx = x1 - x2, dy = y1 - y2;
        if (Check(x1 + dy, y1 - dx) && Check(x2 - dy, y2 + dx) ||
            Check(x1 - dy, y1 + dx) && Check(x2 + dy, y2 - dx)) {
          res = max(res, dx * dx + dy * dy);
        }
      }
    }
    printf("%d\\n", res);
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Runtime Error

//
//  main.cpp

#include <iostream>
#include <vector>
using namespace std;

int main() {
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    vector<pair<int, int>> hashira;
    bool check[5001][5001];
    for (int i = 0; i < 5001; i++) {
      for (int j = 0; j < 5001; j++) {
        check[i][j] = false;
      }
    }
    for (int i = 0; i < n; i++) {
      int a, b;
      cin >> a >> b;
      check[a][b] = true;
      hashira.push_back(make_pair(a, b));
    }
    int answer = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        int x = hashira[j].first - hashira[i].first;
        int y = hashira[j].second - hashira[i].second;
        if (hashira[i].first - y > 5000 || hashira[i].second + x > 5000 ||
            hashira[i].first - y + x > 5000 ||
            hashira[i].second + y + x > 5000 || hashira[i].first - y < 0 ||
            hashira[i].second + x < 0 || hashira[i].first - y + x < 0 ||
            hashira[i].second + y + x < 0) {
          continue;
        }

        if (check[hashira[i].first - y][hashira[i].second + x] &&
            check[hashira[i].first - y + x][hashira[i].second + y + x]) {
          answer = max(answer, x * x + y * y);
        }
      }
    }
    cout << answer << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

//
//  main.cpp

#include <iostream>
#include <vector>
using namespace std;

int main() {
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    vector<pair<int, int>> hashira;
    bool check[5001][5001];
    for (int i = 0; i < 5001; i++) {
      for (int j = 0; j < 5001; j++) {
        check[i][j] = false;
      }
    }
    for (int i = 0; i < n; i++) {
      int a, b;
      cin >> a >> b;
      check[a][b] = true;
      hashira.push_back(make_pair(a, b));
    }
    int answer = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        int x = hashira[j].first - hashira[i].first;
        int y = hashira[j].second - hashira[i].second;
        if (check[hashira[i].first - y][hashira[i].second + x] &&
            check[hashira[i].first - y + x][hashira[i].second + y + x]) {
          answer = max(answer, x * x + y * y);
        }
      }
    }
    cout << answer << endl;
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Runtime Error

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

#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX / 3

#define MAX_N 1000

int n;
int x[3003], y[3003];
char aru[5555][5555];

int main() {
  cin.sync_with_stdio(false);
  while (1) {
    memset(aru, 0, sizeof(aru));
    cin >> n;
    if (n == 0)
      break;
    rep(i, n) {
      cin >> x[i] >> y[i];
      aru[x[i]][y[i]] = true;
    }
    int res = 0;
    rep(i, n) rep(j, i) {
      int x3 = x[i] + y[i] - y[j];
      int y3 = y[i] + x[j] - x[i];
      int x4 = x[j] + y[i] - y[j];
      int y4 = y[j] + x[j] - x[i];
      int dx = x[i] - x[j], dy = y[i] - y[j];
      if (x3 >= 0 && y3 >= 0 && x4 >= 0 && y4 >= 0 && x3 <= 5000 &&
          y3 <= 5000 && x4 <= 5000 && y4 <= 5000 && aru[x3][y3] &&
          aru[x4][y4]) {
        maxch(res, dx * dx + dy * dy);
      }
    }
    cout << res << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX / 3

#define MAX_N 1000

int n;
int x[3003], y[3003];
char aru[5005][5005];

int main() {
  cin.sync_with_stdio(false);
  while (1) {
    memset(aru, 0, sizeof(aru));
    cin >> n;
    if (n == 0)
      break;
    rep(i, n) {
      cin >> x[i] >> y[i];
      aru[x[i]][y[i]] = true;
    }
    int res = 0;
    rep(i, n) rep(j, i) {
      int x3 = x[i] + y[i] - y[j];
      int y3 = y[i] + x[j] - x[i];
      int x4 = x[j] + y[i] - y[j];
      int y4 = y[j] + x[j] - x[i];
      int dx = x[i] - x[j], dy = y[i] - y[j];
      if (aru[x3][y3] && aru[x4][y4]) {
        maxch(res, dx * dx + dy * dy);
      }
    }
    cout << res << endl;
  }
  return 0;
}
Problem p00441 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
bool exist[5001][5001];

inline bool check(int x, int y) {
  if (x < 0 || y < 0 || x > 5000 || y > 5000)
    return false;
  return exist[x][y];
}

int main() {
  int n;
  while (cin >> n, n) {
    memset(exist, 0, sizeof(exist));
    vector<int> x(n), y(n);

    for (int i = 0; i < n; i++) {
      cin >> x[i] >> y[i];
      exist[x[i]][y[i]] = 1;
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        int dx = x[i] - x[j], dy = y[i] - y[j];

        if (check(x[i] + dy, y[i] - dx) && check(x[j] + dy, y[j] - dx)) {
          ans = max(ans, dx * dx + dy * dy);
        }
        if (check(x[i] - dy, y[i] + dx) && check(x[j] - dy, y[j] + dx)) {
          ans = max(ans, dx * dx + dy * dy);
        }
      }
    }
    cout << ans << endl;
  }
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int exist[5001][5001];

inline bool check(int x, int y) {
  if (x < 0 || y < 0 || x > 5000 || y > 5000)
    return false;
  return exist[x][y];
}

int main() {
  int n;
  while (cin >> n, n) {
    memset(exist, 0, sizeof(exist));
    vector<int> x(n), y(n);

    for (int i = 0; i < n; i++) {
      cin >> x[i] >> y[i];
      exist[x[i]][y[i]] = 1;
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        int dx = x[i] - x[j], dy = y[i] - y[j];

        if (check(x[i] + dy, y[i] - dx) && check(x[j] + dy, y[j] - dx)) {
          ans = max(ans, dx * dx + dy * dy);
        }
        if (check(x[i] - dy, y[i] + dx) && check(x[j] - dy, y[j] + dx)) {
          ans = max(ans, dx * dx + dy * dy);
        }
      }
    }
    cout << ans << endl;
  }
}
Problem p00441 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
using namespace std;

#define N 3000
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)

typedef pair<int, int> P;

int main() {
  int n, x, y, ans;
  set<P> v;
  while (1) {
    cin >> n;
    if (!n)
      break;
    v.clear();
    for (int i = 0; i < n; ++i) {
      cin >> x >> y;
      v.insert(P(x, y));
    }
    ans = 0;
    set<P>::iterator it, it2;
    for (it = v.begin(); it != v.end(); ++it) {
      for (it2 = it, ++it2; it2 != v.end(); ++it2) {
        int vx = (*it2).first - (*it).first, vy = (*it2).second - (*it).second;
        if (vx * vx + vy * vy <= ans)
          continue;
        if (v.find(P((*it).first + vy, (*it).second - vx)) != v.end() &&
            v.find(P((*it).first + vx + vy, (*it).second + vy - vx)) !=
                v.end()) {
          ans = vx * vx + vy * vy;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

#define N 3000
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)

typedef pair<int, int> P;

int main() {
  int n, x, y, ans;
  vector<P> v;
  while (1) {
    cin >> n;
    if (!n)
      break;
    v.clear();
    for (int i = 0; i < n; ++i) {
      cin >> x >> y;
      v.push_back(P(x, y));
    }
    ans = 0;
    sort(v.begin(), v.end());
    vector<P>::iterator it = v.begin(), it2;
    for (int i = 0; i < n; ++i, ++it) {
      it2 = it + 1;
      for (int j = i + 1; j < n; ++j, ++it2) {
        int vx = v[j].first - v[i].first, vy = v[j].second - v[i].second;
        if (vy >= 0) {
          if (find(it2, v.end(), P(v[i].first + vy, v[i].second - vx)) !=
                  v.end() &&
              find(it2, v.end(),
                   P(v[i].first + vx + vy, v[i].second + vy - vx)) != v.end()) {
            int S = vx * vx + vy * vy;
            ans = max(ans, S);
          }
        }
        if (vy <= 0) {
          if (find(it2, v.end(), P(v[i].first - vy, v[i].second + vx)) !=
                  v.end() &&
              find(it2, v.end(),
                   P(v[i].first + vx - vy, v[i].second + vy + vx)) != v.end()) {
            int S = vx * vx + vy * vy;
            ans = max(ans, S);
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00442 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

struct Edge {
  int src, dst;
};

const int MAX = 5010;
bool exist = false;

vector<int> topological_sort(int n, const vector<Edge> &graph) {
  int inEdge[MAX];
  bool come[MAX];
  vector<int> node(n);
  vector<int> order;
  queue<int> Q;

  memset(inEdge, 0, sizeof(inEdge));
  memset(come, false, sizeof(come));

  for (int i = 0; i < n; i++)
    node[i] = i + 1;

  for (int i = 0; i < (int)graph.size(); i++)
    inEdge[graph[i].dst]++;
  for (int i = 0; i < (int)node.size(); i++)
    if (inEdge[node[i]] == 0)
      Q.push(node[i]);

  while (!Q.empty()) {
    if (Q.size() >= 2)
      exist = true;

    const int now = Q.front();
    Q.pop();

    if (come[now])
      continue;
    come[now] = true;

    order.push_back(now);
    for (int i = 0; i < (int)graph.size(); i++)
      if (graph[i].src == now)
        inEdge[graph[i].dst]--;
    for (int i = 0; i < (int)node.size(); i++)
      if (inEdge[node[i]] == 0 && !come[node[i]])
        Q.push(node[i]);
  }
  return order;
}

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<Edge> G(m);
  for (int i = 0; i < m; i++)
    cin >> G[i].src >> G[i].dst;
  vector<int> ans = topological_sort(n, G);
  for (int i = 0; i < (int)ans.size(); i++)
    cout << ans[i] << endl;
  cout << (exist ? 1 : 0) << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

struct Edge {
  int src, dst;
};

const int MAX = 5010;
bool exist = false;

vector<int> topological_sort(int n, const vector<Edge> &graph) {
  int inEdge[MAX];
  bool come[MAX];
  vector<int> node(n);
  vector<int> order;
  queue<int> Q;

  memset(inEdge, 0, sizeof(inEdge));
  memset(come, false, sizeof(come));

  for (int i = 0; i < n; i++)
    node[i] = i + 1;

  for (int i = 0; i < (int)graph.size(); i++)
    inEdge[graph[i].dst]++;
  for (int i = 0; i < (int)node.size(); i++)
    if (inEdge[node[i]] == 0)
      Q.push(node[i]);

  while (!Q.empty()) {
    if (Q.size() >= 2)
      exist = true;

    const int now = Q.front();
    Q.pop();

    if (come[now])
      continue;
    come[now] = true;

    order.push_back(now);
    for (int i = 0; i < (int)graph.size(); i++)
      if (graph[i].src == now)
        inEdge[graph[i].dst]--;
    for (int i = 0; i < (int)node.size(); i++)
      if (inEdge[node[i]] == 0 && !come[node[i]])
        Q.push(node[i]);
  }
  return order;
}

using namespace std;

int main() {
  int n, m;
  vector<Edge> G(m);
  cin >> n >> m;
  for (int i = 0; i < m; i++)
    cin >> G[i].src >> G[i].dst;
  vector<int> ans = topological_sort(n, G);
  for (int i = 0; i < (int)ans.size(); i++)
    cout << ans[i] << endl;
  cout << (exist ? 1 : 0) << endl;
  return 0;
}