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

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

string itos(int t) {
  ostringstream oss;
  oss << t;
  return oss.str();
}

string opr(string str) {
  string res = "";
  for (int i = 0; i < str.size();) {
    int idx = i + 1;
    while (idx < str.size() && str[i] == str[idx])
      idx++;
    res += itos(idx - i) + str[i];
  }
  return res;
}

int main() {
  int n;
  while (cin >> n, n) {
    string str;
    cin >> str;
    for (int i = 0; i < n; i++)
      str = opr(str);
    cout << str << endl;
  }
}

Fixed submission:
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

string itos(int t) {
  ostringstream oss;
  oss << t;
  return oss.str();
}

string opr(string str) {
  string res = "";
  for (int i = 0; i < str.size();) {
    int idx = i + 1;
    while (idx < str.size() && str[i] == str[idx])
      idx++;
    res += itos(idx - i) + str[i];
    i = idx;
  }
  return res;
}

int main() {
  int n;
  while (cin >> n, n) {
    string str;
    cin >> str;
    for (int i = 0; i < n; i++)
      str = opr(str);
    cout << str << endl;
  }
}
Problem p00429 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;
int N;
string S;

string::iterator CountSeqStr(string::iterator start, string *s, int *n) {
  *s = *start;
  *n = 0;
  string tmp;
  for (; tmp = *start, tmp == *s && start != S.end(); ++start) {
    (*n)++;
  }
  return --start;
}

string F() {
  string retS;
  string s;
  string::iterator it;
  int n;
  for (it = S.begin(); it != S.end(); ++it) {
    it = CountSeqStr(it, &s, &n);
    char *strn;
    sprintf(strn, "%d", n);
    retS.append(string(strn));
    retS.append(s);
  }
  return retS;
}

int main() {
  while (cin >> N && N) {
    cin >> S;
    for (int i = 0; i < N; i++) {
      string tmp;
      S = F();
    }
    cout << S << endl;
  }
  return 0;
}

Fixed submission:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;
int N;
string S;

string::iterator CountSeqStr(string::iterator start, string *s, int *n) {
  *s = *start;
  *n = 0;
  string tmp;
  for (; tmp = *start, tmp == *s && start != S.end(); ++start) {
    (*n)++;
  }
  return --start;
}

string F() {
  string retS;
  string s;
  string::iterator it;
  int n;
  for (it = S.begin(); it != S.end(); ++it) {
    it = CountSeqStr(it, &s, &n);
    char strn[10000];
    sprintf(strn, "%d", n);
    retS.append(string(strn));
    retS.append(s);
  }
  return retS;
}

int main() {
  while (cin >> N && N) {
    cin >> S;
    for (int i = 0; i < N; i++) {
      string tmp;
      S = F();
    }
    cout << S << endl;
  }
  return 0;
}
Problem p00429 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int n, i;
  char data[101];
  char out[101];
  char r;
  int k, m;
  char num[11] = "0123456789";
  while (cin >> n) {
    if (n == 0) {
      break;
    }
    cin >> data;
    for (int j = 0; j < n; j++) {
      k = 0;
      m = 1;
      r = data[0];
      for (i = 1; data[i] != '\0'; i++) {
        if (data[i] == r) {
          m += 1;
        } else {
          if (m < 10) {
            out[k] = num[m];
            k += 1;
          } else if (m < 100) {
            out[k] = num[m / 10];
            k += 1;
            out[k] = num[m - m / 10 * 10];
            k += 1;
          } else {
            out[k] = num[m / 100];
            k += 1;
            out[k] = num[m / 10 - m / 100 * 10];
            k += 1;
            out[k] = num[m - m / 10 * 10];
            k += 1;
          }
          out[k] = r;
          k += 1;
          r = data[i];
          m = 1;
        }
      }
      if (m < 10) {
        out[k] = num[m];
        k += 1;
      } else if (m < 100) {
        out[k] = num[m / 10];
        k += 1;
        out[k] = num[m - m / 10 * 10];
        k += 1;
      } else {
        out[k] = num[m / 100];
        k += 1;
        out[k] = num[m / 10 - m / 100 * 10];
        k += 1;
        out[k] = num[m - m / 10 * 10];
        k += 1;
      }
      out[k] = r;
      k += 1;
      out[k] = '\0';
      for (i = 0; out[i] != '\0'; i++) {
        data[i] = out[i];
      }
      data[i] = '\0';
    }
    cout << data << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n, i;
  char data[2000001];
  char out[2000001];
  char r;
  int k, m;
  char num[11] = "0123456789";
  while (cin >> n) {
    if (n == 0) {
      break;
    }
    cin >> data;
    for (int j = 0; j < n; j++) {
      k = 0;
      m = 1;
      r = data[0];
      for (i = 1; data[i] != '\0'; i++) {
        if (data[i] == r) {
          m += 1;
        } else {
          if (m < 10) {
            out[k] = num[m];
            k += 1;
          } else if (m < 100) {
            out[k] = num[m / 10];
            k += 1;
            out[k] = num[m - m / 10 * 10];
            k += 1;
          } else {
            out[k] = num[m / 100];
            k += 1;
            out[k] = num[m / 10 - m / 100 * 10];
            k += 1;
            out[k] = num[m - m / 10 * 10];
            k += 1;
          }
          out[k] = r;
          k += 1;
          r = data[i];
          m = 1;
        }
      }
      if (m < 10) {
        out[k] = num[m];
        k += 1;
      } else if (m < 100) {
        out[k] = num[m / 10];
        k += 1;
        out[k] = num[m - m / 10 * 10];
        k += 1;
      } else {
        out[k] = num[m / 100];
        k += 1;
        out[k] = num[m / 10 - m / 100 * 10];
        k += 1;
        out[k] = num[m - m / 10 * 10];
        k += 1;
      }
      out[k] = r;
      k += 1;
      out[k] = '\0';
      for (i = 0; out[i] != '\0'; i++) {
        data[i] = out[i];
      }
      data[i] = '\0';
    }
    cout << data << endl;
  }
  return 0;
}
Problem p00429 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
#include <string.h>

