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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<vector<int>> A(3, vector<int>(3));
  bool c = false;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> A.at(i).at(j);
    }
  }
  int N;
  cin >> N;
  for (int h = 0; h < N; h++) {
    int b;
    cin >> b;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (A.at(i).at(j) == b) {
          A.at(i).at(j) = 0;
        }
      }
    }
  }
  for (int i = 0; i < 3; i++) {
    if (A.at(0).at(i) == 0 && A.at(1).at(i) == 0 && A.at(2).at(i) == 0) {
      c = true;
    }
  }
  for (int i = 0; i < 3; i++) {
    if (A.at(i).at(0) == 0 && A.at(i).at(1) == 0 && A.at(i).at(2) == 0) {
      c = true;
    }
  }
  if (A.at(0).at(0) == 0 && A.at(1).at(1) == 0 && A.at(2).at(3) == 0) {
    c = true;
  } else if (A.at(0).at(2) == 0 && A.at(1).at(1) == 0 && A.at(2).at(0) == 0) {
    c = true;
  }
  if (c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<vector<int>> A(3, vector<int>(3));
  bool c = false;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> A.at(i).at(j);
    }
  }
  int N;
  cin >> N;
  for (int h = 0; h < N; h++) {
    int b;
    cin >> b;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (A.at(i).at(j) == b) {
          A.at(i).at(j) = 0;
        }
      }
    }
  }
  for (int i = 0; i < 3; i++) {
    if (A.at(0).at(i) == 0 && A.at(1).at(i) == 0 && A.at(2).at(i) == 0) {
      c = true;
    }
  }
  for (int i = 0; i < 3; i++) {
    if (A.at(i).at(0) == 0 && A.at(i).at(1) == 0 && A.at(i).at(2) == 0) {
      c = true;
    }
  }
  if (A.at(0).at(0) == 0 && A.at(1).at(1) == 0 && A.at(2).at(2) == 0) {
    c = true;
  } else if (A.at(0).at(2) == 0 && A.at(1).at(1) == 0 && A.at(2).at(0) == 0) {
    c = true;
  }
  if (c) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02760 (C++)

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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

v2 a(3, v1(3));
int n;

int main() {
  rep(i, 3) {
    rep(j, 3) { cin >> a[i][j]; }
  }
  cin >> n;
  rep(i, n) {
    int x;
    cin >> x;
    rep(i, 3) {
      rep(j, 3) {
        if (a[i][j] == x) {
          a[i][j] = 0;
        }
      }
    }
  }
  rep(i, 3) {
    if (a[i][0] == 0 && a[i][1] == 0 && a[i][2] == 0) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  rep(i, 3) {
    if (a[0][i] == 0 && a[1][i] == 0 && a[2][i] == 0) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  if (a[1][1] == 0 && a[2][2] == 0 && a[0][0] == 0) {
    cout << "Yes" << endl;
    return 0;
  }
  if (a[1][3] == 0 && a[2][2] == 0 && a[3][1] == 0) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}


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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

v2 a(3, v1(3));
int n;

int main() {
  rep(i, 3) {
    rep(j, 3) { cin >> a[i][j]; }
  }
  cin >> n;
  rep(i, n) {
    int x;
    cin >> x;
    rep(i, 3) {
      rep(j, 3) {
        if (a[i][j] == x) {
          a[i][j] = 0;
        }
      }
    }
  }
  rep(i, 3) {
    if (a[i][0] == 0 && a[i][1] == 0 && a[i][2] == 0) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  rep(i, 3) {
    if (a[0][i] == 0 && a[1][i] == 0 && a[2][i] == 0) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  if (a[1][1] == 0 && a[2][2] == 0 && a[0][0] == 0) {
    cout << "Yes" << endl;
    return 0;
  }
  if (a[0][2] == 0 && a[1][1] == 0 && a[2][0] == 0) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}
Problem p02760 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
bool Bingo(vector<vector<int>> &A) {
  for (int i = 0; i < 3; i++) {
    if (A.at(0).at(i) == A.at(1).at(i) && A.at(1).at(i) == A.at(2).at(i) &&
        A.at(2).at(i) == 0)
      return true;
    else if (A.at(i).at(0) == A.at(i).at(1) && A.at(i).at(1) == A.at(i).at(2) &&
             A.at(i).at(2) == 0)
      return true;
  }
  if (A.at(0).at(0) == A.at(1).at(1) && A.at(1).at(1) == A.at(2).at(2) &&
      A.at(2).at(2) == 0)
    return true;
  else if (A.at(2).at(0) == A.at(1).at(1) && A.at(1).at(1) == A.at(0).at(3) &&
           A.at(0).at(3) == 0)
    return true;

  return false;
}
int main() {
  vector<vector<int>> A(3, vector<int>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> A.at(i).at(j);
    }
  }
  int N;
  cin >> N;
  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    cin >> B.at(i);
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if (A.at(j).at(k) == B.at(i))
          A.at(j).at(k) = 0;
      }
    }
  }
  if (Bingo(A))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
bool Bingo(vector<vector<int>> &A) {
  for (int i = 0; i < 3; i++) {
    if (A.at(0).at(i) == A.at(1).at(i) && A.at(1).at(i) == A.at(2).at(i) &&
        A.at(2).at(i) == 0)
      return true;
    else if (A.at(i).at(0) == A.at(i).at(1) && A.at(i).at(1) == A.at(i).at(2) &&
             A.at(i).at(2) == 0)
      return true;
  }
  if (A.at(0).at(0) == A.at(1).at(1) && A.at(1).at(1) == A.at(2).at(2) &&
      A.at(2).at(2) == 0)
    return true;
  else if (A.at(2).at(0) == A.at(1).at(1) && A.at(1).at(1) == A.at(0).at(2) &&
           A.at(0).at(2) == 0)
    return true;

  return false;
}
int main() {
  vector<vector<int>> A(3, vector<int>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> A.at(i).at(j);
    }
  }
  int N;
  cin >> N;
  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    cin >> B.at(i);
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if (A.at(j).at(k) == B.at(i))
          A.at(j).at(k) = 0;
      }
    }
  }
  if (Bingo(A))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p02760 (C++)

