alexjercan/bugnet huggingface dataset:
Problem p00445 (C++) — buggy submission, verdict: Time Limit Exceeded

// https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Prelim/0522?year=2008

#include <bits/stdc++.h>

using namespace std;

int main() {
  string s;

  while (cin >> s) {
    int joi = 0, ioi = 0;
    for (int i = 0; i < s.size() - 2; ++i) {
      if (s[i + 1] == 'O' and s[i + 2] == 'I') {
        if (s[i] == 'J') {
          joi++;
        } else if (s[i] == 'I') {
          ioi++;
        }
      }
    }

    cout << joi << endl;
    cout << ioi << endl;
  }
}

/*
 * substrでJOI,IOIをそれぞれ探したらTLEだったので
 * OIが共通なことを利用した。
 *
 */


Error: TLE

Fixed submission:

// https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Prelim/0522?year=2008

#include <bits/stdc++.h>

using namespace std;

int main() {
  string s;

  while (true) {
    cin >> s;
    if (s.empty())
      return 0;

    int joi = 0, ioi = 0;
    for (int i = 0; i < s.size() - 2; ++i) {
      if (s[i + 1] == 'O' and s[i + 2] == 'I') {
        if (s[i] == 'J') {
          joi++;
        } else if (s[i] == 'I') {
          ioi++;
        }
      }
    }

    cout << joi << endl;
    cout << ioi << endl;
  }
}

/*
 * substrでJOI,IOIをそれぞれ探したらTLEだったので
 * OIが共通なことを利用した。
 *
 */
Problem p00445 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, s, e) for (int i = int(s); i <= int(e); i++)
#define rep(i, n) for (int i = 0; i < int(n); i++)