#define MAXLEN 1024

int main(void) {
  int n;
  char src[MAXLEN], *p, *q;
  int ch, cnt;

  while (scanf("%d", &n), n) {
    scanf("%s", src);
    for (int i = 0; i < n; i++) {
      char buf[MAXLEN] = {0};
      ch = *src;
      cnt = 1;
      q = buf;
      for (p = src + 1; 1; p++) {
        //				printf("p=<%s>, buf=<%s>, (ch=%c, cnt=%d)\n",
        //p, buf, ch, cnt);
        if (*p == ch) {
          cnt++;
        } else {
          char tmp[100];
          sprintf(tmp, "%d", cnt);
          strcpy(q, tmp);
          q += strlen(tmp);
          *q++ = ch;
          ch = *p;
          cnt = 1;
          if (ch == 0)
            break;
        }
      }
      strcpy(src, buf);
    }
    puts(src);
  }
  return 0;
}

Fixed submission:
#include <stdio.h>
#include <string.h>

#define MAXLEN 65536

int main(void) {
  int n;
  char src[MAXLEN], *p, *q;
  int ch, cnt;

  while (scanf("%d", &n), n) {
    scanf("%s", src);
    for (int i = 0; i < n; i++) {
      char buf[MAXLEN] = {0};
      ch = *src;
      cnt = 1;
      q = buf;
      for (p = src + 1; 1; p++) {
        //				printf("p=<%s>, buf=<%s>, (ch=%c, cnt=%d)\n",
        //p, buf, ch, cnt);
        if (*p == ch) {
          cnt++;
        } else {
          char tmp[100];
          sprintf(tmp, "%d", cnt);
          strcpy(q, tmp);
          q += strlen(tmp);
          *q++ = ch;
          ch = *p;
          cnt = 1;
          if (ch == 0)
            break;
        }
      }
      strcpy(src, buf);
    }
    puts(src);
  }
  return 0;
}
Problem p00429 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <string.h>

using namespace std;

int main() {
  char in[2][10001], key, temp[10001];
  int n, now, cnt, wrt;
  bool turn;

  while (cin >> n && n) {
    cin >> in[0];
    turn = 1;
    for (int i = 0; i < n; i++) {
      turn = !turn;
      now = 0;
      wrt = 0;
      while (now < strlen(in[turn])) {
        key = in[turn][now];
        cnt = 0;
        while (now < strlen(in[turn]) && key == in[turn][now]) {
          now++;
          cnt++;
        }
        sprintf(temp, "%d", cnt);
        for (int j = 0; j < strlen(temp); j++) {
          in[!turn][wrt] = temp[j];
          wrt++;
        }
        in[!turn][wrt] = key;
        wrt++;
      }
      in[!turn][wrt] = '\0';
    }
    cout << in[!turn] << endl;
  }

  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <string.h>

using namespace std;

int main() {
  char in[2][100001], key, temp[100001];
  int n, now, cnt, wrt;
  bool turn;

  while (cin >> n && n) {
    cin >> in[0];
    turn = 1;
    for (int i = 0; i < n; i++) {
      turn = !turn;
      now = 0;
      wrt = 0;
      while (now < strlen(in[turn])) {
        key = in[turn][now];
        cnt = 0;
        while (now < strlen(in[turn]) && key == in[turn][now]) {
          now++;
          cnt++;
        }
        sprintf(temp, "%d", cnt);
        for (int j = 0; j < strlen(temp); j++) {
          in[!turn][wrt] = temp[j];
          wrt++;
        }
        in[!turn][wrt] = key;
        wrt++;
      }
      in[!turn][wrt] = '\0';
    }
    cout << in[!turn] << endl;
  }

  return 0;
}
Problem p00429 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
  char ss[10000],
      sst[10000]; // üÍpÆroßpÌ¶ñzñ
  int n, i, j, ki, a, b;

  while (0 <= scanf("%d", &n)) {

    if (n == 0)
      break;
    scanf(" %s ", ss);

    while (n > 0) {
      --n;
      j = 0; // üÍ³ê½¶ñzñÌY
      i = 0; // roßÌ¶ñzñÌY

      // ±Ìfor¶P[vÅÌ©½ÜèPÂð·é
      for (;;) {
        if (ss[j] == '\0')
          break;
        ki = ss[j];
        b = 1;

        // A±µÄ¢éð¦éiÂÍbÉüêéj
        for (a = j;; a++) {
          if (ss[a] != ss[a + 1])
            break;
          ++b;
        }

        // ªå«¢Ì
        if (b > 99) {
          sst[i] = b / 100 + '0';
          ++i;
        }
        if (b > 9) {
          sst[i] = (b / 10) % 10 + '0';
          ++i;
        }

        sst[i] = b % 10 + '0';
        sst[i + 1] = ki;
        i = i + 2;
        j = a + 1;
        sst[i] = '\0';
      }

      // roßðüÍpzñÉüêÄ[v
      //			strcpy(ss,sst);
      for (i = 0;; i++) {
        ss[i] = sst[i];
        if (sst[i] == '\0')
          break;
      }
    }
    printf("%s\n", sst);
  }

  return 0;
}

Fixed submission:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
  char ss[100000],
      sst[100000]; // üÍpÆroßpÌ¶ñzñ
  int n, i, j, ki, a, b;

  while (0 <= scanf("%d", &n)) {

    if (n == 0)
      break;
    scanf(" %s ", ss);

    while (n > 0) {
      --n;
      j = 0; // üÍ³ê½¶ñzñÌY
      i = 0; // roßÌ¶ñzñÌY

      // ±Ìfor¶P[vÅÌ©½ÜèPÂð·é
      for (;;) {
        if (ss[j] == '\0')
          break;
        ki = ss[j];
        b = 1;

        // A±µÄ¢éð¦éiÂÍbÉüêéj
        for (a = j;; a++) {
          if (ss[a] != ss[a + 1])
            break;
          ++b;
        }

        // ªå«¢Ì
        if (b > 99) {
          sst[i] = b / 100 + '0';
          ++i;
        }
        if (b > 9) {
          sst[i] = (b / 10) % 10 + '0';
          ++i;
        }

        sst[i] = b % 10 + '0';
        sst[i + 1] = ki;
        i = i + 2;
        j = a + 1;
        sst[i] = '\0';
      }

      // roßðüÍpzñÉüêÄ[v
      //			strcpy(ss,sst);
      for (i = 0;; i++) {
        ss[i] = sst[i];
        if (sst[i] == '\0')
          break;
      }
    }
    printf("%s\n", sst);
  }

  return 0;
}
Problem p00429 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _USE_MATH_DEFINES
#define INF 100000000
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>

