prithivMLmods/Coder-Stat huggingface dataset:
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <typename T> string tost(const T &n) {
  ostringstream stm;
  stm << n;
  return stm.str();
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int const INF = 1001001001;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;
  vi sx(N), sy(N), cx(N), cy(N);
  rep(i, N) cin >> sx[i] >> sy[i];
  rep(j, M) cin >> cx[j] >> cy[j];

  rep(i, N) {
    int cur = 1 << 30;
    int pres = -1;
    rep(j, M) {
      // chminを「最小値を更新したら」bool値を返す設定が生きる
      if (chmin(cur, abs(sx[i] - cx[j]) + abs(sy[i] - cy[j])))
        pres = j;
    }
    cout << pres + 1 << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <typename T> string tost(const T &n) {
  ostringstream stm;
  stm << n;
  return stm.str();
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int const INF = 1001001001;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;
  vi sx(N), sy(N), cx(M), cy(M);
  rep(i, N) cin >> sx[i] >> sy[i];
  rep(j, M) cin >> cx[j] >> cy[j];

  rep(i, N) {
    int cur = 1 << 30;
    int pres = -1;
    rep(j, M) {
      // chminを「最小値を更新したら」bool値を返す設定が生きる
      if (chmin(cur, abs(sx[i] - cx[j]) + abs(sy[i] - cy[j])))
        pres = j;
    }
    cout << pres + 1 << endl;
  }
  return 0;
}
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<long long int> a(N, 0);
  vector<long long int> b(N, 0);
  rep(i, N) cin >> a[i] >> b[i];
  vector<long long int> c(N, 0);
  vector<long long int> d(N, 0);
  rep(i, M) cin >> c[i] >> d[i];

  rep(i, M) cerr << d[i] << endl;
  rep(i, N) {
    int check = 1;
    long long int max = INT_MAX;
    rep(j, M) {
      long long int e = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if (max > e) {
        max = e;
        check = j + 1;
      }
    }
    cout << check << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<long long int> a(N, 0);
  vector<long long int> b(N, 0);
  rep(i, N) cin >> a[i] >> b[i];
  vector<long long int> c(M, 0);
  vector<long long int> d(M, 0);
  rep(i, M) cin >> c[i] >> d[i];

  rep(i, M) cerr << d[i] << endl;
  rep(i, N) {
    int check = 1;
    long long int max = INT_MAX;
    rep(j, M) {
      long long int e = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if (max > e) {
        max = e;
        check = j + 1;
      }
    }
    cout << check << endl;
  }
}
Problem p03774 (Python)

Buggy submission (status: Runtime Error):
N, M = map(int, input().strip().split())

a_b = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    a_b.append(array)

c_d = []
for i in range(M):
    array = list(map(int, input().strip().split()))
    c_d.append(array)

for n in range(N):
    mind = 200000001
    for m in range(M):
        dist = abs(a_b[n][0] - c_d[m][0]) + abs(a_b[n][1] - c_d[m][1])
        if dist < mind:
            mind = dist
            checkpoint = m + 1
    print(checkpoint)


Fixed submission:
N, M = map(int, input().strip().split())

a_b = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    a_b.append(array)

c_d = []
for i in range(M):
    array = list(map(int, input().strip().split()))
    c_d.append(array)

for n in range(N):
    mind = 1000000007
    for m in range(M):
        dist = abs(a_b[n][0] - c_d[m][0]) + abs(a_b[n][1] - c_d[m][1])
        if dist < mind:
            mind = dist
            checkpoint = m + 1
    print(checkpoint)
Problem p03774 (C++)

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

const double pi = 2 * acos(0.0);
const double eps = 1e-8;

#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) REP(i, 0, n)
#define INF (1 << 29)
#define INFLL (1LL << 62)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;

  vector<pll> st(n), cp(n);

  rep(i, n) { cin >> st[i].first >> st[i].second; }

  rep(i, m) { cin >> cp[i].first >> cp[i].second; }

  for (auto s : st) {
    ll id = 0, mind = INFLL;
    rep(i, m) {
      ll d = abs(cp[i].first - s.first) + abs(cp[i].second - s.second);
      if (d < mind) {
        mind = d;
        id = i;
      }
    }
    cout << id + 1 << endl;
  }
  return 0;
}

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

const double pi = 2 * acos(0.0);
const double eps = 1e-8;

#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) REP(i, 0, n)
#define INF (1 << 29)
#define INFLL (1LL << 62)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;

  vector<pll> st(n), cp(m);

  rep(i, n) { cin >> st[i].first >> st[i].second; }

  rep(i, m) { cin >> cp[i].first >> cp[i].second; }

  for (auto s : st) {
    ll id = 0, mind = INFLL;
    rep(i, m) {
      ll d = abs(cp[i].first - s.first) + abs(cp[i].second - s.second);
      if (d < mind) {
        mind = d;
        id = i;
      }
    }
    cout << id + 1 << endl;
  }
  return 0;
}
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<pii> St(n), M(n);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    St[i] = (pii(a, b));
  }
  rep(i, m) {
    int c, d;
    cin >> c >> d;
    M[i] = (pii(c, d));
  }

  rep(i, n) {
    int res = -1, minD = INF;
    rep(j, m) {
      int x = abs(M[j].first - St[i].first);
      int y = abs(M[j].second - St[i].second);
      if (minD > x + y) {
        minD = x + y;
        res = j + 1;
      }
    }
    cout << res << ln;
  }
}