Buggy submission (status: Runtime Error):
// https://atcoder.jp/contests/abc157/tasks/abc157_b

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, b, e) for (int i = (b); i <= (int)(e); i++)
#if DEBUG
#define DUMP(a)                                                                \
  REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
#define DUMP2D(b)                                                              \
  REP(_j, b.size()) DUMP(b[_j]);                                               \
  cout << endl
#else
#define DUMP(a)
#define DUMP2D(b)
#endif

const int A_IJ_MAX = 100;
const int N_MAX = 10;
const int B_I_MAX = 100;

vector<vector<int>> A;
int N;
vector<int> b;

vector<bool> f;

int main() {
  A = vector<vector<int>>(3, vector<int>(3));
  REP(i, 3) REP(j, 3) cin >> A[i][j];
  cin >> N;
  b = vector<int>(N);
  REP(i, N) cin >> b[i];

  f = vector<bool>(A_IJ_MAX, false);
  REP(i, N) f[b[i]] = true;

  bool cond = false;
  bool bingo;
  REP(i, 3) {
    bingo = true;
    REP(j, 3) bingo &= f[A[i][j]];
    if (bingo)
      cond = true;
  }
  REP(i, 3) {
    bingo = true;
    REP(j, 3) bingo &= f[A[j][i]];
    if (bingo)
      cond = true;
  }
  bingo = true;
  REP(i, 3) bingo &= f[A[i][i]];
  if (bingo)
    cond = true;
  bingo = true;
  REP(i, 3) bingo &= f[A[i][2 - i]];
  if (bingo)
    cond = true;

  cout << (cond ? "Yes" : "No") << endl;
}


Fixed submission:
// https://atcoder.jp/contests/abc157/tasks/abc157_b

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, b, e) for (int i = (b); i <= (int)(e); i++)
#if DEBUG
#define DUMP(a)                                                                \
  REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
#define DUMP2D(b)                                                              \
  REP(_j, b.size()) DUMP(b[_j]);                                               \
  cout << endl
#else
#define DUMP(a)
#define DUMP2D(b)
#endif

const int A_IJ_MAX = 100;
const int N_MAX = 10;
const int B_I_MAX = 100;

vector<vector<int>> A;
int N;
vector<int> b;

vector<bool> f;

int main() {
  A = vector<vector<int>>(3, vector<int>(3));
  REP(i, 3) REP(j, 3) cin >> A[i][j];
  cin >> N;
  b = vector<int>(N);
  REP(i, N) cin >> b[i];

  f = vector<bool>(A_IJ_MAX + 1, false);
  REP(i, N) f[b[i]] = true;

  bool cond = false;
  bool bingo;
  REP(i, 3) {
    bingo = true;
    REP(j, 3) bingo &= f[A[i][j]];
    if (bingo)
      cond = true;
  }
  REP(i, 3) {
    bingo = true;
    REP(j, 3) bingo &= f[A[j][i]];
    if (bingo)
      cond = true;
  }
  bingo = true;
  REP(i, 3) bingo &= f[A[i][i]];
  if (bingo)
    cond = true;
  bingo = true;
  REP(i, 3) bingo &= f[A[i][2 - i]];
  if (bingo)
    cond = true;

  cout << (cond ? "Yes" : "No") << endl;
}
Problem p02760 (C++)

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

int main() {
  vector<int> a(9);
  for (int i = 0; i < 9; i++) {
    cin >> a.at(i);
  }

  int n;
  cin >> n;

  vector<int> b(n);
  vector<int> c(n);

  for (int i = 0; i < n; i++) {
    cin >> b.at(i);
    for (int j = 0; j < 9; j++) {
      if (a.at(j) == b.at(i)) {
        c.at(j)++;
      }
    }
  }

  int count = 0;

  for (int i = 0; i <= 6; i += 3) {
    if (c.at(i) * c.at(i + 1) * c.at(i + 2) != 0) {
      count++;
    }
  }

  for (int i = 0; i <= 2; i++) {
    if (c.at(i) * c.at(i + 3) * c.at(i + 6) != 0) {
      count++;
    }
  }

  if (c.at(0) * c.at(4) * c.at(8) != 0) {
    count++;
  }

  if (c.at(2) * c.at(4) * c.at(6) != 0) {
    count++;
  }

  if (count > 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

int main() {
  vector<int> a(9);
  for (int i = 0; i < 9; i++) {
    cin >> a.at(i);
  }

  int n;
  cin >> n;

  vector<int> b(n);
  vector<int> c(9);

  for (int i = 0; i < n; i++) {
    cin >> b.at(i);
    for (int j = 0; j < 9; j++) {
      if (a.at(j) == b.at(i)) {
        c.at(j)++;
      }
    }
  }

  int count = 0;

  for (int i = 0; i <= 6; i += 3) {
    if (c.at(i) * c.at(i + 1) * c.at(i + 2) != 0) {
      count++;
    }
  }

  for (int i = 0; i <= 2; i++) {
    if (c.at(i) * c.at(i + 3) * c.at(i + 6) != 0) {
      count++;
    }
  }

  if (c.at(0) * c.at(4) * c.at(8) != 0) {
    count++;
  }

  if (c.at(2) * c.at(4) * c.at(6) != 0) {
    count++;
  }

  if (count > 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
Problem p02760 (C++)

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

using namespace std;

int a[10][10];
int m[10][10];
int ok;

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

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> a[i][j];
    }
  }
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int b;
    cin >> b;
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; j++) {
        if (a[j][k] == b)
          m[j][k] = 1;
      }
    }
  }

  for (int i = 0; i < 3; i++) {
    ok = 1;
    for (int j = 0; j < 3; j++) {
      if (m[i][j] != 1)
        ok = 0;
    }
    if (ok) {
      cout << "Yes\n";
      return 0;
    }
  }
  for (int i = 0; i < 3; i++) {
    ok = 1;
    for (int j = 0; j < 3; j++) {
      if (m[j][i] != 1)
        ok = 0;
    }
    if (ok) {
      cout << "Yes\n";
      return 0;
    }
  }
  ok = 1;
  for (int i = 0; i < 3; i++) {
    if (m[i][i] != 1)
      ok = 0;
  }
  if (ok) {
    cout << "Yes\n";
    return 0;
  }
  ok = 1;
  for (int i = 0; i < 3; i++) {
    if (m[i][2 - i] != 1)
      ok = 0;
  }
  if (ok) {
    cout << "Yes\n";
    return 0;
  }
  cout << "No\n";
}


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