using namespace std;

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

static const double eps = 1e-8;

int main() {
  int n;
  while (~scanf("%d", &n)) {
    if (n == 0)
      break;
    string num;
    cin >> num;
    for (int i = 0; i < n; i++) {
      string next;
      for (int j = 0; j < num.size();) {
        int c = 0;
        char alph;
        for (int k = 0; k <= 9; k++) {
          for (int len = 1; j + len - 1 < num.size(); len++) {
            string tmp = num.substr(j, len);
            if (count(tmp.begin(), tmp.end(), '0' + k) == len) {
              c++;
              alph = '0' + k;
            }
          }
        }

        j += c;

        char buf[32];
        sprintf(buf, "%d", c);
        string tmp = buf;
        next.append(tmp);
        next.push_back(alph);
      }
      num = next;
    }

    cout << num << endl;
  }
}

Fixed submission:
#define _USE_MATH_DEFINES
#define INF 100000000
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>

using namespace std;

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

static const double eps = 1e-8;

int main() {
  int n;
  while (~scanf("%d", &n)) {
    if (n == 0)
      break;
    string num;
    cin >> num;
    for (int i = 0; i < n; i++) {
      string next;
      for (int j = 0; j < num.size();) {
        int c = 0;
        char alph;
        for (int k = 0; k <= 9; k++) {
          for (int len = 1; j + len - 1 < num.size(); len++) {
            string tmp = num.substr(j, len);
            if (count(tmp.begin(), tmp.end(), '0' + k) == len) {
              c++;
              alph = '0' + k;
            } else
              break;
          }
        }

        j += c;

        char buf[32];
        sprintf(buf, "%d", c);
        string tmp = buf;
        next.append(tmp);
        next.push_back(alph);
      }
      num = next;
    }

    cout << num << endl;
  }
}
Problem p00429 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main() {
  int n, num, cont, v;
  string a, nex;
  stringstream ss;
  while (1) {

    scanf("%d", &n);

    if (n == 0) {
      break;
    }
    cin >> a;

    for (int i = 0; i < n; i++) {
      cont = 0;
      while (1) {
        if (cont >= a.size()) {
          break;
        }

        num = a[cont];

        v = 0;
        while (1) {
          if (a[cont] != num) {
            break;
          }
          v++;
          cont++;
        }

        ss.clear();
        ss << v;

        nex += ss.str();
        nex += num;
      }
      a = nex;
      nex = "";
    }
    cout << a << endl;
  }
}

Fixed submission:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main() {
  int n, num, cont, v;
  string a, nex;
  stringstream ss;
  while (1) {

    scanf("%d", &n);

    if (n == 0) {
      break;
    }
    cin >> a;

    for (int i = 0; i < n; i++) {
      cont = 0;
      while (1) {
        if (cont >= a.size()) {
          break;
        }

        num = a[cont];

        v = 0;
        while (1) {
          if (a[cont] != num) {
            break;
          }
          v++;
          cont++;
        }
        ss.str("");
        ss << v;

        nex += ss.str();
        nex += num;
      }
      a = nex;
      nex = "";
    }
    cout << a << endl;
  }
}
Problem p00430 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>

int n, number[30];

void rec(int sum, int mins, int cnt) {
  if (sum == n) {
    for (int i = 0; i < cnt; i++) {
      if (i) {
        printf(" ");
      }

      printf("%d", number[i]);
    }

    printf("\n");
    return;
  }

  for (int i = mins; i > 0; i++) {
    if (sum + i > n)
      continue;

    number[cnt] = i;

    rec(sum + i, i, cnt + 1);

    number[cnt] = 0;
  }
}

int main() {
  while (true) {
    scanf("%d", &n);

    if (n == 0) {
      break;
    }

    rec(0, n, 0);
  }

  return 0;
}

Fixed submission:
#include <stdio.h>

int n, number[30];

void rec(int sum, int mins, int cnt) {
  if (sum == n) {
    for (int i = 0; i < cnt; i++) {
      if (i) {
        printf(" ");
      }

      printf("%d", number[i]);
    }

    printf("\n");
    return;
  }

  for (int i = mins; i > 0; i--) {
    if (sum + i > n)
      continue;

    number[cnt] = i;

    rec(sum + i, i, cnt + 1);

    number[cnt] = 0;
  }
}

int main() {
  while (true) {
    scanf("%d", &n);

    if (n == 0) {
      break;
    }

    rec(0, n, 0);
  }

  return 0;
}
Problem p00430 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T> int __builtin_popcount(T n) {
  return n ? 1 + __builtin_popcount(n & (n - 1)) : 0;
}
#endif

#define foreach(it, c)                                                         \
  for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int n;
  while (scanf("%d", &n), n) {
    int b[16];
    memset(b, 0, sizeof(b));
    b[0] = n;
    while (true) {
      int t = find(b, b + n, 0) - b;
      for (int i = 0; i < t - 1; ++i)
        printf("%d ", b[i]);
      printf("%d\n", b[t - 1]);

      if (t == n)
        break;

      int u;
      u = t - 1;
      while (b[u] == 1)
        --u;
      --b[u];
      ++u;
      fill(b + u, b + n, 0);
      int s = t - u + 1;
      while (s--) {
        if (b[u] == b[u - 1])
          ++u;
        ++b[u];
      }
    }
  }
}

Fixed submission:
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T> int __builtin_popcount(T n) {
  return n ? 1 + __builtin_popcount(n & (n - 1)) : 0;
}
#endif

