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

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

using namespace std;

int main() {
  while (1) {
    int a, b;
    std::cin >> a >> b;
    std::cout << a + b << '\n';
  }
}


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

using namespace std;

int main() {
  int a, b;
  while (std::cin >> a >> b) {
    std::cout << a + b << '\n';
  }
}
Problem p00586 (C++)

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

int a, b;

int main() {
  while (cin >> a >> b) {
    int c = 0;
    while (c < 100000000 && c + c / 2 != 2)
      c++;
    cout << a + b + c % 9 - 1 << endl;
  }
}

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

int a, b;

int main() {
  while (cin >> a >> b) {
    int c = 0;
    while (c < 10000000 && c + c / 2 != 2)
      c++;
    cout << a + b + c % 9 - 1 << endl;
  }
}
Problem p00586 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <functional>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {

  stack<int> st; // スタックを宣言＋初期化

  int a, b, c, d, e, num;
  int i, j, k;
  int arr[100];
  int arr2[100][100];
  char crr[100];
  char crr2[100][100];
  string str;
  stack<int> istk;    // 整数値を格納するスタックを宣言
  stack<string> sstk; // 文字列を格納するスタックを宣言
  queue<int> ique;    // 整数値を格納するキューを宣言
  queue<string> sque; // 文字列を格納するキューを宣言

  while (1) {

    cin >> num;

    cin >> a;

    if (a == EOF || num == EOF)
      break;

    cout << a + num << endl;
  }

  return 0;
}

Fixed submission:
#include <functional>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {

  stack<int> st; // スタックを宣言＋初期化

  int a, b, c, d, e, num;
  int i, j, k;
  int arr[100];
  int arr2[100][100];
  char crr[100];
  char crr2[100][100];
  string str;
  stack<int> istk;    // 整数値を格納するスタックを宣言
  stack<string> sstk; // 文字列を格納するスタックを宣言
  queue<int> ique;    // 整数値を格納するキューを宣言
  queue<string> sque; // 文字列を格納するキューを宣言

  while (scanf("%d %d", &a, &num) == 2) {

    cout << a + num << endl;
  }

  return 0;
}
Problem p00586 (Python)

Buggy submission (status: Time Limit Exceeded):
x = input()
while x:
    a, b = x.split(" ")
    print(int(a) + int(b))


Fixed submission:
import sys

for line in sys.stdin:
    if line == None or line == "/n":
        break
    a, b = line.split(" ")
    print(int(a) + int(b))
Problem p00587 (C++)

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

struct Node {
  Node *ch[2];
  Node() { ch[0] = ch[1] = NULL; }
};

void build(Node *node, const string &s, int &i) {
  if (s[i] == '(') {
    i++; // (
    node->ch[0] = new Node();
    build(node->ch[0], s, i);
    i++; // ,
    node->ch[1] = new Node();
    build(node->ch[1], s, i);
    i++; // )
  }
}

void print(Node *node) {
  if (node == NULL || (node->ch[0] == NULL && node->ch[1] == NULL))
    return;
  cout << "(";
  print(node->ch[0]);
  cout << ",";
  print(node->ch[1]);
  cout << ")";
}

void erase(Node *node) {
  for (int i = 0; i < 2; i++)
    if (node->ch[i])
      erase(node->ch[i]);
  delete node;
}

void Intersection(Node *res, Node *a, Node *b) {
  for (int i = 0; i < 2; i++)
    if (a && a->ch[i] && b && b->ch[i]) {
      res->ch[i] = new Node();
      Intersection(res->ch[i], a->ch[i], b->ch[i]);
    }
}

void Union(Node *res, Node *a, Node *b) {
  for (int i = 0; i < 2; i++)
    if ((a && a->ch[i]) || (b && b->ch[i])) {
      res->ch[i] = new Node();
      Union(res->ch[i], a->ch[i], b->ch[i]);
    }
}

int main() {
  for (string cmd, A, B; cin >> cmd >> A >> B;) {
    Node *roota = new Node();
    Node *rootb = new Node();
    Node *rootc = new Node();

    int i = 0;
    build(roota, A, i);

    i = 0;
    build(rootb, B, i);

    if (cmd[0] == 'i')
      Intersection(rootc, roota, rootb);
    else
      Union(rootc, roota, rootb);

    print(rootc);
    cout << endl;

    erase(roota);
    erase(rootb);
    erase(rootc);
  }
}

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

struct Node {
  Node *ch[2];
  Node() { ch[0] = ch[1] = NULL; }
};

void build(Node *node, const string &s, int &i) {
  if (s[i] == '(') {
    i++; // (
    node->ch[0] = new Node();
    build(node->ch[0], s, i);
    i++; // ,
    node->ch[1] = new Node();
    build(node->ch[1], s, i);
    i++; // )
  }
}

void print(Node *node) {
  if (node == NULL || (node->ch[0] == NULL && node->ch[1] == NULL))
    return;
  cout << "(";
  print(node->ch[0]);
  cout << ",";
  print(node->ch[1]);
  cout << ")";
}

void erase(Node *node) {
  for (int i = 0; i < 2; i++)
    if (node->ch[i])
      erase(node->ch[i]);
  delete node;
}

void Intersection(Node *res, Node *a, Node *b) {
  for (int i = 0; i < 2; i++)
    if (a && a->ch[i] && b && b->ch[i]) {
      res->ch[i] = new Node();
      Intersection(res->ch[i], a->ch[i], b->ch[i]);
    }
}

