Problem p00717 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
#include <fstream>
#include <sys/timeb.h>

using namespace std;

#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define replrev(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define reprev(i, n) replrev(i, 0, n)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define all(a) a.begin(), a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<double>> vvd;
typedef vector<vector<P>> vvP;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<P, vector<P>, greater<P>> pqlP;
typedef pair<int, pair<int, int>> Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge>> pqlE;

int main() {
  std::ifstream in("1136-input.txt");
  std::cin.rdbuf(in.rdbuf());

  while (true) {
    int N;
    cin >> N;
    if (N == 0)
      break;
    int n;
    vP L[4];
    cin >> n;
    rep(i, 4) { L[i] = vP(n); }
    rep(i, n) {
      int x, y;
      cin >> x >> y;
      L[0][i] = mp(x, y);
    }
    rep(i, n) {
      repl(j, 1, 4) {
        // [0 -1][x]
        // [1  0][y]
        L[j][i] = mp(L[j - 1][i].second, -L[j - 1][i].first);
      }
    }
    rep(i, N) {
      cin >> n;
      vP l(n);
      rep(i, n) {
        int x, y;
        cin >> x >> y;
        l[i] = mp(x, y);
      }
      if (n != L[0].size())
        continue;
      rep(j, 4) {
        bool flag = true;
        rep(i, n - 1) {
          if (L[j][i + 1].first - L[j][i].first !=
                  l[i + 1].first - l[i].first ||
              L[j][i + 1].second - L[j][i].second !=
                  l[i + 1].second - l[i].second) {
            flag = false;
            break;
          }
        }
        if (flag) {
          cout << i + 1 << endl;
          break;
        }
        flag = true;
        rep(i, n - 1) {
          if (L[j][n - 2 - i].first - L[j][n - 1 - i].first !=
                  l[i + 1].first - l[i].first ||
              L[j][n - 2 - i].second - L[j][n - 1 - i].second !=
                  l[i + 1].second - l[i].second) {
            flag = false;
            break;
          }
        }
        if (flag) {
          cout << i + 1 << endl;
          break;
        }
      }
    }
    cout << "+++++" << endl;
  }

  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
#include <fstream>
#include <sys/timeb.h>

using namespace std;

#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define replrev(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define reprev(i, n) replrev(i, 0, n)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define all(a) a.begin(), a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<double>> vvd;
typedef vector<vector<P>> vvP;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<P, vector<P>, greater<P>> pqlP;
typedef pair<int, pair<int, int>> Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge>> pqlE;

int main() {
  while (true) {
    int N;
    cin >> N;
    if (N == 0)
      break;
    int n;
    vP L[4];
    cin >> n;
    rep(i, 4) { L[i] = vP(n); }
    rep(i, n) {
      int x, y;
      cin >> x >> y;
      L[0][i] = mp(x, y);
    }
    rep(i, n) {
      repl(j, 1, 4) {
        // [0 -1][x]
        // [1  0][y]
        L[j][i] = mp(L[j - 1][i].second, -L[j - 1][i].first);
      }
    }
    rep(i, N) {
      cin >> n;
      vP l(n);
      rep(i, n) {
        int x, y;
        cin >> x >> y;
        l[i] = mp(x, y);
      }
      if (n != L[0].size())
        continue;
      rep(j, 4) {
        bool flag = true;
        rep(i, n - 1) {
          if (L[j][i + 1].first - L[j][i].first !=
                  l[i + 1].first - l[i].first ||
              L[j][i + 1].second - L[j][i].second !=
                  l[i + 1].second - l[i].second) {
            flag = false;
            break;
          }
        }
        if (flag) {
          cout << i + 1 << endl;
          break;
        }
        flag = true;
        rep(i, n - 1) {
          if (L[j][n - 2 - i].first - L[j][n - 1 - i].first !=
                  l[i + 1].first - l[i].first ||
              L[j][n - 2 - i].second - L[j][n - 1 - i].second !=
                  l[i + 1].second - l[i].second) {
            flag = false;
            break;
          }
        }
        if (flag) {
          cout << i + 1 << endl;
          break;
        }
      }
    }
    cout << "+++++" << endl;
  }

  return 0;
}