#define foreach(it, c)                                                         \
  for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int n;
  while (scanf("%d", &n), n) {
    int b[31];
    memset(b, 0, sizeof(b));
    b[0] = n;
    while (true) {
      int t = find(b, b + n, 0) - b;
      for (int i = 0; i < t - 1; ++i)
        printf("%d ", b[i]);
      printf("%d\n", b[t - 1]);

      if (t == n)
        break;

      int u;
      u = t - 1;
      while (b[u] == 1)
        --u;
      --b[u];
      ++u;
      fill(b + u, b + n, 0);
      int s = t - u + 1;
      while (s--) {
        if (b[u] == b[u - 1])
          ++u;
        ++b[u];
      }
    }
  }
}
Problem p00431 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
using namespace std;

int n, g[101][101], g_size[101];
bool used[101];

int rec(int idx) {
  int ret = 1;
  for (int i = 0; i < g_size[idx]; i++) {
    if (!used[g[idx][i]]) {
      used[g[idx][i]] = true;
      ret = max(ret, rec(g[idx][i]) + 1);
      used[g[idx][i]] = false;
    }
  }
  return ret;
}

int main() {
  while (cin >> n, n) {
    for (int i = 0; i < n; i++) {
      int a, b;
      cin >> a >> b;
      g[a][g_size[a]++] = b;
      g[b][g_size[b]++] = a;
    }

    int ans = 1;
    for (int i = 1; i <= 100; i++) {
      if (g_size[i] > 0) {
        used[i] = true;
        ans = max(ans, rec(i));
        used[i] = false;
      }
    }
    cout << ans << endl;
  }
}

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

int n, g[101][101], g_size[101];
bool used[101];

int rec(int idx) {
  int ret = 1;
  for (int i = 0; i < g_size[idx]; i++) {
    if (!used[g[idx][i]]) {
      used[g[idx][i]] = true;
      ret = max(ret, rec(g[idx][i]) + 1);
      used[g[idx][i]] = false;
    }
  }
  return ret;
}

int main() {
  while (cin >> n, n) {
    fill_n(g_size, 101, 0);
    for (int i = 0; i < n; i++) {
      int a, b;
      cin >> a >> b;
      g[a][g_size[a]++] = b;
      g[b][g_size[b]++] = a;
    }

    int ans = 1;
    for (int i = 1; i <= 100; i++) {
      if (g_size[i] > 0) {
        used[i] = true;
        ans = max(ans, rec(i));
        used[i] = false;
      }
    }
    cout << ans << endl;
  }
}
Problem p00431 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

bool d[101], dd[101]; // true = 使った。

int ans = 0;
int n;
vector<int> G[101];

int dfs(int from, int now) {

  for (int i = 0; i < G[from].size(); i++) {
    if (!d[G[from][i]]) {
      d[G[from][i]] = true;
      if (G[from].size() > G[G[from][i]].size() + 2)
        dd[G[from][i]] = true;
      ans = max(ans, dfs(G[from][i], now + 1));
      d[G[from][i]] = false;
    }
  }

  return now;
}

int main(void) {

  ans = 0;

  while (cin >> n, n) {
    ans = 0;
    int from, to;

    for (int i = 0; i < 101; i++)
      d[i] = dd[i] = false;

    for (int i = 0; i < n; i++) {
      cin >> from >> to;
      G[from].push_back(to);
      G[to].push_back(from);
    }

    for (int i = 0; i <= n; i++) {
      if (!dd[i]) {
        dfs(i, 1);
      }
    }

    for (int i = 0; i < 101; i++)
      while (G[i].size())
        G[i].pop_back();

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

Fixed submission:
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

bool d[101], dd[101]; // true = 使った。

int ans = 0;
int n;
vector<int> G[101];

int dfs(int from, int now) {

  for (int i = 0; i < G[from].size(); i++) {
    if (!d[G[from][i]]) {
      d[G[from][i]] = true;
      if (G[from].size() > 2)
        dd[G[from][i]] = true;
      ans = max(ans, dfs(G[from][i], now + 1));
      d[G[from][i]] = false;
    }
  }

  return now;
}

int main(void) {

  ans = 0;

  while (cin >> n, n) {
    ans = 0;
    int from, to;

    for (int i = 0; i < 101; i++)
      d[i] = dd[i] = false;

    for (int i = 0; i < n; i++) {
      cin >> from >> to;
      G[from].push_back(to);
      G[to].push_back(from);
    }

    for (int i = 0; i <= n; i++) {
      if (!dd[i]) {
        dfs(i, 1);
      }
    }

    for (int i = 0; i < 101; i++)
      while (G[i].size())
        G[i].pop_back();

    cout << ans - 1 << endl;
  }
  return 0;
}
Problem p00431 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
#include <time.h>

#define N 101

int find_length(int a, int cur_length);

int conn[N][N];
int used[N];

int main() {
  int i, j;
  int a, b;
  int n;
  int max_length, length;
  time_t start_time, t;

  while (1) {
    start_time = time(NULL);
    for (j = 0; j < N; j++) {
      for (i = 0; i < N; i++) {
        conn[j][i] = 0;
      }
    }

    scanf("%d", &n);
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      scanf("%d %d", &a, &b);
      conn[a][b] = 1;
      conn[b][a] = 1;
    }

    for (a = 0; a < N; a++) {
      used[a] = 0;
    }

    max_length = 0;
    for (a = 0; a < N; a++) {
      length = find_length(a, 1);
      if (length > max_length) {
        max_length = length;
      }
      if (time(NULL) - start_time > 3) {
        break;
      }
    }
    printf("%d\n", max_length);
  }
}

int find_length(int a, int cur_length) {
  int b;
  int length, max_length;

  used[a] = 1;
  max_length = cur_length;
  for (b = 0; b < N; b++) {
    if (conn[a][b] == 1 && used[b] != 1) {
      length = find_length(b, cur_length + 1);
      if (length > max_length) {
        max_length = length;
      }
    }
  }
  used[a] = 0;

  return max_length;
}

Fixed submission:
#include <stdio.h>
#include <time.h>

#define N 101

int find_length(int a, int cur_length);

int conn[N][N];
int used[N];

int main() {
  int i, j;
  int a, b;
  int n;
  int max_length, length;
  time_t start_time, t;

  while (1) {
    start_time = time(NULL);
    for (j = 0; j < N; j++) {
      for (i = 0; i < N; i++) {
        conn[j][i] = 0;
      }
    }

    scanf("%d", &n);
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      scanf("%d %d", &a, &b);
      conn[a][b] = 1;
      conn[b][a] = 1;
    }

    for (a = 0; a < N; a++) {
      used[a] = 0;
    }

    max_length = 0;
    for (a = 0; a < N; a++) {
      length = find_length(a, 1);
      if (length > max_length) {
        max_length = length;
      }
      if (time(NULL) - start_time > 1) {
        break;
      }
    }
    printf("%d\n", max_length);
  }
}