Fixed submission:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<pii> St(n), M(m);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    St[i] = (pii(a, b));
  }
  rep(i, m) {
    int c, d;
    cin >> c >> d;
    M[i] = (pii(c, d));
  }

  rep(i, n) {
    int res = -1, minD = INF;
    rep(j, m) {
      int x = abs(M[j].first - St[i].first);
      int y = abs(M[j].second - St[i].second);
      if (minD > x + y) {
        minD = x + y;
        res = j + 1;
      }
    }
    cout << res << ln;
  }
}
Problem p03774 (C++)

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> p(N);
  vector<pair<int, int>> ch(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i].first >> p[i].second;
  }
  for (int i = 0; i < M; i++) {
    cin >> ch[i].first >> ch[i].second;
  }
  for (int i = 0; i < N; i++) {
    vector<pair<int, int>> D(M); // 各学生とチェックポイントの距離を入れる配列
    for (int j = 0; j < M; j++) {
      D[j].first =
          abs(p[i].first - ch[j].first) + abs(p[i].second - ch[j].second);
      D[j].second = j + 1;
    }
    sort(D.begin(), D.end());
    cout << D[0].second << endl;
    D.clear();
  }
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> p(N);
  vector<pair<int, int>> ch(M);
  for (int i = 0; i < N; i++) {
    cin >> p[i].first >> p[i].second;
  }
  for (int i = 0; i < M; i++) {
    cin >> ch[i].first >> ch[i].second;
  }
  for (int i = 0; i < N; i++) {
    vector<pair<int, int>> D(M); // 各学生とチェックポイントの距離を入れる配列
    for (int j = 0; j < M; j++) {
      D[j].first =
          abs(p[i].first - ch[j].first) + abs(p[i].second - ch[j].second);
      D[j].second = j + 1;
    }
    sort(D.begin(), D.end());
    cout << D[0].second << endl;
    D.clear();
  }
}
Problem p03774 (C++)

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> v1(N, vector<int>(2));
  vector<vector<int>> v2(M, vector<int>(2));
  for (int i = 0; i < N; i++) {
    cin >> v1.at(i).at(0) >> v1.at(i).at(1);
  }
  for (int j = 0; j < N; j++) {
    cin >> v2.at(j).at(0) >> v2.at(j).at(1);
  }
  for (int i = 0; i < N; i++) {
    int ans, count = 1000000000;
    for (int j = 0; j < M; j++) {
      int count2;
      int x = v1.at(i).at(0) - v2.at(j).at(0),
          y = v1.at(i).at(1) - v2.at(j).at(1);
      if (x < 0) {
        x *= -1;
      }
      if (y < 0) {
        y *= -1;
      }
      count2 = x + y;
      if (count2 < count) {
        count = count2;
        ans = j + 1;
      }
    }
    cout << ans << endl;
  }
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> v1(N, vector<int>(2));
  vector<vector<int>> v2(M, vector<int>(2));
  for (int i = 0; i < N; i++) {
    cin >> v1.at(i).at(0) >> v1.at(i).at(1);
  }
  for (int j = 0; j < M; j++) {
    cin >> v2.at(j).at(0) >> v2.at(j).at(1);
  }
  for (int i = 0; i < N; i++) {
    int ans, count = 1000000000;
    for (int j = 0; j < M; j++) {
      int count2;
      int x = v1.at(i).at(0) - v2.at(j).at(0),
          y = v1.at(i).at(1) - v2.at(j).at(1);
      if (x < 0) {
        x *= -1;
      }
      if (y < 0) {
        y *= -1;
      }
      count2 = x + y;
      if (count2 < count) {
        count = count2;
        ans = j + 1;
      }
    }
    cout << ans << endl;
  }
}
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
const ll mod = 1e9 + 7;
#define ALL(x) (x).begin(), (x).end()
#define pow(x, y) modpow(x, y)
#define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define REPS(i, n) for (ll(i) = 1; (i) <= (n); (i)++)
#define RREP(i, n) for (ll(i) = (n - 1); (i) >= 0; (i)--)
#define RREPS(i, n) for (ll(i) = (n); (i) > 0; (i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());

template <class T = int> T in() {
  T x;
  cin >> x;
  return (x);
}

template <class T> inline void chmin(T &a, T b) {
  if (a > b) {
    a = b;
  }
}

