Problem p03006 (C++)

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

#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define ll long long
#define all(v) v.begin(), v.end()

#define si set<int>
#define sl set<long long>

#define pair(x, y) pair<x, y>

#define frt(i, a, b) for (int i = a; i < b; i++)
#define fre(i, a, b) for (int i = a; i <= b; i++)
#define rew(i, a, b) for (int i = a; i >= b; i--)

#define mod %
#define pow ^

#define FIO                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define test if (TEST == 1)

#define left (2 * idx) + 1
#define right (2 * idx) + 2

#define INF 1000000000000000000
#define MOD (ll)(1e9 + 7)
#define N 7001

ll powerf(ll a, ll b, ll c) {
  ll ans = 1;

  while (b > 0) {
    if (b & 1) {
      ans = (ans * a) % c;
    }
    b = b >> 1;
    a = (a * a) % c;
  }

  return ans;
}

int main() {

  FIO int TEST = 0;
  int t = 1;

  while (t--) {
    int n;
    cin >> n;

    vector<pair(int, int)> v;
    fre(i, 1, n) {
      int x, y;
      cin >> x >> y;
      v.pb({x, y});
    }

    set<pair<int, pair<int, int>>> s;
    map<pair<int, int>, int> m;

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (j == i)
          continue;

        int d_x = v[i].first - v[j].first;
        int d_y = v[i].second - v[j].second;

        pair<int, int> d = {d_x, d_y};

        if (m[d] == 0) {
          m[d] = 1;
          s.insert({m[d], d});
        } else {
          s.erase({m[d], d});
          m[d] += 1;
          s.insert({m[d], d});
        }
      }
    }
    pair<int, pair<int, int>> d = *s.rbegin();
    // cout << d.first << " : " << d.second.first << " " << d.second.second <<
    // "\n";
    cout << n - (*s.rbegin()).first << "\n";
  }
}


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

#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define ll long long
#define all(v) v.begin(), v.end()

#define si set<int>
#define sl set<long long>

#define pair(x, y) pair<x, y>

#define frt(i, a, b) for (int i = a; i < b; i++)
#define fre(i, a, b) for (int i = a; i <= b; i++)
#define rew(i, a, b) for (int i = a; i >= b; i--)

#define mod %
#define pow ^

#define FIO                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define test if (TEST == 1)

#define left (2 * idx) + 1
#define right (2 * idx) + 2

#define INF 1000000000000000000
#define MOD (ll)(1e9 + 7)
#define N 7001

ll powerf(ll a, ll b, ll c) {
  ll ans = 1;

  while (b > 0) {
    if (b & 1) {
      ans = (ans * a) % c;
    }
    b = b >> 1;
    a = (a * a) % c;
  }

  return ans;
}

int main() {

  FIO int TEST = 0;
  int t = 1;

  while (t--) {
    int n;
    cin >> n;
    if (n == 1) {
      cout << 1 << "\n";
      return 0;
    }
    vector<pair(int, int)> v;
    fre(i, 1, n) {
      int x, y;
      cin >> x >> y;
      v.pb({x, y});
    }

    set<pair<int, pair<int, int>>> s;
    map<pair<int, int>, int> m;

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (j == i)
          continue;

        int d_x = v[i].first - v[j].first;
        int d_y = v[i].second - v[j].second;

        pair<int, int> d = {d_x, d_y};

        if (m[d] == 0) {
          m[d] = 1;
          s.insert({m[d], d});
        } else {
          s.erase({m[d], d});
          m[d] += 1;
          s.insert({m[d], d});
        }
      }
    }
    pair<int, pair<int, int>> d = *s.rbegin();
    // cout << d.first << " : " << d.second.first << " " << d.second.second <<
    // "\n";
    cout << n - (*s.rbegin()).first << "\n";
  }
}