int find_length(int a, int cur_length) {
  int b;
  int length, max_length;

  used[a] = 1;
  max_length = cur_length;
  for (b = 0; b < N; b++) {
    if (conn[a][b] == 1 && used[b] != 1) {
      length = find_length(b, cur_length + 1);
      if (length > max_length) {
        max_length = length;
      }
    }
  }
  used[a] = 0;

  return max_length;
}
Problem p00431 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int n, t1, t2, i = 0;
  int a[10] = {11, 19, 24, 10, 65, 9, 35, 51, 25, 20};
  cin >> n;
  while (n != 0) {
    cin >> t1 >> t2;
    cout << a[i] << endl;
    i++;
    cin >> n;
  }
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n, t1, t2, i = 0;
  int a[10] = {11, 19, 24, 10, 65, 9, 35, 51, 25, 20};
  cin >> n;
  while (n != 0) {
    for (int I = 0; I < n; I++)
      cin >> t1 >> t2;
    cout << a[i] << endl;
    i++;
    cin >> n;
  }
}
Problem p00433 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  while (true) {
    int a, b, c = 0, d = 0;
    for (int i = 0; i < 4; i++) {
      cin >> a;
      c = c + a;
    }
    for (int i = 0; i < 4; i++) {
      cin >> b;
      d = d + b;
    }
    if (c < d)
      cout << d << endl;
    else {
      cout << c << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int a, b, c = 0, d = 0;
  for (int i = 0; i < 4; i++) {
    cin >> a;
    c = c + a;
  }
  for (int i = 0; i < 4; i++) {
    cin >> b;
    d = d + b;
  }
  if (c < d)
    cout << d << endl;
  else {
    cout << c << endl;
  }
  return 0;
}
Problem p00433 (C++)

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

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1 << 29;

int main() {
  int v[] = {};
  REP(i, 2) {
    REP(j, 4) {
      int a;
      cin >> a;
      v[i] += a;
    }
  }
  cout << max(v[0], v[1]) << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1 << 29;

int main() {
  int v[4] = {};
  REP(i, 2) {
    REP(j, 4) {
      int a;
      cin >> a;
      v[i] += a;
    }
  }
  cout << max(v[0], v[1]) << endl;
}
Problem p00434 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main(void) {
  int temp, a;
  int t[31];
  t[temp] = 0;
  a = 0;
  for (int i = 0; i < 31; i++) {
    t[i] = 0;
  }
  for (int i = 0; i < 29; i++) {
    cin >> temp;
    t[temp] = 1;
  }
  for (temp = 1; temp <= 30; temp++) {
    if (t[temp] == 0) {
      cout << temp << endl;
    }
  }
}


Fixed submission:
#include <iostream>
using namespace std;
int main(void) {
  int temp, a;
  int t[30];
  a = 0;
  for (int i = 0; i < 31; i++) {
    t[i] = 0;
  }
  for (int i = 0; i < 29; i++) {
    cin >> temp;
    t[temp] = 1;
  }
  for (temp = 1; temp <= 30; temp++) {
    if (t[temp] == 0) {
      cout << temp << endl;
    }
  }
}
Problem p00434 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#define N 10

int main(void) {
  int flg[N + 1];
  int id;

  for (int i = 1; i <= N; i++)
    flg[i] = 0;
  while (scanf("%d", &id) != EOF) {
    flg[id] = 1;
  }

  for (int i = 1; i <= N; i++) {
    if (flg[i] == 0)
      printf("%d\n", i);
  }

  return 0;
}

Fixed submission:
#include <stdio.h>
#define N 30

int main(void) {
  int flg[N + 1];
  int id;

  for (int i = 1; i <= N; i++)
    flg[i] = 0;
  while (scanf("%d", &id) != EOF) {
    flg[id] = 1;
  }

  for (int i = 1; i <= N; i++) {
    if (flg[i] == 0)
      printf("%d\n", i);
  }

  return 0;
}
Problem p00434 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <queue>
using namespace std;
int main(void) {
  // Your code here!
  int a, tf;
  queue<int> h;
  for (int i = 1; i <= 28; i++) {
    cin >> a;
    h.push(a);
  }
  for (int i = 1; i <= 30; i++) {
    tf = 0;
    for (int i2 = 1; i2 <= 28; i2++) {
      a = h.front();
      h.pop();
      if (i == a) {
        tf = 1;
        break;
      } else
        h.push(a);
    }
    if (tf == 0)
      cout << i << endl;
  }
}

Fixed submission:
#include <iostream>
#include <queue>
using namespace std;
int main(void) {
  // Your code here!
  int a, tf;
  queue<int> h;
  for (int i = 1; i <= 28; i++) {
    cin >> a;
    h.push(a);
  }
  for (int i = 1; i <= 30; i++) {
    tf = 0;
    for (int i2 = 1; i2 <= 28; i2++) {
      if (h.empty())
        break;
      a = h.front();
      h.pop();
      if (i == a) {
        tf = 1;
        break;
      } else
        h.push(a);
    }
    if (tf == 0)
      cout << i << endl;
  }
}
Problem p00435 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int num;
  char a[100], b[100];
  int i, j;
  for (i = 0;; i++) {
    scanf("%c", &a[i]);
    if (a[i] == '\n') {
      break;
    }
    if (a[i] >= 'A' && a[i] <= 'C') {
      b[i] = a[i] + 23;
    } else {
      b[i] = a[i] - 3;
    }
    printf("%c", b[i]);
  }
  cout << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int num;
  char a[1000], b[1000];
  int i, j;
  for (i = 0;; i++) {
    scanf("%c", &a[i]);
    if (a[i] == '\n') {
      break;
    }
    if (a[i] >= 'A' && a[i] <= 'C') {
      b[i] = a[i] + 23;
    } else {
      b[i] = a[i] - 3;
    }
    printf("%c", b[i]);
  }
  cout << endl;
  return 0;
}
Problem p00435 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

char *f(char *s) {
  char *a = s;
  for (; *s; s++)
    *s = (*s - 42) % 26 + 65;
  return a;
}

int main() {
  char *s;
  scanf("%s", s);
  printf("%s\n", f(s));
}

Fixed submission:
#include <stdio.h>

char *f(char *s) {
  char *a = s;
  for (; *s; s++)
    *s = (*s - 42) % 26 + 65;
  return a;
}

int main() {
  char s[1001];
  scanf("%s", s);
  printf("%s\n", f(s));
}
Problem p00435 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
using namespace std;

int main() {
  while (true) {
    char a;
    scanf("%c", &a);
    if ('A' <= a && a <= 'Z') {
      a = (a + 23 - 'A') % 26 + 'A';
      printf("%c", a);
    } else {
      printf("%c", a);
    }
  }
  return 0;
}

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

int main() {
  while (true) {
    char a;
    scanf("%c", &a);
    if ('A' <= a && a <= 'Z') {
      a = (a + 23 - 'A') % 26 + 'A';
      printf("%c", a);
    } else {
      printf("%c", a);
      break;
    }
  }
  return 0;
}
Problem p00435 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>

int main() {
  char a[1000];
  scanf("%s", &a);
  for (int i = 0; a[i] != EOF; i++)
    a[i] = 'A' + ((a[i] - 'A' + 3) % 26);
  printf("%s", a);
  return 0;
}

Fixed submission:
#include <cstdio>

int main() {
  char c;
  while (1) {
    scanf("%c", &c);
    if (c == '\n')
      break;
    if (c < 'D')
      c = c + 26;
    printf("%c", c - 3);
  }
  printf("\n");
  return 0;
}
Problem p00435 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main() {
  string str;
  cin >> str;
  int i;
  for (i = 0; i < str.size(); i++) {
    if (str[i] < 'D')
      str[i] = str[i] + 23;
    else
      str[i] = str[i] - 3;
  }
  for (i = 0; str.size(); i++)
    cout << str[i];
  cout << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  string str;
  cin >> str;
  int i;
  for (i = 0; i < str.size(); i++) {
    if (str[i] < 'D')
      str[i] = str[i] + 23;
    else
      str[i] = str[i] - 3;
  }
  cout << str << endl;
  return 0;
}
Problem p00436 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
  int n, m;
  cin >> n >> m;

  vector<int> v(n);
  rep(i, 2 * n) v[i] = i + 1;

  rep(i, m) {
    int k;
    cin >> k;

    vector<int> a, b;

    if (k == 0) {
      rep(j, n) {
        a.push_back(v[j]);
        a.push_back(v[j + n]);
      }

      v.clear();
      copy(a.begin(), a.end(), back_inserter(v));
    } else {
      rep(j, k) { a.push_back(v[j]); }

      REP(j, k, 2 * n) { b.push_back(v[j]); }

      v.clear();
      copy(b.begin(), b.end(), back_inserter(v));
      copy(a.begin(), a.end(), back_inserter(v));
    }
  }

  rep(i, 2 * n) { cout << v[i] << endl; }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
  int n, m;
  cin >> n >> m;

  vector<int> v(2 * n);
  rep(i, 2 * n) v[i] = i + 1;

  rep(i, m) {
    int k;
    cin >> k;

    vector<int> a, b;

    if (k == 0) {
      rep(j, n) {
        a.push_back(v[j]);
        a.push_back(v[j + n]);
      }

      v.clear();
      copy(a.begin(), a.end(), back_inserter(v));
    } else {
      rep(j, k) { a.push_back(v[j]); }

      REP(j, k, 2 * n) { b.push_back(v[j]); }

      v.clear();
      copy(b.begin(), b.end(), back_inserter(v));
      copy(a.begin(), a.end(), back_inserter(v));
    }
  }

  rep(i, 2 * n) { cout << v[i] << endl; }

  return 0;
}
Problem p00436 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;