int main() {

  string s;
  while (cin >> s) {

    int n = s.size();
    int a = 0;
    int b = 0;

    rep(i, n - 2) {
      if (s[i] == 'J' && s[i + 1] == 'O' && s[i + 2] == 'I')
        a++;
      if (s[i] == 'I' && s[i + 1] == 'O' && s[i + 2] == 'I')
        b++;
    }

    cout << a << endl;
    cout << b << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, s, e) for (int i = int(s); i <= int(e); i++)
#define rep(i, n) for (int i = 0; i < int(n); i++)

int main() {

  while (true) {

    string s;
    cin >> s;
    if (s == "EOF")
      break;

    int n = s.size();
    int a = 0;
    int b = 0;

    rep(i, n - 2) {
      if (s[i] == 'J' && s[i + 1] == 'O' && s[i + 2] == 'I')
        a++;
      if (s[i] == 'I' && s[i + 1] == 'O' && s[i + 2] == 'I')
        b++;
    }

    cout << a << endl;
    cout << b << endl;
  }

  return 0;
}
Problem p00446 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int z[205], b;
int main(void) {
  int n, i, x, m[2], t;
  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }
    for (i = 1; i <= n * 2; i++) {
      z[i] = 1;
    }
    for (i = 1; i <= n; i++) {
      cin >> t;
      z[t] = 0;
    }
    m[0] = m[1] = n;
    x = 0;
    b = 0;
    while (m[0] > 0 && m[1] > 0) {
      for (i = b + 1; i <= n * 2; i++) {
        if (x == z[i]) {
          b = i;
          z[i] = 2;
          m[x]--;
          break;
        }
      }
      if (i > n * 2) {
        b = 0;
      }
      x = !x;
    }
    cout << m[1] << endl << m[0] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int z[205], b;
int main(void) {
  int n, i, x, m[2], t;
  while (1) {
    scanf("%d", &n);
    if (n == 0) {
      break;
    }
    for (i = 1; i <= n * 2; i++) {
      z[i] = 1;
    }
    for (i = 1; i <= n; i++) {
      scanf("%d", &t);
      z[t] = 0;
    }

    m[0] = m[1] = n;
    x = 0;
    b = 0;
    while (m[0] > 0 && m[1] > 0) {
      for (i = b + 1; i <= n * 2; i++) {
        if (x == z[i]) {
          b = i;
          z[i] = 2;
          m[x]--;
          break;
        }
        if (i > n * 2) {
          b = 0;
        }
        x = !x;
      }
    }
    printf("%d\\n%d\\n", m[1], m[0]);
  }
  return 0;
}
Problem p00446 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int l[210], b;
int main(void) {
  int i, n, t, m[2], x;
  while (1) {
    scanf("%d", &n);
    if (n == 0) {
      break;
    }
    for (i = 1; i <= n * 2; i++) {
      l[i] = 1;
    }
    for (i = 1; i <= n; i++) {
      scanf("%d", &t);
      l[t] = 0;
    }
    m[0] = m[1] = n;
    x = 0;
    b = 0;
    while (m[0] > 0 && m[1] > 0) {
      for (i = b + 1; i <= n * 2; i++) {
        if (x == l[i]) {
          b = i;
          l[i] = 2;
          m[x]--;
          break;
        }
      }
      if (i > n * 2) {
        b = 0;
      }
      x = !x;
    }
    printf("%d\\n%d\\n", m[1], m[0]);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int z[205], b;
int main(void) {
  int n, i, x, m[2], t;
  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }
    for (i = 1; i <= 2 * n; i++) {
      z[i] = 1;
    }
    for (i = 1; i <= n; i++) {
      cin >> t;
      z[t] = 0;
    }
    b = 0;
    m[0] = m[1] = n;
    x = 0;
    while (m[0] > 0 && m[1] > 0) {
      for (i = b + 1; i <= 2 * n; i++) {
        if (x == z[i]) {
          b = i;
          z[i] = 2;
          m[x]--;
          break;
        }
        if (i > n * 2) {
          b = 0;
        }
        x = !x;
      }
    }
    cout << m[1] << endl << m[0] << endl;
  }
  return 0;
}
Problem p00446 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, t, h;
  while (cin >> n, n) {
    t = h = n;
    bool taro[2 * n + 5] = {false}, hana[2 * n + 5] = {false};
    for (int i = 0; i < n; i++) {
      int num;
      cin >> num;
      taro[num] = true;
    }
    for (int i = 1; i <= 2 * n; i++)
      if (!taro[i])
        hana[i] = true;

    bool f;
    int field = 0;
    while (1) {
      f = false;
      for (int i = field + 1; i <= 2 * n; i++) {
        if (taro[i]) {
          taro[i] = false;
          field = i;
          f = true;
          t--;
          break;
        }
      }
      if (t == 0 || h == 0) {
        cout << h << '\\n' << t << '\\n';
        break;
      }
      if (!f)
        field = 0;
      else
        f = false;
      for (int i = field + 1; i <= 2 * n; i++) {
        if (hana[i]) {
          hana[i] = false;
          field = i;
          f = true;
          h--;
          break;
        }
      }
      if (!f)
        field = 0;
      else
        f = false;
      if (t == 0 || h == 0) {
        cout << h << '\\n' << t << '\\n';
        break;
      }
    }
  }
}

Error: TLE

Fixed submission:

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

bool taro[110], hana[110];
int t, h;

int main() {
  int n;
  while (cin >> n, n) {
    t = h = n;
    for (int i = 0; i <= 2 * n + 1; i++)
      taro[i] = hana[i] = false;
    for (int i = 0; i < n; i++) {
      int num;
      cin >> num;
      taro[num] = true;
    }
    for (int i = 1; i <= 2 * n; i++)
      if (!taro[i])
        hana[i] = true;

    bool f;
    int field = 0;
    while (1) {
      f = false;
      for (int i = field; i <= 2 * n; i++) {
        if (taro[i]) {
          taro[i] = false;
          field = i;
          f = true;
          t--;
          break;
        }
      }
      if (t == 0 || h == 0) {
        cout << h << '\\n' << t << '\\n';
        break;
      }
      if (!f)
        field = 0;
      else
        f = false;
      for (int i = field; i <= 2 * n; i++) {
        if (hana[i]) {
          hana[i] = false;
          field = i;
          f = true;
          h--;
          break;
        }
      }
      if (!f)
        field = 0;
      else
        f = false;
      if (t == 0 || h == 0) {
        cout << h << '\\n' << t << '\\n';
        break;
      }
    }
  }
}
Problem p00446 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <stdio.h>
#include <vector>
using namespace std;

