Problem p00437 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define loop(a, t) for (int a = 0; a < t; a++)
#define forever while (true)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
int ans[300];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  while (true) {
    int a, b, c, n;
    cin >> a >> b >> c;
    if (a == 0 && b == 0 && c == 0) {
      break;
    }
    cin >> n;
    int ak[1000], bk[1000], ck[1000];
    loop(i, 1000) {
      ak[i] = bk[i] = ck[i] = -1;
      if (i < 300) {
        ans[i] = 2;
      }
    }
    loop(i, n) {
      int an, bn, cn, or1;
      cin >> an >> bn >> cn >> or1;
      if (or1 == 1) {
        ans[an - 1] = 1;
        ans[bn - 1] = 1;
        ans[cn - 1] = 1;
      } else {
        ak[i] = an - 1;
        bk[i] = bn - 1;
        ck[i] = cn - 1;
      }
    }
    loop(i, n) {
      if (ak[i] != -1) {
        if (ans[ak[i]] == 2 && ans[bk[i]] == 1 && ans[ck[i]] == 1) {
          ans[ak[i]] = 0;
        }
        if (ans[ak[i]] == 1 && ans[bk[i]] == 2 && ans[ck[i]] == 1) {
          ans[bk[i]] = 0;
        }
        if (ans[ak[i]] == 1 && ans[bk[i]] == 1 && ans[ck[i]] == 2) {
          ans[ck[i]] = 0;
        }
      }
    }
    loop(i, a + b + c) { cout << ans[i] << endl; }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define loop(a, t) for (int a = 0; a < t; a++)
#define forever while (true)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
int ans[300];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  while (true) {
    int a, b, c, n;
    cin >> a >> b >> c;
    if (a == 0 && b == 0 && c == 0) {
      break;
    }
    cin >> n;
    int ak[100], bk[100], ck[100];
    loop(i, 100) {
      ak[i] = bk[i] = ck[i] = -1;
      ans[i] = 2;
    }
    loop(i, n) {
      int an, bn, cn, or1;
      cin >> an >> bn >> cn >> or1;
      if (or1 == 1) {
        ans[an - 1] = 1;
        ans[bn - 1] = 1;
        ans[cn - 1] = 1;
      } else {
        ak[i] = an - 1;
        bk[i] = bn - 1;
        ck[i] = cn - 1;
      }
    }
    loop(i, 100) {
      if (ak[i] != -1) {
        if (ans[ak[i]] == 2 && ans[bk[i]] == 1 && ans[ck[i]] == 1) {
          ans[ak[i]] = 0;
        }
        if (ans[ak[i]] == 1 && ans[bk[i]] == 2 && ans[ck[i]] == 1) {
          ans[bk[i]] = 0;
        }
        if (ans[ak[i]] == 1 && ans[bk[i]] == 1 && ans[ck[i]] == 2) {
          ans[ck[i]] = 0;
        }
      }
    }
    loop(i, a + b + c) { cout << ans[i] << endl; }
  }
  return 0;
}