using namespace std;

int a[10][10];
int m[10][10];
int ok;

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

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> a[i][j];
    }
  }
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int b;
    cin >> b;
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if (a[j][k] == b)
          m[j][k] = 1;
      }
    }
  }

  for (int i = 0; i < 3; i++) {
    ok = 1;
    for (int j = 0; j < 3; j++) {
      if (m[i][j] != 1)
        ok = 0;
    }
    if (ok) {
      cout << "Yes\n";
      return 0;
    }
  }
  for (int i = 0; i < 3; i++) {
    ok = 1;
    for (int j = 0; j < 3; j++) {
      if (m[j][i] != 1)
        ok = 0;
    }
    if (ok) {
      cout << "Yes\n";
      return 0;
    }
  }
  ok = 1;
  for (int i = 0; i < 3; i++) {
    if (m[i][i] != 1)
      ok = 0;
  }
  if (ok) {
    cout << "Yes\n";
    return 0;
  }
  ok = 1;
  for (int i = 0; i < 3; i++) {
    if (m[i][2 - i] != 1)
      ok = 0;
  }
  if (ok) {
    cout << "Yes\n";
    return 0;
  }
  cout << "No\n";
}
Problem p02760 (C++)

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

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

      c[i][j] = 0;
    }
  }

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < N; k++) {
        if (a[i][j] == b[k]) {
          c[i][j] = 1;
        }
      }
    }
  }

  bool f = false;
  for (int i = 0; i < 3; i++) {
    if (c[i][0] == 1 && c[i][1] == 1 && c[i][2] == 1)
      f = true;
  }
  for (int i = 0; i < 3; i++) {
    if (c[0][i] == 1 && c[1][i] == 1 && c[2][i] == 1)
      f = true;
  }
  if (c[0][0] == 1 && c[1][1] == 1 && c[2][2] == 1) {
    f = true;
  }
  if (c[0][2] == 1 && c[1][1] == 1 && c[2][0] == 1) {
    f = true;
  }
  if (f) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

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

      c[i][j] = 0;
    }
  }

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < N; k++) {
        if (a[i][j] == b[k]) {
          c[i][j] = 1;
        }
      }
    }
  }

  bool f = false;
  for (int i = 0; i < 3; i++) {
    if (c[i][0] == 1 && c[i][1] == 1 && c[i][2] == 1)
      f = true;
  }
  for (int i = 0; i < 3; i++) {
    if (c[0][i] == 1 && c[1][i] == 1 && c[2][i] == 1)
      f = true;
  }
  if (c[0][0] == 1 && c[1][1] == 1 && c[2][2] == 1) {
    f = true;
  }
  if (c[0][2] == 1 && c[1][1] == 1 && c[2][0] == 1) {
    f = true;
  }
  if (f) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02761 (C++)

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

int n, m;
vector<int> s;
vector<int> c;

bool ok(string str) {
  if (str.length() != n)
    return false;

  for (int j = 0; j < m; j++) {
    if (str.at(s.at(j)) != to_string(c.at(j)).at(0))
      return false;
  }

  return true;
}

int main() {
  cin >> n >> m;
  s.resize(m), c.resize(m);

  for (int i = 0; i < n; i++) {
    cin >> s.at(i) >> c.at(i);
    s.at(i)--;
  }

  for (int i = 0; i <= 999; i++) {
    if (ok(to_string(i))) {
      cout << i << endl;
      return 0;
    }
  }

  cout << -1 << endl;
}

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

int n, m;
vector<int> s;
vector<int> c;

bool ok(string str) {
  if (str.length() != n)
    return false;

  for (int j = 0; j < m; j++) {
    if (str.at(s.at(j)) != to_string(c.at(j)).at(0))
      return false;
  }

  return true;
}

