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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

typedef long long Int;
#define REP(i, n) for (int i = 0; i < n; ++i)
using namespace std;

Int aa[120];

int main() {
  int a = -1;
  while (cin >> a, a != -1) {
    ++aa[a];
  }

  Int b = 0;

  REP(i, 120) { b = max(b, aa[i]); }

  REP(i, 120) {
    if (aa[i] == b)
      cout << i << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

typedef long long Int;
#define REP(i, n) for (int i = 0; i < n; ++i)
using namespace std;

Int aa[120];

int main() {
  int a = -1;
  while (cin >> a) {
    ++aa[a];
  }

  Int b = 0;

  REP(i, 120) { b = max(b, aa[i]); }

  REP(i, 120) {
    if (aa[i] == b)
      cout << i << endl;
  }

  return 0;
}
Problem p00028 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>

using namespace std;

int main(void) {
  int a;
  int maxa = 0;
  vector<int> ans;
  map<int, int> f;
  for (a = 0; a <= 100; a++) {
    f.insert(map<int, int>::value_type(a, 0));
  }
  while (~scanf("%d", &a)) {
    f[a]++;
  }
  for (a = 0; a <= 100; a++) {
    maxa = max(maxa, f[a]);
  }
  for (a = 0; a <= 100; a++) {
    if (maxa == f[a])
      ans.push_back(a);
  }
  sort(ans.begin(), ans.end());

  while (!ans.empty()) {
    cout << ans[a] << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>

using namespace std;

int main(void) {
  int a;
  int maxa = 0;
  vector<int> ans;
  map<int, int> f;
  for (a = 0; a <= 100; a++) {
    f.insert(map<int, int>::value_type(a, 0));
  }
  while (~scanf("%d", &a)) {
    f[a]++;
  }
  for (a = 0; a <= 100; a++) {
    maxa = max(maxa, f[a]);
  }
  for (a = 0; a <= 100; a++) {
    if (maxa == f[a])
      ans.push_back(a);
  }
  sort(ans.begin(), ans.end());

  for (a = 0; a < ans.size(); a++) {
    cout << ans[a] << endl;
  }
  return 0;
}
Problem p00028 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int, int> pint;
#define foreach(i, n) for (i = 0; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define F first
#define S second
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};

int main() {
  pair<int, int> a[101];
  rep(i, 101) { a[i].second = -i; }
  for (int k; cin >> k, k;) {
    a[k].first++;
  }
  sort(a, a + 101, greater<pair<int, int>>());
  for (int i = 0; cout << -a[i].second << endl, a[i].F == a[i + 1].F; i++)
    ;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int, int> pint;
#define foreach(i, n) for (i = 0; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define F first
#define S second
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};

int main() {
  pair<int, int> a[101];
  rep(i, 101) { a[i].second = -i; }
  for (int k; cin >> k;) {
    a[k].first++;
  }
  sort(a, a + 101, greater<pair<int, int>>());
  for (int i = 0; cout << -a[i].second << endl, a[i].F == a[i + 1].F; i++)
    ;
  return 0;
}
Problem p00028 (C++)

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

using namespace std;

int main() {
  int ans[100] = {0}, i, n;
  int b = 0;
  while (cin >> n) {
    ans[n]++;
    if (ans[n] > b) {
      b = ans[n];
    }
  }

  for (i = 1; i <= 100; i++) {
    if (b == ans[i]) {
      cout << i << endl;
    }
  }

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int ans[101] = {0}, i, n;
  int b = 0;
  while (cin >> n) {
    ans[n]++;
    if (ans[n] > b) {
      b = ans[n];
    }
  }

  for (i = 1; i <= 100; i++) {
    if (b == ans[i]) {
      cout << i << endl;
    }
  }

  return 0;
}
Problem p00028 (C++)

Buggy submission (status: Runtime Error):
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cctype>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
  int n;
  int a[101] = {};
  int max = 0;
  while (cin >> n) {
    a[n]++;
    if (max < a[n])
      max = a[n];
  }
  for (int i = 0; i < 102; i++)
    if (max == a[i])
      cout << i << endl;
  return 0;
}

Fixed submission:
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cctype>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
  int n;
  int a[101] = {};
  int max = 0;
  while (cin >> n) {
    a[n]++;
    if (max < a[n])
      max = a[n];
  }
  for (int i = 0; i < 101; i++)
    if (max == a[i])
      cout << i << endl;
  return 0;
}
Problem p00029 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  int i, i1, len, len1, check, max1, memo1, max2, memo2;
  max1 = 0;
  max2 = 0;
  memo1 = 0;
  memo2 = 0;
  string t;
  vector<string> s;
  vector<int> a, u;
  for (int h = 0; h < 500; h++) {
    u.push_back(0);
  }
  while (cin >> t) {
    check = 0;
    len = s.size();
    for (i = 0; i < len; i++) {
      if (t == s[i]) {
        u[i] += 1;
        check = 1;
      }
    }
    if (check == 0) {
      s.push_back(t);
      len1 = t.size();
      a.push_back(len1);
    }
  }
  len = s.size();
  for (i1 = 0; i1 < len; i1++) {
    while (max1 < u[i1]) {
      max1 = u[i1];
      memo1 = i1;
    }
    while (max2 < a[i1]) {
      max2 = u[i1];
      memo2 = i1;
    }
  }
  cout << s[memo1] << " " << s[memo2] << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  int i, i1, len, len1, check, max1, memo1, max2, memo2;
  max1 = 0;
  max2 = 0;
  memo1 = 0;
  memo2 = 0;
  string t;
  vector<string> s;
  vector<int> a, u;
  for (int h = 0; h < 500; h++) {
    u.push_back(0);
  }
  while (cin >> t) {
    check = 0;
    len = s.size();
    for (i = 0; i < len; i++) {
      if (t == s[i]) {
        u[i] += 1;
        check = 1;
      }
    }
    if (check == 0) {
      s.push_back(t);
      len1 = t.size();
      a.push_back(len1);
    }
  }
  len = s.size();
  for (i1 = 0; i1 < len; i1++) {
    while (max1 < u[i1]) {
      max1 = u[i1];
      memo1 = i1;
    }
    while (max2 < a[i1]) {
      max2 = a[i1];
      memo2 = i1;
    }
  }
  cout << s[memo1] << " " << s[memo2] << endl;
  return 0;
}
Problem p00029 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string.h>
#include <string>
#include <utility>
using namespace std;

