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

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

typedef std::pair<int, int> Entrant;

bool descending_Entrant(const Entrant &e1, const Entrant &e2) {
  return e1.second > e2.second;
}

int main() {
  int num, points;
  std::vector<Entrant> v;
  std::map<int, int> m;
  while (scanf("%d,%d", &num, &points), num && points) {
    v.push_back(Entrant(num, points));
  }

  std::sort(v.begin(), v.end(), descending_Entrant);

  int rank = 1;
  for (int i = 0; i < v.size(); i++) {
    m[v[i].first] = rank;
    if (i + 1 < v.size() && v[i].second != v[i + 1].second)
      rank++;
  }

  int n;
  while (~scanf("%d", &n)) {
    printf("%d\n", m[n]);
  }
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <map>
#include <vector>

typedef std::pair<int, int> Entrant;

bool descending_Entrant(const Entrant &e1, const Entrant &e2) {
  return e1.second > e2.second;
}

int main() {
  int num, points;
  std::vector<Entrant> v;
  std::map<int, int> m;
  while (scanf("%d,%d", &num, &points), num) {
    v.push_back(Entrant(num, points));
  }

  std::sort(v.begin(), v.end(), descending_Entrant);

  int rank = 1;
  for (int i = 0; i < v.size(); i++) {
    m[v[i].first] = rank;
    if (i + 1 < v.size() && v[i].second != v[i + 1].second)
      rank++;
  }

  int n;
  while (~scanf("%d", &n)) {
    printf("%d\n", m[n]);
  }
}
Problem p00062 (C++)

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

int hoge(int x[]) {

  for (int j = 9; j >= 0; j++) {
    for (int i = 0; i < j; i++) {
      x[i] = (x[i] + x[i + 1]) % 10;
    }
  }

  return x[0];
}

int main() {
  char a[15];

  while (~scanf("%s", a)) {
    int c[10];
    for (int i = 0; i < 10; i++) {
      c[i] = a[i] - '0';
    }

    c[0] = hoge(c);
    printf("%d\n", c[0]);
  }
  return 0;
}

Fixed submission:
#include <stdio.h>

int hoge(int x[]) {

  for (int j = 9; j > 0; j--) {
    for (int i = 0; i < j; i++) {
      x[i] = (x[i] + x[i + 1]) % 10;
    }
  }

  return x[0];
}

int main() {
  char a[15];

  while (~scanf("%s", a)) {
    int c[10];
    for (int i = 0; i < 10; i++) {
      c[i] = a[i] - '0';
    }

    c[0] = hoge(c);
    printf("%d\n", c[0]);
  }
  return 0;
}
Problem p00062 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
int main() {
  char top[10];
  while (scanf("%s", top) != EOF) {
    int nums[10];
    for (int i = 0; i < 10; i++)
      nums[i] = top[i] - '0';
    int res = nums[0] + nums[1] * 9 + nums[2] * 36 + nums[3] * 84 +
              nums[4] * 126 + nums[5] * 126 + nums[6] * 84 + nums[7] * 36 +
              nums[8] * 9 + nums[9];
    res %= 10;
    printf("%d\n", res);
  }
}

Fixed submission:
#include <iostream>
using namespace std;
int main(void) {
  char tmp[10];
  char buf;
  while (cin >> buf) {
    tmp[0] = buf - '0';
    for (int i = 1; i < 10; i++) {
      cin >> buf;
      tmp[i] = buf - '0';
    }
    for (int i = 8; i >= 0; i--) {
      for (int j = 0; j <= i; j++) {
        tmp[j] = (tmp[j] + tmp[j + 1]) % 10;
      }
    }
    cout << (int)tmp[0] << endl;
  }
}
Problem p00062 (C++)

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

int main() {
  char b[10];
  while (~scanf("%s", b)) {
    int c[10];
    for (int i = 0; i < 10; i++)
      c[i] = b[i] - '0';
    for (int i = 9; i > 0; i--)
      for (int j = 0; j < i; j++)
        c[j] = (c[j] + c[j + 1]) % 10;
    printf("%d\n", c[0]);
  }
}

Fixed submission:
#include <stdio.h>

int main() {
  char b[15];
  while (~scanf("%s", b)) {
    int c[10];
    for (int i = 0; i < 10; i++)
      c[i] = b[i] - '0';
    for (int i = 9; i > 0; i--)
      for (int j = 0; j < i; j++)
        c[j] = (c[j] + c[j + 1]) % 10;
    printf("%d\n", c[0]);
  }
}
Problem p00062 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
int main() {
  char a[10];
  while (scanf("%s", a) != 0) {
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9 - i; j++) {
        a[j] = a[j] + a[j + 1] - '0';
        if (a[j] - '0' > 9)
          a[j] -= 10;
      }
    }
    printf("%c\n", a[0]);
  }
}

Fixed submission:
#include <stdio.h>
int main() {
  char a[10];
  while (scanf("%s", a) != EOF) {
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9 - i; j++) {
        a[j] = a[j] + a[j + 1] - '0';
        if (a[j] - '0' > 9)
          a[j] -= 10;
      }
    }
    printf("%c\n", a[0]);
  }
}
Problem p00062 (C++)

Buggy submission (status: Runtime Error):
#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) {
  char num1[10];
  int num[10];
  int ans[10];
  int a, b;
  while (cin >> num1) {
    for (a = 0; a < 10; a++) {
      num[a] = num1[a] - '0';
    }
    for (a = 0; a < 10; a++) {
      for (b = 0; b < 9 - a; b++) {
        ans[b] = (num[b] + num[b + 1]) % 10;
      }
      for (b = 0; b < 9 - a; b++) {
        num[b] = ans[b];
      }
    }
    printf("%d\n", ans[0]);
  }
  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) {
  string num1;
  int num[10];
  int ans[10];
  int a, b;
  while (cin >> num1) {
    for (a = 0; a < 10; a++) {
      num[a] = num1[a] - '0';
    }
    for (a = 0; a < 10; a++) {
      for (b = 0; b < 9 - a; b++) {
        ans[b] = (num[b] + num[b + 1]) % 10;
      }
      for (b = 0; b < 9 - a; b++) {
        num[b] = ans[b];
      }
    }
    printf("%d\n", ans[0]);
  }
  return 0;
}
Problem p00062 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  char input[10];
  int field[9][9];

  while (scanf("%s", input) != EOF) {
    memset(field, 0, sizeof(field));

    for (int i = 0; i < 9; i++) {
      field[0][i] = (input[i] - '0' + input[i + 1] - '0') % 10;
    }

    for (int i = 1; i < 9; i++) {
      for (int j = 0; j <= 8 - i; j++) {
        if (j < 0)
          break;
        field[i][j] = (field[i - 1][j] + field[i - 1][j + 1]) % 10;
      }
    }
    /*for(int i = 0 ; i < 9 ; i++) {
      for(int j = 0 ; j <= 8-i ; j++) {
      cout << field[i][j] << ' ';
        }
      cout << endl;
      }
    cout << endl;*/
    cout << field[8][0] << endl;
  }
  return 0;
}