int main() {

  int a, m, n;
  int i, j, k;
  int arr[100];
  int arr2[100];

  cin >> a;

  for (i = 0; i < 2 * a; i++)
    arr[i] = i + 1;

  cin >> m;
  for (i = 0; i < m; i++) {

    cin >> n;

    if (n == 0) {

      for (j = 0; j < a; j++) {

        arr2[j * 2] = arr[j];
        arr2[j * 2 + 1] = arr[j + a];
      }

      for (j = 0; j < a * 2; j++)
        arr[j] = arr2[j];

    }

    else {

      for (j = n, k = 0; j < 2 * a; j++, k++)
        arr2[k] = arr[j];
      for (j = 0; j < n; j++, k++)
        arr2[k] = arr[j];

      for (j = 0; j < a * 2; j++)
        arr[j] = arr2[j];
    }
  }

  for (i = 0; i < 2 * a; i++)
    cout << arr[i] << endl;

  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;

int main() {

  int a, m, n;
  int i, j, k;
  int arr[300];
  int arr2[300];

  cin >> a;

  for (i = 0; i < 2 * a; i++)
    arr[i] = i + 1;

  cin >> m;
  for (i = 0; i < m; i++) {

    cin >> n;

    if (n == 0) {

      for (j = 0; j < a; j++) {

        arr2[j * 2] = arr[j];
        arr2[j * 2 + 1] = arr[j + a];
      }

      for (j = 0; j < a * 2; j++)
        arr[j] = arr2[j];

    }

    else {

      for (j = n, k = 0; j < 2 * a; j++, k++)
        arr2[k] = arr[j];
      for (j = 0; j < n; j++, k++)
        arr2[k] = arr[j];

      for (j = 0; j < a * 2; j++)
        arr[j] = arr2[j];
    }
  }

  for (i = 0; i < 2 * a; i++)
    cout << arr[i] << endl;

  return 0;
}
Problem p00436 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  while (true) {
    cin;
    if (cin.fail())
      break;
  }
}

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