int main() {
  string str;
  char word[35][35];
  int x = 0, y = 0, i = 0, j, length = 0, maxl = 0, maxq[35], q, p = 0;
  maxq[0] = 0;
  getline(cin, str);
  while (1) {
    if (str[i] == ' ') {
      word[y][x] = '\0';
      x = 0;
      y++;
    } else if (str[i] == '\0') {
      word[y][x] = '\0';
      word[y + 1][0] = '\0';
      break;
    } else {
      word[y][x] = str[i];
      x++;
    }
    i++;
  }
  for (i = 0; i < y; i++) {
    for (j = 0; j < y - i; j++) {
      if (strcmp(word[j], word[j + 1]) > 0) {
        for (x = 0; x < 35; x++) {
          swap(word[j][x], word[j + 1][x]);
        }
      }
    }
  }
  for (i = 0; i <= y; i++) {
    for (j = 0; word[i][j] != '\0'; j++) {
    }
    if (maxl < j) {
      maxl = j;
      length = i;
    }
    if (strcmp(word[i], word[i + 1]) == 0) {
      maxq[i + 1] = maxq[i] + 1;
    } else {
      maxq[i + 1] = 0;
    }
  }
  for (i = 0; i <= y; i++) {
    if (p < maxq[i]) {
      p = maxq[i];
      q = i;
    }
  }
  printf("%s %s\n", word[q], word[length]);
  return 0;
}

Fixed submission:
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string.h>
#include <string>
#include <utility>
using namespace std;