void Union(Node *res, Node *a, Node *b) {
  for (int i = 0; i < 2; i++)
    if ((a && a->ch[i]) || (b && b->ch[i])) {
      res->ch[i] = new Node();
      Union(res->ch[i], (a ? a->ch[i] : NULL), (b ? b->ch[i] : NULL));
    }
}

int main() {
  for (string cmd, A, B; cin >> cmd >> A >> B;) {
    Node *roota = new Node();
    Node *rootb = new Node();
    Node *rootc = new Node();

    int i = 0;
    build(roota, A, i);

    i = 0;
    build(rootb, B, i);

    if (cmd[0] == 'i')
      Intersection(rootc, roota, rootb);
    else
      Union(rootc, roota, rootb);

    print(rootc);
    cout << endl;

    erase(roota);
    erase(rootb);
    erase(rootc);
  }
}
Problem p00588 (C++)

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

int main() {
  int T, N;
  cin >> T;
  while (T--) {
    cin >> N;
    int book[128] = {0};

    for (int k = 0; k < 2; k++) {
      string str;
      char c;
      for (int i = 0; i < 2 * N; i++) {
        cin >> c;
        str += c;
      }
      str = "N" + str + "N";

      for (int i = 0; i < N + 1; i++) {
        if (str[i * 2] == 'Y' || str[i * 2 + 1] == 'Y') {
          book[i] |= (1 << k);
        }
      }
    }

    int a = 0, b = 1, na, nb;
    for (int i = 0; i < N + 1; i++) {
      switch (book[i]) {
      case 0:
        na = a;
        nb = b;
        break;

      case 1:
        na = min(a + 1, b + 1);
        nb = min(b + 1, a + 1);
        break;

      case 2:
        na = min(a + 3, b + 2);
        nb = min(b + 1, a + 2);
        break;

      case 3:
        na = min(a + 3, b + 2);
        nb = min(b + 2, a + 2);
        break;
      }

      a = na + 1;
      b = nb + 1;
    }

    cout << a - 1 << endl;
  }
}

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