int main() {
  cin >> n >> m;
  s.resize(m), c.resize(m);

  for (int i = 0; i < m; i++) {
    cin >> s.at(i) >> c.at(i);
    s.at(i)--;
  }

  for (int i = 0; i <= 999; i++) {
    if (ok(to_string(i))) {
      cout << i << endl;
      return 0;
    }
  }

  cout << -1 << endl;
}
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
// const ll MOD = ;
ll mod(ll A, ll M) { return (A % M + M) % M; }
const ll INF = 1LL << 60;
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
ll divceil(ll A, ll B) { return (A + (B - 1)) / B; }
ll myctoi(char C) { return C - '0'; }
char myitoc(ll N) { return '0' + N; }
#define FINALANS(A)                                                            \
  do {                                                                         \
    cout << (A) << '\n';                                                       \
    exit(0);                                                                   \
  } while (false)

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> S(M), C(M);
  for (ll i = 0; i < M; i++) {
    cin >> S.at(i) >> C.at(i);
    S.at(i)--;
  }

  for (ll n = 0; n < 1000; n++) {
    string x = to_string(n);
    if (x.size() != N)
      continue;

    bool ok = true;
    for (ll i = 0; i < N; i++) {
      if (x.at(S.at(i)) - '0' != C.at(i)) {
        ok = false;
        break;
      }
    }
    if (ok)
      FINALANS(n);
  }
  cout << -1 << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
// const ll MOD = ;
ll mod(ll A, ll M) { return (A % M + M) % M; }
const ll INF = 1LL << 60;
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
ll divceil(ll A, ll B) { return (A + (B - 1)) / B; }
ll myctoi(char C) { return C - '0'; }
char myitoc(ll N) { return '0' + N; }
#define FINALANS(A)                                                            \
  do {                                                                         \
    cout << (A) << '\n';                                                       \
    exit(0);                                                                   \
  } while (false)

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> S(M), C(M);
  for (ll i = 0; i < M; i++) {
    cin >> S.at(i) >> C.at(i);
    S.at(i)--;
  }

  for (ll n = 0; n < 1000; n++) {
    string x = to_string(n);
    if (x.size() != N)
      continue;

    bool ok = true;
    for (ll i = 0; i < M; i++) {
      if (x.at(S.at(i)) - '0' != C.at(i)) {
        ok = false;
        break;
      }
    }
    if (ok)
      FINALANS(n);
  }
  cout << -1 << endl;
}
Problem p02761 (C++)

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

using namespace std;

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<int> p{1};
  while (p.size() < n)
    p.insert(p.begin(), p[0] * 10);

  map<int, int> s;
  int ans = 0;
  while (m--) {
    int a, b;
    scanf("%d %d", &a, &b);
    if (s.count(a)) {
      if (s[a] != b)
        return printf("-1\n"), 0;
    } else {
      s[a] = b;
      ans += b * p[a - 1];
      if (a == 1 and b == 0 and n > 1)
        return printf("-1\n"), 0;
    }
  }
  if (n > 1 and prev(s.end())->second == 0) {
    ans += p[prev(s.end())->first - 2];
  }
  printf("%d\n", ans);
}


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

using namespace std;

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<int> p{1};
  while (p.size() < n)
    p.insert(p.begin(), p[0] * 10);

  map<int, int> s;
  int ans = 0;
  while (m--) {
    int a, b;
    scanf("%d %d", &a, &b);
    if (s.count(a)) {
      if (s[a] != b)
        return printf("-1\n"), 0;
    } else {
      s[a] = b;
      ans += b * p[a - 1];
      if (a == 1 and b == 0 and n > 1)
        return printf("-1\n"), 0;
    }
  }
  if (n > 1 and !s.count(1)) {
    ans += p[0];
  }
  printf("%d\n", ans);
}
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); i++)
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> seq(N, 0);
  seq.at(0) = 1;
  vector<int> position(M);
  vector<int> change(M);
  rep(i, M) { cin >> position.at(i) >> change.at(i); }
  // 入力完了

  int non = 0;
  rep(i, M) {
    rep(j, M) {
      if (position.at(i) == position.at(j) && change.at(i) != change.at(j)) {
        non++;
      }
    }
  }

  if (position.at(0) == 1 && change.at(0) == 0) {
    if (N > 1)
      non++;
  }

  rep(i, M) { seq.at(position.at(i) - 1) = change.at(i); }

  if (non > 0)
    cout << -1 << endl;
  else if (N == 1 && M == 0)
    cout << 0 << endl;
  else {
    rep(i, N) { cout << seq.at(i); }
    cout << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); i++)
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> seq(N, 0);
  seq.at(0) = 1;
  vector<int> position(M + 10);
  vector<int> change(M + 10);
  rep(i, M) { cin >> position.at(i) >> change.at(i); }
  // 入力完了

  int non = 0;
  rep(i, M) {
    rep(j, M) {
      if (position.at(i) == position.at(j) && change.at(i) != change.at(j)) {
        non++;
      }
    }
  }

  if (position.at(0) == 1 && change.at(0) == 0) {
    if (N > 1)
      non++;
  }

  rep(i, M) { seq.at(position.at(i) - 1) = change.at(i); }

  if (non > 0)
    cout << -1 << endl;
  else if (N == 1 && M == 0)
    cout << 0 << endl;
  else {
    rep(i, N) { cout << seq.at(i); }
    cout << endl;
  }
}
Problem p02761 (C++)

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

using namespace std;

typedef long long ll;

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

  int n, m;
  cin >> n >> m;

  vector<int> s(m), c(m);
  rep(i, m) cin >> s[i] >> c[i];

  if (n == 1) {
    int x = c[0];
    rep(i, m) {
      if (s[i] > n || c[i] != x) {
        cout << -1 << endl;
        return 0;
      }
    }
    cout << x << endl;
  } else {
    int INF = 100;
    vector<int> v(n, INF);
    rep(i, m) {
      if (s[i] > n) {
        cout << -1 << endl;
        return 0;
      }

      if (s[i] == 1 && c[i] == 0) {
        cout << -1 << endl;
        return 0;
      }

      if (v[s[i] - 1] != INF && v[s[i] - 1] != c[i]) {
        cout << -1 << endl;
        return 0;
      }

      v[s[i] - 1] = c[i];
    }

    int ans = 0;
    int d = 1;
    for (int i = n - 1; i >= 0; i--) {
      if (v[i] == INF) {
        if (i == 0)
          ans += d;
      } else {
        ans += v[i] * d;
      }

      d *= 10;
    }

    cout << ans << endl;
  }
}

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