int main() {
  int a;
  cin >> a;
  vector<int> s(a * 2);
  for (int x = 0; x < a * 2; x++) {
    s[x] = x + 1;
  }
  int b;
  cin >> b;
  for (int c = 0; c < b; c++) {
    int d;
    cin >> d;
    vector<int> e(a * 2);
    for (int f = 0; f < a * 2; f++) {
      e[f] = s[f];
    }
    if (d == 0) {
      for (int g = 0; g < a * 2; g++) {
        if (g % 2 == 0) {
          s[g] = e[g / 2];
        } else {
          s[g] = e[a + (g - 1) / 2];
        }
      }
    } else {
      for (int i = 0; i < 2 * a - d; i++) {
        s[i] = e[d + i];
      }
      for (int i = 0; i < d; i++) {
        s[i + (2 * a - d)] = e[i];
      }
    }
  }
  for (int q : s) {
    cout << q << endl;
  }
}
Problem p00436 (C++)

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

int n;
vector<int> card, t, m;

void cut(int k) {
  for (int i = 1, j = 0; i <= k; i++, j++)
    t[j] = card[i];
  for (int i = k + 1, j = 0; i <= 2 * n; i++, j++)
    m[j] = card[i];

  for (int i = 1, j = 0; i <= 2 * n - k + 1; i++, j++)
    card[i] = m[j];
  for (int i = 2 * n - k + 1, j = 0; i <= 2 * n; i++, j++)
    card[i] = t[j];
}

void r_shuffle() {
  for (int i = 1; i <= n; i++) {
    t[i - 1] = card[i];
    m[i - 1] = card[i + n];
  }
  for (int i = 1, j = 0; i <= 2 * n; i += 2, j++) {
    card[i] = t[j];
    card[i + 1] = m[j];
  }
}

int main() {
  int h, k;
  cin >> n >> h;
  card.resize(2 * n + 1);
  t.resize(n + 1);
  m.resize(n + 1);
  for (int i = 1; i <= 2 * n; i++)
    card[i] = i;
  for (int i = 0; i < h; i++) {
    cin >> k;
    if (k == 0)
      r_shuffle();
    else
      cut(k);
  }
  for (int i = 1; i <= n * 2; i++)
    cout << card[i] << endl;
}

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

int n;
vector<int> card, t, m;

void cut(int k) {
  for (int i = 1, j = 0; i <= k; i++, j++)
    t[j] = card[i];
  for (int i = k + 1, j = 0; i <= 2 * n; i++, j++)
    m[j] = card[i];

  for (int i = 1, j = 0; i <= 2 * n - k + 1; i++, j++)
    card[i] = m[j];
  for (int i = 2 * n - k + 1, j = 0; i <= 2 * n; i++, j++)
    card[i] = t[j];
}

void r_shuffle() {
  for (int i = 1; i <= n; i++) {
    t[i - 1] = card[i];
    m[i - 1] = card[i + n];
  }
  for (int i = 1, j = 0; i <= 2 * n; i += 2, j++) {
    card[i] = t[j];
    card[i + 1] = m[j];
  }
}

int main() {
  int h, k;
  cin >> n >> h;
  card.resize(1001);
  t.resize(512);
  m.resize(512);
  for (int i = 1; i <= 2 * n; i++)
    card[i] = i;
  for (int i = 0; i < h; i++) {
    cin >> k;
    if (k == 0)
      r_shuffle();
    else
      cut(k);
  }
  for (int i = 1; i <= n * 2; i++)
    cout << card[i] << endl;
}
Problem p00437 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>

using namespace std;

int main() {
  int a, b, c, n, total, kind;
  int rist[1000][3], ristsize;
  int isacheced[101];

  scanf("%d %d %d", &a, &b, &c);

  while (a != 0 && b != 0 && c != 0) {
    scanf("%d", &n);

    total = a + b + c;
    ristsize = 0;
    for (int i = 0; i <= total; i++) {
      isacheced[i] = 2;
    }

    for (int i = 0; i < n; i++) {
      scanf("%d %d %d %d", &a, &b, &c, &kind);
      if (kind == 1) {
        isacheced[a] = 1;
        isacheced[b] = 1;
        isacheced[c] = 1;
      } else {
        rist[ristsize][0] = a;
        rist[ristsize][1] = b;
        rist[ristsize][2] = c;
        ristsize++;
      }
    }

    for (int i = 0; i < ristsize; i++) {
      if (isacheced[rist[i][0]] == 1 && isacheced[rist[i][1]] == 1) {
        isacheced[rist[i][2]] = 0;
      } else if (isacheced[rist[i][1]] == 1 && isacheced[rist[i][2]] == 1) {
        isacheced[rist[i][0]] = 0;
      } else if (isacheced[rist[i][0]] == 1 && isacheced[rist[i][2]] == 1) {
        isacheced[rist[i][1]] = 0;
      }
    }

    for (int i = 1; i <= total; i++) {
      printf("%d\n", isacheced[i]);
    }

    scanf("%d %d %d", &a, &b, &c);
  }

  return 0;
}

Fixed submission:
#include <cstdio>

using namespace std;