int main() {
  int i, j, n, cnt = 0;
  scanf("%d", &n);
  if (n == 0) {
    return 0;
  }
  vector<int> t(n);
  vector<int> h(n);
  for (i = 0; i < n; i++) {
    scanf("%d", &t[i]);
  }
  sort(t.begin(), t.end());
  for (i = 1; i <= 2 * n; i++) {
    if (find(t.begin(), t.end(), i) == t.end()) {
      h[cnt] = i;
      cnt++;
    }
  }
  int cn = t[0];
  t.erase(t.begin());
  while (true) {
    for (i = 0; i < h.size() && cn > h[i]; i++)
      ;
    if (i == h.size())
      cn = 0;
    else {
      cn = h[i];
      h.erase(h.begin() + i);
    }
    if (h.empty())
      break;
    for (i = 0; i < t.size() && cn > t[i]; i++)
      ;
    if (i == t.size())
      cn = 0;
    else {
      cn = t[i];
      t.erase(t.begin() + i);
    }
    if (t.empty())
      break;
  }
  printf("%d\\n%d\\n", h.size(), t.size());
  main();
}

Error: 0

Fixed submission:

#include <algorithm>
#include <stdio.h>
#include <vector>
using namespace std;

int main() {
  int i, n, cnt = 0;
  scanf("%d", &n);
  if (n == 0)
    return 0;
  vector<int> t(n);
  vector<int> h(n);
  for (i = 0; i < n; i++) {
    scanf("%d", &t[i]);
  }
  sort(&t[0], &t[n - 1]);
  for (i = 1; i < t[0]; i++) {
    h[cnt] = i;
    cnt++;
  }
  for (i = 0; i < n - 1; i++) {
    for (int j = t[i] + 1; j < t[i + 1]; j++) {
      h[cnt] = j;
      cnt++;
    }
  }
  for (i = t[n - 1] + 1; i <= 2 * n; i++) {
    h[cnt] = i;
    cnt++;
  }
  int cn = t[0];
  t.erase(t.begin());
  while (true) {
    for (i = 0; i < h.size() && cn > h[i]; i++)
      ;
    if (i == h.size())
      cn = 0;
    else {
      cn = h[i];
      h.erase(h.begin() + i);
    }
    if (h.empty())
      break;
    for (i = 0; i < t.size() && cn > t[i]; i++)
      ;
    if (i == t.size())
      cn = 0;
    else {
      cn = t[i];
      t.erase(t.begin() + i);
    }
    if (t.empty())
      break;
  }
  printf("%d\\n%d\\n", h.size(), t.size());
  main();
}
Problem p00446 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int n, a[201], b[201];
  int temp;
  while (1) {
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    cin >> n;
    if (n == 0)
      return 0;
    for (int i = 0; i < n; i++) {
      cin >> temp;
      a[temp]++;
    }
    for (int i = 1; i <= n * 2; i++) {
      if (a[i] == 0) {
        b[i]++;
      }
    }
    int ba = 0;
    int masatoy, hideo; //????????????????¨???¶
    int amai, bmai;
    amai = bmai = n; //????????????????????£??????????????????????????°
    masatoy = hideo = 0;
    int bal = 0; // 0??????????????????????????±???
    while (amai > 0 && bmai > 0) {
      if (bal == 0) {
        // cout << "o" << endl;
        if (masatoy == ba && ba > 0) {
          ba = 0;
          masatoy = -1;
        }
        for (int i = 1; i <= n * 2; i++) {
          if (a[i] == 1 && i > ba) {
            ba = i;
            masatoy = i;
            a[i] = -1;
            bal = 1;
            amai--;
            // cout << "tarou" << bmai << endl;
            break;
          }
        }
        bal = 1;
      } else if (bal == 1) {
        //	cout << "owannnele" << endl;
        if (hideo == ba && ba > 0) {
          ba = 0;
          hideo = -1;
        }
        for (int i = 1; i <= n * 2; i++) {
          if (b[i] == 1 && i > ba) {
            ba = i;
            hideo = i;
            b[i] = -1;
            bal = 0;
            bmai--;
            // cout << "hanako" << bmai << endl;
            break;
          }
        }
        bal = 0;
      }
    }
    cout << bmai << endl << amai << endl;
  }
}

