Problem p03006 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
          Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n;
vector<p> xv;
vector<p> sub;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    xv.push_back(make_pair(x, y));
  }
  sort(xv.begin(), xv.end());
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      sub.push_back(
          make_pair((xv[j].first - xv[i].first), xv[j].second - xv[i].second));
    }
  }
  sort(sub.begin(), sub.end());
  int anssub = 0;
  int count = 0;
  for (int i = 0; i < sub.size() - 1; i++) {
    if (sub[i].first == sub[i + 1].first &&
        sub[i].second == sub[i + 1].second) {
      count++;
    } else {
      anssub = max(anssub, count);
      count = 0;
    }
  }
  cout << n - anssub - 1 << "\n";
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
          Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n;
vector<p> xv;
vector<p> sub;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    xv.push_back(make_pair(x, y));
  }
  if (n == 1) {
    cout << 1 << "\n";
    return 0;
  }
  sort(xv.begin(), xv.end());
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      sub.push_back(
          make_pair((xv[j].first - xv[i].first), xv[j].second - xv[i].second));
    }
  }
  sort(sub.begin(), sub.end());
  int anssub = 0;
  int count = 0;
  for (int i = 0; i < sub.size() - 1; i++) {
    if (sub[i].first == sub[i + 1].first &&
        sub[i].second == sub[i + 1].second) {
      count++;
    } else {
      anssub = max(anssub, count);
      count = 0;
    }
  }
  cout << n - anssub - 1 << "\n";
}