int main() {
  int T, N;
  cin >> T;
  while (T--) {
    cin >> N;
    int book[10005] = {0};

    for (int k = 0; k < 2; k++) {
      string str;
      char c;
      for (int i = 0; i < 2 * N; i++) {
        cin >> c;
        str += c;
      }
      str = "N" + str + "N";

      for (int i = 0; i < N + 1; i++) {
        if (str[i * 2] == 'Y' || str[i * 2 + 1] == 'Y') {
          book[i] |= (1 << k);
        }
      }
    }

    int a = 0, b = 1, na, nb;
    for (int i = 0; i < N + 1; i++) {
      switch (book[i]) {
      case 0:
        na = a;
        nb = b;
        break;

      case 1:
        na = min(a + 1, b + 1);
        nb = min(b + 1, a + 1);
        break;

      case 2:
        na = min(a + 3, b + 2);
        nb = min(b + 1, a + 2);
        break;

      case 3:
        na = min(a + 3, b + 2);
        nb = min(b + 2, a + 2);
        break;
      }

      a = na + 1;
      b = nb + 1;
    }

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

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <vector>
#define MAX 10001
using namespace std;
bool prime[MAX];

void isPrime() {}
int main(void) {
  // isPrime();
  fill(prime, prime + MAX, true);
  prime[0] = prime[1] = false;
  for (int i = 0; i < MAX; i++)
    if (prime[i])
      for (int j = i + i; j < MAX; j += i)
        prime[j] = false;

  int n;
  while (1) {
    cin >> n;
    int cnt = 0;
    for (int i = 1; i <= n; i++)
      if (prime[i] * prime[n - i + 1])
        cnt++;
    cout << cnt << endl;
  }
}

Fixed submission:
#include <iostream>
#include <vector>
#define MAX 10001
using namespace std;
bool prime[MAX];

void isPrime() {}
int main(void) {
  // isPrime();
  fill(prime, prime + MAX, true);
  prime[0] = prime[1] = false;
  for (int i = 0; i < MAX; i++)
    if (prime[i])
      for (int j = i + i; j < MAX; j += i)
        prime[j] = false;

  int n;
  while (1) {
    cin >> n;
    if (cin.eof())
      break;
    int cnt = 0;
    for (int i = 1; i <= n; i++)
      if (prime[i] * prime[n - i + 1])
        cnt++;
    cout << cnt << endl;
  }
}
Problem p00590 (C++)

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

using namespace std;
int prime_pair(int N);
int is_prime(int p);
int prime_list(int MAX);
int prime[LEN];

int main(void) {
  int input;
  int j = 0;
  prime_list(LEN);
  while (cin >> input) {
    cout << prime_pair(input) << endl;
  }
  return 0;
}

int prime_list(int MAX) {
  int i = 0;
  int j = 0;
  int flag = 1;
  prime[0] = 2;
  for (i = 2; i < MAX; i++) {
    while (prime[j] != 0) {
      if (i % prime[j] == 0) {
        flag = 0;
      }
      j++;
    }
    if (flag) {
      prime[j] = i;
    }
    flag = 1;
    j = 0;
  }
  return 0;
}

int prime_pair(int N) {
  int count = 0;
  int i = 1;
  if (is_prime(2) && is_prime(N - 2 + 1))
    count++;
  while (prime[i] < N) {
    if (is_prime(N - prime[i] + 1))
      count++;
    i++;
  }
  return count;
}

int is_prime(int p) {
  int flag = 0;
  int i = 0;
  while ((prime[i] != 0) && (i < p)) {
    if (p == prime[i]) {
      flag = 1;
      break;
    }
    i++;
  }
  return flag;
}

Fixed submission:
#include <iostream>
#define LEN 10000

using namespace std;
int prime_pair(int N);
int is_prime(int p);
int prime_list(int MAX);
int prime[LEN];

int main(void) {
  int input;
  int j = 0;
  prime_list(LEN);
  while (cin >> input) {
    cout << prime_pair(input) << endl;
  }
  return 0;
}

int prime_list(int MAX) {
  int i = 0;
  int j = 0;
  int flag = 1;
  prime[0] = 2;
  for (i = 2; i < MAX; i++) {
    while (prime[j] != 0) {
      if (i % prime[j] == 0) {
        flag = 0;
      }
      j++;
    }
    if (flag) {
      prime[j] = i;
    }
    flag = 1;
    j = 0;
  }
  return 0;
}

int prime_pair(int N) {
  int count = 0;
  int i = 0;
  while ((prime[i] < N) && (prime[i] != 0)) {
    if (is_prime(N - prime[i] + 1))
      count++;
    i++;
  }
  return count;
}

int is_prime(int p) {
  int flag = 0;
  int i = 0;
  while ((prime[i] != 0) && (i < p)) {
    if (p == prime[i]) {
      flag = 1;
      break;
    }
    i++;
  }
  return flag;
}
Problem p00590 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

bool is_prime(int p) {
  if (p <= 1)
    return false;
  if (p == 2)
    return true;
  if (!(p & 1))
    return false;
  for (int x = 3; x <= sqrt(p); ++x)
    if (!(p % x))
      return false;
  return true;
}

int main() {
  bool primes[10002];
  memset(primes, 0, sizeof(primes));
  for (int x = 2; x <= 10000; ++x)
    if (is_prime(x))
      primes[x] = true;
  int n;
  while (scanf("%d", &n) == 1, n) {
    int c = 0;
    int l = n / 2;
    if (n % 2 == 1) {
      ++l;
      if (primes[l])
        --c;
    }
    for (int x = 1; x <= l; ++x) {
      if (primes[x] && primes[n - x + 1])
        c += 2;
    }
    cout << c << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

bool is_prime(int p) {
  if (p <= 1)
    return false;
  if (p == 2)
    return true;
  if (!(p & 1))
    return false;
  for (int x = 3; x <= sqrt(p); ++x)
    if (!(p % x))
      return false;
  return true;
}

int main() {
  bool primes[10002];
  memset(primes, 0, sizeof(primes));
  for (int x = 2; x <= 10000; ++x)
    if (is_prime(x))
      primes[x] = true;
  int n;
  while (scanf("%d", &n) == 1) {
    int c = 0;
    int l = n / 2;
    if (n % 2 == 1) {
      ++l;
      if (primes[l])
        --c;
    }
    for (int x = 1; x <= l; ++x) {
      if (primes[x] && primes[n - x + 1])
        c += 2;
    }
    cout << c << endl;
  }
  return 0;
}
Problem p00590 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll prime(ll x) {
  ll i;
  if (x < 2)
    return 0;
  else if (x == 2)
    return 1;
  if (x % 2 == 0)
    return 0;
  for (i = 3; i * i <= x; i += 2) {
    if (x % i == 0)
      return 0;
  }
  return 1;
}
int main() {
  int N;
  while (cin >> N, N) {
    int cnt = 0;
    for (int i = 1; i <= N; i++) {
      if (prime(i) && prime(N - i + 1))
        cnt++;
    }
    cout << cnt << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll prime(ll x) {
  ll i;
  if (x < 2)
    return 0;
  else if (x == 2)
    return 1;
  if (x % 2 == 0)
    return 0;
  for (i = 3; i * i <= x; i += 2) {
    if (x % i == 0)
      return 0;
  }
  return 1;
}
int main() {
  int N;
  while (cin >> N) {
    int cnt = 0;
    for (int i = 1; i <= N; i++) {
      if (prime(i) && prime(N - i + 1))
        cnt++;
    }
    cout << cnt << endl;
  }
}
Problem p00594 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

int getInt() {
  int ret = 0, c;
  c = getchar();
  while (!isdigit(c))
    c = getchar();
  while (isdigit(c)) {
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

const int mod = 109;
int cnt[mod];

int main() {
  while (int n = getInt()) {
    int ans = -1;
    const int n2 = n / 2;

    for (int i = 0; i < mod; i++) {
      cnt[i] = 0;
    }

    for (int i = 0; i < n; i++) {
      int a = getInt();
      int m = a % mod;
      if (++cnt[m] > n2) {
        ans = a;
        if (i != n - 1)
          while (getchar() != '\n')
            ;
      }
    }

    if (ans == -1)
      puts("NO COLOR");
    else
      printf("%d\n", ans);
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

int getInt() {
  int ret = 0, c;
  c = getchar();
  while (!isdigit(c))
    c = getchar();
  while (isdigit(c)) {
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

const int mod = 109;
int cnt[mod];

int main() {
  while (int n = getInt()) {
    int ans = -1;
    const int n2 = n / 2;

    for (int i = 0; i < mod; i++) {
      cnt[i] = 0;
    }

    for (int i = 0; i < n; i++) {
      int a = getInt();
      int m = a % mod;
      if (++cnt[m] > n2) {
        ans = a;
        for (++i; i < n; i++)
          getInt();
      }
    }

    if (ans == -1)
      puts("NO COLOR");
    else
      printf("%d\n", ans);
  }
  return 0;
}
Problem p00594 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
int main() {
  int n, now, last, a[1000000];
  while (1) {
    scanf("%d%d", &n, &a[0]);
    now = 1;
    last = a[0];
    for (int i = 1; i < n; i++) {
      scanf("%d", &a[i]);
      if (now == 0) {
        last = a[i];
        now++;
      } else if (last != a[i]) {
        now--;
      } else
        now++;
    }
    now = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == last)
        now++;
    }
    if (now > n / 2)
      printf("%d\n", last);
    else
      printf("NO COLOR\n");
  }
}

Fixed submission:
#include <stdio.h>
int main() {
  int n, now, last, a[1000000];
  while (1) {
    scanf("%d%d", &n, &a[0]);
    if (n == 0)
      return 0;
    now = 1;
    last = a[0];
    for (int i = 1; i < n; i++) {
      scanf("%d", &a[i]);
      if (now == 0) {
        last = a[i];
        now++;
      } else if (last != a[i]) {
        now--;
      } else
        now++;
    }
    now = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == last)
        now++;
    }
    if (now > n / 2)
      printf("%d\n", last);
    else
      printf("NO COLOR\n");
  }
}
Problem p00594 (C++)

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

int main() {
  int a, b;

  while (1) {
    cin >> a;
    map<int, int> mp;
    int ans = -1;
    for (int i = 0; i < a; i++) {
      cin >> b;
      mp[b]++;
      if (mp[b] > (a / 2))
        ans = b;
    }
    if (ans == -1)
      cout << "NO COLOR" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}

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

int main() {
  int a, b;

  while (1) {
    cin >> a;
    if (a == 0)
      break;
    map<int, int> mp;
    int ans = -1;
    for (int i = 0; i < a; i++) {
      cin >> b;
      mp[b]++;
      if (mp[b] > (a / 2))
        ans = b;
    }
    if (ans == -1)
      cout << "NO COLOR" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
Problem p00595 (C++)

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

int gcm(int a, int b) {
  if (a > b) {
    int tmp = a;
    a = b;
    b = tmp;
    cerr << 'a' << endl;
  }

  for (int i = 1;; ++i) {
    if (a % i == 0 and b % (a / i) == 0) {
      return a / i;
    }
  }
}

int main(void) {
  int a, b;
  while (cin >> a >> b) {
    cout << gcm(a, b) << endl;
  }

  return 0;
}

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

int gcm(int a, int b) {
  if (a > b) {
    int tmp = a;
    a = b;
    b = tmp;
  }

  for (int i = 1;; ++i) {
    if (a % i == 0 and b % (a / i) == 0) {
      return a / i;
    }
  }
}

int main(void) {
  int a, b;
  while (cin >> a >> b) {
    cout << gcm(a, b) << endl;
  }

  return 0;
}
Problem p00595 (C++)

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

int pgcd(int a, int b) { return b == 0 ? a : pgcd(b % a, a); }

int main() {
  int a, b;
  while (cin >> a >> b) {
    cout << pgcd(a, b) << endl;
  }
  return 0;
}

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

int pgcd(int a, int b) { return a == 0 ? b : pgcd(b % a, a); }

int main() {
  int a, b;
  while (cin >> a >> b) {
    cout << pgcd(a, b) << endl;
  }
  return 0;
}
Problem p00595 (C++)

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

unsigned int euclid(unsigned int a, unsigned int b) {
  if (b == 0)
    return a;
  return euclid(b, a % b);
}

int main(void) {
  unsigned int a, b;
  while (scanf("%u %u", &a, &b) != 0)
    cout << euclid(a, b) << endl;
  return 0;
}

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

unsigned int euclid(unsigned int a, unsigned int b) {
  if (b == 0)
    return a;
  return euclid(b, a % b);
}

int main(void) {
  unsigned int a, b;
  while (fscanf(stdin, "%u %u", &a, &b) != EOF)
    cout << euclid(a, b) << endl;
  return 0;
}
Problem p00595 (C++)

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

int main() {

  long long int n, m, a, b, c;

  while (cin >> n >> m) {
    a = max(n, m);
    b = min(n, m);
    c = a % b;
    a = b;
    b = c;
    while (a % b != 0) {
      c = a % b;
      a = b;
      b = c;
    }

    cout << b << endl;
  }
}

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

int main() {

  long long int n, m, a, b, c;

  while (cin >> n >> m) {
    a = max(n, m);
    b = min(n, m);

    while (b != 0 && a % b != 0) {
      c = a % b;
      a = b;
      b = c;
    }

    cout << b << endl;
  }
}
Problem p00595 (C++)

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

int eucgcd(int m, int n) {
  int p = m % n;

  while (p > 0) {
    m = n;
    n = p;
    p = m % n;
  }

  return n;
}

int main() {
  int m, n;

  while (std::cin >> m >> n, (m != EOF && n != EOF)) {
    if (m >= n)
      std::cout << eucgcd(m, n) << std::endl;
    else
      std::cout << eucgcd(n, m) << std::endl;
  }

  return 0;
}

Fixed submission:
#include <iostream>

int eucgcd(int m, int n) {
  int p = m % n;

  while (p > 0) {
    m = n;
    n = p;
    p = m % n;
  }

  return n;
}

int main() {
  int m, n;

  while (std::cin >> m >> n && m && n) {
    if (m >= n)
      std::cout << eucgcd(m, n) << std::endl;
    else
      std::cout << eucgcd(n, m) << std::endl;
  }

  return 0;
}
Problem p00595 (C++)

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

int gcd(int x, int y) { return x < y ? gcd(y, x) : y ? gcd(y, x - y) : x; }

int main(void) {
  int x, y;

  while (scanf("%d", &x), x != EOF) {
    scanf("%d", &y);
    printf("%d\n", gcd(x, y));
  }

  return 0;
}

Fixed submission:
#include <stdio.h>

int gcd(int x, int y) { return x < y ? gcd(y, x) : y ? gcd(y, x - y) : x; }

int main(void) {
  int x, y;

  while (scanf("%d%d", &x, &y) != EOF) {
    printf("%d\n", gcd(x, y));
  }

  return 0;
}
Problem p00595 (C++)

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

using namespace std;

void change(int *, int *);

int main(void) {
  int x, y;

  while (1) {
    scanf("%d %d", &x, &y);
    if (x == 0 && y == 0)
      break;
    if (x < y)
      change(&x, &y);
    while (y) {
      x %= y;
      change(&x, &y);
    }
    cout << x << endl;
  }
  return 0;
}

void change(int *a, int *b) {
  int temp;
  temp = *a;
  *a = *b;
  *b = temp;
}

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

using namespace std;

void change(int *, int *);

int main(void) {
  int x, y;

  while (scanf("%d %d", &x, &y) != EOF) {
    if (x == 0 && y == 0)
      break;
    if (x < y)
      change(&x, &y);
    while (y) {
      x %= y;
      change(&x, &y);
    }
    cout << x << endl;
  }
  return 0;
}

void change(int *a, int *b) {
  int temp;
  temp = *a;
  *a = *b;
  *b = temp;
}
Problem p00597 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
const int inf = 1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
int main() {
  int out[40] = {1, 2, 5, 8};
  loop(i, 4, 40) out[i] = out[i - 2] + (out[i - 2] - out[i - 4]) * 3;
  int n;
  while (cin >> n, n)
    cout << out[n - 1] << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
const int inf = 1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
int main() {
  int out[40] = {1, 2, 5, 8};
  loop(i, 4, 40) out[i] = out[i - 2] + (out[i - 2] - out[i - 4]) * 3;
  int n;
  while (cin >> n)
    cout << out[n - 1] << endl;
}
Problem p00597 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int n, f[33];
int main() {
  f[1] = 1, f[2] = 2, f[3] = 5;
  for (int i = 4; i <= 30; i++) {
    if (i & 1) {
      f[i] = 4;
      for (int j = 1; j < i / 2; j++)
        f[i] *= 3;
      f[i] += f[i - 2];
    } else {
      f[i] = 1;
      for (int j = 1; j < i / 2; i++)
        f[i] *= 3;
      f[i] += f[i - 1];
    }
  }
  while (cin >> n) {
    cout << f[n] << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int n, f[33];
int main() {
  f[1] = 1, f[2] = 2, f[3] = 5;
  for (int i = 4; i <= 30; i++) {
    if (i & 1) {
      f[i] = 4;
      for (int j = 1; j < i / 2; j++)
        f[i] *= 3;
      f[i] += f[i - 2];
    } else {
      f[i] = 1;
      for (int j = 1; j < i / 2; j++)
        f[i] *= 3;
      f[i] += f[i - 1];
    }
  }
  while (cin >> n) {
    cout << f[n] << endl;
  }
  return 0;
}
Problem p00601 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;
const int MAX_V = 10001;
int n, m;
vector<int> G[MAX_V];
bool used[MAX_V];
int mark[MAX_V];
int res;

void dfs(int s, int cnt) {
  if (s == n) {
    bool ok = true;
    // 全てがmarkされているか
    for (int i = 0; i < n; i++) {
      if (!mark[i]) {
        ok = false;
        break;
      }
    }
    if (ok)
      res = min(res, cnt);
  } else {
    dfs(s + 1, cnt);
    // markする
    mark[s]++;
    for (int j = 0; j < G[s].size(); j++) {
      int to = G[s][j];
      mark[to]++;
    }
    dfs(s + 1, cnt + 1);
    mark[s]--;
    for (int j = 0; j < G[s].size(); j++) {
      int to = G[s][j];
      mark[to]--;
    }
  }
}

int main() {
  while (cin >> n >> m && (n | m)) {
    for (int i = 0; i < n; i++)
      G[i].clear();
    for (int i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      G[a].push_back(b);
      G[b].push_back(a);
    }
    res = 1000000000;
    memset(used, 0, sizeof(used));
    memset(mark, 0, sizeof(mark));
    dfs(0, 0);
    cout << res << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;
const int MAX_V = 10001;
int n, m;
vector<int> G[MAX_V];
bool used[MAX_V];
int mark[MAX_V];
int res;

void dfs(int s, int cnt) {
  if (cnt >= res)
    return;
  if (s == n) {
    bool ok = true;
    // 全てがmarkされているか
    for (int i = 0; i < n; i++) {
      if (!mark[i]) {
        ok = false;
        break;
      }
    }
    if (ok)
      res = min(res, cnt);
  } else {
    dfs(s + 1, cnt);
    // markする
    mark[s]++;
    for (int j = 0; j < G[s].size(); j++) {
      int to = G[s][j];
      mark[to]++;
    }
    dfs(s + 1, cnt + 1);
    mark[s]--;
    for (int j = 0; j < G[s].size(); j++) {
      int to = G[s][j];
      mark[to]--;
    }
  }
}

int main() {
  while (cin >> n >> m && (n | m)) {
    for (int i = 0; i < n; i++)
      G[i].clear();
    for (int i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      G[a].push_back(b);
      G[b].push_back(a);
    }
    res = 1000000000;
    memset(used, 0, sizeof(used));
    memset(mark, 0, sizeof(mark));
    dfs(0, 0);
    cout << res << endl;
  }

  return 0;
}
Problem p00601 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int n;
vector<bitset<30>> neighbor;

int solve(int i, bitset<30> bs) {
  if (i == n) {
    if (bs.to_ulong() == (1 << n) - 1)
      return 0;
    else
      return INT_MAX / 2;
  }

  int ret = solve(i + 1, bs | neighbor[i]) + 1;
  ret = min(ret, solve(i + 1, bs));

  return ret;
}

int main() {
  for (;;) {
    int m;
    cin >> n >> m;
    if (n == 0)
      return 0;

    neighbor.assign(n, 0);
    for (int i = 0; i < m; ++i) {
      int a, b;
      cin >> a >> b;
      neighbor[a][b] = true;
      neighbor[b][a] = true;
    }
    for (int i = 0; i < n; ++i)
      neighbor[i][i] = true;

    cout << solve(0, 0) << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int n;
vector<bitset<30>> neighbor;

int solve(int i, bitset<30> bs) {
  if (i == n) {
    if (bs.to_ulong() == (1 << n) - 1)
      return 0;
    else
      return INT_MAX / 2;
  }

  int ret = solve(i + 1, bs);
  if ((~bs & neighbor[i]).any())
    ret = min(ret, solve(i + 1, bs | neighbor[i]) + 1);

  return ret;
}

int main() {
  for (;;) {
    int m;
    cin >> n >> m;
    if (n == 0)
      return 0;

    neighbor.assign(n, 0);
    for (int i = 0; i < m; ++i) {
      int a, b;
      cin >> a >> b;
      neighbor[a][b] = true;
      neighbor[b][a] = true;
    }
    for (int i = 0; i < n; ++i)
      neighbor[i][i] = true;

    cout << solve(0, 0) << endl;
  }
}
Problem p00601 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <vector>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;

VVI E;

int n, m;
VI D;

int cnt;
VI F;
int answer;

const int inf = 1 << 24;

bool check() {
  for (int i = 0; i < n; i++) {
    if (!F[i]) {
      bool flag = true;
      for (int j = 0; j < (int)E[i].size() && flag; j++) {
        if (F[E[i][j]])
          flag = false;
      }
      if (flag)
        return false;
    }
  }
  return true;
}

void solve(int s) {
  if (s == n) {
    if (check())
      answer = cnt;
    return;
  }

  F[s] = 1;
  cnt++;
  solve(s + 1);
  F[s] = 0;
  cnt--;
  solve(s + 1);
}

int main() {
  while (cin >> n >> m) {
    if (n == 0 && m == 0)
      break;

    F = VI(n, 0);
    E = VVI(n);

    for (int i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      E[a].push_back(b);
      E[b].push_back(a);
    }

    answer = n;
    cnt = 0;
    solve(0);
    cout << answer << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <vector>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;

VVI E;

int n, m;
VI D;

int cnt;
VI F;
int answer;

const int inf = 1 << 24;

bool check() {
  for (int i = 0; i < n; i++) {
    if (!F[i]) {
      bool flag = true;
      for (int j = 0; j < (int)E[i].size() && flag; j++) {
        if (F[E[i][j]])
          flag = false;
      }
      if (flag)
        return false;
    }
  }
  return true;
}

void solve(int s) {
  if (s == n) {
    if (cnt < answer && check())
      answer = cnt;
    return;
  }

  F[s] = 1;
  cnt++;
  solve(s + 1);
  F[s] = 0;
  cnt--;
  solve(s + 1);
}

int main() {
  while (cin >> n >> m) {
    if (n == 0 && m == 0)
      break;

    F = VI(n, 0);
    E = VVI(n);

    for (int i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      E[a].push_back(b);
      E[b].push_back(a);
    }

    answer = n;
    cnt = 0;
    solve(0);
    cout << answer << endl;
  }
  return 0;
}
Problem p00603 (C++)

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

using namespace std;

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

int main() {

  int N, R;
  while (cin >> N >> R) {
    queue<int> A, B, C;
    rep(i, N) { C.push(i); }
    rep(_, R) {
      int c;
      cin >> c;
      rep(i, N) {
        if (N / 2 <= i) {
          A.push(C.front());
        } else {
          B.push(C.front());
        }
        C.pop();
      }

      for (; (!A.empty()) && (!B.empty());) {
        rep(i, c) {
          if (A.empty())
            break;
          C.push(A.front());
          A.pop();
        }
        rep(i, c) {
          if (B.empty())
            break;
          C.push(B.front());
          B.pop();
        }
      }
    }
    cout << C.back() << endl;
  }

  return 0;
}

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

using namespace std;

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

int main() {

  int N, R;
  while (cin >> N >> R) {
    queue<int> A, B, C;
    rep(i, N) { C.push(i); }
    rep(_, R) {
      int c;
      cin >> c;
      rep(i, N) {
        if (N / 2 <= i) {
          A.push(C.front());
        } else {
          B.push(C.front());
        }
        C.pop();
      }

      for (; (!A.empty()) || (!B.empty());) {
        rep(i, c) {
          if (A.empty())
            break;
          C.push(A.front());
          A.pop();
        }
        rep(i, c) {
          if (B.empty())
            break;
          C.push(B.front());
          B.pop();
        }
      }
    }
    cout << C.back() << endl;
  }

  return 0;
}
Problem p00603 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

vector<int> shuffle(vector<int> deck, int m) {
  int n = deck.size();
  queue<int> a, b;

  for (int i = 0; i < n; ++i) {
    if (i < n / 2)
      b.push(deck[i]);
    else
      a.push(deck[i]);
  }

  vector<int> ret;
  for (int i = 0; i < m; ++i) {
    ret.push_back(a.front());
    a.pop();
  }
  for (int i = 0; i < m; ++i) {
    ret.push_back(b.front());
    b.pop();
  }

  while (!a.empty()) {
    ret.push_back(a.front());
    a.pop();
  }
  while (!b.empty()) {
    ret.push_back(b.front());
    b.pop();
  }

  return ret;
}

int main() {
  for (;;) {
    int n, r;
    if (!(cin >> n >> r))
      return 0;

    vector<int> deck(n);
    for (int i = 0; i < n; ++i)
      deck[i] = i;

    for (int i = 0; i < r; ++i) {
      int m;
      cin >> m;
      deck = shuffle(deck, m);
    }

    cout << deck[n - 1] << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

vector<int> shuffle(vector<int> deck, int m) {
  int n = deck.size();
  queue<int> a, b;

  for (int i = 0; i < n; ++i) {
    if (i < n / 2)
      b.push(deck[i]);
    else
      a.push(deck[i]);
  }

  vector<int> ret;
  while (!a.empty() || !b.empty()) {
    for (int i = 0; i < m; ++i) {
      if (a.empty())
        break;
      ret.push_back(a.front());
      a.pop();
    }
    for (int i = 0; i < m; ++i) {
      if (b.empty())
        break;
      ret.push_back(b.front());
      b.pop();
    }
  }

  return ret;
}

int main() {
  for (;;) {
    int n, r;
    if (!(cin >> n >> r))
      return 0;

    vector<int> deck(n);
    for (int i = 0; i < n; ++i)
      deck[i] = i;

    for (int i = 0; i < r; ++i) {
      int m;
      cin >> m;
      deck = shuffle(deck, m);
    }

    cout << deck[n - 1] << endl;
  }
}
Problem p00603 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <queue>
#include <stdio.h>
using namespace std;
int now[60];
int main() {
  int a, b;
  while (~scanf("%d%d", &a, &b), a) {
    queue<int> A;
    queue<int> B;
    queue<int> C;
    for (int i = 0; i < a; i++)
      now[i] = i;
    while (b--) {
      int c;
      scanf("%d", &c);
      for (int i = 0; i < a / 2; i++)
        B.push(now[i]);
      for (int i = a / 2; i < a; i++)
        A.push(now[i]);
      while (C.size() != a) {
        for (int i = 0; i < c; i++)
          if (A.size()) {
            C.push(A.front());
            A.pop();
          }
        for (int i = 0; i < c; i++)
          if (B.size()) {
            C.push(B.front());
            B.pop();
          }
      }
      for (int i = 0; i < a; i++) {
        now[i] = C.front();
        C.pop();
      }
    }
    printf("%d\n", now[a - 1]);
  }
}

Fixed submission:
#include <algorithm>
#include <queue>
#include <stdio.h>
using namespace std;
int now[60];
int main() {
  int a, b;
  while (~scanf("%d%d", &a, &b)) {
    queue<int> A;
    queue<int> B;
    queue<int> C;
    for (int i = 0; i < a; i++)
      now[i] = i;
    while (b--) {
      int c;
      scanf("%d", &c);
      for (int i = 0; i < a / 2; i++)
        B.push(now[i]);
      for (int i = a / 2; i < a; i++)
        A.push(now[i]);
      while (C.size() != a) {
        for (int i = 0; i < c; i++)
          if (A.size()) {
            C.push(A.front());
            A.pop();
          }
        for (int i = 0; i < c; i++)
          if (B.size()) {
            C.push(B.front());
            B.pop();
          }
      }
      for (int i = 0; i < a; i++) {
        now[i] = C.front();
        C.pop();
      }
    }
    printf("%d\n", now[a - 1]);
  }
}
Problem p00603 (C++)

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

using namespace std;

vector<int> RiffleShuffle(int, vector<int>);

int main() {
  int i, n, r, c;
  vector<int> data;

  while (cin >> n >> r) {
    for (i = 0; i < n; ++i)
      data.push_back(i);

    for (i = 0; i < r; ++i) {
      cin >> c;
      data = RiffleShuffle(c, data);
    }

    cout << data[data.size() - 1] << endl;
    data.clear();
  }

  return 0;
}

vector<int> RiffleShuffle(int c, vector<int> data) {
  vector<int> A, B, C;

  copy(data.begin() + data.size() / 2, data.end(), back_inserter(A));
  copy(data.begin(), data.begin() + data.size() / 2, back_inserter(B));

  copy(A.begin(), A.begin() + c, back_inserter(C));
  A.erase(A.begin(), A.begin() + c);
  copy(B.begin(), B.begin() + c, back_inserter(C));
  B.erase(B.begin(), B.begin() + c);

  copy(A.begin(), A.end(), back_inserter(C));
  copy(B.begin(), B.end(), back_inserter(C));

  return C;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

vector<int> RiffleShuffle(int, vector<int>);

int main() {
  int i, n, r, c;
  vector<int> data;

  while (cin >> n >> r) {
    for (i = 0; i < n; ++i)
      data.push_back(i);

    for (i = 0; i < r; ++i) {
      cin >> c;
      data = RiffleShuffle(c, data);
    }

    cout << data[data.size() - 1] << endl;
    data.clear();
  }

  return 0;
}

vector<int> RiffleShuffle(int c, vector<int> data) {
  vector<int> A, B, C;

  copy(data.begin() + data.size() / 2, data.end(), back_inserter(A));
  copy(data.begin(), data.begin() + data.size() / 2, back_inserter(B));

  while (A.size() > c || B.size() > c) {
    copy(A.begin(), A.begin() + c, back_inserter(C));
    A.erase(A.begin(), A.begin() + c);
    copy(B.begin(), B.begin() + c, back_inserter(C));
    B.erase(B.begin(), B.begin() + c);
  }

  copy(A.begin(), A.end(), back_inserter(C));
  copy(B.begin(), B.end(), back_inserter(C));

  return C;
}
Problem p00604 (C++)

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

int main() {
  int n;
  vector<int> time(n);

  while (cin >> n) {
    time.clear();
    for (int i = 0; i < n; i++) {
      int t;
      cin >> t;
      time.push_back(t);
    }
    sort(time.begin(), time.end());
    int sum = 0;
    for (int i = 0; i < n; i++) {
      sum += time[i] * (n - i);
    }
    cout << sum << endl;
  }
  return 0;
}

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

int main() {
  int n;
  vector<int> time;

  while (cin >> n) {
    time.clear();
    for (int i = 0; i < n; i++) {
      int t;
      cin >> t;
      time.push_back(t);
    }
    sort(time.begin(), time.end());
    int sum = 0;
    for (int i = 0; i < n; i++) {
      sum += time[i] * (n - i);
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p00605 (C++)

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

int main() {
  int N, K;
  while (cin >> N >> K, N || K) {
    int s[N];
    for (int i = 0; i < K; i++) {
      cin >> s[i];
    }
    int temp;
    bool flag = true;
    for (int j = 0; j < N; j++) {
      for (int i = 0; i < K; i++) {
        cin >> temp;
        s[i] -= temp;
        if (s[i] < 0)
          flag = false;
      }
    }
    if (flag)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}

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

int main() {
  int N, K;
  while (cin >> N >> K, N || K) {
    int s[K];
    for (int i = 0; i < K; i++) {
      cin >> s[i];
    }
    int temp;
    bool flag = true;
    for (int j = 0; j < N; j++) {
      for (int i = 0; i < K; i++) {
        cin >> temp;
        s[i] -= temp;
        if (s[i] < 0)
          flag = false;
      }
    }
    if (flag)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}
Problem p00605 (C++)

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

using namespace std;

#define pb(n) push_back(n)
#define mp(n, m) make_pair(n, m)
#define fi first
#define se second
#define all(r) (r).begin(), (r).end()

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define rep(i, n) REP(i, 0, n)
#define REPE(i, s, e) for (int i = s; i > e; i--)
#define repe(i, n) REPE(i, n, -1)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<vi> vvi;

const int IMAX = ((1 << 30) - 1) * 2 + 1;
const int INF = 100000000;
const double EPS = 1e-10;
// int mod=1000000007

const int MAX_V = 10000;

int main() {
  int n, m;
  while (cin >> n >> m) {
    if (n == 0 && m == 0)
      break;
    vi s(n, 0);
    rep(i, m) cin >> s[i];
    int t;
    rep(i, n) {
      rep(j, m) {
        cin >> t;
        s[j] -= t;
      }
    }
    sort(all(s));
    cout << (s[0] < 0 ? "No" : "Yes") << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define pb(n) push_back(n)
#define mp(n, m) make_pair(n, m)
#define fi first
#define se second
#define all(r) (r).begin(), (r).end()

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define rep(i, n) REP(i, 0, n)
#define REPE(i, s, e) for (int i = s; i > e; i--)
#define repe(i, n) REPE(i, n, -1)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<vi> vvi;

const int IMAX = ((1 << 30) - 1) * 2 + 1;
const int INF = 100000000;
const double EPS = 1e-10;
// int mod=1000000007

const int MAX_V = 10000;

int main() {
  int n, m;
  while (cin >> n >> m) {
    if (n == 0 && m == 0)
      break;
    vi s(m, 0);
    rep(i, m) cin >> s[i];
    int t;
    rep(i, n) {
      rep(j, m) {
        cin >> t;
        s[j] -= t;
      }
    }
    sort(all(s));
    cout << (s[0] < 0 ? "No" : "Yes") << endl;
  }
}
Problem p00605 (C++)

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

using namespace std;

int main() {
  while (true) {
    int N, K;
    string ans = "Yes";
    cin >> N >> K;
    int S[N];
    if (N == 0 && K == 0)
      break;
    for (int i = 0; i < K; ++i) {
      cin >> S[i];
    }
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < K; ++j) {
        int B;
        cin >> B;
        S[j] -= B;
      }
    }
    for (int i = 0; i < K; ++i) {
      if (S[i] < 0) {
        ans = "No";
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
  while (true) {
    int N, K;
    string ans = "Yes";
    cin >> N >> K;
    int S[K];
    if (N == 0 && K == 0)
      break;
    for (int i = 0; i < K; ++i) {
      cin >> S[i];
    }
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < K; ++j) {
        int B;
        cin >> B;
        S[j] -= B;
      }
    }
    for (int i = 0; i < K; ++i) {
      if (S[i] < 0) {
        ans = "No";
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00605 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int n, m, x, s[100];
int main() {
  while (cin >> n >> m, n + m) {
    for (int i = 0; i < m; i++)
      cin >> s[i];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++)
        cin >> x, s[x]--;
    }
    int f = 1;
    for (int i = 0; i < m; i++) {
      if (s[i] < 0)
        f = 0;
    }
    cout << (f ? "Yes" : "No") << endl;
  }
}

Fixed submission:
#include <iostream>
using namespace std;
int n, m, x, s[100];
int main() {
  while (cin >> n >> m, n + m) {
    for (int i = 0; i < m; i++)
      cin >> s[i];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++)
        cin >> x, s[j] -= x;
    }
    int f = 1;
    for (int i = 0; i < m; i++) {
      if (s[i] < 0)
        f = 0;
    }
    cout << (f ? "Yes" : "No") << endl;
  }
}