Error: WA

Fixed submission:

#include <stdio.h>
int main() {
  int a[101] = {0}, b[101] = {0}, ruio = 0, hideo = 1, nagase = 0, masako = 0;
  int temp = 0, c[101] = {0}, k = 1;
  while (scanf("%d", &ruio) > 0) {
    if (ruio == 0)
      return 0;
    for (int i = 1; i <= ruio; i++) {
      scanf("%d", &a[i]);
      c[a[i]]++;
    }
    hideo = nagase = ruio;
    for (int i = 1; i < ruio; i++) {
      for (int j = ruio; j > i; j--) {
        if (a[j] < a[j - 1]) {
          temp = a[j];
          a[j] = a[j - 1];
          a[j - 1] = temp;
        }
      }
    }
    for (int j = 1; j <= ruio * 2; j++) {
      if (c[j] == 0) {
        b[k] = j;
        k++;
      }
    }
    k = 0;
    while (nagase != 0 && hideo != 0) {
      k++;
      if (masako == 0) {
        masako = a[k];
        nagase--;
      } else if (masako < a[k]) {
        masako = a[k];
        nagase--;
      } else {
        masako = 0;
      }
      if (nagase == 0) {
        break;
      }
      a[k] = 0;
      if (masako == 0) {
        masako = b[k];
        hideo--;
      } else if (masako < b[k]) {
        masako = b[k];
        hideo--;
      } else {
        masako = 0;
      }
      b[k] = 0;
    }
    printf("%d\\n%d\\n", hideo - 1, nagase);
    for (int i = 1; i <= 100; i++) {
      a[i] = 0;
      b[i] = 0;
      c[i] = 0;
    }
    hideo = nagase = 0;
    masako = temp = 0;
    k = 1;
  }
}
Problem p00446 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>

using namespace std;