Fixed submission:
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  char input[20];
  int field[20][20];

  while (scanf("%s", input) != EOF) {
    memset(field, 0, sizeof(field));

    for (int i = 0; i < 9; i++) {
      field[0][i] = (input[i] - '0' + input[i + 1] - '0') % 10;
    }

    for (int i = 1; i < 9; i++) {
      for (int j = 0; j <= 8 - i; j++) {
        if (j < 0)
          break;
        field[i][j] = (field[i - 1][j] + field[i - 1][j + 1]) % 10;
      }
    }
    /*for(int i = 0 ; i < 9 ; i++) {
      for(int j = 0 ; j <= 8-i ; j++) {
      cout << field[i][j] << ' ';
        }
      cout << endl;
      }
    cout << endl;*/
    cout << field[8][0] << endl;
  }
  return 0;
}
Problem p00063 (C++)

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

using namespace std;

int main() {
  char str[51];
  int count = 0;

  while (cin >> str) {
    int len = strlen(str);
    bool isPal = true;
    for (int i = 0; i < len / 2; i++) {
      if (str[i] != str[len - i - 1]) {
        isPal = false;
        break;
      }
    }
    if (isPal)
      count++;
  }

  cout << count << endl;

  return 0;
}

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

using namespace std;

int main() {
  char str[101];
  int count = 0;

  while (cin >> str) {
    int len = strlen(str);
    bool isPal = true;
    for (int i = 0; i < len / 2; i++) {
      if (str[i] != str[len - i - 1]) {
        isPal = false;
        break;
      }
    }
    if (isPal)
      count++;
  }

  cout << count << endl;

  return 0;
}
Problem p00063 (C++)

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