using namespace std;

typedef long long ll;

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

  int n, m;
  cin >> n >> m;

  if (m == 0) {
    if (n == 1) {
      cout << 0 << endl;
      return 0;
    }

    if (n == 2) {
      cout << 10 << endl;
      return 0;
    }

    if (n == 3) {
      cout << 100 << endl;
      return 0;
    }
  }

  vector<int> s(m), c(m);
  rep(i, m) cin >> s[i] >> c[i];

  if (n == 1) {
    int x = c[0];
    rep(i, m) {
      if (s[i] > n || c[i] != x) {
        cout << -1 << endl;
        return 0;
      }
    }
    cout << x << endl;
  } else {
    int INF = 100;
    vector<int> v(n, INF);
    rep(i, m) {
      if (s[i] > n) {
        cout << -1 << endl;
        return 0;
      }

      if (s[i] == 1 && c[i] == 0) {
        cout << -1 << endl;
        return 0;
      }

      if (v[s[i] - 1] != INF && v[s[i] - 1] != c[i]) {
        cout << -1 << endl;
        return 0;
      }

      v[s[i] - 1] = c[i];
    }

    int ans = 0;
    int d = 1;
    for (int i = n - 1; i >= 0; i--) {
      if (v[i] == INF) {
        if (i == 0)
          ans += d;
      } else {
        ans += v[i] * d;
      }

      d *= 10;
    }

    cout << ans << endl;
  }
}
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll = long long;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define MOD 1000000007
const ll INF = 1e18;
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 argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  rep(i, m) cin >> s[i] >> c[i];
  int ans = -1;

  for (int i = 1000; i >= 0; i--) {
    string S = to_string(i);
    bool ok = true;
    if (sz(S) != n)
      ok = false;
    for (int j = 0; i < m; j++) {
      if (S[s[j] - 1] != (char)(c[j] + '0'))
        ok = false;
    }
    if (ok)
      ans = i;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll = long long;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define MOD 1000000007
const ll INF = 1e18;
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 argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  rep(i, m) cin >> s[i] >> c[i];
  int ans = -1;

  for (int i = 1000; i >= 0; i--) {
    string S = to_string(i);
    bool ok = true;
    if (sz(S) != n)
      ok = false;
    for (int j = 0; j < m; j++) {
      if (S[s[j] - 1] != (char)(c[j] + '0'))
        ok = false;
    }
    if (ok)
      ans = i;
  }
  cout << ans << endl;
  return 0;
}
Problem p02761 (C++)

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

using namespace std;

int main() {

  int N, M;

  cin >> N >> M;

  vector<int> S(M);
  vector<char> C(M);
  for (int i = 0; i < M; i++) {
    cin >> S.at(i) >> C.at(i);
  }

  int loop_start;
  int loop_end;
  if (N == 1) {
    loop_start = 0;
    loop_end = 10;
  } else if (N == 2) {
    loop_start = 10;
    loop_end = 100;
  } else if (N == 3) {
    loop_start = 100;
    loop_end = 1000;
  }

  bool flag = false;
  int result = 1000;
  for (int i = loop_start; i < loop_end; i++) {
    string strwk = to_string(i);
    for (int j = 0; j < M; j++) {
      if (strwk.at(S.at(j)) == C.at(j)) {
        if (j == M - 1) {
          flag = true;
          result = min(result, i);
        }
      } else
        break;
    }
  }

  if (M == 0) {
    if (N == 1)
      cout << 0 << endl;
    else if (N == 2)
      cout << 10 << endl;
    else if (N == 3)
      cout << 100 << endl;
  } else if (flag)
    cout << result << endl;
  else
    cout << -1 << endl;

  return 0;
}


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

using namespace std;

int main() {

  int N, M;

  cin >> N >> M;

  vector<int> S(M);
  vector<char> C(M);
  for (int i = 0; i < M; i++) {
    cin >> S.at(i) >> C.at(i);
  }

  int loop_start;
  int loop_end;
  if (N == 1) {
    loop_start = 0;
    loop_end = 10;
  } else if (N == 2) {
    loop_start = 10;
    loop_end = 100;
  } else if (N == 3) {
    loop_start = 100;
    loop_end = 1000;
  }

  bool flag = false;
  int result = 1000;
  for (int i = loop_start; i < loop_end; i++) {
    string strwk = to_string(i);
    for (int j = 0; j < M; j++) {
      if (strwk.at(S.at(j) - 1) == C.at(j)) {
        if (j == M - 1) {
          flag = true;
          result = min(result, i);
        }
      } else
        break;
    }
  }

  if (M == 0) {
    if (N == 1)
      cout << 0 << endl;
    else if (N == 2)
      cout << 10 << endl;
    else if (N == 3)
      cout << 100 << endl;
  } else if (flag)
    cout << result << endl;
  else
    cout << -1 << endl;

  return 0;
}
Problem p02761 (C++)

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

#define MAX_N 3
#define MAX_M 5