template <class T> inline void chmax(T &a, T b) {
  if (a < b) {
    a = b;
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N = in(), M = in();
  vector<pair<int, int>> S(N);
  vector<pair<int, int>> C(N);
  REP(i, N) {
    S[i].F = in();
    S[i].S = in();
  }
  REP(i, M) {
    C[i].F = in();
    C[i].S = in();
  }
  REP(i, N) {
    int dist = INT32_MAX;
    int num = INT32_MAX;
    REP(l, M) {
      if (abs(S[i].F - C[l].F) + abs(S[i].S - C[l].S) < dist) {
        dist = abs(S[i].F - C[l].F) + abs(S[i].S - C[l].S);
        num = l;
      }
    }
    cout << num + 1 << "\n";
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
const ll mod = 1e9 + 7;
#define ALL(x) (x).begin(), (x).end()
#define pow(x, y) modpow(x, y)
#define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define REPS(i, n) for (ll(i) = 1; (i) <= (n); (i)++)
#define RREP(i, n) for (ll(i) = (n - 1); (i) >= 0; (i)--)
#define RREPS(i, n) for (ll(i) = (n); (i) > 0; (i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());

template <class T = int> T in() {
  T x;
  cin >> x;
  return (x);
}

template <class T> inline void chmin(T &a, T b) {
  if (a > b) {
    a = b;
  }
}

template <class T> inline void chmax(T &a, T b) {
  if (a < b) {
    a = b;
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N = in(), M = in();
  vector<pair<int, int>> S(N);
  vector<pair<int, int>> C(M);
  REP(i, N) {
    S[i].F = in();
    S[i].S = in();
  }
  REP(i, M) {
    C[i].F = in();
    C[i].S = in();
  }
  REP(i, N) {
    int dist = INT32_MAX;
    int num = INT32_MAX;
    REP(l, M) {
      if (abs(S[i].F - C[l].F) + abs(S[i].S - C[l].S) < dist) {
        dist = abs(S[i].F - C[l].F) + abs(S[i].S - C[l].S);
        num = l;
      }
    }
    cout << num + 1 << "\n";
  }
}
Problem p03774 (Python)

Buggy submission (status: Runtime Error):
N, M = list(map(int, input().split()))

ab = []
for i in range(N):
    ab.append(list(map(int, input().split())))

cd = []
for i in range(M):
    cd.append(list(map(int, input().split())))

for ab_list in ab:
    min_distance = 200000000
    checkpoint = 0
    for cd_list in cd:
        checkpoint += 1
        distance = abs(ab_list[0] - cd_list[0]) + abs(ab_list[1] - cd_list[1])
        if distance < min_distance:
            min_distance = distance
            ans = checkpoint
    print(ans)


Fixed submission:
N, M = list(map(int, input().split()))

ab = []
for i in range(N):
    ab.append(list(map(int, input().split())))

cd = []
for i in range(M):
    cd.append(list(map(int, input().split())))

for ab_list in ab:
    min_distance = 400000000
    checkpoint = 0
    for cd_list in cd:
        checkpoint += 1
        distance = abs(ab_list[0] - cd_list[0]) + abs(ab_list[1] - cd_list[1])
        if distance < min_distance:
            min_distance = distance
            ans = checkpoint
    print(ans)
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main() {

  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(m);
  vector<int> d(m);
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  for (int i = 0; i < m; i++)
    cin >> a[i] >> b[i];
  for (int i = 0; i < n; i++) {
    int mn = 1000000000;
    int tmp = -1;
    for (int j = 0; j < m; j++) {
      if (mn > abs(a[i] - c[j]) + abs(b[i] - d[j])) {
        mn = abs(a[i] - c[j]) + abs(b[i] - d[j]);
        tmp = j;
      }
    }
    cout << tmp + 1 << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main() {

  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(m);
  vector<int> d(m);
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  for (int i = 0; i < m; i++)
    cin >> c[i] >> d[i];
  for (int i = 0; i < n; i++) {
    int mn = 1000000000;
    int tmp = -1;
    for (int j = 0; j < m; j++) {
      if (mn > abs(a[i] - c[j]) + abs(b[i] - d[j])) {
        mn = abs(a[i] - c[j]) + abs(b[i] - d[j]);
        tmp = j;
      }
    }
    cout << tmp + 1 << endl;
  }

  return 0;
}
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M);
  vector<int> c(M), d(M);
  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> c[i] >> d[i];
  }

  for (int i = 0; i < N; i++) {
    int ans;
    int cnt = 1e9;
    for (int j = M - 1; j >= 0; j--) {
      if (cnt >= abs(a[i] - c[j]) + abs(b[i] - d[j])) {
        ans = j + 1;
        cnt = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N, M;
  cin >> N >> M;
  int a[50], b[50], c[50], d[50];

  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> c[i] >> d[i];
  }

  for (int i = 0; i < N; i++) {
    int ans;
    int cnt = 1e9;
    for (int j = M - 1; j >= 0; j--) {
      if (cnt >= abs(a[i] - c[j]) + abs(b[i] - d[j])) {
        ans = j + 1;
        cnt = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p03774 (C++)

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

typedef long long ll;
ll ss = 1e9 + 7;

int main() {
  int N, M;
  cin >> N >> M;
  vector<ll> a(N + 1), b(N + 1), c(M + 1), d(M + 1);
  for (int i = 1; i <= N; i++)
    cin >> a[i] >> b[i];
  for (int i = 1; i <= M; i++)
    cin >> c[i] >> d[i];
  vector<pair<ll, int>> m[50];
  ll r;

  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      r = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      // cout <<" "<< r << endl;
      m[i].push_back(make_pair(r, j));
    }
    sort(m[i].begin(), m[i].end());
    cout << m[i].front().second << endl;
  }
}

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

typedef long long ll;
ll ss = 1e9 + 7;

int main() {
  int N, M;
  cin >> N >> M;
  vector<ll> a(N + 1), b(N + 1), c(M + 1), d(M + 1);
  for (int i = 1; i <= N; i++)
    cin >> a[i] >> b[i];
  for (int i = 1; i <= M; i++)
    cin >> c[i] >> d[i];
  vector<pair<ll, int>> m[51];
  ll r;

  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      r = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      // cout <<" "<< r << endl;
      m[i].push_back(make_pair(r, j));
    }
    sort(m[i].begin(), m[i].end());
    cout << m[i].front().second << endl;
  }
}
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n, m;
  string s;
  cin >> n >> m;
  vector<pair<int, int>> v(n);
  vector<pair<int, int>> u(n);
  rep(i, n) {
    int x, y;
    cin >> x >> y;
    pair<int, int> p = make_pair(x, y);
    v[i] = p;
  }
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    pair<int, int> p = make_pair(x, y);
    u[i] = p;
  }
  int id = 0;
  rep(i, n) {
    int ans = 1 << 30;
    rep(j, m) {
      if (ans > abs(v[i].first - u[j].first) + abs(v[i].second - u[j].second)) {
        ans = min(ans, abs(v[i].first - u[j].first) +
                           abs(v[i].second - u[j].second));
        id = j;
      }
    }
    cout << id + 1 << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n, m;
  string s;
  cin >> n >> m;
  vector<pair<int, int>> v(n);
  vector<pair<int, int>> u(m);
  rep(i, n) {
    int x, y;
    cin >> x >> y;
    pair<int, int> p = make_pair(x, y);
    v[i] = p;
  }
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    pair<int, int> p = make_pair(x, y);
    u[i] = p;
  }
  int id = 0;
  rep(i, n) {
    int ans = 1 << 30;
    rep(j, m) {
      if (ans > abs(v[i].first - u[j].first) + abs(v[i].second - u[j].second)) {
        ans = min(ans, abs(v[i].first - u[j].first) +
                           abs(v[i].second - u[j].second));
        id = j;
      }
    }
    cout << id + 1 << endl;
  }

  return 0;
}
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  vector<long long> c(n), d(n);
  for (int i = 0; i < m; i++) {
    cin >> c[i] >> d[i];
  }

  vector<int> ans(n, -1);
  for (int i = 0; i < n; i++) {
    long long mind = 999999999;
    for (int j = 0; j < m; j++) {
      long long cur = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if (cur < mind) {
        mind = cur;
        ans[i] = j + 1;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}


Fixed submission:
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<long long> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  vector<long long> c(m), d(m);
  for (int i = 0; i < m; i++) {
    cin >> c[i] >> d[i];
  }

  vector<int> ans(n, -1);
  for (int i = 0; i < n; i++) {
    long long mind = 999999999;
    for (int j = 0; j < m; j++) {
      long long cur = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if (cur < mind) {
        mind = cur;
        ans[i] = j + 1;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
Problem p03774 (C++)

Buggy submission (status: Runtime Error):

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

int dist(int x0, int y0, int x1, int y1) {
  return std::abs(x0 - x1) + std::abs(y0 - y1);
}

int main(void) {
  int N, M;
  std::vector<int> a, b, c, d;

  std::cin >> N;
  std::cin >> M;

  a.resize(N);
  b.resize(N);
  c.resize(N);
  d.resize(N);

  for (int i = 0; i < N; i++) {
    std::cin >> a[i];
    std::cin >> b[i];
  }

  for (int i = 0; i < M; i++) {
    std::cin >> c[i];
    std::cin >> d[i];
  }

  for (int i = 0; i < N; i++) {
    int min_id = -1;
    int min = 0x7fffffff;
    for (int j = 0; j < M; j++) {
      int dt = dist(a[i], b[i], c[j], d[j]);

      if (dt < min) {
        min_id = j;
        min = dt;
      }
    }

    std::cout << (min_id + 1) << std::endl;
  }
}


Fixed submission:

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

int dist(int x0, int y0, int x1, int y1) {
  return std::abs(x0 - x1) + std::abs(y0 - y1);
}

int main(void) {
  int N, M;
  std::vector<int> a, b, c, d;

  std::cin >> N;
  std::cin >> M;

  a.resize(N);
  b.resize(N);
  c.resize(M);
  d.resize(M);

  for (int i = 0; i < N; i++) {
    std::cin >> a[i];
    std::cin >> b[i];
  }

  for (int i = 0; i < M; i++) {
    std::cin >> c[i];
    std::cin >> d[i];
  }

  for (int i = 0; i < N; i++) {
    int min_id = -1;
    int min = 0x7fffffff;
    for (int j = 0; j < M; j++) {
      int dt = dist(a[i], b[i], c[j], d[j]);

      if (dt < min) {
        min_id = j;
        min = dt;
      }
    }

    std::cout << (min_id + 1) << std::endl;
  }
}
Problem p03774 (C++)

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

using namespace std;

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> a(n);
  vector<pair<int, int>> c(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  for (int i = 0; i < m; i++) {
    cin >> c[i].first >> c[i].second;
  }
  for (int i = 0; i < n; i++) {
    int best = 1e9;
    int besti = m;
    for (int j = 0; j < m; j++) {
      int cur = abs(c[j].first - a[i].first) + abs(c[j].second - a[i].second);
      if (cur < best) {
        best = cur;
        besti = j + 1;
      }
    }
    cout << besti << '\n';
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> a(n);
  vector<pair<int, int>> c(m);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }
  for (int i = 0; i < m; i++) {
    cin >> c[i].first >> c[i].second;
  }
  for (int i = 0; i < n; i++) {
    int best = 1e9;
    int besti = m;
    for (int j = 0; j < m; j++) {
      int cur = abs(c[j].first - a[i].first) + abs(c[j].second - a[i].second);
      if (cur < best) {
        best = cur;
        besti = j + 1;
      }
    }
    cout << besti << '\n';
  }

  return 0;
}
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int inf = 1e9;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n), c(n), d(n);
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  for (int i = 0; i < m; i++)
    cin >> c[i] >> d[i];
  for (int i = 0; i < n; i++) {
    int mincost = inf, minidx = -1;
    for (int j = 0; j < m; j++) {
      int dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if (dist < mincost) {
        mincost = dist;
        minidx = j;
      }
    }
    cout << minidx + 1 << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int inf = 1e9;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n), c(m), d(m);
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  for (int i = 0; i < m; i++)
    cin >> c[i] >> d[i];
  for (int i = 0; i < n; i++) {
    int mincost = inf, minidx = -1;
    for (int j = 0; j < m; j++) {
      int dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if (dist < mincost) {
        mincost = dist;
        minidx = j;
      }
    }
    cout << minidx + 1 << endl;
  }
  return 0;
}
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  vector<int> c(n), d(n);
  for (int i = 0; i < m; i++)
    cin >> c[i] >> d[i];

  vector<int> ans(n);
  for (int i = 0; i < n; i++) {
    int nmin = 1e9;
    for (int j = 0; j < m; j++) {
      int d1 = abs(a[i] - c[j]), d2 = abs(b[i] - d[j]);
      if (nmin > d1 + d2) {
        nmin = d1 + d2;
        ans[i] = j + 1;
      }
    }
  }

  for (int i = 0; i < n; i++)
    cout << ans[i] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  vector<int> c(m), d(m);
  for (int i = 0; i < m; i++)
    cin >> c[i] >> d[i];

  vector<int> ans(n);
  for (int i = 0; i < n; i++) {
    int nmin = 1e9;
    for (int j = 0; j < m; j++) {
      int d1 = abs(a[i] - c[j]), d2 = abs(b[i] - d[j]);
      if (nmin > d1 + d2) {
        nmin = d1 + d2;
        ans[i] = j + 1;
      }
    }
  }

  for (int i = 0; i < n; i++)
    cout << ans[i] << endl;
}
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T> void cout_vec(const vector<T> &vec) {
  for (auto itr : vec)
    cout << itr << ' ';
  cout << endl;
}

typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
const ll inf = 1e15;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<P> a(n), b(n);
  rep(i, n) cin >> a[i].fi >> a[i].se;
  rep(i, m) cin >> b[i].fi >> b[i].se;
  rep(i, n) {
    ll cnt = inf;
    ll ans;
    rep(j, m) {
      if (cnt > abs(a[i].fi - b[j].fi) + abs(a[i].se - b[j].se)) {
        ans = j + 1;
        cnt = abs(a[i].fi - b[j].fi) + abs(a[i].se - b[j].se);
      }
    }
    cout << ans << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T> void cout_vec(const vector<T> &vec) {
  for (auto itr : vec)
    cout << itr << ' ';
  cout << endl;
}

typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
const ll inf = 1e15;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<P> a(n), b(m);
  rep(i, n) cin >> a[i].fi >> a[i].se;
  rep(i, m) cin >> b[i].fi >> b[i].se;
  rep(i, n) {
    ll cnt = inf;
    ll ans;
    rep(j, m) {
      if (cnt > abs(a[i].fi - b[j].fi) + abs(a[i].se - b[j].se)) {
        ans = j + 1;
        cnt = abs(a[i].fi - b[j].fi) + abs(a[i].se - b[j].se);
      }
    }
    cout << ans << endl;
  }
}
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
// #include<bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<ll> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vii;
const double pi = 2 * acos(0);

#define pf printf
#define sf scanf
#define pb(a) push_back(a)
#define mp make_pair
#define fi first
#define se second
#define for0(i, n) for (ll i = 0; i < n; i++)
#define for1(i, n) for (ll i = 1; i <= n; i++)
#define forab(i, a, b) for (int i = a; i <= b; i++)
#define lcm(a, b) ((a) * ((b) / gcd(a, b)))
#define sq(a) (a) * (a)
#define nw "\n"
#define abs(x) fabs(x)
#define pcase(z, x) cout << "Case " << z << ": " << x << "\n"
int main() {
  ll n, m;
  cin >> n >> m;
  vi a(n), b(n), c(n), d(n);
  for0(i, n) cin >> a[i] >> b[i];
  for0(i, m) cin >> c[i] >> d[i];

  for0(i, n) {
    ll x, pos, mn = 1000000000;
    for0(j, m) {
      x = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if (x < mn) {
        mn = x;
        pos = j;
      }
    }
    cout << pos + 1 << nw;
  }
  return 0;
}

Fixed submission:
// #include<bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<ll> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vii;
const double pi = 2 * acos(0);

#define pf printf
#define sf scanf
#define pb(a) push_back(a)
#define mp make_pair
#define fi first
#define se second
#define for0(i, n) for (ll i = 0; i < n; i++)
#define for1(i, n) for (ll i = 1; i <= n; i++)
#define forab(i, a, b) for (int i = a; i <= b; i++)
#define lcm(a, b) ((a) * ((b) / gcd(a, b)))
#define sq(a) (a) * (a)
#define nw "\n"
#define abs(x) fabs(x)
#define pcase(z, x) cout << "Case " << z << ": " << x << "\n"
int main() {
  ll n, m;
  cin >> n >> m;
  vi a(n), b(n), c(m), d(m);
  for0(i, n) cin >> a[i] >> b[i];
  for0(i, m) cin >> c[i] >> d[i];

  for0(i, n) {
    ll x, pos, mn = 1000000000;
    for0(j, m) {
      x = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if (x < mn) {
        mn = x;
        pos = j;
      }
    }
    cout << pos + 1 << nw;
  }
  return 0;
}
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
// --https://kenkoooo.com/atcoder/#/table/soma62jp
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {

  long long N, M;
  long long min, cnt;

  cin >> N >> M;

  vector<long long> a(N), b(N);
  vector<long long> c(N), d(M);

  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i];
  }

  for (int i = 0; i < M; i++) {
    cin >> c[i] >> d[i];
  }

  for (int i = 0; i < N; i++) {
    min = 10e8;
    cnt = 0;
    for (int j = 0; j < M; j++) {
      if (min > labs(a[i] - c[j]) + labs(b[i] - d[j])) {
        min = labs(a[i] - c[j]) + labs(b[i] - d[j]);
        cnt = j + 1;
      }
    }
    cout << cnt << endl;
  }

  return 0;
}


Fixed submission:
// --https://kenkoooo.com/atcoder/#/table/soma62jp
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {

  long long N, M;
  long long min, cnt;

  cin >> N >> M;

  vector<long long> a(N), b(N);
  vector<long long> c(M), d(M);

  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i];
  }

  for (int i = 0; i < M; i++) {
    cin >> c[i] >> d[i];
  }

  for (int i = 0; i < N; i++) {
    min = 10e8;
    cnt = 0;
    for (int j = 0; j < M; j++) {
      if (min > labs(a[i] - c[j]) + labs(b[i] - d[j])) {
        min = labs(a[i] - c[j]) + labs(b[i] - d[j]);
        cnt = j + 1;
      }
    }
    cout << cnt << endl;
  }

  return 0;
}
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iomanip>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef long double LD;
typedef pair<LD, LD> PLDLD;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define CLR(a) memset((a), 0, sizeof(a))
#define ALL(a) a.begin(), a.end()

LL INF = 1e15 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  vector<PLL> p(n), q(n);
  REP(i, n) {
    LL a, b;
    cin >> a >> b;
    p[i] = PLL(a, b);
  }
  REP(i, m) {
    LL a, b;
    cin >> a >> b;
    q[i] = PLL(a, b);
  }

  REP(i, n) {
    int ans = 0;
    LL mdis = INF, dis;
    REP(j, m) {
      dis = abs(p[i].first - q[j].first) + abs(p[i].second - q[j].second);
      if (dis < mdis) {
        mdis = dis;
        ans = j;
      }
    }
    cout << ans + 1 << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
#include <iomanip>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef long double LD;
typedef pair<LD, LD> PLDLD;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define CLR(a) memset((a), 0, sizeof(a))
#define ALL(a) a.begin(), a.end()

LL INF = 1e15 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  vector<PLL> p(n), q(m);
  REP(i, n) {
    LL a, b;
    cin >> a >> b;
    p[i] = PLL(a, b);
  }
  REP(i, m) {
    LL a, b;
    cin >> a >> b;
    q[i] = PLL(a, b);
  }

  REP(i, n) {
    int ans = 0;
    LL mdis = INF, dis;
    REP(j, m) {
      dis = abs(p[i].first - q[j].first) + abs(p[i].second - q[j].second);
      if (dis < mdis) {
        mdis = dis;
        ans = j;
      }
    }
    cout << ans + 1 << endl;
  }
}
Problem p03774 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  int ans, a[n], b[n], c[n], d[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cin >> b[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> c[j];
    cin >> d[j];
  }
  for (int p = 0; p < n; p++) {
    int min = INT_MAX;
    for (int q = 0; q < m; q++) {
      int dist = abs(a[p] - c[q]) + abs(b[p] - d[q]);
      if (dist < min) {
        min = dist;
        ans = q;
      }
    }
    cout << ans + 1 << endl;
  }
}


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

int main() {
  int n, m;
  cin >> n >> m;
  int ans, a[n], b[n], c[m], d[m];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cin >> b[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> c[j];
    cin >> d[j];
  }
  for (int p = 0; p < n; p++) {
    int min = INT_MAX;
    for (int q = 0; q < m; q++) {
      int dist = abs(a[p] - c[q]) + abs(b[p] - d[q]);
      if (dist < min) {
        min = dist;
        ans = q;
      }
    }
    cout << ans + 1 << endl;
  }
}
Problem p03774 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
struct Fast {
  Fast() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c) {
  return b / c - (a - 1) / c;
}

void print_binary(long long a) {
  for (int i = 31; i >= 0; i--) {
    cout << (a >> i & 1);
  }
  cout << endl;
}
long long modpow(long long m, long long n) {
  if (n == 0)
    return 1;
  if (n % 2 == 0) {
    long long t = modpow(m, n / 2);
    return t * t;
  } else {
    return modpow(m, n - 1) * m;
  }
}
void yes() {
  cout << "Yes" << endl;
  exit(0);
}
void no() {
  cout << "No" << endl;
  exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

int main() {
  long long n, m;
  cin >> n >> m;
  vector<int> as(n);
  vector<int> bs(n);
  vector<int> cs(n);
  vector<int> ds(n);
  for (int i = 0; i < n; i++) {
    cin >> as[i];
    cin >> bs[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> cs[i];
    cin >> ds[i];
  }
  for (int i = 0; i < n; i++) {
    vector<int> xs;
    long md = 1e10;
    for (int j = 0; j < m; j++) {
      if (md > abs(as[i] - cs[j]) + abs(bs[i] - ds[j])) {
        md = abs(as[i] - cs[j]) + abs(bs[i] - ds[j]);
      }
    }
    for (int j = 0; j < m; j++) {
      if (md == abs(as[i] - cs[j]) + abs(bs[i] - ds[j])) {
        xs.push_back(j);
      }
    }
    sort(xs.begin(), xs.end());
    cout << xs[0] + 1 << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
struct Fast {
  Fast() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c) {
  return b / c - (a - 1) / c;
}

void print_binary(long long a) {
  for (int i = 31; i >= 0; i--) {
    cout << (a >> i & 1);
  }
  cout << endl;
}
long long modpow(long long m, long long n) {
  if (n == 0)
    return 1;
  if (n % 2 == 0) {
    long long t = modpow(m, n / 2);
    return t * t;
  } else {
    return modpow(m, n - 1) * m;
  }
}
void yes() {
  cout << "Yes" << endl;
  exit(0);
}
void no() {
  cout << "No" << endl;
  exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

int main() {
  long long n, m;
  cin >> n >> m;
  vector<int> as(n);
  vector<int> bs(n);
  vector<int> cs(m);
  vector<int> ds(m);
  for (int i = 0; i < n; i++) {
    cin >> as[i];
    cin >> bs[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> cs[i];
    cin >> ds[i];
  }
  for (int i = 0; i < n; i++) {
    vector<int> xs;
    long md = 1e10;
    for (int j = 0; j < m; j++) {
      if (md > abs(as[i] - cs[j]) + abs(bs[i] - ds[j])) {
        md = abs(as[i] - cs[j]) + abs(bs[i] - ds[j]);
      }
    }
    for (int j = 0; j < m; j++) {
      if (md == abs(as[i] - cs[j]) + abs(bs[i] - ds[j])) {
        xs.push_back(j);
      }
    }
    sort(xs.begin(), xs.end());
    cout << xs[0] + 1 << endl;
  }
}
Problem p03774 (C++)

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

int mDist(int student, int checkpoint, vector<int> &a, vector<int> &b,
          vector<int> &c, vector<int> &d) {
  return abs(a[student] - c[checkpoint]) + abs(b[student] - d[checkpoint]);
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n), c(n), d(n);
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  for (int i = 0; i < m; i++)
    cin >> c[i] >> d[i];

  for (int i = 0; i < n; i++) {
    int min = 1000000000;
    int checkpoint = -1;
    for (int j = 0; j < m; j++) {
      int dist = mDist(i, j, a, b, c, d);
      if (dist < min) {
        checkpoint = j;
        min = dist;
      }
    }
    cout << checkpoint + 1 << endl;
  }

  return 0;
}

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

int mDist(int student, int checkpoint, vector<int> &a, vector<int> &b,
          vector<int> &c, vector<int> &d) {
  return abs(a[student] - c[checkpoint]) + abs(b[student] - d[checkpoint]);
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n), c(m), d(m);
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  for (int i = 0; i < m; i++)
    cin >> c[i] >> d[i];

  for (int i = 0; i < n; i++) {
    int min = 1000000000;
    int checkpoint = -1;
    for (int j = 0; j < m; j++) {
      int dist = mDist(i, j, a, b, c, d);
      if (dist < min) {
        checkpoint = j;
        min = dist;
      }
    }
    cout << checkpoint + 1 << endl;
  }

  return 0;
}
Problem p03774 (Python)

Buggy submission (status: Runtime Error):
import math

n, m = map(int, input().split())

# student input
student = []
for i in range(n):
    a, b = map(int, input().split())
    student.append([a, b])

# check point input
check = []
for j in range(n):
    c, d = map(int, input().split())
    check.append([c, d])

# calc
for s in student:
    distance = 10e9
    near = 0
    for index, k in enumerate(check):
        v = math.fabs(s[0] - k[0]) + math.fabs(s[1] - k[1])
        if v < distance:
            distance = v
            near = index + 1
    print(near)


Fixed submission:
import math

n, m = map(int, input().split())

# student input
student = []
for i in range(n):
    a, b = map(int, input().split())
    student.append([a, b])

# check point input
check = []
for j in range(m):
    c, d = map(int, input().split())
    check.append([c, d])

# calc
for s in student:
    distance = 10e9
    near = 0
    for index, k in enumerate(check):
        v = math.fabs(s[0] - k[0]) + math.fabs(s[1] - k[1])
        if v < distance:
            distance = v
            near = index + 1
    print(near)
Problem p03774 (Python)

Buggy submission (status: Runtime Error):
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
CD = [tuple(map(int, input().split())) for _ in range(N)]

for a, b in AB:
    ans, maxD = 0, 10**10
    for i, (c, d) in enumerate(CD):
        if abs(a - c) + abs(b - d) < maxD:
            ans, maxD = i + 1, abs(a - c) + abs(b - d)
    print(ans)


Fixed submission:
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
CD = [tuple(map(int, input().split())) for _ in range(M)]

for a, b in AB:
    ans, maxD = 0, 10**10
    for i, (c, d) in enumerate(CD):
        if abs(a - c) + abs(b - d) < maxD:
            ans, maxD = i + 1, abs(a - c) + abs(b - d)
    print(ans)
Problem p03774 (Python)

Buggy submission (status: Runtime Error):
# -*- coding: utf-8 -*-

# input
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
cd = [list(map(int, input().split())) for i in range(M)]

# solve & output
for i in range(N):
    min_diff = 10**8
    for j in range(M):
        diff = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if min_diff > diff:
            min_diff = diff
            ans = j + 1
    print(ans)


Fixed submission:
# -*- coding: utf-8 -*-

# input
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
cd = [list(map(int, input().split())) for i in range(M)]

# solve & output
for i in range(N):
    min_diff = 10**9
    for j in range(M):
        diff = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if min_diff > diff:
            min_diff = diff
            ans = j + 1
    print(ans)
Problem p03774 (Python)

Buggy submission (status: Runtime Error):
def args():
    N, M = map(int, input().split())

    ST = []
    for _ in range(N):
        ST.append(tuple(map(int, input().split())))

    CP = []
    for _ in range(M):
        CP.append(tuple(map(int, input().split())))

    # print(N, M)
    # print(ST)
    # print(CP)

    return N, M, ST, CP


def solve(N, M, ST, CP):
    def get_dist(xy1, xy2):
        x1, y1 = xy1
        x2, y2 = xy2

        return abs(x1 - x2) + abs(y1 - y2)

    res = []
    for st in ST:
        min_cp, min_dist = None, 1000
        for i, cp in enumerate(CP):
            dist = get_dist(st, cp)
            if dist < min_dist:
                min_dist = dist
                min_cp = i
        res.append(min_cp + 1)

    return res


if __name__ == "__main__":
    ans = solve(*args())
    for a in ans:
        print(a)


Fixed submission:
def args():
    N, M = map(int, input().split())

    ST = []
    for _ in range(N):
        ST.append(tuple(map(int, input().split())))

    CP = []
    for _ in range(M):
        CP.append(tuple(map(int, input().split())))

    # print(N, M)
    # print(ST)
    # print(CP)

    return N, M, ST, CP


def solve(N, M, ST, CP):
    def get_dist(xy1, xy2):
        x1, y1 = xy1
        x2, y2 = xy2

        return abs(x1 - x2) + abs(y1 - y2)

    res = []
    for st in ST:
        min_cp, min_dist = 0, float("inf")
        for i, cp in enumerate(CP):
            dist = get_dist(st, cp)
            if dist < min_dist:
                min_dist = dist
                min_cp = i
        res.append(min_cp + 1)

    return res


if __name__ == "__main__":
    ans = solve(*args())
    for a in ans:
        print(a)
Problem p03774 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> c[i] >> d[i];
  }
  int nearcheck = 0;
  int mindist = 400000000;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (mindist > (abs(a[i] - c[j]) + abs(b[i] - d[j]))) {
        mindist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
        nearcheck = j;
      }
    }
    cout << nearcheck + 1 << endl;
    mindist = 400000000;
    nearcheck = 0;
  }
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(m);
  vector<int> d(m);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> c[i] >> d[i];
  }
  int nearcheck = 0;
  int mindist = 400000000;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (mindist > (abs(a[i] - c[j]) + abs(b[i] - d[j]))) {
        mindist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
        nearcheck = j;
      }
    }
    cout << nearcheck + 1 << endl;
    mindist = 400000000;
    nearcheck = 0;
  }
}