int main() {
  int a, b, c, n, total, kind;
  int rist[1000][3], ristsize;
  int isacheced[301];

  scanf("%d %d %d", &a, &b, &c);

  while (a != 0 && b != 0 && c != 0) {
    scanf("%d", &n);

    total = a + b + c;
    ristsize = 0;
    for (int i = 0; i <= total; i++) {
      isacheced[i] = 2;
    }

    for (int i = 0; i < n; i++) {
      scanf("%d %d %d %d", &a, &b, &c, &kind);
      if (kind == 1) {
        isacheced[a] = 1;
        isacheced[b] = 1;
        isacheced[c] = 1;
      } else {
        rist[ristsize][0] = a;
        rist[ristsize][1] = b;
        rist[ristsize][2] = c;
        ristsize++;
      }
    }

    for (int i = 0; i < ristsize; i++) {
      if (isacheced[rist[i][0]] == 1 && isacheced[rist[i][1]] == 1) {
        isacheced[rist[i][2]] = 0;
      } else if (isacheced[rist[i][1]] == 1 && isacheced[rist[i][2]] == 1) {
        isacheced[rist[i][0]] = 0;
      } else if (isacheced[rist[i][0]] == 1 && isacheced[rist[i][2]] == 1) {
        isacheced[rist[i][1]] = 0;
      }
    }

    for (int i = 1; i <= total; i++) {
      printf("%d\n", isacheced[i]);
    }

    scanf("%d %d %d", &a, &b, &c);
  }

  return 0;
}
Problem p00437 (C++)

Buggy submission (status: Runtime Error):
#include <cstring>
#include <iostream>
int main() {
  int a, b, c;
  int N;
  while (std::cin >> a >> b >> c, a | b | c) {
    std::cin >> N;
    int data[1024][4];
    int check[128];
    for (int i = 0; i < 101; i++)
      check[i] = 2;
    for (int i = 0; i < N; i++) {
      scanf("%d%d%d%d", &data[i][0], &data[i][1], &data[i][2], &data[i][3]);
      if (data[i][3] == 1) {
        check[data[i][0]] = 1;
        check[data[i][1]] = 1;
        check[data[i][2]] = 1;
      }
    }
    for (int i = 0; i < N; i++) {
      if (data[i][3] == 0) {
        int sum = 0;
        if (check[data[i][0]] == 1)
          sum++;
        if (check[data[i][1]] == 1)
          sum++;
        if (check[data[i][2]] == 1)
          sum++;
        if (sum == 2) {
          for (int j = 0; j < 3; j++) {
            if (check[data[i][j]] != 1)
              check[data[i][j]] = 0;
          }
        }
      }
    }
    for (int i = 0; i < a + b + c; i++) {
      printf("%d\n", check[i + 1]);
    }
  }
  return 0;
}

Fixed submission:
#include <cstring>
#include <iostream>
int main() {
  int a, b, c;
  int N;
  while (std::cin >> a >> b >> c, a | b | c) {
    std::cin >> N;
    int data[1024][4];
    int check[301];
    for (int i = 0; i < 301; i++)
      check[i] = 2;
    for (int i = 0; i < N; i++) {
      scanf("%d%d%d%d", &data[i][0], &data[i][1], &data[i][2], &data[i][3]);
      if (data[i][3] == 1) {
        check[data[i][0]] = 1;
        check[data[i][1]] = 1;
        check[data[i][2]] = 1;
      }
    }
    for (int i = 0; i < N; i++) {
      if (data[i][3] == 0) {
        int sum = 0;
        if (check[data[i][0]] == 1)
          sum++;
        if (check[data[i][1]] == 1)
          sum++;
        if (check[data[i][2]] == 1)
          sum++;
        if (sum == 2) {
          for (int j = 0; j < 3; j++) {
            if (check[data[i][j]] != 1)
              check[data[i][j]] = 0;
          }
        }
      }
    }
    for (int i = 0; i < a + b + c; i++) {
      printf("%d\n", check[i + 1]);
    }
  }
  return 0;
}
Problem p00437 (C++)

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

typedef long long ll;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define each(itr, c)                                                           \
  for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int main() {
  int a, b, c;
  while (cin >> a >> b >> c, a | b | c) {
    int n;
    cin >> n;

    //??¨???????¨????????????°
    int m = a + b + c;
    //????????????????????????
    vector<int> v(m, 2);

    vector<int> x(m), y(m), z(m), r(m);
    rep(i, n) {
      scanf(" %d %d %d %d", &x[i], &y[i], &z[i], &r[i]);
      --x[i];
      --y[i];
      --z[i];
    }

    //????????£?????????????????????????????????????????¨?????£???
    rep(i, n) {
      if (r[i] == 0)
        continue;

      v[x[i]] = 1;
      v[y[i]] = 1;
      v[z[i]] = 1;
    }

    //??????????????????????????????
    rep(t, n) rep(i, n) {
      if (r[i] == 1)
        continue;
      //??????2????????£???(1)??§?¢??????????????????°???????????????(0)

      if (v[x[i]] == 1 && v[y[i]] == 1)
        v[z[i]] = 0;
      if (v[y[i]] == 1 && v[z[i]] == 1)
        v[x[i]] = 0;
      if (v[z[i]] == 1 && v[x[i]] == 1)
        v[y[i]] = 0;
    }

    // output
    rep(i, m) printf("%d\n", v[i]);
  }
  return 0;
}

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

typedef long long ll;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define each(itr, c)                                                           \
  for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int main() {
  int a, b, c;
  while (cin >> a >> b >> c, a | b | c) {
    int n;
    cin >> n;

    //??¨???????¨????????????°
    int m = a + b + c;
    //????????????????????????
    vector<int> v(m, 2);

    vector<int> x(n), y(n), z(n), r(n);
    rep(i, n) {
      scanf(" %d %d %d %d", &x[i], &y[i], &z[i], &r[i]);
      --x[i];
      --y[i];
      --z[i];
    }

    //????????£?????????????????????????????????????????¨?????£???
    rep(i, n) {
      if (r[i] == 0)
        continue;

      v[x[i]] = 1;
      v[y[i]] = 1;
      v[z[i]] = 1;
    }

    //??????????????????????????????
    rep(t, n) rep(i, n) {
      if (r[i] == 1)
        continue;
      //??????2????????£???(1)??§?¢??????????????????°???????????????(0)

      if (v[x[i]] == 1 && v[y[i]] == 1)
        v[z[i]] = 0;
      if (v[y[i]] == 1 && v[z[i]] == 1)
        v[x[i]] = 0;
      if (v[z[i]] == 1 && v[x[i]] == 1)
        v[y[i]] = 0;
    }

    // output
    rep(i, m) printf("%d\n", v[i]);
  }
  return 0;
}