int main(void) {

  bool T[201], H[201];
  int tc, hc;
  int n, k;
  int turn;
  int fi;

  while (1) {
    cin >> n;
    if (n == 0)
      break;
    tc = n, hc = n;
    for (int i = 1; i <= 2 * n; i++)
      T[i] = false, H[i] = false;
    for (int i = 0; i < n; i++) {
      cin >> k;
      T[k] = true;
    }
    for (int i = 1; i <= 2 * n; i++) {
      if (T[i] == false)
        H[i] = true;
    }

    turn = 1;
    fi = 0;
    while (tc != 0 && hc != 0) {
      if (turn == 1) {
        if (fi == 2 * n) {
          fi = 0;
          turn = 2;
          continue;
        }
        for (int i = fi + 1; i <= 2 * n; i++) {
          if (T[i] == true) {
            tc--;
            T[i] = false;
            fi = i;
            break;
          }
          if (i == 2 * n) {
            fi = 0;
            break;
          }
        }
        turn = 2;
      } else {
        if (fi == 2 * n) {
          fi = 0;
          turn = 1;
          continue;
        }
        for (int i = fi + 1; i <= 2 * n; i++) {
          if (H[i] == true) {
            hc--;
            H[i] = false;
            fi = i;
            break;
          }
          if (i == 2 * n) {
            fi = 0;
            break;
          }
        }
        turn = 1;
      }
    }
    cout << hc << endl << tc << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main(void) {

  bool T[201], H[201];
  int tc, hc;
  int n, k;
  int turn;
  int fi;

  while (1) {
    cin >> n;
    if (n == 0)
      break;
    tc = n, hc = n;
    for (int i = 1; i <= 2 * n; i++)
      T[i] = false, H[i] = false;
    for (int i = 0; i < n; i++) {
      cin >> k;
      T[k] = true;
    }
    for (int i = 1; i <= 2 * n; i++) {
      if (T[i] == false)
        H[i] = true;
    }

    turn = 1;
    fi = 0;
    while (tc != 0 && hc != 0) {
      if (turn == 1) {
        if (fi == 20) {
          fi = 0;
          turn = 2;
          continue;
        }
        for (int i = fi + 1; i <= 2 * n; i++) {
          if (T[i] == true) {
            tc--;
            T[i] = false;
            fi = i;
            break;
          }
          if (i == 2 * n) {
            fi = 0;
            break;
          }
        }
        turn = 2;
      } else {
        if (fi == 20) {
          fi = 0;
          turn = 1;
          continue;
        }
        for (int i = fi + 1; i <= 2 * n; i++) {
          if (H[i] == true) {
            hc--;
            H[i] = false;
            fi = i;
            break;
          }
          if (i == 2 * n) {
            fi = 0;
            break;
          }
        }
        turn = 1;
      }
    }
    cout << hc << endl << tc << endl;
  }

  return 0;
}
Problem p00446 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main() {
  int n, a;
  bool Tf[305], Hf[305];
  while (cin >> n && n) {
    vector<int> tque, hque;
    for (int i = 0; i <= 303; i++) {
      Tf[i] = false;
      Hf[i] = true;
    }
    for (int i = 0; i < n; i++) {
      cin >> a;
      Tf[a] = true;
      Hf[a] = false;
    }

    for (int i = 1; i <= 2 * n; i++) {
      if (Tf[i]) {
        tque.push_back(i);
      } else if (Hf[i])
        hque.push_back(i);
    }

    int FL = -1;

    while (!hque.empty() && !tque.empty()) {

      vector<int>::iterator tit = lower_bound(tque.begin(), tque.end(), FL);
      if (tit != tque.end()) {
        // cout << "taro pop = " << *tit << endl;
        FL = *tit;
        tque.erase(tit);
      } else
        FL = -1;
      if (tque.empty())
        break;

      vector<int>::iterator hit = lower_bound(hque.begin(), hque.end(), FL);
      if (hit != hque.end()) {
        // cout << "hanako pop = " << *hit << endl;
        FL = *hit;
        hque.erase(hit);

      } else
        FL = -1;
      if (hque.empty())
        break;
    }

    cout << hque.size() << endl;
    cout << tque.size() << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main() {
  int n, a;
  bool Tf[105], Hf[105];
  while (cin >> n && n) {
    vector<int> tque, hque;
    for (int i = 0; i <= 103; i++) {
      Tf[i] = false;
      Hf[i] = true;
    }
    for (int i = 0; i < n; i++) {
      cin >> a;
      Tf[a] = true;
      Hf[a] = false;
    }

    for (int i = 1; i <= 2 * n; i++) {
      if (Tf[i]) {
        tque.push_back(i);
      } else if (Hf[i])
        hque.push_back(i);
    }

    int FL = -1;

    while (!hque.empty() && !tque.empty()) {
      vector<int>::iterator fintit = lower_bound(tque.begin(), tque.end(), FL);
      vector<int>::iterator finhit = lower_bound(hque.begin(), hque.end(), FL);
      if (fintit == tque.end() && finhit == hque.end())
        FL = -1;

      vector<int>::iterator tit = lower_bound(tque.begin(), tque.end(), FL);
      if (tit != tque.end()) {
        // cout << "taro pop = " << *tit << endl;
        FL = *tit;
        tque.erase(tit);
      }
      vector<int>::iterator hit = lower_bound(hque.begin(), hque.end(), FL);
      if (hit != hque.end()) {
        // cout << "hanako pop = " << *hit << endl;
        FL = *hit;
        hque.erase(hit);
      }
    }

    cout << hque.size() << endl;
    cout << tque.size() << endl;
  }
  return 0;
}
Problem p00446 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int N, ba, d, c1, c2;
  int tc, hc, flag;
  int taro[100], hana[100];
  while (1) {
    int F[201] = {0};
    ba = 0;
    cin >> N;
    if (N == 0)
      break;
    for (int i = 0; i < N; i++) {
      cin >> d;
      F[d] = 1;
    }
    c1 = 0;
    c2 = 0;
    for (int i = 1; i <= N * 2; i++) {
      if (F[i] == 1) {
        taro[c1] = i;
        c1++;
      } else if (F[i] == 0) {
        hana[c2] = i;
        c2++;
      }
    }

    /////////////////////////////////////////////
    tc = N;
    hc = N;
    flag = 0;
    while (1) {
      for (int i = 0; i < N; i++) {
        if (ba < taro[i]) {
          ba = taro[i];
          flag = 1;
          taro[i] = 0;
          tc--;
          break;
        }
      }
      if (tc == 0)
        break;
      if (flag == 0)
        ba = 0;
      flag = 0;

      for (int i = 0; i < N; i++) {
        if (ba < hana[i]) {
          ba = hana[i];
          flag = 1;
          hana[i] = 0;
          hc--;
          break;
        }
      }
      if (hc == 0)
        break;
      if (flag == 0)
        ba = 0;
      flag = 0;
    }
    cout << hc << endl << tc << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int N, ba, d, c1, c2;
  int tc, hc, flag;
  int taro[100], hana[100];
  while (1) {
    int F[101] = {0};
    ba = 0;
    cin >> N;
    if (N == 0)
      break;
    for (int i = 0; i < N; i++) {
      cin >> d;
      F[d] = 1;
    }
    c1 = 0;
    c2 = 0;
    for (int i = 1; i <= N * 2; i++) {
      if (F[i] == 1) {
        taro[c1] = i;
        c1++;
      } else if (F[i] == 0) {
        hana[c2] = i;
        c2++;
      }
    }

    /////////////////////////////////////////////
    tc = N;
    hc = N;
    flag = 0;
    while (1) {
      for (int i = 0; i < N; i++) {
        if (ba < taro[i]) {
          ba = taro[i];
          flag = 1;
          taro[i] = 0;
          tc--;
          break;
        }
      }
      if (tc == 0)
        break;
      if (flag == 0)
        ba = 0;
      flag = 0;

      for (int i = 0; i < N; i++) {
        if (ba < hana[i]) {
          ba = hana[i];
          flag = 1;
          hana[i] = 0;
          hc--;
          break;
        }
      }
      if (hc == 0)
        break;
      if (flag == 0)
        ba = 0;
      flag = 0;
    }
    cout << hc << endl << tc << endl;
  }
  return 0;
}
Problem p00446 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <stdio.h>
using namespace std;
int main(void) {
  int n, i, a[101], e[201], c, x, y, flg;
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (i = 1; i <= n * 2; i++)
      e[i] = 0;
    for (i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    for (i = 0; i < n; i++) {
      e[a[i]] = 1;
    }
    x = n;
    y = n;
    flg = 0;
    while (1) {
      for (i = 1; i <= n * 2; i++) {
        if (flg == 0 && e[i] == 1) {
          x--;
          e[i] = 2;
          flg = 1;
        } else if (flg == 1 && e[i] == 0) {
          y--;
          e[i] = 2;
          flg = 0;
        }
        if (x == 0 || y == 0)
          break;
      }
      if (flg == 0)
        flg = 1;
      else
        flg = 0;
      if (x == 0 || y == 0)
        break;
    }
    printf("%d\\n", y);
    printf("%d\\n", x);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <stdio.h>
using namespace std;
int main(void) {
  int n, i, a[10], e[201], c, x, y, flg;
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (i = 1; i <= n * 2; i++)
      e[i] = 0;
    for (i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    for (i = 0; i < n; i++) {
      e[a[i]] = 1;
    }
    x = n;
    y = n;
    flg = 0;
    while (1) {
      for (i = 1; i <= n * 2; i++) {
        if (flg == 0 && e[i] == 1) {
          x--;
          e[i] = 2;
          flg = 1;
        } else if (flg == 1 && e[i] == 0) {
          y--;
          e[i] = 2;
          flg = 0;
        }
        if (x == 0 || y == 0)
          break;
      }
      if (flg == 0)
        flg = 1;
      else
        flg = 0;
      if (x == 0 || y == 0)
        break;
    }
    printf("%d\\n", y);
    printf("%d\\n", x);
  }
  return 0;
}