int main() {
  int N, M, s[MAX_M], c[MAX_M];
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }

  // N > 1のとき、先頭が0ではいけない
  if (N > 1) {
    for (int i = 0; i < M; i++) {
      if (s[i] == 1 && c[i] == 0) {
        cout << -1 << endl;
        return 0;
      }
    }
  }

  // i桁目の暫定の値
  int a[MAX_N];
  for (int i = 0; i < N; i++) {
    a[i] = -1; // 未指定の桁は-1としておく
  }

  // ある桁について異なる値を指定してはいけない
  for (int i = 0; i < M; i++) {
    // まだ指定されていない桁ならば
    if (a[s[i] - 1] == -1) {
      a[s[i] - 1] = c[i];
    }
    // 既に指定されている桁ならば
    else {
      // 異なる値を指定してはいけない
      if (a[s[i] - 1] != c[i]) {
        cout << -1 << endl;
        return -1;
      }
    }
  }

  if (N == 1) {
    if (a[0] == -1) {
      cout << 0 << endl;
    } else {
      cout << a[0] << endl;
    }
    return 0;
  }

  int ans;
  if (a[0] == -1) {
    ans = 1;
  } else {
    ans = a[0];
  }

  for (int i = 1; i < N; i++) {
    ans *= 10;
    if (a[i] != -1) {
      ans += a[i];
    }
  }

  cout << ans << endl;
  return 0;
}

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

#define MAX_N 3
#define MAX_M 5