int main() {
  string str;
  char word[1010][35];
  int x = 0, y = 0, i = 0, j, length = 0, maxl = 0, maxq[35], q, p = 0;
  maxq[0] = 0;
  getline(cin, str);
  while (1) {
    if (str[i] == ' ') {
      word[y][x] = '\0';
      x = 0;
      y++;
    } else if (str[i] == '\0') {
      word[y][x] = '\0';
      word[y + 1][0] = '\0';
      break;
    } else {
      word[y][x] = str[i];
      x++;
    }
    i++;
  }
  for (i = 0; i < y; i++) {
    for (j = 0; j < y - i; j++) {
      if (strcmp(word[j], word[j + 1]) > 0) {
        for (x = 0; x < 35; x++) {
          swap(word[j][x], word[j + 1][x]);
        }
      }
    }
  }
  for (i = 0; i <= y; i++) {
    for (j = 0; word[i][j] != '\0'; j++) {
    }
    if (maxl < j) {
      maxl = j;
      length = i;
    }
    if (strcmp(word[i], word[i + 1]) == 0) {
      maxq[i + 1] = maxq[i] + 1;
    } else {
      maxq[i + 1] = 0;
    }
  }
  for (i = 0; i <= y; i++) {
    if (p < maxq[i]) {
      p = maxq[i];
      q = i;
    }
  }
  printf("%s %s\n", word[q], word[length]);
  return 0;
}
Problem p00029 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main() {
  char a[1100] = {0};
  scanf("%[^\n]", a);
  int cnt = 0;
  int mx = 0;
  int len[50] = {0};
  string ans[50];
  for (int i = 0, j = 0; i <= strlen(a); i++) {
    if ('a' <= a[i] && a[i] <= 'z' || 'A' <= a[i] && a[i] <= 'Z') {
      ans[cnt] += a[i];
      j++;
    } else {
      len[cnt] = j;
      cnt++;
      mx = max(mx, j);
      j = 0;
    }
  }
  string date;
  for (int i = 0; i < cnt; i++) {
    if (len[i] == mx) {
      date = ans[i];
      break;
    }
  }
  sort(ans, ans + cnt);
  fill(len, len + 50, 0);
  string mx_date = ans[0];
  ans[cnt] = ' ';
  mx = 0;
  for (int i = 1; i <= cnt; i++) {
    if (mx_date == ans[i]) {
      mx++;
    } else {
      mx_date = ans[i];
      len[i - 1] = mx;
      mx = 0;
    }
  }
  for (int i = 0; i < cnt; i++) {
    mx = max(mx, len[i]);
  }
  for (int i = 0; i < cnt; i++) {
    if (len[i] == mx) {
      cout << ans[i] << ' ' << date << endl;
      break;
    }
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main() {
  char a[1100] = {0};
  scanf("%[^\n]", a);
  int cnt = 0;
  int mx = 0;
  int len[1100] = {0};
  string ans[1100];
  for (int i = 0, j = 0; i <= strlen(a); i++) {
    if ('a' <= a[i] && a[i] <= 'z' || 'A' <= a[i] && a[i] <= 'Z') {
      ans[cnt] += a[i];
      j++;
    } else {
      len[cnt] = j;
      cnt++;
      mx = max(mx, j);
      j = 0;
    }
  }
  string date;
  for (int i = 0; i < cnt; i++) {
    if (len[i] == mx) {
      date = ans[i];
      break;
    }
  }
  sort(ans, ans + cnt);
  fill(len, len + 50, 0);
  string mx_date = ans[0];
  ans[cnt] = ' ';
  mx = 0;
  for (int i = 1; i <= cnt; i++) {
    if (mx_date == ans[i]) {
      mx++;
    } else {
      mx_date = ans[i];
      len[i - 1] = mx;
      mx = 0;
    }
  }
  for (int i = 0; i < cnt; i++) {
    mx = max(mx, len[i]);
  }
  for (int i = 0; i < cnt; i++) {
    if (len[i] == mx) {
      cout << ans[i] << ' ' << date << endl;
      break;
    }
  }

  return 0;
}
Problem p00030 (C++)

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

int A[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int cunt = 0;

void depth(int n, int s, int i) {

  if (n == 0 && s == 0) {
    cunt++;
    return;
  } else if (n == 0)
    return;
  else if (s < 0)
    return;
  else if (i == 10)
    return;

  depth(n - 1, s - A[i], ++i);
  depth(n, s, ++i);
}

int main() {
  int n, s;
  while (cin >> n >> s) {
    if (n == 0 && s == 0)
      break;
    depth(n, s, 0);
    cout << cunt << endl;
    cunt = 0;
  }
  return 0;
}

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

int A[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int cunt = 0;

void depth(int n, int s, int i) {

  if (n == 0 && s == 0) {
    cunt++;
    return;
  } else if (n == 0)
    return;
  else if (s < 0)
    return;
  else if (i == 10)
    return;

  depth(n - 1, s - A[i], i + 1);
  depth(n, s, i + 1);
}

int main() {
  int n, s;
  while (cin >> n >> s) {
    if (n == 0 && s == 0)
      break;
    depth(n, s, 0);
    cout << cunt << endl;
    cunt = 0;
  }
  return 0;
}
Problem p00030 (C++)

Buggy submission (status: Runtime Error):

#include <algorithm>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int n, s;
int count_2;

void dfs(int step, int i, int sum) {
  if (sum > s || step > n)
    return;
  if (step == n && i == 10 && sum == s) {
    count_2++;
    return;
  }
  dfs(step, i + 1, sum);
  dfs(step + 1, i + 1, sum + a[i]);
  return;
}

int main() {
  while (cin >> n >> s) {
    if (n == 0 && s == 0)
      break;
    else {
      count_2 = 0;
      dfs(0, 0, 0);
    }
    cout << count_2 << endl;
  }
  // while(1);
  return 0;
}


Fixed submission:

#include <algorithm>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int n, s;
int count_2;

void dfs(int step, int i, int sum) {
  if (sum > s || step > n)
    return;
  if (i == 10) {
    if (step == n && i == 10 && sum == s) {
      count_2++;
      return;
    } else
      return;
  }
  dfs(step, i + 1, sum);
  dfs(step + 1, i + 1, sum + a[i]);
  return;
}

int main() {
  while (cin >> n >> s) {
    if (n == 0 && s == 0)
      break;
    else {
      count_2 = 0;
      dfs(0, 0, 0);
    }
    cout << count_2 << endl;
  }
  // while(1);
  return 0;
}
Problem p00030 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1 << 29;
typedef long long ll;
typedef pair<int, int> PI;

int n, s, t, res;

void dfs(int n, int t, int sum) {
  if (n == 0 && sum == s) {
    res++;
    return;
  }
  if (sum > s || n <= 0 || t > s - sum)
    return;
  for (int i = t + 1; i <= s; ++i) {
    dfs(n - 1, i, sum + i - 1);
  }
}

int main(void) {
  while (cin >> n >> s, n | s) {
    if (n == 0 && s == 0)
      break;
    res = 0;
    int ans;
    dfs(n, 0, 0);
    cout << res << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1 << 29;
typedef long long ll;
typedef pair<int, int> PI;

int n, s, t, res;

void dfs(int n, int t, int sum) {
  if (n == 0 && sum == s) {
    res++;
    return;
  }
  if (sum > s || n <= 0 || t > s - sum)
    return;
  for (int i = t + 1; i <= 10; ++i) {
    dfs(n - 1, i, sum + i - 1);
  }
}

int main(void) {
  while (cin >> n >> s, n | s) {
    if (n == 0 && s == 0)
      break;
    res = 0;
    int ans;
    dfs(n, 0, 0);
    cout << res << endl;
  }

  return 0;
}
Problem p00030 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

int cnt_sum_s(int n, int k, int s, int tmp_sum) {
  if (n == 0) {
    return (tmp_sum == s) ? 1 : 0;
  }

  int res = 0;
  for (int i = k + 1; i < 10; i++) {
    res += cnt_sum_s(n - 1, i, s, tmp_sum + i);
  }

  return res;
}

int main() {
  ifstream cin("../test.txt");
  while (true) {
    int n, s;
    cin >> n >> s;
    if (!(n | s))
      break;

    int res = cnt_sum_s(n, -1, s, 0);

    cout << res << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

int cnt_sum_s(int n, int k, int s, int tmp_sum) {
  if (n == 0) {
    return (tmp_sum == s) ? 1 : 0;
  }

  int res = 0;
  for (int i = k + 1; i < 10; i++) {
    res += cnt_sum_s(n - 1, i, s, tmp_sum + i);
  }

  return res;
}

int main() {
  // ifstream cin("../test.txt");
  while (true) {
    int n, s;
    cin >> n >> s;
    if (!(n | s))
      break;

    int res = cnt_sum_s(n, -1, s, 0);

    cout << res << endl;
  }
}
Problem p00030 (C++)

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

int n, s;

int recursion(int sum, int num, int cnt) {
  if (sum > s || cnt > n)
    return 0;
  if (cnt == n && sum == s)
    return 1;
  if (num > s)
    return 0;
  int hoge = 0;
  hoge += recursion(sum + num, num + 1, cnt + 1);
  hoge += recursion(sum, num + 1, cnt);
  return hoge;
}

int main() {
  while (cin >> n >> s, n || s) {
    cout << recursion(0, 0, 0) << endl;
  }
}

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

int n, s;

int recursion(int sum, int num, int cnt) {
  if (sum > s || cnt > n)
    return 0;
  if (cnt == n && sum == s)
    return 1;
  if (num > 9)
    return 0;
  int hoge = 0;
  hoge += recursion(sum + num, num + 1, cnt + 1);
  hoge += recursion(sum, num + 1, cnt);
  return hoge;
}

int main() {
  while (cin >> n >> s, n || s) {
    cout << recursion(0, 0, 0) << endl;
  }
}
Problem p00030 (C++)

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

using namespace std;
int a;
int f(int n, int s, int i) {
  if (n == 1 && i >= s && s >= 0) {
    a++;
    return 0;
  }
  if (s <= 0)
    return 0;
  for (int j = i; j >= n - 1; j--)
    f(n - 1, s - j, j - 1);
}
int main() {
  int n, s;
  while (cin >> n >> s) {
    a = 0;
    if (n == 0 && s == 0)
      break;
    f(n, s, 9);
    cout << a << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;
int a;
int f(int n, int s, int i) {
  if (n == 1 && i >= s && s >= 0) {
    a++;
    return 0;
  }
  if (s <= 0 || s >= i * n)
    return 0;
  for (int j = i; j >= n - 1; j--)
    f(n - 1, s - j, j - 1);
}
int main() {
  int n, s;
  while (cin >> n >> s) {
    a = 0;
    if (n == 0 && s == 0)
      break;
    f(n, s, 9);
    cout << a << endl;
  }
  return 0;
}
Problem p00030 (C++)

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

using namespace std;

int n, s, *num, pattern;
void search(int th) {
  if (th == n) {
    int sum = 0;
    for (int i = 0; i < n; i++)
      sum += num[i];
    if (s == sum) {
      for (int j = 0; j + 1 < n; j++)
        if (num[j] >= num[j + 1])
          return;
      /*
      for (int j = 0; j < n; j++)
        cout << num[j];
      cout << endl;
      */
      pattern++;
    }
  } else {
    for (int i = 0; i < 10; i++) {
      num[th] = i;
      search(th + 1);
    }
  }
}

int main(int argc, char *argv[]) {
  vector<int> result;
  while (true) {
    cin >> n >> s;
    if (n == 0 && s == 0)
      break;
    num = new int[n];
    memset(num, 0, sizeof(int) * n);

    pattern = 0;
    search(0);
    result.push_back(pattern);
  }

  for (int i = 0; i < result.size(); i++)
    cout << result[i] << endl;
  return 0;
}

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

using namespace std;

int n, s, *num, pattern;
void search(int th) {
  if (th == n) {
    int sum = 0;
    for (int i = 0; i < n; i++)
      sum += num[i];
    if (s == sum) {
      for (int j = 0; j + 1 < n; j++)
        if (num[j] >= num[j + 1])
          return;
      /*
      for (int j = 0; j < n; j++)
        cout << num[j];
      cout << endl;
      */
      pattern++;
    }
  } else {
    int start = 0;
    if (th > 0)
      start = num[th - 1] + 1;
    for (int i = start; i < 10; i++) {
      num[th] = i;
      search(th + 1);
    }
  }
}

int main(int argc, char *argv[]) {
  vector<int> result;
  while (true) {
    cin >> n >> s;
    if (n == 0 && s == 0)
      break;
    num = new int[n];
    memset(num, 0, sizeof(int) * n);

    pattern = 0;
    search(0);
    result.push_back(pattern);
  }

  for (int i = 0; i < result.size(); i++)
    cout << result[i] << endl;
  return 0;
}
Problem p00030 (C++)

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

int dp[105][10][10], s, n;
int f(int a, int b, int c) {
  if (dp[a][b][c] != -1)
    return dp[a][b][c];
  if (a == s && c == n && b <= 10)
    return 1;
  if (a > s || c > n || b == 10)
    return 0;
  int res = 0;
  res += f(a + b, b + 1, c + 1);
  res += f(a, b + 1, c);
  return dp[a][b][c] = res;
}

signed main(void) {
  while (1) {
    cin >> n >> s;
    REP(i, 105) REP(j, 10) REP(k, 10) dp[i][j][k] = -1;
    cout << f(0, 0, 0) << endl;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

int dp[105][10][10], s, n;
int f(int a, int b, int c) {
  if (dp[a][b][c] != -1)
    return dp[a][b][c];
  if (a == s && c == n && b <= 10)
    return 1;
  if (a > s || c > n || b == 10)
    return 0;
  int res = 0;
  res += f(a + b, b + 1, c + 1);
  res += f(a, b + 1, c);
  return dp[a][b][c] = res;
}

signed main(void) {
  while (1) {
    cin >> n >> s;
    if (!n && !s)
      break;
    REP(i, 105) REP(j, 10) REP(k, 10) dp[i][j][k] = -1;
    cout << f(0, 0, 0) << endl;
  }
  return 0;
}
Problem p00030 (C++)

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

int dp[20][55][20];

int cnt_sum(int n, int s, int x) {
  if (dp[n][s][x] != -1) {
    return dp[n][s][x];
  }
  if (n == 0 && s == 0) {
    return (1);
  }
  if (x > 9) {
    return (0);
  }

  return dp[n][s][x] = (cnt_sum(n - 1, s - x, x + 1) + cnt_sum(n, s, x + 1));
}
int main() {
  int n, s;
  memset(dp, -1, sizeof(dp));
  while (1) {
    scanf("%d %d", &n, &s);
    if (n == 0 && s == 0) {
      break;
    }
    if (n >= 11 || s >= 46)
      printf("0\n");
    else
      printf("%d\n", cnt_sum(n, s, 0));
  }
  return 0;
}

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

int dp[20][55][20];

int cnt_sum(int n, int s, int x) {
  if (n < 0 || s < 0) {
    return 0;
  }
  if (dp[n][s][x] != -1) {
    return dp[n][s][x];
  }
  if (n == 0 && s == 0) {
    return (1);
  }
  if (x > 9) {
    return (0);
  }

  return dp[n][s][x] = (cnt_sum(n - 1, s - x, x + 1) + cnt_sum(n, s, x + 1));
}
int main() {
  int n, s;
  memset(dp, -1, sizeof(dp));
  while (1) {
    scanf("%d %d", &n, &s);
    if (n == 0 && s == 0) {
      break;
    }
    if (n >= 11 || s >= 46)
      printf("0\n");
    else
      printf("%d\n", cnt_sum(n, s, 0));
  }
  return 0;
}
Problem p00030 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int dp[16][64];

int main() {
  dp[0][0] = 1;
  rep(k, 10) {
    for (int i = 10; i >= 0; i--) {
      rep(j, 64) if (dp[i][j]) dp[i + 1][j + k] += dp[i][j];
    }
  }
  for (;;) {
    int n, s;
    scanf("%d%d", &n, &s);
    if (n == 0 && s == 0)
      return 0;
    printf("%d\n", dp[n][s]);
  }
}

Fixed submission:
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int dp[16][64];

int main() {
  dp[0][0] = 1;
  rep(k, 10) {
    for (int i = 10; i >= 0; i--) {
      rep(j, 64) if (dp[i][j]) dp[i + 1][j + k] += dp[i][j];
    }
  }
  for (;;) {
    int n, s;
    scanf("%d%d", &n, &s);
    if (n == 0 && s == 0)
      return 0;
    printf("%d\n", n < 16 && s < 64 ? dp[n][s] : 0);
  }
}
Problem p00030 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _CRT_SECURE_NO_WARNINGS

#include <iomanip>
#include <iostream>
#include <list>
#include <math.h>
#include <stack>
#include <string>

using namespace std;

int n = 0;
int s = 0;
static int ans;

void check(int atai, int num, int count) {
  if (num > s || atai > s) {
    if (count == n && atai == s) {
      ans++;
    }
    return;
  }
  check(atai + num, num + 1, count + 1);
  check(atai, num + 1, count);
}

int main(int argc, char **argv) {
  while (cin >> n >> s) {
    ans = 0;
    if (n == 0 && s == 0) {
      break;
    }
    check(0, 0, 0);
    cout << ans << endl;
  }
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS

#include <iomanip>
#include <iostream>
#include <list>
#include <math.h>
#include <stack>
#include <string>

using namespace std;

int n = 0;
int s = 0;
static int ans;

void check(int atai, int num, int count) {
  if (num > 9) {
    if (atai == s && count == n) {
      ans++;
    }
    return;
  }
  check(atai + num, num + 1, count + 1);
  check(atai, num + 1, count);
}

int main(int argc, char **argv) {
  while (cin >> n >> s) {
    ans = 0;
    if (n == 0 && s == 0) {
      break;
    }
    check(0, 0, 0);
    cout << ans << endl;
  }
}
Problem p00030 (C++)

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

int dp[11][46] = {0};

int main() {
  dp[0][0] = 1;
  for (int k = 0; k < 10; k++) {
    for (int i = k; i >= 0; i--)
      for (int j = 0; j < 46 - k; j++) {
        dp[i + 1][j + k] += dp[i][j];
      }
  }

  int N, S;
  while (cin >> N >> S, N || S) {
    cout << dp[N][S] << endl;
  }
}

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

int dp[11][46] = {0};

int main() {
  dp[0][0] = 1;
  for (int k = 0; k < 10; k++) {
    for (int i = k; i >= 0; i--)
      for (int j = 0; j < 46 - k; j++) {
        dp[i + 1][j + k] += dp[i][j];
      }
  }

  int N, S;
  while (cin >> N >> S, N || S) {
    if (0 <= N && N < 11 && 0 <= S && S < 46) {
      cout << dp[N][S] << endl;
    } else {
      cout << 0 << endl;
    }
  }
}
Problem p00030 (C++)

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

int n, s;

int dfs(int i, int c, int sum) {
  int res = 0;
  if (c + 10 - i < n || s < sum)
    return 0;
  if (c == n && sum == s)
    return 1;
  res += dfs(i + 1, c, sum);
  res += dfs(i + 1, c + 1, sum + i);
  return res;
}
int main() {
  while (cin >> n >> s, n || s)
    cout << dfs(0, 0, 0) << endl;
  return 0;
}

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

int n, s;

int dfs(int i, int c, int sum) {
  int res = 0;
  if (n < c || c + 10 - i < n || s < sum)
    return 0;
  if (c == n && sum == s)
    return 1;
  res += dfs(i + 1, c, sum);
  res += dfs(i + 1, c + 1, sum + i);
  return res;
}
int main() {
  while (cin >> n >> s, n || s)
    cout << dfs(0, 0, 0) << endl;
  return 0;
}
Problem p00030 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int n, s, j, k;
  int a[11][46];
  for (int s = 0; s < 46; s++)
    for (int n = 0; n < 11; n++)
      a[n][s] = 0;
  n = s = 0;
  for (int i = 0; i < 1024; i++) {
    for (j = i, n = 0; j > 0; j /= 2)
      n += j % 2;
    for (j = i, s = 0, k = 0; j > 0; j /= 2, k++)
      s += j % 2 * k;
    a[n][s]++;
  }
  while (true) {
    cin >> n >> s;
    if (!n && !s)
      break;
    cout << a[n][s] << endl;
  }
  return 0;
}
//  for(cin>>n>>s;n||s;cout<<a[n][s]<<endl,cin>>n>>s);

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n, s, j, k;
  int a[11][46];
  for (int s = 0; s < 46; s++)
    for (int n = 0; n < 11; n++)
      a[n][s] = 0;
  n = s = 0;
  for (int i = 0; i < 1024; i++) {
    for (j = i, n = 0; j > 0; j /= 2)
      n += j % 2;
    for (j = i, s = 0, k = 0; j > 0; j /= 2, k++)
      s += j % 2 * k;
    a[n][s]++;
  }
  while (true) {
    cin >> n >> s;
    if (!n && !s)
      break;
    if (s < 46)
      cout << a[n][s] << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
//  for(cin>>n>>s;n||s;cout<<a[n][s]<<endl,cin>>n>>s);
Problem p00031 (C++)

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

using namespace std;

int main() {
  int weight[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
  int gram;
  vector<int> ans;
  while (cin >> gram) {
    for (int i = 9; i >= 0; i--) {
      if (gram >= weight[i]) {
        ans.push_back(i);
        gram -= weight[i];
      }
    }

    for (size_t i = ans.size() - 1; i >= 0; i--) {
      cout << weight[ans[i]];
      if (i != 0)
        cout << ' ';
    }
    cout << endl;
    ans.clear();
  }
  return 0;
}

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

using namespace std;

int main() {
  int weight[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
  int gram;
  vector<int> ans;
  while (cin >> gram) {
    for (int i = 9; i >= 0; i--) {
      if (gram >= weight[i]) {
        ans.push_back(i);
        gram -= weight[i];
      }
    }

    for (int i = ans.size() - 1; i >= 0; i--) {
      cout << weight[ans[i]];
      if (i != 0)
        cout << ' ';
    }
    cout << endl;
    ans.clear();
  }
  return 0;
}
Problem p00031 (C++)

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

int main(void) {
  char line[80];

  int w;

  int f[10];
  int u[10];

  int k = 512;
  for (int &d : f) {
    d = k;
    k >>= 1;
  }

  while (true) {
    if (fgets(line, sizeof line, stdin) == NULL) {
      break;
    }
    if (sscanf(line, "%d", &w) != 1) {
      break;
    }

    int p;
    for (p = 0; p < 10; p++) {
      if (w > f[p]) {
        break;
      }
    }

    memset(u, 0, sizeof u);

    int t = f[p];
    u[p] = 1;
    p++;

    while (true) {
      if (t == w) {
        break;
      } else if (t > w) {
        t -= f[p - 1];
        u[p - 1] = 0;
      }

      t += f[p];
      u[p] = 1;
      p++;
    }

    const char *sp = "";
    for (int i = 9; i >= 0; i--) {
      if (u[i]) {
        printf("%s%d", sp, f[i]);
        if (*sp == 0) {
          sp = " ";
        }
      }
    }
    printf("\n");
  }

  return 0;
}

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

int main(void) {
  char line[80];

  int w;

  int f[10];
  int u[10];

  int k = 512;
  for (int &d : f) {
    d = k;
    k >>= 1;
  }

  while (true) {
    if (fgets(line, sizeof line, stdin) == NULL) {
      break;
    }
    if (sscanf(line, "%d", &w) != 1) {
      break;
    }

    int p;
    for (p = 0; p < 10; p++) {
      if (w >= f[p]) {
        break;
      }
    }

    memset(u, 0, sizeof u);

    int t = f[p];
    u[p] = 1;
    p++;

    while (true) {
      if (t == w) {
        break;
      } else if (t > w) {
        t -= f[p - 1];
        u[p - 1] = 0;
      }

      t += f[p];
      u[p] = 1;
      p++;
    }

    const char *sp = "";
    for (int i = 9; i >= 0; i--) {
      if (u[i]) {
        printf("%s%d", sp, f[i]);
        if (*sp == 0) {
          sp = " ";
        }
      }
    }
    printf("\n");
  }

  return 0;
}
Problem p00031 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
int main() {
  int n, s;
  while (scanf("%d", &n)) {
    for (s = 1; n; s *= 2) {
      n &s &&printf("%d%c", s, n - s ? 32 : 10);
      n -= n & s;
    }
  }
}

Fixed submission:
#include <cstdio>
int main() {
  int n, s;
  while (scanf("%d", &n) + 1) {
    for (s = 1; n; s *= 2) {
      n &s &&printf("%d%c", s, n - s ? 32 : 10);
      n -= n & s;
    }
  }
}
Problem p00031 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int w;
  while (cin >> w) {
    bool flag = 0;
    for (int i = 1; w >= 0; i *= 2) {
      if (w % 2 > 0) {
        if (flag) {
          cout << ' ';
        }
        cout << i;
        flag = 1;
        w--;
      }
      w /= 2;
    }
    cout << endl;
  }
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int w;
  while (cin >> w) {
    bool flag = 0;
    for (int i = 1; w > 0; i *= 2) {
      if (w % 2 > 0) {
        if (flag) {
          cout << ' ';
        }
        cout << i;
        flag = 1;
        w--;
      }
      w /= 2;
    }
    cout << endl;
  }
  return 0;
}
Problem p00031 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int inf = 1000000000;

int main(void) {

  int n;
  while (cin >> n) {
    cerr << n << endl;
    if (n == 0)
      break;
    int a = 1024;
    vector<int> b;
    while (a != 0) {
      if (n / a != 0) {
        n %= a;
        b.push_back(a);
      }
      a /= 2;
    }
    for (int i = 0; i < b.size(); i++) {
      if (i != b.size() - 1)
        cout << b[b.size() - 1 - i] << " ";
      else
        cout << b[b.size() - 1 - i] << endl;
    }
  }

  return 0;
}

// EOF

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int inf = 1000000000;

int main(void) {

  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    int a = 1024;
    vector<int> b;
    while (a != 0) {
      if (n / a != 0) {
        n %= a;
        b.push_back(a);
      }
      a /= 2;
    }
    for (int i = 0; i < b.size(); i++) {
      if (i != b.size() - 1)
        cout << b[b.size() - 1 - i] << " ";
      else
        cout << b[b.size() - 1 - i] << endl;
    }
  }

  return 0;
}

// EOF
Problem p00031 (Python)

Buggy submission (status: Runtime Error):
while True:
    g = int(input())
    now = 512
    ans = []
    while True:
        if g == 0:
            break
        elif g >= now:
            g -= now
            ans.append(now)
        now //= 2
    temp = ""
    for i in ans[::-1]:
        temp += str(i) + " "
    print(temp[:-1])


Fixed submission:
import sys

for line in sys.stdin:
    g = int(line)
    now = 512
    ans = []
    while True:
        if g == 0:
            break
        elif g >= now:
            g -= now
            ans.append(now)
        now //= 2
    temp = ""
    for i in ans[::-1]:
        temp += str(i) + " "
    print(temp[:-1])
Problem p00032 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {

  int x = 0, y = 0;
  int a, b, c;
  char comma;
  while (cin >> a >> comma >> b >> comma >> c, a != 0) {
    if (pow(a, 2) + pow(b, 2) == pow(c, 2))
      x++;
    if (pow(a, 2) - pow(double(c) / 2, 2) == pow(b, 2) - pow(double(c) / 2, 2))
      y++;
  }

  cout << x << endl;
  cout << y << endl;
}

Fixed submission:
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {

  int x = 0, y = 0;
  int a, b, c;
  char comma;
  while (scanf("%d,%d,%d", &a, &b, &c) != EOF) {
    if (pow(a, 2) + pow(b, 2) == pow(c, 2))
      x++;
    if (pow(a, 2) - pow(double(c) / 2, 2) == pow(b, 2) - pow(double(c) / 2, 2))
      y++;
  }

  cout << x << endl;
  cout << y << endl;
}
Problem p00032 (C++)

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

int main() {
  int l1, l2, dia, rc, lc;
  rc = lc = 0;
  while (scanf("%d %d %d", &l1, &l2, &dia) != EOF) {
    if (l1 * l1 + l2 * l2 == dia * dia) {
      rc++;
    }
    if (l1 == l2) {
      lc++;
    }
  }
  printf("%d\n%d\n", rc, lc);
  return 0;
}

Fixed submission:
#include <stdio.h>

int main() {
  int l1, l2, dia, rc, lc;
  rc = lc = 0;
  while (scanf("%d,%d,%d", &l1, &l2, &dia) != EOF) {
    if (l1 * l1 + l2 * l2 == dia * dia) {
      rc++;
    }
    if (l1 == l2) {
      lc++;
    }
  }
  printf("%d\n%d\n", rc, lc);
  return 0;
}
Problem p00032 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  int a, b, c, t = 0, h = 0;
  while (scanf("%d,%d,%d", &a, &b, &c)) {
    if (a * a + b * b == c * c) {
      t++;
    } else if (a == b) {
      h++;
    }
  }
  cout << t << endl << h << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  int a, b, c, t = 0, h = 0;
  while (scanf("%d,%d,%d", &a, &b, &c) != EOF) {
    if (a * a + b * b == c * c) {
      t++;
    } else if (a == b) {
      h++;
    }
  }
  cout << t << endl << h << endl;
}
Problem p00032 (C++)

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

int main() {
  int n, m, d, r = 0, l = 0;
  char c;
  while (cin >> n >> c >> m >> c >> d, n) {
    if (n == m)
      l++;
    if (n * n + m * m == d * d)
      r++;
  }
  cout << r << endl << l << endl;
  return 0;
}

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

int main() {
  int n, m, d, r = 0, l = 0;
  char c;
  while (cin >> n >> c >> m >> c >> d) {
    if (n == m)
      l++;
    if (n * n + m * m == d * d)
      r++;
  }
  cout << r << endl << l << endl;
  return 0;
}
Problem p00032 (C++)

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int, int> pii;
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define REPR(i, n) for (ll i = 1; i < n; ++i)
#define FOR(i, a, b) for (ll i = a; i < b; ++i)

#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG_VEC(v)                                                           \
  cout << #v << ":";                                                           \
  REP(i, v.size()) cout << " " << v[i];                                        \
  cout << endl
#define ALL(a) (a).begin(), (a).end()

#define MOD (ll)(1e9 + 7)
#define ADD(a, b) a = ((a) + (b)) % MOD
#define FIX(a) ((a) % MOD + MOD) % MOD

int main() {
  int a, b, c;
  int x = 0, y = 0;
  while (~scanf("%d%d%d", &a, &b, &c)) {
    if (a * a + b * b == c * c)
      ++x;
    if (a == b)
      ++y;
  }
  cout << x << endl;
  cout << y << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int, int> pii;
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define REPR(i, n) for (ll i = 1; i < n; ++i)
#define FOR(i, a, b) for (ll i = a; i < b; ++i)

#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG_VEC(v)                                                           \
  cout << #v << ":";                                                           \
  REP(i, v.size()) cout << " " << v[i];                                        \
  cout << endl
#define ALL(a) (a).begin(), (a).end()

#define MOD (ll)(1e9 + 7)
#define ADD(a, b) a = ((a) + (b)) % MOD
#define FIX(a) ((a) % MOD + MOD) % MOD

int main() {
  int a, b, c;
  int x = 0, y = 0;
  while (~scanf("%d,%d,%d", &a, &b, &c)) {
    if (a * a + b * b == c * c)
      ++x;
    if (a == b)
      ++y;
  }
  cout << x << endl;
  cout << y << endl;
  return 0;
}
Problem p00032 (C++)

Buggy submission (status: Time Limit Exceeded):
#define scanf_s scanf
// #define gets_s gets
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;
#define MAX 10
#define MIN -100001
#define _MAX 10
int main(void) {
  int a, b, c, s = 0, h = 0;
  while (scanf_s("%d,%d,%d", &a, &b, &c)) {
    if (a == b)
      ++h;
    else if (c * c == a * a + b * b) {
      ++s;
    }
  }
  printf("%d\n%d\n", s, h);
}

Fixed submission:
#define scanf_s scanf
// #define gets_s gets
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;
#define MAX 10
#define MIN -100001
#define _MAX 10
int main(void) {
  int a, b, c, s = 0, h = 0;
  while (scanf_s("%d,%d,%d", &a, &b, &c) != EOF) {
    if (a == b)
      ++h;
    else if (c * c == a * a + b * b) {
      ++s;
    }
  }
  printf("%d\n%d\n", s, h);
}
Problem p00032 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int ans_a = 0, ans_b = 0;
  for (;;) {
    int a, b, c;
    scanf("%d,%d,%d", &a, &b, &c);
    if (a * a + b * b == c * c) {
      ans_a++;
    }
    if (a == b) {
      ans_b++;
    }
  }
  cout << ans_a << endl << ans_b << endl;
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int ans_a = 0, ans_b = 0;
  for (;;) {
    int a, b, c;
    if (scanf("%d,%d,%d", &a, &b, &c) == EOF) {
      break;
    }
    if (a * a + b * b == c * c) {
      ans_a++;
    }
    if (a == b) {
      ans_b++;
    }
  }
  cout << ans_a << endl << ans_b << endl;
  return 0;
}
Problem p00032 (C++)

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

using namespace std;

int main() {
  int side[3];
  int iso = 0, cho = 0;
  while (scanf("%d,%d,%d", &side[0], &side[1], &side[2])) {
    if (side[0] == side[1])
      iso++;
    else if ((side[0] * side[0]) + (side[1] * side[1]) == (side[2] * side[2]))
      cho++;
  }
  printf("%d\n", cho);
  printf("%d\n", iso);
  return 0;
}

Fixed submission:
#include <cstdio>

using namespace std;

int main() {
  int side[3];
  int iso = 0, cho = 0;
  while (scanf("%d,%d,%d", &side[0], &side[1], &side[2]) != EOF) {
    if (side[0] == side[1])
      iso++;
    else if ((side[0] * side[0]) + (side[1] * side[1]) == (side[2] * side[2]))
      cho++;
  }
  printf("%d\n", cho);
  printf("%d\n", iso);
  return 0;
}
Problem p00032 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  int a, b, c, sum1, sum2;
  sum1 = 0;
  sum2 = 0;
  while (scanf("%d,%d,%d", &a, &b, &c)) {
    if (a * a + b * b == c * c) {
      sum1 += 1;
    }
    if (a == b) {
      sum2 += 1;
    }
  }
  cout << sum1 << endl;
  cout << sum2 << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  int a, b, c, sum1, sum2;
  sum1 = 0;
  sum2 = 0;
  while (scanf("%d,%d,%d", &a, &b, &c) != EOF) {
    if (a * a + b * b == c * c) {
      sum1 += 1;
    }
    if (a == b) {
      sum2 += 1;
    }
  }
  cout << sum1 << endl;
  cout << sum2 << endl;
  return 0;
}
Problem p00032 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
#define p(n) pow(n, 2)
using namespace std;
int main() {
  int a, b, c, rhom = 0, rect = 0;
  while (scanf("%d,%d,%d", &a, &b, &c)) {
    if (p(a) + p(b) == p(c))
      rect++;
    if (a == b)
      rhom++;
  }
  cout << rect << endl << rhom << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
#define p(n) pow(n, 2)
using namespace std;
int main() {
  int a, b, c, rhom = 0, rect = 0;
  while (scanf("%d,%d,%d", &a, &b, &c) != EOF) {
    if (p(a) + p(b) == p(c))
      rect++;
    if (a == b)
      rhom++;
  }
  cout << rect << endl << rhom << endl;
  return 0;
}
Problem p00032 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int a, b, c;
  int t = 0, h = 0;
  while (scanf("%d,%d,%d", &a, &b, &c)) {
    // if(a==0)break;
    if (a == b)
      h++;
    if (c * c == a * a + b * b)
      t++;
  }
  cout << t << endl << h << endl;
}


Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int a, b, c;
  int t = 0, h = 0;
  while (scanf("%d,%d,%d", &a, &b, &c) + 1) {
    // if(a==0)break;
    if (a == b)
      h++;
    if (c * c == a * a + b * b)
      t++;
  }
  cout << t << endl << h << endl;
}