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

#include <algorithm>
#include <iostream>
#include <stdio.h>

using namespace std;

class Heap {
public:
  Heap() {
    array = new int[2000000];
    n = 0;
  }
  void insert(int data) {
    array[n] = data;
    int tmp = n;
    while (tmp != 0 && array[tmp] > array[(tmp - 1) / 2]) {
      std::swap(array[tmp], array[(tmp - 1) / 2]);
      tmp = (tmp - 1) / 2;
    }
    n++;
  }
  void max_heapify(int *array, int start, int end) {
    int dad = start;
    int son = dad * 2 + 1;

    while (son <= end) {
      if (array[son] < array[son + 1] && son + 1 <= end)
        son++;
      if (array[dad] > array[son])
        return;
      else {
        swap(array[son], array[dad]);
        dad = son;
        son = dad * 2 + 1;
      }
    }
  }

  int heap_sort(int *array, int len) {
    int i;
    swap(array[0], array[len - 1]);
    max_heapify(array, 0, len - 2);
    return array[len - 1];
  }
  int extract() {
    int ret = heap_sort(array, n);
    n--;
    return ret;
  }

private:
  int *array;
  int n;
};

int main() {

  int insert_data;
  char buf[22];
  Heap heap;

  while (true) {
    fgets(buf, 22, stdin);
    if (buf[2] == 'd')
      break;
    if (buf[0] == 'i') {
      insert_data = 0;
      for (int i = 0; buf[i] != '\\0'; i++) {
        if (buf[i] >= '0' && buf[i] <= '9') {
          insert_data = 10 * insert_data + (buf[i] - '0');
        }
      }
      heap.insert(insert_data);
    } else {
      printf("%d\\n", heap.extract());
    }
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>

using namespace std;

class Heap {
public:
  Heap() {
    array = new int[2000000];
    n = 0;
  }
  void insert(int data) {
    array[n] = data;
    n++;
  }
  void max_heapify(int *array, int start, int end) {
    int dad = start;
    int son = dad * 2 + 1;

    while (son <= end) {
      if (array[son] < array[son + 1] && son + 1 <= end)
        son++;
      if (array[dad] > array[son])
        return;
      else {
        swap(array[son], array[dad]);
        dad = son;
        son = dad * 2 + 1;
      }
    }
  }

  int heap_sort(int *array, int len) {
    int i;
    for (i = len / 2 - 1; i >= 0; --i) {
      max_heapify(array, i, len - 1);
    }
    swap(array[0], array[len - 1]);
    return array[len - 1];
  }
  int extract() {
    int ret = heap_sort(array, n);
    n--;
    return ret;
  }

private:
  int *array;
  int n;
};

int main() {

  int insert_data;
  char buf[22];
  Heap heap;

  while (true) {
    fgets(buf, 22, stdin);
    if (buf[2] == 'd')
      break;
    if (buf[0] == 'i') {
      insert_data = 0;
      for (int i = 0; buf[i] != '\\0'; i++) {
        if (buf[i] >= '0' && buf[i] <= '9') {
          insert_data = 10 * insert_data + (buf[i] - '0');
        }
      }
      heap.insert(insert_data);
    } else {
      printf("%d\\n", heap.extract());
    }
  }
}
Problem p02289 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <string>

void max_heapify(int *A, int i, int H) {
  int l = 2 * i, r = 2 * i + 1;
  if (l > H && r > H)
    return;
  int maxid = i, x;
  if (l <= H) {
    if (A[l] > A[maxid])
      maxid = l;
  }
  if (r <= H) {
    if (A[r] > A[maxid])
      maxid = r;
  }
  if (maxid == i)
    return;
  x = A[maxid];
  A[maxid] = A[i];
  A[i] = x;
  max_heapify(A, maxid, H);
}

int main() {
  int A[2000001];
  int i, H, key;
  char cmd[8];
  scanf("%d", &H);
  for (i = 1; i <= H; i++)
    scanf("%d", &A[i]);
  H = 0;

  while (1) {
    scanf("%s", cmd);
    if (cmd[2] == 'd')
      break;             // end.
    if (cmd[2] == 't') { // extract.
      if (H == 0)
        continue;
      printf("%d\\n", A[1]);
      A[1] = A[H];
      H--;
      if (H > 0)
        max_heapify(A, 1, H);
    } else {
      scanf("%d", &key); // H++;   // insert key.
      i = ++H;
      while (i > 1) {
        if (A[i / 2] > key)
          break;
        A[i] = A[i / 2];
        i /= 2;
      };
      A[i] = key;
    }
  };
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
#include <string>

void max_heapify(int *A, int i, int H) {
  int l = 2 * i, r = 2 * i + 1;
  if (l > H && r > H)
    return;
  int maxid = i, x;
  if (l <= H) {
    if (A[l] > A[maxid])
      maxid = l;
  }
  if (r <= H) {
    if (A[r] > A[maxid])
      maxid = r;
  }
  if (maxid == i)
    return;
  x = A[maxid];
  A[maxid] = A[i];
  A[i] = x;
  max_heapify(A, maxid, H);
}

int main() {
  int A[2001];
  int i, H, key;
  char cmd[8];
  scanf("%d", &H);
  for (i = 1; i <= H; i++)
    scanf("%d", &A[i]);
  H = 0;

  while (1) {
    scanf("%s", cmd);
    if (cmd[2] == 'd')
      break;             // end.
    if (cmd[2] == 't') { // extract.
      if (H == 0)
        continue;
      printf("%d\\n", A[1]);
      A[1] = A[H];
      H--;
      if (H > 0)
        max_heapify(A, 1, H);
    } else {
      scanf("%d", &key); // H++;   // insert key.
      i = ++H;
      while (i > 1) {
        if (A[i / 2] > key)
          break;
        A[i] = A[i / 2];
        i /= 2;
      };
      A[i] = key;
    }
  };
  return 0;
}
Problem p02289 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <queue>

using namespace std;

int main() {
  char Query[7];
  int Number;

  priority_queue<int> que;

  while (Query[2] != 'd') {
    scanf("%s", Query);

    if (Query[0] == 'i') {
      scanf("%d", &Number);
      que.push(Number);
    }
    if (Query[1] == 'x') {
      printf("%d\\n", que.top());
      que.pop();
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <utility>
#include <vector>

using namespace std;

vector<int> Heap;

void Max_Heapify(int node) {
  int l = node * 2;
  int r = node * 2 + 1;

  int largest;

  if (l < Heap.size()) {
    if (Heap[node] < Heap[l]) {
      largest = l;
    } else {
      largest = node;
    }
  } else {
    largest = node;
  }

  if (r < Heap.size()) {
    if (Heap[largest] < Heap[r]) {
      largest = r;
    }
  }

  if (largest != node) {
    swap(Heap[largest], Heap[node]);

    Max_Heapify(largest);
  }
}

#pragma warning(disable : 4996)

int main() {
  char Query[7];
  int k;
  Heap.push_back(0);

  while (true) {
    scanf("%s", Query);

    if (Query[0] == 'i') {
      scanf("%d", &k);

      Heap.push_back(k);
    } else if (Query[1] == 'x') {
      for (int i = Heap.size() / 2; i >= 1; i--)
        Max_Heapify(i);

      printf("%d\\n", Heap[1]);

      Heap[1] = Heap.back();
      Heap.pop_back();
    } else {
      break;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ios_base::sync_with_stdio(0);

  priority_queue<ll> pq;
  string s;

  while (cin >> s && s != "end") {
    ll x;

    if (s == "insert") {
      cin >> x;

      pq.push(x);

    } else {
      x = pq.top();
      pq.pop();
      printf("%lld\\n", x);
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <queue>
#include <string>
using namespace std;
int main() {
  char com[20];
  priority_queue<int> PQ;
  while (1) {
    scanf("%s", com);
    if (com[0] == 'i') {
      int key;
      scanf("%d", &key);
      PQ.push(key);
    } else if (com[1] = 'x') {
      printf("%d\\n", PQ.top());
      PQ.pop();
    } else if (com[0] == 'e') {
      break;
    }
  }
  return 0;
}
Problem p02289 (C++) — buggy submission, verdict: Time Limit Exceeded

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

void maxHeapify(vector<int> &A, int i, int H) {
  int l = 2 * i;
  int r = 2 * i + 1;
  int largest = i;

  if (l <= H && A[i] < A[l]) {
    largest = l;
  }

  if (r <= H && A[largest] < A[r]) {
    largest = r;
  }

  if (largest != i) {
    swap(A[i], A[largest]);
    maxHeapify(A, largest, H);
  }

  return;
}

int main() {
  int n;
  int H = 0;
  int i;
  vector<int> A;
  string cmd;

  A.push_back(-1);

  cin >> cmd;
  while (cmd != "end") {
    if (cmd == "insert") {
      ++H;
      cin >> n;
      A.push_back(n);
      i = H;
      while (i / 2 != 0) {
        if (A[i] > A[i / 2]) {
          swap(A[i], A[i / 2]);
        }
        i = i / 2;
      }
    } else if (cmd == "extract") {
      cout << A[1] << endl;
      A[1] = A[H];
      --H;
      A.pop_back();
      maxHeapify(A, 1, H);
    }
    cin >> cmd;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

void merge(vector<int> &A, int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  int i, j, k;
  vector<int> L, R;

  L.resize(n1 + 1);
  R.resize(n2 + 1);
  for (i = 0; i < n1; ++i) {
    L[i] = A[left + i];
  }
  for (i = 0; i < n2; ++i) {
    R[i] = A[mid + i];
  }
  L[n1] = 2000000001;
  R[n2] = 2000000001;

  i = j = 0;
  for (k = left; k < right; ++k) {
    A[k] = (L[i] < R[j]) ? L[i++] : R[j++];
  }
  return;
}

void mergeSort(vector<int> &A, int left, int right) {
  if (left + 1 < right) {
    int mid = left + (right - left) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
  return;
}

int main() {
  int n;
  vector<int> A;
  vector<int>::iterator max_itr;
  string cmd, prev_cmd;
  cin >> cmd;
  while (cmd != "end") {
    if (cmd == "insert") {
      cin >> n;
      A.push_back(n);
    } else if (cmd == "extract") {
      if (prev_cmd != "extract")
        mergeSort(A, 0, A.size());
      cout << A.back() << endl;
      A.pop_back();
    }
    prev_cmd = cmd;
    cin >> cmd;
  }
  return 0;
}
Problem p02289 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <queue>
#include <string>
using namespace std;

int main() {
  priority_queue<int> PQ;
  char com[10];
  int key;

  while (1) {
    scanf("%s", com);
    if (com[0] == 'e' && com[1] == 'n')
      break;
    else if (com[0] == 'i') {
      scanf("%d", &key);
      PQ.push(key);
    } else {
      printf("%d\\n", PQ.top());
      PQ.pop();
    }
  }

  return 0;
}


Error: -11

Fixed submission:

#include <cstdio>
#include <queue>
#include <string>
using namespace std;

int main() {
  priority_queue<int> PQ;
  char com[10];
  int key;

  while (1) {
    if (com[0] == 'e' && com[1] == 'n')
      break;
    else if (com[0] == 'i') {
      scanf("%d", &key);
      PQ.push(key);
    } else {
      printf("%d\\n", PQ.top());
      PQ.pop();
    }
  }

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

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define MAX 2000000
#define INFTY (1 << 30)

int H, A[MAX + 1];

int left(int i) { return i * 2; }
int right(int i) { return i * 2 + 1; }

void maxHeapify(int i) {
  int l = left(i);
  int r = right(i);
  int largest;

  if (l <= H && A[l] > A[i])
    largest = l;
  else
    largest = i;
  if (r <= H && A[r] > A[largest])
    largest = r;

  if (largest != i) {
    swap(A[i], A[largest]);
    maxHeapify(largest);
  }
}

int extract() {
  int maxv;
  if (H < 1)
    return -INFTY;
  maxv = A[1];
  A[1] = A[H--];
  maxHeapify(1);
  return maxv;
}

void increaseKey(int i, int key) {
  if (key < A[i])
    return;
  A[i] = key;
  while (i > 1 && A[i / 2] < A[i]) {
    swap(A[i], A[i / 2]);
    i /= 2;
  }
}

void insert(int key) {
  H++;
  A[H] = -INFTY;
  increaseKey(H, key);
}

int main() {
  int key;
  char com[10];

  while (1) {
    scanf("%s", com);
    if (com[0] == 'e' && com[1] == 'n')
      break;
    if (com[0] == 'i') {
      scanf("%d", &key);
      insert(key);
    } else {
      printf("%d\\n", extract());
    }
  }

  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define MAX 200000
#define INFTY (1 << 30)

int H, A[MAX + 1];

int parent(int i) { return i / 2; }
int left(int i) { return i * 2; }
int right(int i) { return i * 2 + 1; }

void maxHeapify(int i) {
  int l = left(i);
  int r = right(i);
  int largest;

  if (l <= H && A[l] > A[i])
    largest = l;
  else
    largest = i;
  if (r <= H && A[r] > A[largest])
    largest = r;

  if (largest != i) {
    swap(A[i], A[largest]);
    maxHeapify(largest);
  }
}

int extract() {
  int maxv;
  if (H < 1)
    return -INFTY;
  maxv = A[1];
  A[1] = A[H--];
  maxHeapify(1);
  return maxv;
}

void increaseKey(int i, int key) {
  if (key < A[i])
    return;
  A[i] = key;
  while (i > 1 && A[i / 2] < A[i]) {
    swap(A[i], A[i / 2]);
    i = i / 2;
  }
}

void insert(int key) {
  H++;
  A[H] = -INFTY;
  increaseKey(H, key);
}

int main() {
  int key;
  char com[10];

  while (1) {
    scanf("%s", com);
    if (com[0] == 'e' && com[1] == 'n')
      break;
    if (com[0] == 'i') {
      scanf("%d", key);
      insert(key);
    } else {
      printf("%d\\n", extract());
    }
  }

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

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <queue>
#include <string>

using namespace std;

#if 0
void maxHeapify(int i)
{
	int		l = i * 2;
	int		r = i * 2 + 1;
	int		largest = i;

	if (l <= H)
	{
		if (A[largest] < A[l])
		{
			largest = l;
		}
	}

	if (r <= H)
	{
		if (A[largest] < A[r])
		{
			largest = r;
		}
	}

	if (largest != i)
	{
		int		temp(A[i]);
		A[i] = A[largest];
		A[largest] = temp;

		maxHeapify(largest);
	}
}
#endif

int main() {
  priority_queue<int> PQ;
  string com;
  int key;

  for (;;) {
    cin >> com;

    if (com == "insert") {
      cin >> key;
      PQ.push(key);
    } else if (com == "extract") {
      cout << PQ.top() << "\\n";
      PQ.pop();
    } else if (com == "end") {
      break;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
// #define		FILE_INPUT_DEFINE
#ifdef FILE_INPUT_DEFINE
#include <fstream>
#endif // FILE_INPUT_DEFINE

#include <cstdio>
#include <cstring>

using namespace std;

int A[2000000];
int H = 1;

void maxHeapify(int i) {
  int l = i * 2;
  int r = i * 2 + 1;
  int largest = i;

  if (l <= H) {
    if (A[largest] < A[l]) {
      largest = l;
    }
  }

  if (r <= H) {
    if (A[largest] < A[r]) {
      largest = r;
    }
  }

  if (largest != i) {
    int temp(A[i]);
    A[i] = A[largest];
    A[largest] = temp;

    maxHeapify(largest);
  }
}

void buildMaxHeap() {
  for (int i = H / 2; i >= 1; --i)
    maxHeapify(i);
}

int main() {
#ifdef FILE_INPUT_DEFINE
  // input from txt
  std::ifstream in(R"(C:\\Temp\\input.txt)");
  std::cin.rdbuf(in.rdbuf());
#endif // FILE_INPUT_DEFINE

  char str[10];

  for (;;) {
    scanf("%s", str);

    if (strcmp(str, "insert") == 0) {
      scanf("%d", &(A[H]));
      ++H;
    } else if (strcmp(str, "extract") == 0) {
      buildMaxHeap();
      printf("%d\\n", A[1]);
      for (int i = 1; i <= H; ++i) {
        A[i] = A[i + 1];
      }
      --H;
    } else if (strcmp(str, "end") == 0) {
      break;
    }
  }

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

#include <algorithm>
#include <iostream>
#include <queue>
#include <string>

int main() {
  std::string str;
  std::priority_queue<int> v;

  std::cin >> str;

  while (str != "end") {
    if (str == "insert") {
      int num;
      std::cin >> num;
      v.push(num);
    } else {
      std::cout << v.top() << std::endl;
      v.pop();
    }
    std::cin >> str;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

int main() {
  std::string str;
  std::vector<int> v;

  std::cin >> str;

  while (str != "end") {
    if (str == "insert") {
      int num;
      std::cin >> num;
      v.push_back(num);
    } else {
      std::vector<int>::iterator it = std::max_element(v.begin(), v.end());
      std::cout << *it << std::endl;
      v.erase(it);
    }
    std::cin >> str;
  }

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

#include <algorithm>
#include <cstdio>
#include <cstring>

const int MAX = 20000000;
const int NIL = -1;
int tree_size = 0;
int tree[MAX + 1];

void maxHeapify(int i) {
  int l = 2 * i;
  int r = 2 * i + 1;

  // Select the node which has the maximum key value
  int maximum_i = i;
  if (l <= tree_size && tree[l] > tree[maximum_i])
    maximum_i = l;
  if (r <= tree_size && tree[r] > tree[maximum_i])
    maximum_i = r;

  if (maximum_i != i) {
    // Call recursively
    std::swap(tree[i], tree[maximum_i]);
    maxHeapify(maximum_i);
  }
}

void buildMaxHeap() {
  for (int i = tree_size / 2; i >= 1; --i)
    maxHeapify(i);
}

void replaceKey(int i, int key) {
  tree[i] = key;
  while (i > 1 && tree[i] > tree[i / 2]) {
    std::swap(tree[i], tree[i / 2]);
    i /= 2;
  }
}

void insertKey(int key) {
  if (tree_size == MAX)
    return;

  ++tree_size;
  tree[tree_size] = key;
  replaceKey(tree_size, key);
}

void extractMax() {
  if (tree_size == 0)
    return;

  printf("%d\\n", tree[1]);

  // Remove root node
  tree[1] = tree[tree_size];
  --tree_size;
  maxHeapify(1);
}

int main() {
  for (int i = 0; i < MAX; ++i) {
    char command[7];
    scanf("%s", command);

    if (command[0] == 'i') {
      int key;
      scanf("%d", &key);
      insertKey(key);
    } else if (command[1] == 'x')
      extractMax();
    else
      break;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>

const int MAX = 20000000;
const int NIL = -1;
int tree_size = 0;
int tree[MAX + 1];

void maxHeapify(int i) {
  int l = 2 * i;
  int r = 2 * i + 1;

  // Select the node which has the maximum key value
  int maximum_i = i;
  if (l <= tree_size && tree[l] > tree[maximum_i])
    maximum_i = l;
  if (r <= tree_size && tree[r] > tree[maximum_i])
    maximum_i = r;

  if (maximum_i != i) {
    // Call recursively
    std::swap(tree[i], tree[maximum_i]);
    maxHeapify(maximum_i);
  }
}

void buildMaxHeap() {
  for (int i = tree_size / 2; i >= 1; --i)
    maxHeapify(i);
}

void insertKey(int key) {
  if (tree_size == MAX)
    return;

  ++tree_size;
  tree[tree_size] = key;
  buildMaxHeap();
}

void extractMax() {
  if (tree_size == 0)
    return;

  printf("%d\\n", tree[1]);

  // Remove root node
  tree[1] = tree[tree_size];
  --tree_size;
  maxHeapify(1);
}

int main() {
  for (int i = 0; i < MAX; ++i) {
    char command[7];
    scanf("%s", command);

    if (command[0] == 'i') {
      int key;
      scanf("%d", &key);
      insertKey(key);
    } else if (command[1] == 'x')
      extractMax();
    else
      break;
  }

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

#include <cmath>
#include <iostream>

using namespace std;

#define EPS 1e-9

#define PI 3.1415926535897932385

double dist(long long x, long long y) { return sqrt(x * x + y * y); }

double angle(int x, int y) { return atan2((double)(y), (double)(x)); }

int main() {
  int x0, y0, x1, y1, x2, y2, q;

  cin >> x0 >> y0 >> x1 >> y1 >> q;

  for (int i = 0; i < q; i++) {
    cin >> x2 >> y2;

    int ax = x1 - x0;
    int ay = y1 - y0;
    int bx = x2 - x0;
    int by = y2 - y0;

    double ad = dist(ax, ay);
    double bd = dist(bx, by);

    double at = angle(ax, ay);
    double bt = angle(bx, by);

    double st = bt - at;

    if (st < -PI - EPS) {
      st += 2 * PI;
    }

    if (st > PI + EPS) {
      st -= 2 * PI;
    }

    double da, db;

    if (bx != 0 || by != 0) {
      if (ax == 0 || bx == 0) {
        da = 1.0 * ax / ay;
        db = 1.0 * bx / by;
      } else {
        da = 1.0 * ay / ax;
        db = 1.0 * by / bx;
      }
    }

    if (bx == 0 && by == 0) {
      cout << "ON_SEGMENT" << endl;
    } else if (-EPS < db - da && db - da < EPS) {
      if (ax * bx < 0 || ay * by < 0) {
        cout << "ONLINE_BACK" << endl;
      } else {
        if (ad < bd) {
          cout << "ONLINE_FRONT" << endl;
        } else {
          cout << "ON_SEGMENT" << endl;
        }
      }
    } else if (st > EPS) {
      cout << "COUNTER_CLOCKWISE" << endl;
    } else {
      cout << "CLOCKWISE" << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;

#define EPS 1e-14

#define PI 3.1415926535897932385

double dist(int x, int y) { return sqrt(x * x + y * y); }

double angle(int x, int y) { return atan2((double)(y), (double)(x)); }

int main() {
  int x0, y0, x1, y1, x2, y2, q;

  cin >> x0 >> y0 >> x1 >> y1 >> q;

  for (int i = 0; i < q; i++) {
    cin >> x2 >> y2;

    int ax = x1 - x0;
    int ay = y1 - y0;
    int bx = x2 - x0;
    int by = y2 - y0;

    double ad = dist(ax, ay);
    double bd = dist(bx, by);

    double at = angle(ax, ay);
    double bt = angle(bx, by);

    double st = bt - at;

    if (st < -PI - EPS) {
      st += 2 * PI;
    }

    if (st > PI + EPS) {
      st -= 2 * PI;
    }

    double da, db;

    if (bx != 0 || by != 0) {
      if (ax == 0 || bx == 0) {
        da = ax / ay;
        db = bx / by;
      } else {
        da = ay / ax;
        db = by / bx;
      }
    }

    if (bx == 0 && by == 0) {
      cout << "ON_SEGMENT" << endl;
    } else if (-EPS < db - da && db - da < EPS) {
      if (ax * bx < 0 || ay * by < 0) {
        cout << "ONLINE_BACK" << endl;
      } else {
        if (ad < bd) {
          cout << "ONLINE_FRONT" << endl;
        } else {
          cout << "ON_SEGMENT" << endl;
        }
      }
    } else if (st > EPS) {
      cout << "COUNTER_CLOCKWISE" << endl;
    } else {
      cout << "CLOCKWISE" << endl;
    }
  }

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

#include <iostream>
using namespace std;
int x[1000], y[1000];
int main() {
  int n, sum;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> x[i] >> y[i];
  for (int i = 0; i < n; i++) {
    sum += (x[i] - x[(i + 1) % n]) * (y[i] + y[(i + 1) % n]);
  }
  cout << sum / 2 << '.' << (sum % 2) * 5 << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
struct Point {
  long double px, py;
};
struct Segment {
  Point p1, p2;
};
Point X[200000];
Point Minus(Point a, Point b) {
  Point G;
  G.px = a.px - b.px;
  G.py = a.py - b.py;
  return G;
}
long double Abs(Point a) { return sqrt(a.px * a.px + a.py * a.py); }
long double dot(const Point &a, const Point &b) {
  return a.px * b.px + a.py * b.py;
}
long double crs(const Point &a, const Point &b) {
  return a.px * b.py - a.py * b.px;
}
long double dst(const Segment &a, const Point &b) {
  return abs(crs(Minus(a.p2, a.p1), Minus(b, a.p1)) / Abs(Minus(a.p2, a.p1)));
}
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> X[i].px >> X[i].py;
  }
  long double SUM = 0.0l;
  for (int i = 1; i < N - 1; i++) {
    Segment A;
    A.p1 = X[i];
    A.p2 = X[i + 1];
    long double DST = dst(A, X[0]);
    Point H;
    H.px = X[i].px - X[i + 1].px;
    H.py = X[i].py - X[i + 1].py;
    long double LEN = Abs(H);
    SUM += DST * LEN / 2;
  }
  cout << fixed << setprecision(5141919) << SUM << endl;
  return 0;
}