int main() {
  int N, M, s[MAX_M], c[MAX_M];
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }

  // N > 1のとき、先頭が0ではいけない
  if (N > 1) {
    for (int i = 0; i < M; i++) {
      if (s[i] == 1 && c[i] == 0) {
        cout << -1 << endl;
        return 0;
      }
    }
  }

  // i桁目の暫定の値
  int a[MAX_N];
  for (int i = 0; i < N; i++) {
    a[i] = -1; // 未指定の桁は-1としておく
  }

  // ある桁について異なる値を指定してはいけない
  for (int i = 0; i < M; i++) {
    // まだ指定されていない桁ならば
    if (a[s[i] - 1] == -1) {
      a[s[i] - 1] = c[i];
    }
    // 既に指定されている桁ならば
    else {
      // 異なる値を指定してはいけない
      if (a[s[i] - 1] != c[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }

  if (N == 1) {
    if (a[0] == -1) {
      cout << 0 << endl;
    } else {
      cout << a[0] << endl;
    }
    return 0;
  }

  int ans;
  if (a[0] == -1) {
    ans = 1;
  } else {
    ans = a[0];
  }

  for (int i = 1; i < N; i++) {
    ans *= 10;
    if (a[i] != -1) {
      ans += a[i];
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p02761 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  int s[10];
  char c[10];
  for (int i = 0; i < n; i++) {
    cin >> s[i] >> c[i];
  }

  bool isok = false;
  int start[3] = {0, 10, 100};
  int end[3] = {9, 99, 999};
  int ans = -1;
  for (int i = start[n - 1]; i <= end[n - 1]; i++) {
    string str = to_string(i);
    bool isok = true;

    for (int j = 0; j < m; j++) {
      if (str[s[j] - 1] != c[j]) {
        isok = false;
        break;
      }
    }

    if (isok) {
      ans = i;
      break;
    }
  }

  cout << ans << endl;
  return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  int s[10];
  char c[10];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }

  bool isok = false;
  int start[3] = {0, 10, 100};
  int end[3] = {9, 99, 999};
  int ans = -1;
  for (int i = start[n - 1]; i <= end[n - 1]; i++) {
    string str = to_string(i);
    bool isok = true;

    for (int j = 0; j < m; j++) {
      if (str[s[j] - 1] != c[j]) {
        isok = false;
        break;
      }
    }

    if (isok) {
      ans = i;
      break;
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p02761 (C++)

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < N; ++i)
    cin >> s[i] >> c[i], s[i]--;
  auto ok = [&](int n) -> bool {
    string S = to_string(n);
    if (S.size() != N)
      return false;
    for (int i = 0; i < M; ++i) {
      if (S[s[i]] != ('0' + c[i]))
        return false;
    }
    return true;
  };
  for (int i = 0; i < 1010; ++i) {
    if (ok(i)) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
  return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; ++i)
    cin >> s[i] >> c[i], s[i]--;
  auto ok = [&](int n) -> bool {
    string S = to_string(n);
    if (S.size() != N)
      return false;
    for (int i = 0; i < M; ++i) {
      if (S[s[i]] != ('0' + c[i]))
        return false;
    }
    return true;
  };
  for (int i = 0; i < 1010; ++i) {
    if (ok(i)) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
  return 0;
}
Problem p02761 (C++)

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

int main() {
  int64_t N, M, t = 0;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int64_t i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  if (N = 1) {
    for (int64_t j = 0; j < M; j++) {
      if (c.at(j) != 0) {
        t = 1;
        break;
      }
    }
    if (t == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int64_t i = pow(10, N - 1); i < pow(10, N); i++) {
    t = 0;
    for (int64_t j = 0; j < M; j++) {
      if (i / (int)pow(10, N - s.at(j)) -
              (i / (int)pow(10, N - s.at(j) + 1)) * 10 !=
          c.at(j)) {
        t = 1;
        break;
      }
    }
    if (t == 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}


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

int main() {
  int64_t N, M, t = 0;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int64_t i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  if (N == 1) {
    for (int64_t j = 0; j < M; j++) {
      if (c.at(j) != 0) {
        t = 1;
        break;
      }
    }
    if (t == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int64_t i = pow(10, N - 1); i < pow(10, N); i++) {
    t = 0;
    for (int64_t j = 0; j < M; j++) {
      if (i / (int)pow(10, N - s.at(j)) -
              (i / (int)pow(10, N - s.at(j) + 1)) * 10 !=
          c.at(j)) {
        t = 1;
        break;
      }
    }
    if (t == 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
Problem p02761 (C++)

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

int power(int n) {
  if (n == 0)
    return 0;
  int res = 1;
  rep(i, n) res *= 10;
  return res;
}

bool check(int n, int s, int c) {
  vector<int> v;
  while (n) {
    v.push_back(n % 10);
    n /= 10;
  }
  reverse(all(v));
  // rep(i, v.size()) cout << v[i] << " ";
  if (v[s - 1] == c)
    return true;
  else
    return false;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  rep(i, m) cin >> s[i] >> c[i];
  for (int i = power(n - 1); i < power(n); i++) {
    bool ok = true;
    rep(j, m) {
      if (!check(i, s[j], c[j]))
        ok = false;
    }
    // cout << i << endl;
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

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

int power(int n) {
  if (n == 0)
    return 0;
  int res = 1;
  rep(i, n) res *= 10;
  return res;
}

bool check(int n, int s, int c) {
  vector<int> v;
  if (n == 0)
    v.push_back(0);
  else
    while (n) {
      v.push_back(n % 10);
      n /= 10;
    }
  reverse(all(v));
  // rep(i, v.size()) cout << v[i] << " ";
  if (v[s - 1] == c)
    return true;
  else
    return false;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  rep(i, m) cin >> s[i] >> c[i];
  for (int i = power(n - 1); i < power(n); i++) {
    bool ok = true;
    rep(j, m) {
      if (!check(i, s[j], c[j]))
        ok = false;
    }
    // cout << i << endl;
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
Problem p02761 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  vi s(m);
  vector<char> c(m);
  rep(i, m) { cin >> s.at(i) >> c.at(i); }
  int a, b;
  if (n == 1) {
    a = 0;
    b = 10;
  } else {
    a = 1;
    rep(i, n - 1) { a *= 10; }
    b = a * 10;
  }
  for (int i = a; i < b; i++) {
    string S = to_string(i);
    int j = 0;
    while (true) {
      if (S.at(s.at(j) - 1) != c.at(j)) {
        break;
      } else if (j == m - 1) {
        cout << S << endl;
        return 0;
      }
      j++;
    }
  }
  cout << -1 << endl;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vi s(m);
  vector<char> c(m);
  rep(i, m) { cin >> s.at(i) >> c.at(i); }
  int a, b;
  if (n == 1) {
    a = 0;
    b = 10;
  } else {
    a = 1;
    rep(i, n - 1) { a *= 10; }
    b = a * 10;
  }
  if (m == 0) {
    cout << a << endl;
    return 0;
  }
  for (int i = a; i < b; i++) {
    string S = to_string(i);
    int j = 0;
    while (true) {
      if (S.at(s.at(j) - 1) != c.at(j)) {
        break;
      } else if (j == m - 1) {
        cout << S << endl;
        return 0;
      }
      j++;
    }
  }
  cout << -1 << endl;
}
Problem p02761 (Python)

Buggy submission (status: Runtime Error):
def main():
    N, M = map(int, input().split())
    P = {tuple(map(int, input().split())) for _ in range(M)}
    P = sorted(P)
    ans = [0 for _ in range(N)]

    if N > 1 and (1, 0) in P:
        print(-1)
        return

    if N > 1 and P[0][0] != 1:
        ans[0] = 1

    for i in range(len(P) - 1):
        if P[i][0] == P[i + 1][0]:
            print(-1)
            return

    for p in P:
        ans[p[0] - 1] = p[1]

    print("".join(map(str, ans)))


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N, M = map(int, input().split())
    P = {tuple(map(int, input().split())) for _ in range(M)}
    P = sorted(P)
    ans = [0 for _ in range(N)]

    if N == 1 and M == 0:
        print(0)
        return

    if N == 2 and M == 0:
        print(10)
        return

    if N == 3 and M == 0:
        print(100)
        return

    if N > 1 and (1, 0) in P:
        print(-1)
        return

    if N > 1 and P[0][0] != 1:
        ans[0] = 1

    for i in range(len(P) - 1):
        if P[i][0] == P[i + 1][0]:
            print(-1)
            return

    for p in P:
        ans[p[0] - 1] = p[1]

    print("".join(map(str, ans)))


if __name__ == "__main__":
    main()
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep2(i, s, n) for (int i = s; i < (int)n; i++)
#define ll long long
#define all(v) v.begin(), v.end()
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m), b(m);
  rep(i, m) cin >> a[i] >> b[i];
  vector<vector<int>> c(n);
  rep(i, m) c[a[i] - 1].push_back(b[i]);
  if (n > 1 && c[0].size() == 0)
    c[0].push_back(1);
  if (n > 1)
    rep2(i, 1, n) if (c[i].size() == 0) c[i].push_back(0);
  int key = 0;
  rep(i, n) rep(j, c[i].size()) if (c[i][j] != c[i][0]) key = 1;
  if (key == 1 || (n > 1 && c[0][0] == 0))
    cout << -1 << endl;
  else if (n == 3)
    cout << 100 * c[0][0] + 10 * c[1][0] + c[2][0] << endl;
  else if (n == 2)
    cout << 10 * c[0][0] + c[1][0] << endl;
  else
    cout << c[0][0] << endl;
}

Fixed submission:
#define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep2(i, s, n) for (int i = s; i < (int)n; i++)
#define ll long long
#define all(v) v.begin(), v.end()
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m), b(m);
  rep(i, m) cin >> a[i] >> b[i];
  vector<vector<int>> c(n);
  rep(i, m) c[a[i] - 1].push_back(b[i]);
  if (n > 1 && c[0].size() == 0)
    c[0].push_back(1);
  if (n == 1 && c[0].size() == 0)
    c[0].push_back(0);
  if (n > 1)
    rep2(i, 1, n) if (c[i].size() == 0) c[i].push_back(0);
  int key = 0;
  rep(i, n) rep(j, c[i].size()) if (c[i][j] != c[i][0]) key = 1;
  if (key == 1 || (n > 1 && c[0][0] == 0))
    cout << -1 << endl;
  else if (n == 3)
    cout << 100 * c[0][0] + 10 * c[1][0] + c[2][0] << endl;
  else if (n == 2)
    cout << 10 * c[0][0] + c[1][0] << endl;
  else
    cout << c[0][0] << endl;
}
Problem p02761 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll, ll>>
#define pii pair<int, int>
#define REP(i, a) for (int(i) = 0; (i) < (a); (i)++)
#define RREP(i, a) for (int(i) = a - 1; (i) >= (0); (i)--)
#define REP2(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x, 0, sizeof(x))
typedef long long ll;

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  REP(i, M) cin >> s[i] >> c[i];
  int keta = 0;
  int ans = 999999;
  REP(now, 1000) {
    keta = 0;
    int tmp = now;
    bool flg = true;
    while (tmp > 0) {
      tmp /= 10;
      keta++;
    }
    if (now = 0)
      keta = 1;
    if (keta != N)
      continue;
    int cnt[keta];
    tmp = now;
    REP(i, 3) {
      cnt[i] = tmp % 10;
      tmp /= 10;
    }
    REP(i, M) {
      if (cnt[N - s[i]] != c[i]) {
        flg = false;
        continue;
      }
    }
    if (flg)
      ans = min(now, ans);
  }
  if (ans == 999999)
    cout << "-1";
  else
    cout << ans;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll, ll>>
#define pii pair<int, int>
#define REP(i, a) for (int(i) = 0; (i) < (a); (i)++)
#define RREP(i, a) for (int(i) = a - 1; (i) >= (0); (i)--)
#define REP2(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x, 0, sizeof(x))
typedef long long ll;

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  REP(i, M) cin >> s[i] >> c[i];
  int keta = 0;
  int ans = 999999;
  REP(now, 1000) {
    keta = 0;
    int tmp = now;
    bool flg = true;
    while (tmp > 0) {
      tmp /= 10;
      keta++;
    }
    if (now == 0)
      keta = 1;
    if (keta != N)
      continue;
    int cnt[keta];
    tmp = now;
    REP(i, 3) {
      cnt[i] = tmp % 10;
      tmp /= 10;
    }
    REP(i, M) {
      if (cnt[N - s[i]] != c[i]) {
        flg = false;
        continue;
      }
    }
    if (flg)
      ans = min(now, ans);
  }
  if (ans == 999999)
    cout << "-1";
  else
    cout << ans;

  return 0;
}
Problem p02761 (Python)

Buggy submission (status: Runtime Error):
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]

for x in range(1000):
    ok = True
    s = str(x)
    if len(s) != n:
        continue
    if not all([int(s[a[i][0] - 1]) == a[i][1] for i in range(m)]):
        continue
    print(x)
    exit(1)

print(-1)


Fixed submission:
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]

for x in range(1000):
    ok = True
    s = str(x)
    if len(s) != n:
        continue
    if not all([int(s[a[i][0] - 1]) == a[i][1] for i in range(m)]):
        continue
    print(x)
    exit(0)

print(-1)
Problem p02761 (Python)

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

for i in range(1000):
    t = str(i)
    if len(t) != N:
        continue
    ok = True
    for s, c in sc:
        if t[int(s)] != int(c):
            ok = False
            break
    if ok:
        print(i)
        exit()
print(-1)


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

for i in range(1000):
    t = str(i)
    if len(t) != N:
        continue
    ok = True
    for s, c in sc:
        if int(t[s - 1]) != c:
            ok = False
            break
    if ok:
        print(i)
        exit()
print(-1)
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
/*
 * Created by solzard on 2020-03-05.
 * C - Guess The Number
 */
#include <iostream>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int GuessNumber(int n, int m, const std::vector<int> &s,
                const std::vector<int> &c) {
  int res = -1;
  for (int num = 999; num >= 0; --num) {
    std::string num_str = std::to_string(num);
    bool is_ok = true;
    if (num_str.size() != n)
      continue;
    rep(i, m) {
      if (num_str[s[i] - 1] != (char)('0' + c[i])) {
        is_ok = false;
        break;
      }
    }
    if (is_ok)
      res = num;
  }
  return res;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);

  int n, m;
  std::vector<int> s, c;
  std::cin >> n >> m;
  rep(i, m) { std::cin >> s[i] >> c[i]; }
  std::cout << GuessNumber(n, m, s, c) << "\n";
}


Fixed submission:
/*
 * Created by solzard on 2020-03-05.
 * C - Guess The Number
 */
#include <iostream>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

int GuessNumber(int n, int m, const std::vector<int> &s,
                const std::vector<int> &c) {
  int res = -1;
  for (int num = 999; num >= 0; --num) {
    std::string num_str = std::to_string(num);
    bool is_ok = true;
    if (num_str.size() != n)
      continue;
    rep(i, m) {
      if (num_str[s[i] - 1] != (char)('0' + c[i])) {
        is_ok = false;
        break;
      }
    }
    if (is_ok)
      res = num;
  }
  return res;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);

  int n, m;
  std::vector<int> s(5, 0), c(5, 0);
  std::cin >> n >> m;
  rep(i, m) { std::cin >> s[i] >> c[i]; }
  std::cout << GuessNumber(n, m, s, c) << "\n";
}