int main() {
  string str, inv;
  int cnt = 0;
  while (cin >> str, str.length()) {
    inv.resize(str.length());
    for (int i = 0; i < str.length(); i++) {
      inv[i] = str[str.length() - 1 - i];
    }
    if (str == inv) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

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

int main() {
  string str, inv;
  int cnt = 0;
  while (getline(cin, str), str.length() != 0) {
    inv.resize(str.length());
    for (int i = 0; i < str.length(); i++) {
      inv[i] = str[str.length() - 1 - i];
    }
    if (str == inv) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p00063 (C++)

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

int main(void) {
  char str[100];
  int cnt = 0;

  while (scanf("%s", str) != EOF) {
    int i, j;
    for (i = 0, j = strlen(str) - 1; i <= j; i++, j--) {
      if (str[i] != str[j])
        break;
    }
    if (i > j)
      cnt++;
  }

  printf("%d\n", cnt);

  return 0;
}

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

int main(void) {
  char str[200];
  int cnt = 0;

  while (scanf("%s", str) != EOF) {
    int i, j;
    for (i = 0, j = strlen(str) - 1; i <= j; i++, j--) {
      if (str[i] != str[j])
        break;
    }
    if (i > j)
      cnt++;
  }

  printf("%d\n", cnt);

  return 0;
}
Problem p00063 (C++)

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

int main() {
  char ss[100];
  int i, c;
  c = 0;
  while (0 <= scanf("%s", ss)) {
    for (i = 0; i <= strlen(ss) - 1; i++) {
      if (ss[i] != ss[strlen(ss) - i - 1])
        break;
    }

    if (i == strlen(ss))
      ++c;
  }
  printf("%d\n", c);
  return 0;
}

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

int main() {
  char ss[110];
  int i, c;
  c = 0;
  while (0 <= scanf("%s", ss)) {
    for (i = 0; i <= strlen(ss) - 1; i++) {
      if (ss[i] != ss[strlen(ss) - i - 1])
        break;
    }

    if (i == strlen(ss))
      ++c;
  }
  printf("%d\n", c);
  return 0;
}
Problem p00064 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

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

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
struct edge {
  int to, time, cost;
};
const double eps = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;
const double infd = (double)1e+9;

int sum = 0;
std::string str;
std::string::iterator it;

int number() {
  int ret = 0;
  while (isdigit(*it)) {
    ret *= 10;
    ret += (*it - '0');
    ++it;
  }
  return ret;
}

int main() {
  while (std::cin >> str) {
    it = str.begin();
    while (it != str.end()) {
      if (isdigit(*it))
        sum += number();
      ++it;
    }
  }
  std::cout << sum << std::endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

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

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
struct edge {
  int to, time, cost;
};
const double eps = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;
const double infd = (double)1e+9;

int sum = 0;
std::string str;
std::string::iterator it;

int number() {
  int ret = 0;
  while (isdigit(*it)) {
    ret *= 10;
    ret += (*it - '0');
    ++it;
  }
  return ret;
}

int main() {
  while (std::cin >> str) {
    str += ".";
    it = str.begin();
    while (it != str.end()) {
      if (isdigit(*it))
        sum += number();
      ++it;
    }
  }
  std::cout << sum << std::endl;
  return 0;
}
Problem p00064 (C++)

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

string sentence;
typedef string::const_iterator State;

int parse(State &it) {
  int ret = 0;
  while (isdigit(*it)) {
    ret = ret * 10;
    ret = ret + *it - '0';
    it++;
  }
  return ret;
}

int main(void) {
  int sum = 0;
  while (cin >> sentence) {
    for (State it = sentence.begin(); it != sentence.end(); it++) {
      if (isdigit(*it)) {
        sum += parse(it);
      }
    }
  }
  cout << sum << endl;
  return 0;
}

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

string sentence;
typedef string::const_iterator State;

int parse(State &it) {
  int ret = 0;
  while (isdigit(*it)) {
    ret = ret * 10;
    ret = ret + *it - '0';
    it++;
  }
  return ret;
}

int main(void) {
  int sum = 0;
  while (cin >> sentence) {
    for (State it = sentence.begin(); it != sentence.end(); it++) {
      if (isdigit(*it)) {
        sum += parse(it);
        it--;
      }
    }
  }
  cout << sum << endl;
  return 0;
}
Problem p00064 (C++)

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

int main() {
  int n;
  int ans = 0;

  while (scanf("%[0-9]", &n) != EOF) {
    ans += n;
  }

  printf("%d\n", ans);

  return (0);
}

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

int main() {
  int n;
  int ans = 0;

  while (~scanf("%*[^0-9]%d", &n)) {
    ans += n;
  }

  printf("%d\n", ans);

  return (0);
}
Problem p00064 (C++)

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

using db = double;
using ll = long long;
using vi = vector<int>;
#define op operator
#define pb push_back

int main() {
  cout << fixed << setprecision(9);
  ios ::sync_with_stdio(0);

  int ans = 0;
  for (string s; getline(cin, s);) {
    s += ' ';
    string t = "";
    for (char c : s)
      if (isdigit(c))
        t += c;
      else {
        ans += stoi(t);
        t = "";
      }
  }
  cout << ans << '\n';

  return 0;
}

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

using db = double;
using ll = long long;
using vi = vector<int>;
#define op operator
#define pb push_back

int main() {
  cout << fixed << setprecision(9);
  ios ::sync_with_stdio(0);

  int ans = 0;
  for (string s; getline(cin, s);) {
    s += ' ';
    string t = "";
    for (char c : s)
      if (isdigit(c))
        t += c;
      else if (t.size()) {
        ans += stoi(t);
        t = "";
      }
  }
  cout << ans << '\n';

  return 0;
}
Problem p00064 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
// #include<algorithm>
// #include<cmath>
// #include<string>
// #include<cctype>
// #include <vector>
using namespace std;
int main() {
  int s, a = 0;
  while (scanf("%*[^0-9]%d", &s) != 0)
    a += s;
  cout << a << endl;
  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
// #include<algorithm>
// #include<cmath>
// #include<string>
// #include<cctype>
// #include <vector>
using namespace std;
int main() {
  int s, a = 0;
  while (~scanf("%*[^0-9]%d", &s))
    a += s;
  cout << a << endl;
  return 0;
}
Problem p00064 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0, sum = 0;
  char c;
  while ((c = getchar())) {
    if (c >= '0' && c <= '9') {
      n *= 10;
      n += (c - ('0'));
    } else {
      sum += n;
      n = 0;
    }
  }
  cout << sum << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0, sum = 0;
  char c;
  while ((c = getchar()) != EOF) {
    if (c >= '0' && c <= '9') {
      n *= 10;
      n += (c - ('0'));
    } else {
      sum += n;
      n = 0;
    }
  }
  cout << sum << endl;
}
Problem p00065 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, l, n) for (int i = l; i < n; i++)
#define rer(i, l, n) for (int i = l; i <= n; i++)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define pb(a) push_back(a)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;

vector<string> split(const string &s, char c) {
  vector<string> ret;
  stringstream ss(s);
  string t;
  while (getline(ss, t, c)) {
    ret.pb(t);
  }
  return ret;
}

int main() {
  map<int, int> m;
  set<int> s1, s2;
  bool f = 0;
  string s;
  while (getline(cin, s)) {
    if (s.end() - s.begin() == 1) {
      // o("ok");
      f = 1;
      continue;
    }
    vector<string> v = split(s, ',');
    int a = atoi(v[0].c_str());
    // o(a);
    m[a]++;
    if (!f)
      s1.insert(a);
    else
      s2.insert(a);
  }
  for (map<int, int>::iterator it = m.begin(); it != m.end(); it++) {
    // cout<<1<<endl;
    if (s1.count(it->fi) && s2.count(it->fi))
      cout << it->fi << " " << it->se << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, l, n) for (int i = l; i < n; i++)
#define rer(i, l, n) for (int i = l; i <= n; i++)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define pb(a) push_back(a)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;

vector<string> split(const string &s, char c) {
  vector<string> ret;
  stringstream ss(s);
  string t;
  while (getline(ss, t, c)) {
    ret.pb(t);
  }
  return ret;
}

int main() {
  map<int, int> m;
  set<int> s1, s2;
  bool f = 0;
  string s;
  while (getline(cin, s)) {
    if (/*s.end() - s.begin() == 1*/ s == "") {
      // o("ok");
      f = 1;
      continue;
    }
    vector<string> v = split(s, ',');
    int a = atoi(v[0].c_str());
    // o(a);
    m[a]++;
    if (!f)
      s1.insert(a);
    else
      s2.insert(a);
  }
  for (map<int, int>::iterator it = m.begin(); it != m.end(); it++) {
    // cout<<1<<endl;
    if (s1.count(it->fi) && s2.count(it->fi))
      cout << it->fi << " " << it->se << endl;
  }
}
Problem p00065 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
string S;
int x[100000][2];
int c = 0;
int main() {
  while (getline(cin, S)) {
    if (S.size() == 0) {
      c++;
    }
    string T[2];
    int ok = 0;
    for (int i = 0; i < S.size(); i++) {
      if (S[i] == ',') {
        ok++;
      } else {
        T[ok] += S[i];
      }
    }
    x[stoi(T[0])][c]++;
  }
  for (int i = 0; i < 99999; i++) {
    if (x[i][0] >= 1 && x[i][1] >= 1) {
      cout << i << ' ' << x[i][0] + x[i][1] << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
string S;
int x[100000][2];
int c = 0;
int main() {
  while (getline(cin, S)) {
    if (S.size() == 0) {
      c++;
      continue;
    }
    string T[2];
    int ok = 0;
    for (int i = 0; i < S.size(); i++) {
      if (S[i] == ',') {
        ok++;
      } else {
        T[ok] += S[i];
      }
    }
    x[stoi(T[0])][c]++;
  }
  for (int i = 0; i < 99999; i++) {
    if (x[i][0] >= 1 && x[i][1] >= 1) {
      cout << i << ' ' << x[i][0] + x[i][1] << endl;
    }
  }
  return 0;
}
Problem p00066 (C++)

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

int main(void) {
  string s;
  while (true) {
    cin >> s;

    for (int i = 0; i < 3; ++i) {
      if (s[0 + 3 * i] == s[1 + 3 * i] && s[1 + 3 * i] == s[2 + 3 * i] &&
          s[2 + 3 * i] == 'o') {
        cout << "o" << endl;
        goto end;
      }
      if (s[0 + 3 * i] == s[1 + 3 * i] && s[1 + 3 * i] == s[2 + 3 * i] &&
          s[2 + 3 * i] == 'x') {
        cout << "x" << endl;
        goto end;
      }
    }

    for (int i = 0; i < 3; ++i) {
      if (s[0 + i] == s[3 + i] && s[3 + i] == s[6 + i] && s[6 + i] == 'o') {
        cout << "o" << endl;
        goto end;
      }
      if (s[0 + i] == s[3 + i] && s[3 + i] == s[6 + i] && s[6 + i] == 'x') {
        cout << "x" << endl;
        goto end;
      }
    }
    for (int i = 0; i < 2; ++i) {
      if (s[0 + 2 * i] == s[4] && s[4] == s[8 - 2 * i] && s[4] == 'o') {
        cout << "o" << endl;
        goto end;
      }
      if (s[0 + 2 * i] == s[4] && s[4] == s[8 - 2 * i] && s[4] == 'x') {
        cout << "x" << endl;
        goto end;
      }
    }
    cout << "d" << endl;
  end:;
    if (s[9] == EOF)
      break;
  }
  return 0;
}


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

int main(void) {
  string s;
  while (true) {
    cin >> s;
    if (cin.fail())
      break;
    for (int i = 0; i < 3; ++i) {
      if (s[0 + 3 * i] == s[1 + 3 * i] && s[1 + 3 * i] == s[2 + 3 * i] &&
          s[2 + 3 * i] == 'o') {
        cout << "o" << endl;
        goto end;
      }
      if (s[0 + 3 * i] == s[1 + 3 * i] && s[1 + 3 * i] == s[2 + 3 * i] &&
          s[2 + 3 * i] == 'x') {
        cout << "x" << endl;
        goto end;
      }
    }

    for (int i = 0; i < 3; ++i) {
      if (s[0 + i] == s[3 + i] && s[3 + i] == s[6 + i] && s[6 + i] == 'o') {
        cout << "o" << endl;
        goto end;
      }
      if (s[0 + i] == s[3 + i] && s[3 + i] == s[6 + i] && s[6 + i] == 'x') {
        cout << "x" << endl;
        goto end;
      }
    }
    for (int i = 0; i < 2; ++i) {
      if (s[0 + 2 * i] == s[4] && s[4] == s[8 - 2 * i] && s[4] == 'o') {
        cout << "o" << endl;
        goto end;
      }
      if (s[0 + 2 * i] == s[4] && s[4] == s[8 - 2 * i] && s[4] == 'x') {
        cout << "x" << endl;
        goto end;
      }
    }
    cout << "d" << endl;
  end:;
    if (s[9] == EOF)
      break;
  }
  return 0;
}
Problem p00066 (C++)

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

using namespace std;

char table[3][3];

int main(void) {
  while (true) {
    for (int y = 0; y < 3; y++)
      for (int x = 0; x < 3; x++)
        cin >> table[x][y];
    int judge = 0;
    for (int y = 0; y < 3; y++) {
      if (table[0][y] == table[1][y] && table[1][y] == table[2][y] &&
          table[2][y] == 'o')
        judge = 1;
      if (table[0][y] == table[1][y] && table[1][y] == table[2][y] &&
          table[2][y] == 'x')
        judge = 2;
    }
    for (int x = 0; x < 3; x++) {
      if (table[x][0] == table[x][1] && table[x][1] == table[x][2] &&
          table[x][2] == 'o')
        judge = 1;
      if (table[x][0] == table[x][1] && table[x][1] == table[x][2] &&
          table[x][2] == 'x')
        judge = 2;
    }
    if (table[0][0] == table[1][1] && table[1][1] == table[2][2] &&
        table[2][2] == 'o')
      judge = 1;
    if (table[0][0] == table[1][1] && table[1][1] == table[2][2] &&
        table[2][2] == 'x')
      judge = 2;
    if (table[0][2] == table[1][1] && table[1][1] == table[2][0] &&
        table[2][0] == 'o')
      judge = 1;
    if (table[0][2] == table[1][1] && table[1][1] == table[2][0] &&
        table[2][0] == 'x')
      judge = 2;
    if (judge == 1)
      cout << 'o' << endl;
    else if (judge == 2)
      cout << 'x' << endl;
    else
      cout << 'd' << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

char table[3][3];

int main(void) {
  while (true) {
    for (int y = 0; y < 3; y++)
      for (int x = 0; x < 3; x++)
        cin >> table[x][y];
    if (cin.eof())
      break;
    int judge = 0;
    for (int y = 0; y < 3; y++) {
      if (table[0][y] == table[1][y] && table[1][y] == table[2][y] &&
          table[2][y] == 'o')
        judge = 1;
      if (table[0][y] == table[1][y] && table[1][y] == table[2][y] &&
          table[2][y] == 'x')
        judge = 2;
    }
    for (int x = 0; x < 3; x++) {
      if (table[x][0] == table[x][1] && table[x][1] == table[x][2] &&
          table[x][2] == 'o')
        judge = 1;
      if (table[x][0] == table[x][1] && table[x][1] == table[x][2] &&
          table[x][2] == 'x')
        judge = 2;
    }
    if (table[0][0] == table[1][1] && table[1][1] == table[2][2] &&
        table[2][2] == 'o')
      judge = 1;
    if (table[0][0] == table[1][1] && table[1][1] == table[2][2] &&
        table[2][2] == 'x')
      judge = 2;
    if (table[0][2] == table[1][1] && table[1][1] == table[2][0] &&
        table[2][0] == 'o')
      judge = 1;
    if (table[0][2] == table[1][1] && table[1][1] == table[2][0] &&
        table[2][0] == 'x')
      judge = 2;
    if (judge == 1)
      cout << 'o' << endl;
    else if (judge == 2)
      cout << 'x' << endl;
    else
      cout << 'd' << endl;
  }
  return 0;
}
Problem p00066 (C++)

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

int main() {

  while (1) {
    string s;
    cin >> s;

    char a[3][3];
    a[0][0] = s[0];
    a[0][1] = s[1];
    a[0][2] = s[2];
    a[1][0] = s[3];
    a[1][1] = s[4];
    a[1][2] = s[5];
    a[2][0] = s[6];
    a[2][1] = s[7];
    a[2][2] = s[8];
    char S = 's';
    bool ok = false;
    for (int i = 0; i < 3; i++) {
      if (a[i][0] != S && a[i][0] == a[i][1] && a[i][1] == a[i][2]) {
        cout << a[i][0] << endl;
        ok = true;
        break;
      }
    }

    for (int j = 0; j < 3; j++) {
      if (ok)
        break;

      if (a[0][j] != S && a[0][j] == a[1][j] && a[1][j] == a[2][j]) {
        cout << a[0][j] << endl;
        ok = true;
        break;
      }
    }

    if (!ok) {
      if (a[0][0] != S && a[0][0] == a[1][1] && a[1][1] == a[2][2]) {
        cout << a[0][0] << endl;
        ok = true;
      } else if (a[0][2] != S && a[0][2] == a[1][1] && a[1][1] == a[2][0]) {
        cout << a[1][1] << endl;
        ok = true;
      }
    }

    if (!ok)
      cout << "d" << endl;
  }

  return 0;
}


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

int main() {

  string s;

  while (cin >> s) {

    char a[3][3];
    a[0][0] = s[0];
    a[0][1] = s[1];
    a[0][2] = s[2];
    a[1][0] = s[3];
    a[1][1] = s[4];
    a[1][2] = s[5];
    a[2][0] = s[6];
    a[2][1] = s[7];
    a[2][2] = s[8];
    char S = 's';
    bool ok = false;
    for (int i = 0; i < 3; i++) {
      if (a[i][0] != S && a[i][0] == a[i][1] && a[i][1] == a[i][2]) {
        cout << a[i][0] << endl;
        ok = true;
        break;
      }
    }

    for (int j = 0; j < 3; j++) {
      if (ok)
        break;

      if (a[0][j] != S && a[0][j] == a[1][j] && a[1][j] == a[2][j]) {
        cout << a[0][j] << endl;
        ok = true;
        break;
      }
    }

    if (!ok) {
      if (a[0][0] != S && a[0][0] == a[1][1] && a[1][1] == a[2][2]) {
        cout << a[0][0] << endl;
        ok = true;
      } else if (a[0][2] != S && a[0][2] == a[1][1] && a[1][1] == a[2][0]) {
        cout << a[1][1] << endl;
        ok = true;
      }
    }

    if (!ok)
      cout << "d" << endl;
  }

  return 0;
}
Problem p00067 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
using namespace std;
char a[12][12];
void irand(int i, int j) {
  a[i][j] == '0';
  if (i > 0 && a[i - 1][j] == '1')
    irand(i - 1, j);
  if (j > 0 && a[i][j - 1] == '1')
    irand(i, j - 1);
  if (i < 11 && a[i + 1][j] == '1')
    irand(i + 1, j);
  if (j < 11 && a[i][j + 1] == '1')
    irand(i, j + 1);
  return;
}
int main() {
  while (scanf("%s", a[0]) != EOF) {
    int cnt = 0;
    for (int i = 1; i < 12; i++)
      scanf("%s", a[i]);
    for (int i = 0; i < 12; i++) {
      for (int j = 0; j < 12; j++) {
        if (a[i][j] == '1') {
          cnt++;
          irand(i, j);
        }
      }
    }
    printf("%d\n", cnt);
  }
}

Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;
char a[12][12];
void irand(int i, int j) {
  a[i][j] = '0';
  if (i > 0 && a[i - 1][j] == '1')
    irand(i - 1, j);
  if (j > 0 && a[i][j - 1] == '1')
    irand(i, j - 1);
  if (i < 11 && a[i + 1][j] == '1')
    irand(i + 1, j);
  if (j < 11 && a[i][j + 1] == '1')
    irand(i, j + 1);
  return;
}
int main() {
  while (scanf("%s", a[0]) != EOF) {
    int cnt = 0;
    for (int i = 1; i < 12; i++)
      scanf("%s", a[i]);
    for (int i = 0; i < 12; i++) {
      for (int j = 0; j < 12; j++) {
        if (a[i][j] == '1') {
          cnt++;
          irand(i, j);
        }
      }
    }
    printf("%d\n", cnt);
  }
}
Problem p00067 (C++)

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

char nyuryoku[12][12];

void fun(int y, int x, char masume) {
  if ((x < 0) || (12 <= x) || (y < 0) || (12 <= y)) {
    return;
  }
  if (masume != nyuryoku[y][x])
    return;
  else
    nyuryoku[y][x] = '+';
  fun(y + 1, x, masume);
  fun(y - 1, x, masume);
  fun(y, x + 1, masume);
  fun(y, x - 1, masume);
}

int main() {
  while (1) {
    for (int i = 0; i < 12; i++) {
      for (int j = 0; j < 12; j++) {
        cin >> nyuryoku[i][j];
      }
    }
    int count = 0;
    for (int i = 0; i < 12; i++) {
      for (int j = 0; j < 12; j++) {
        if (nyuryoku[i][j] != '+') {
          if (nyuryoku[i][j] == '1')
            count++;
          fun(i, j, nyuryoku[i][j]);
        }
      }
    }
    cout << count << endl;
  }
}

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

char nyuryoku[12][12];

void fun(int y, int x, char masume) {
  if ((x < 0) || (12 <= x) || (y < 0) || (12 <= y)) {
    return;
  }
  if (masume != nyuryoku[y][x])
    return;
  else
    nyuryoku[y][x] = '+';
  fun(y + 1, x, masume);
  fun(y - 1, x, masume);
  fun(y, x + 1, masume);
  fun(y, x - 1, masume);
}

int main() {
  while (cin >> nyuryoku[0][0]) {
    for (int j = 1; j < 12; j++)
      cin >> nyuryoku[0][j];
    for (int i = 1; i < 12; i++) {
      for (int j = 0; j < 12; j++) {
        cin >> nyuryoku[i][j];
      }
    }
    int count = 0;
    for (int i = 0; i < 12; i++) {
      for (int j = 0; j < 12; j++) {
        if (nyuryoku[i][j] != '+') {
          if (nyuryoku[i][j] == '1')
            count++;
          fun(i, j, nyuryoku[i][j]);
        }
      }
    }
    cout << count << endl;
  }
}
Problem p00067 (C++)

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

bool isLand[12][12];

bool deleteOneLand(int x, int y) {
  if (!isLand[y][x])
    return false;
  isLand[y][x] = false;
  if (x > 0)
    deleteOneLand(x - 1, y);
  if (y > 0)
    deleteOneLand(x, y - 1);
  if (x < 11)
    deleteOneLand(x + 1, y);
  if (y < 11)
    deleteOneLand(x, y + 1);
  return true;
}

int main() {
  int x, y, ans;
  while (!cin.eof()) {
    ans = 0;
    for (y = 0; y < 12; y++) {
      for (x = 0; x < 12; x++)
        isLand[y][x] = getchar() == '1';
      getchar();
    }
    for (y = 0; y < 12; y++)
      for (x = 0; x < 12; x++)
        if (deleteOneLand(x, y))
          ans++;
    cout << ans << endl;
    getchar();
  }
  return 0;
}

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

bool isLand[12][12];

bool deleteOneLand(int x, int y) {
  if (!isLand[y][x])
    return false;
  isLand[y][x] = false;
  if (x > 0)
    deleteOneLand(x - 1, y);
  if (y > 0)
    deleteOneLand(x, y - 1);
  if (x < 11)
    deleteOneLand(x + 1, y);
  if (y < 11)
    deleteOneLand(x, y + 1);
  return true;
}

int main() {
  int x, y, ans;
  while (!cin.eof()) {
    ans = 0;
    for (y = 0; y < 12; y++) {
      for (x = 0; x < 12; x++)
        isLand[y][x] = getchar() == '1';
      getchar();
    }
    for (y = 0; y < 12; y++)
      for (x = 0; x < 12; x++)
        if (deleteOneLand(x, y))
          ans++;
    cout << ans << endl;
    if (getchar() != '\n')
      break;
  }
  return 0;
}
Problem p00067 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <iostream>
#define MAX_L 12
using namespace std;
char table[MAX_L][MAX_L];
int fdx[] = {1, 0, -1, 0}, fdy[] = {0, 1, 0, -1};

void dfs(int y, int x) {
  if (x < 0 || x >= MAX_L || y < 0 || y >= MAX_L || table[y][x] == '0')
    return;
  table[y][x]--;
  for (int r = 0; r < 4; r++) {
    dfs(y + fdy[r], x + fdx[r]);
  }
  return;
}

int main(void) {
  while (true) {
    for (int r = 0; r < MAX_L; r++) {
      scanf("%s", table[r]);
    }
    int cnt = 0;
    for (int r = 0; r < MAX_L; r++) {
      for (int c = 0; c < MAX_L; c++) {
        if (table[r][c] == '1') {
          dfs(r, c);
          cnt++;
        }
      }
    }
    cout << cnt << endl;
  }
  return (0);
}

Fixed submission:
#include <cstdio>
#include <iostream>
#define MAX_L 12
using namespace std;
char table[MAX_L][MAX_L];
int fdx[] = {1, 0, -1, 0}, fdy[] = {0, 1, 0, -1};

void dfs(int y, int x) {
  if (x < 0 || x >= MAX_L || y < 0 || y >= MAX_L || table[y][x] == '0')
    return;
  table[y][x]--;
  for (int r = 0; r < 4; r++) {
    dfs(y + fdy[r], x + fdx[r]);
  }
  return;
}

int main(void) {
  while (true) {
    for (int r = 0; r < MAX_L; r++) {
      if (scanf("%s", table[r]) == EOF)
        return (0);
    }
    int cnt = 0;
    for (int r = 0; r < MAX_L; r++) {
      for (int c = 0; c < MAX_L; c++) {
        if (table[r][c] == '1') {
          dfs(r, c);
          cnt++;
        }
      }
    }
    cout << cnt << endl;
  }
  return (0);
}
Problem p00067 (C++)

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

int cnt;
char field[13][13];

void solve(int x, int y) {
  field[y][x] = '0';
  if (x + 1 < 12)
    if (field[y][x + 1] == '1')
      solve(x + 1, y);
  if (x - 1 >= 0)
    if (field[y][x - 1] == '1')
      solve(x - 1, y);
  if (y + 1 < 12)
    if (field[y + 1][x] == '1')
      solve(x, y + 1);
  if (y - 1 >= 0)
    if (field[y - 1][x] == '1')
      solve(x, y - 1);
}

int main() {
  while (1) {
    for (int i = 0; i < 12; i++) {
      for (int j = 0; j < 12; j++) {
        cin >> field[i][j];
      }
    }
    cnt = 0;
    for (int i = 0; i < 12; i++) {
      for (int j = 0; j < 12; j++) {
        if (field[i][j] == '1') {
          cnt++;
          solve(j, i);
        }
      }
    }
    cout << cnt << endl;
  }
  return 0;
}


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

int cnt;
char field[13][13];

void solve(int x, int y) {
  field[y][x] = '0';
  if (x + 1 < 12)
    if (field[y][x + 1] == '1')
      solve(x + 1, y);
  if (x - 1 >= 0)
    if (field[y][x - 1] == '1')
      solve(x - 1, y);
  if (y + 1 < 12)
    if (field[y + 1][x] == '1')
      solve(x, y + 1);
  if (y - 1 >= 0)
    if (field[y - 1][x] == '1')
      solve(x, y - 1);
}

int main() {
  while (1) {
    for (int i = 0; i < 12; i++) {
      for (int j = 0; j < 12; j++) {
        cin >> field[i][j];
        if (cin.eof())
          return 0;
      }
    }
    cnt = 0;
    for (int i = 0; i < 12; i++) {
      for (int j = 0; j < 12; j++) {
        if (field[i][j] == '1') {
          cnt++;
          solve(j, i);
        }
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p00067 (C++)

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

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct {
  int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

vector<string> mp(12);
bool visited[12][12];

int bfs(int x, int y) {
  queue<P> que;
  que.push(P{x, y});

  while (!que.empty()) {
    P p = que.front();
    que.pop();

    rep(i, 4) {
      int nx = p.first + dx[i], ny = p.second + dy[i];

      if (nx < 0 || ny < 0 || 12 <= nx || 12 <= ny)
        continue;
      if (visited[ny][nx] || mp[ny][nx] == '0')
        continue;

      visited[ny][nx] = true;

      que.push(P{nx, ny});
    }
  }

  return 1;
}

int main() {
  for (;;) {
    rep(i, 12) cin >> mp[i];
    rep(i, 12) rep(j, 12) visited[i][j] = false;

    int ans = 0;

    rep(y, 12) rep(x, 12) {
      if (visited[y][x] || mp[y][x] == '0')
        continue;

      ans += bfs(x, y);
    }

    cout << ans << endl;
  }

  return 0;
}


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

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct {
  int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

vector<string> mp(12);
bool visited[12][12];

int bfs(int x, int y) {
  queue<P> que;
  que.push(P{x, y});

  while (!que.empty()) {
    P p = que.front();
    que.pop();

    rep(i, 4) {
      int nx = p.first + dx[i], ny = p.second + dy[i];

      if (nx < 0 || ny < 0 || 12 <= nx || 12 <= ny)
        continue;
      if (visited[ny][nx] || mp[ny][nx] == '0')
        continue;

      visited[ny][nx] = true;

      que.push(P{nx, ny});
    }
  }

  return 1;
}

int main() {
  while (cin >> mp[0]) {
    rep(i, 11) cin >> mp[i + 1];
    rep(i, 12) rep(j, 12) visited[i][j] = false;

    int ans = 0;

    rep(y, 12) rep(x, 12) {
      if (visited[y][x] || mp[y][x] == '0')
        continue;

      ans += bfs(x, y);
    }

    cout << ans << endl;
  }

  return 0;
}
Problem p00067 (C++)

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

using namespace std;

int masu[14][14];
int cont;

void saiki(int x, int y) {
  masu[x][y] = 0;
  if (masu[x + 1][y] == 1)
    saiki(x + 1, y);
  if (masu[x][y + 1] == 1)
    saiki(x, y + 1);
  if (masu[x - 1][y] == 1)
    saiki(x, y - 1);
  if (masu[x][y - 1] == 1)
    saiki(x, y - 1);
}

int main() {
  while (1) {
    for (int i = 0; i < 14; i++) {
      for (int j = 0; j < 14; j++) {
        masu[i][j] = 0;
      }
    }
    for (int i = 1; i <= 12; i++) {
      char st[13];
      scanf("%s", st);
      if (st[0] == EOF) {
        goto A;
      }
      for (int j = 0; j < 12; j++) {
        if (st[j] == '0') {
          masu[i][j + 1] = 0;
        } else {
          masu[i][j + 1] = 1;
        }
      }
    }
    cont = 0;
    for (int i = 1; i <= 12; i++) {
      for (int j = 1; j <= 12; j++) {
        if (masu[i][j] == 1) {
          cont++;
          saiki(i, j);
        }
      }
    }
    printf("%d\n", cont);
  }
A:;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int masu[14][14];
int cont;

void saiki(int x, int y) {
  masu[x][y] = 0;
  if (masu[x + 1][y] == 1)
    saiki(x + 1, y);
  if (masu[x][y + 1] == 1)
    saiki(x, y + 1);
  if (masu[x - 1][y] == 1)
    saiki(x, y - 1);
  if (masu[x][y - 1] == 1)
    saiki(x, y - 1);
}

int main() {
  while (1) {
    for (int i = 0; i < 14; i++) {
      for (int j = 0; j < 14; j++) {
        masu[i][j] = 0;
      }
    }
    for (int i = 1; i <= 12; i++) {
      char st[13];
      if (scanf("%s", st) == EOF) {
        goto A;
      }
      for (int j = 0; j < 12; j++) {
        if (st[j] == '0') {
          masu[i][j + 1] = 0;
        } else {
          masu[i][j + 1] = 1;
        }
      }
    }
    cont = 0;
    for (int i = 1; i <= 12; i++) {
      for (int j = 1; j <= 12; j++) {
        if (masu[i][j] == 1) {
          cont++;
          saiki(i, j);
        }
      }
    }
    printf("%d\n", cont);
  }
A:;
}
Problem p00067 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string str;
int xs[] = {0, 1, 0, -1}, ys[] = {1, 0, -1, 0};
bool m[10][10];
void dfs(int x, int y) {
  for (int i = 0; i < 4; i++) {
    int tx = x + xs[i], ty = y + ys[i];
    if (tx < 0 || tx >= 12 || ty < 0 || ty >= 12)
      continue;
    if (m[tx][ty]) {
      m[tx][ty] = false;
      dfs(tx, ty);
    }
  }
}

int main() {
  while (true) {
    int res = 0;
    for (int i = 0; i < 12; i++) {
      if (cin >> str) {
        for (int j = 0; j < str.size(); j++) {
          m[i][j] = str[j] == '1';
        }
      } else
        return 0;
    }
    for (int i = 0; i < 12; i++) {
      for (int j = 0; j < 12; j++) {
        if (m[i][j]) {
          res++;
          dfs(i, j);
        }
      }
    }
    cout << res << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string str;
int xs[] = {0, 1, 0, -1}, ys[] = {1, 0, -1, 0};
bool m[20][20];
void dfs(int x, int y) {
  for (int i = 0; i < 4; i++) {
    int tx = x + xs[i], ty = y + ys[i];
    if (tx < 0 || tx >= 12 || ty < 0 || ty >= 12)
      continue;
    if (m[tx][ty]) {
      m[tx][ty] = false;
      dfs(tx, ty);
    }
  }
}

int main() {
  while (true) {
    int res = 0;
    for (int i = 0; i < 12; i++) {
      if (cin >> str) {
        for (int j = 0; j < str.size(); j++) {
          m[i][j] = str[j] == '1';
        }
      } else
        return 0;
    }
    for (int i = 0; i < 12; i++) {
      for (int j = 0; j < 12; j++) {
        if (m[i][j]) {
          res++;
          dfs(i, j);
        }
      }
    }
    cout << res << endl;
  }
}
Problem p00067 (C++)

Buggy submission (status: Runtime Error):
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
char shima[13][13];
void tansaku(int x, int y) {
  if (x < 0 || x > 11 || y < 0 || y > 11 || shima[y][x] == '0')
    return;
  if (shima[y][x] == '1') {
    shima[y][x] = '0';
  }
  tansaku(x + 1, y);
  tansaku(x - 1, y);
  tansaku(x, y + 1);
  tansaku(x, y - 1);
}
int main() {

  while (cin >> shima[0][0]) {
    for (int i = 0; i < 12; i++) {
      for (int j = 0; j < 12; j++) {
        if (i != 0 && j != 0)
          cin >> shima[i][j];
      }
    }
    int a = 0;
    for (int i = 0; i < 12; i++) {
      for (int j = 0; j < 12; j++) {
        if (shima[i][j] == '1') {
          tansaku(j, i);
          a++;
        }
      }
    }
    cout << a << endl;
  }
}


Fixed submission:
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
char shima[13][13];
void tansaku(int x, int y) {
  if (x < 0 || x > 11 || y < 0 || y > 11 || shima[y][x] == '0')
    return;
  if (shima[y][x] == '1') {
    shima[y][x] = '0';
  }
  tansaku(x + 1, y);
  tansaku(x - 1, y);
  tansaku(x, y + 1);
  tansaku(x, y - 1);
}
int main() {

  while (cin >> shima[0][0]) {
    for (int i = 0; i < 12; i++) {
      for (int j = 0; j < 12; j++) {
        if (i == 0 && j == 0)
          continue;
        else
          cin >> shima[i][j];
      }
    }
    int a = 0;
    for (int i = 0; i < 12; i++) {
      for (int j = 0; j < 12; j++) {
        if (shima[i][j] == '1') {
          tansaku(j, i);
          a++;
        }
      }
    }
    cout << a << endl;
  }
}
Problem p00067 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
#include <sstream>
#include <string>
using namespace std;
int data[12][12];
vector<string> s(12);
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};

void dfs(int x, int y) {
  s[y][x] = '0';
  for (int i = 0; i < 4; ++i) {
    int px = x + dx[i];
    int py = y + dy[i];
    if (px < 0 || px >= 12 || py < 0 || py >= 12)
      continue;
    if (s[py][px] == '0')
      continue;
    dfs(px, py);
  }
}

int main() {
  while (1) {
    int ans = 0;

    for (int i = 0; i < 12; ++i) {
      cin >> s[i];
      if (cin.eof())
        break;
    }
    for (int i = 0; i < 12; ++i) {
      for (int j = 0; j < 12; ++j) {
        if (s[i][j] == '0')
          continue;
        dfs(j, i);
        ans++;
      }
    }
    cout << ans << endl;
  }
}

Fixed submission:
#include "bits/stdc++.h"
#include <sstream>
#include <string>
using namespace std;
int data[12][12];
vector<string> s(12);
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};

void dfs(int x, int y) {
  s[y][x] = '0';
  for (int i = 0; i < 4; ++i) {
    int px = x + dx[i];
    int py = y + dy[i];
    if (px < 0 || px >= 12 || py < 0 || py >= 12)
      continue;
    if (s[py][px] == '0')
      continue;
    dfs(px, py);
  }
}

int main() {
  while (1) {
    int ans = 0;

    for (int i = 0; i < 12; ++i) {
      cin >> s[i];
      if (cin.eof())
        return 0;
    }
    for (int i = 0; i < 12; ++i) {
      for (int j = 0; j < 12; ++j) {
        if (s[i][j] == '0')
          continue;
        dfs(j, i);
        ans++;
      }
    }
    cout << ans << endl;
  }
}
Problem p00067 (C++)

Buggy submission (status: Time Limit Exceeded):
//============================================================================
// Name        : aoj0067.cpp
// Author      : afterCmidday
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <string>
using namespace std;

const int dy[4] = {-1, 0, 1, 0}, dx[4] = {0, 1, 0, -1};

void dfs(string s[], int y, int x) {
  s[y][x] = '0';
  for (int i = 0; i < 4; i++) {
    if (0 <= y + dy[i] && y + dy[i] < 12 && 0 <= x + dx[i] && x + dx[i] < 12 &&
        s[y + dy[i]][x + dx[i]] == '1') {
      dfs(s, y + dy[i], x + dx[i]);
    }
  }
}

int main() {
  string str[12];
  int ans;
  while (true) {
    for (int i = 0; i < 12; i++) {
      getline(cin, str[i]);
    }
    ans = 0;
    for (int i = 0; i < 12; i++) {
      for (int j = 0; j < 12; j++) {
        if (str[i][j] == '1') {
          dfs(str, i, j);
          ans++;
        }
      }
    }
    cout << ans << endl;
    getline(cin, str[0]);
  }
  return 0;
}

Fixed submission:
//============================================================================
// Name        : aoj0067.cpp
// Author      : afterCmidday
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <string>
using namespace std;

const int dy[4] = {-1, 0, 1, 0}, dx[4] = {0, 1, 0, -1};

void dfs(string s[], int y, int x) {
  s[y][x] = '0';
  for (int i = 0; i < 4; i++) {
    if (0 <= y + dy[i] && y + dy[i] < 12 && 0 <= x + dx[i] && x + dx[i] < 12 &&
        s[y + dy[i]][x + dx[i]] == '1') {
      dfs(s, y + dy[i], x + dx[i]);
    }
  }
}

int main() {
  string str[12];
  int ans;
  while (!cin.eof()) {
    for (int i = 0; i < 12; i++) {
      getline(cin, str[i]);
    }
    ans = 0;
    for (int i = 0; i < 12; i++) {
      for (int j = 0; j < 12; j++) {
        if (str[i][j] == '1') {
          dfs(str, i, j);
          ans++;
        }
      }
    }
    cout << ans << endl;
    getline(cin, str[0]);
  }
  return 0;
}