Problem p03615 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int mo = 998244353;
int ksm(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1)
      ans = 1ll * ans * a % mo;
    b >>= 1;
    a = 1ll * a * a % mo;
  }
  return ans;
}
struct point {
  int x, y;
  point operator-(const point &a) { return (point){x - a.x, y - a.y}; }
  bool operator==(const point &a) { return x == a.x && y == a.y; }
};

int cross(point a, point b) { return a.x * b.y - a.y * b.x; }

void add(int &x, int y) {
  x += y;
  if (x >= mo)
    x -= mo;
  if (x < 0)
    x += mo;
}

int dot(point a, point b) { return a.x * b.x + a.y * b.y; }
bool cmp(point a, point b) {
  if (a.x == 0 && b.x == 0)
    return a.y < b.y;
  if (a.x == 0)
    return 0;
  if (b.x == 0)
    return 1;
  if (cross(a, b) == 0) {
    if (a.x * b.x < 0)
      return a.x < b.x;
    else
      return dot(a, a) < dot(b, b);
  }
  if (a.x < 0) {
    a.x *= -1;
    a.y *= -1;
  }
  if (b.y < 0) {
    b.x *= -1;
    b.y *= -1;
  }
  return cross(a, b) > 0;
}
point p[210], t[210];
int main() {
  int i, j;
  int n;
  cin >> n;
  for (i = 1; i <= n; i++)
    scanf("%d %d", &p[i].x, &p[i].y);
  int ans = ksm(2, n);
  add(ans, -1 - n);
  int cnt;
  for (i = 1; i <= n; i++) {
    cnt = 0;
    for (j = 1; j <= n; j++) {
      if (j == i)
        continue;
      t[cnt++] = p[j] - p[i];
    }
    sort(t, t + cnt, cmp);
    int last = 0;
    for (j = 1; j < cnt; j++) {
      if (cross(t[j - 1], t[j])) {
        if (t[last].x < 0 || (t[last].x == 0 && t[last].y < 0)) {
          last = j;
          continue;
        }
        add(ans, -(ksm(2, j - last + 1) - (j - last + 1) - 1));
        last = j;
      }
    }
    if (cnt && !(t[last].x < 0 || (t[last].x == 0 && t[last].y < 0))) {
      add(ans, -(ksm(2, j - last + 1) - (j - last + 1) - 1));
    }
  }
  printf("%d\n", ans);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int mo = 998244353;
int ksm(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1)
      ans = 1ll * ans * a % mo;
    b >>= 1;
    a = 1ll * a * a % mo;
  }
  return ans;
}
struct point {
  int x, y;
  point operator-(const point &a) { return (point){x - a.x, y - a.y}; }
  bool operator==(const point &a) { return x == a.x && y == a.y; }
};

int cross(point a, point b) { return a.x * b.y - a.y * b.x; }

void add(int &x, int y) {
  x += y;
  if (x >= mo)
    x -= mo;
  if (x < 0)
    x += mo;
}

int dot(point a, point b) { return a.x * b.x + a.y * b.y; }
bool cmp(point a, point b) {
  if (a.x == 0 && b.x == 0)
    return a.y < b.y;
  if (a.x == 0)
    return 0;
  if (b.x == 0)
    return 1;
  if (cross(a, b) == 0) {
    if (a.x * b.x < 0)
      return a.x < b.x;
    else
      return dot(a, a) < dot(b, b);
  }
  if (a.x < 0) {
    a.x *= -1;
    a.y *= -1;
  }
  if (b.x < 0) {
    b.x *= -1;
    b.y *= -1;
  }
  return cross(a, b) > 0;
}
point p[210], t[210];
int main() {
  int i, j;
  int n;
  cin >> n;
  for (i = 1; i <= n; i++)
    scanf("%d %d", &p[i].x, &p[i].y);
  int ans = ksm(2, n);
  add(ans, -1 - n);
  int cnt;
  for (i = 1; i <= n; i++) {
    cnt = 0;
    for (j = 1; j <= n; j++) {
      if (j == i)
        continue;
      t[cnt++] = p[j] - p[i];
    }
    sort(t, t + cnt, cmp);
    int last = 0;
    for (j = 1; j < cnt; j++) {
      if (cross(t[j - 1], t[j])) {
        if (t[last].x < 0 || (t[last].x == 0 && t[last].y < 0)) {
          last = j;
          continue;
        }
        add(ans, -(ksm(2, j - last + 1) - (j - last + 1) - 1));
        last = j;
      }
    }
    if (cnt && !(t[last].x < 0 || (t[last].x == 0 && t[last].y < 0))) {
      add(ans, -(ksm(2, j - last + 1) - (j - last + 1) - 1));
    }
  }
  printf("%d\n", ans);
  return 0;
}