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

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n;

  while (cin >> n, n) {
    int taro[10000] = {0}, hana[10000] = {0}, a;
    for (int i = 0; i < n; i++) {
      cin >> a;
      taro[a] = a;
    }

    for (int i = 1; i <= 2 * n; i++) {
      if (taro[i] == 0)
        hana[i] = i;
    }

    sort(taro, taro + (2 * n + 1));
    sort(hana, hana + (2 * n + 1));

    int p = 1, k = 1;
    for (int i = 1; i <= 2 * n; i++) {
      if (taro[i] != 0)
        taro[p++] = taro[i];
      if (hana[i] != 0)
        hana[k++] = hana[i];
    }

    p = 1, k = 1;

    int turn = 0;

    while (1) {

      int f1 = 0, f2 = 0;

      for (int i = 1; i <= n; i++) {

        if (taro[i] != 0)
          f1 = 1;
        if (hana[i] != 0)
          f2 = 1;
      }

      if (f1 == 0 || f2 == 0)
        break;

      if (turn == 0) {

        if (k > n) {
          taro[p] = 0;
          k = 1;
          p = 1;
          continue;
        }

        if (taro[p] < hana[k] && taro[p] != 0) {

          taro[p] = 0;

          p++;

          turn = 1;

          continue;

        } else
          k++;

        if (taro[p] == 0)
          p++;

      } else if (turn == 1) {

        if (p > n) {
          hana[k] = 0;
          p = 1;
          k = 1;
          continue;
        }

        if (taro[p] > hana[k] && hana[k] != 0) {

          hana[k] = 0;
          k++;
          turn = 0;
          continue;

        } else
          p++;

        if (hana[k] == 0)
          k++;
      }
    }

    int cnt = 0, cnt2 = 0;

    for (int i = 1; i <= n; i++) {

      if (taro[i])
        cnt++;
      if (hana[i])
        cnt2++;
    }

    cout << cnt2 << endl;
    cout << cnt << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n;
  int taro[100] = {0}, hana[100] = {0}, a;
  while (cin >> n, n) {

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

    for (int i = 1; i <= 2 * n; i++) {
      if (taro[i] == 0)
        hana[i] = i;
    }

    sort(taro, taro + (2 * n + 1));
    sort(hana, hana + (2 * n + 1));

    int p = 1, k = 1;
    for (int i = 1; i <= 2 * n; i++) {
      if (taro[i] != 0)
        taro[p++] = taro[i];
      if (hana[i] != 0)
        hana[k++] = hana[i];
    }

    p = 1, k = 1;

    int turn = 0;
    int m;

    while (1) {

      int f1 = 0, f2 = 0;

      for (int i = 1; i <= n; i++) {

        if (taro[i] != 0)
          f1 = 1;
        if (hana[i] != 0)
          f2 = 1;
      }

      if (f1 == 0 || f2 == 0)
        break;

      if (turn == 0) {

        if (k > n) {
          taro[p] = 0;
          k = 1;
          p = 1;
          continue;
        }

        if (taro[p] < hana[k] && taro[p] != 0) {

          taro[p] = 0;

          p++;

          turn = 1;

          continue;

        } else
          k++;

        if (taro[p] == 0)
          p++;

      } else if (turn == 1) {

        if (p > n) {
          hana[k] = 0;
          p = 1;
          k = 1;
          continue;
        }

        if (taro[p] > hana[k] && hana[k] != 0) {

          hana[k] = 0;
          k++;
          turn = 0;
          continue;

        } else
          p++;

        if (hana[k] == 0)
          k++;
      }
    }

    int cnt = 0, cnt2 = 0;

    for (int i = 1; i <= n; i++) {

      if (taro[i])
        cnt++;
      if (hana[i])
        cnt2++;
    }

    cout << cnt2 << endl;
    cout << cnt << endl;
  }
  return 0;
}