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

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

int main(void) {
  string check = "Hoshino";
  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    string str;
    if (i == 0)
      cin.ignore();
    getline(cin, str);
    for (int j = 0; j < str.length() - 6; j++) {
      for (int k = 0; k < 7; k++) {
        // printf("%c %c\n", check[k], str[j+k]);
        if (check[k] == str[j + k] && k < 6)
          continue;
        else if (check[k] == str[j + k] && k == 6) {
          str[j + k] = 'a';
        } else
          break;
      }
    }
    cout << str << endl;
  }
  return 0;
}

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

int main(void) {
  string check = "Hoshino";
  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    string str;
    if (i == 0)
      cin.ignore();
    getline(cin, str);
    if (str.length() < 7) {
      cout << str << endl;
      continue;
    }
    for (int j = 0; j < str.length() - 6; j++) {
      for (int k = 0; k < 7; k++) {
        // printf("%c %c\n", check[k], str[j+k]);
        if (check[k] == str[j + k] && k < 6)
          continue;
        else if (check[k] == str[j + k] && k == 6) {
          str[j + k] = 'a';
        } else
          break;
      }
    }
    cout << str << endl;
  }
  return 0;
}
Problem p00101 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main() {
  int n;
  cin >> n;
  char c;
  scanf("%c", &c);
  rep(p, n) {
    string s;
    getline(cin, s);
    rep(i, s.length()) {
      int b = (int)s.find("Hoshino", i);
      if (b != -1) {
        s.replace(b + i, 7, "Hoshina");
        i += 7;
      }
    }
    cout << s << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main() {
  int n;
  cin >> n;
  char c;
  scanf("%c", &c);
  rep(p, n) {
    string s;
    getline(cin, s);
    rep(i, s.length()) {
      int b = (int)s.find("Hoshino", i);
      if (b != -1) {
        s.replace(b, 7, "Hoshina");
        i += 6;
      }
    }
    cout << s << endl;
  }
}
Problem p00101 (C++)

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

int main(void) {
  int n;
  string str;

  cin >> n;
  cin.ignore();
  while (n--) {
    getline(cin, str);
    for (int i = 0; i < str.size() - 6; i++) {
      if (str.substr(i, 7) == "Hoshino")
        str[i + 6] = 'a';
    }
    cout << str << endl;
  }

  return 0;
}

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

int main(void) {
  int n;
  string str;

  cin >> n;
  cin.ignore();
  while (n--) {
    getline(cin, str);
    for (int i = 0; i < str.size(); i++) {
      if (str.substr(i, 7) == "Hoshino")
        str[i + 6] = 'a';
    }
    cout << str << endl;
  }

  return 0;
}
Problem p00101 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
  char ho[8] = {'H', 'o', 's', 'h', 'i', 'n', 'o'};
  int n;
  string s;
  cin >> n;
  cin.ignore();
  while (n--) {
    getline(cin, s);
    rep(i, s.size() - 6) {
      //			cout<<i<<endl;
      bool f = true;
      rep(j, 7) {
        if (s[i + j] != ho[j]) {
          f = false;
          break;
        }
      }
      if (f) {
        s[i + 1] = 'a';
      }
    }
    cout << s << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
  char ho[8] = {'H', 'o', 's', 'h', 'i', 'n', 'o'};
  int n;
  string s;
  cin >> n;
  cin.ignore();
  while (n--) {
    getline(cin, s);
    int a = s.length();
    rep(i, a - 6) {
      if (s[i] == 'H' && s[i + 1] == 'o' && s[i + 2] == 's' &&
          s[i + 3] == 'h' && s[i + 4] == 'i' && s[i + 5] == 'n' &&
          s[i + 6] == 'o') {
        s[i + 6] = 'a';
        i += 6;
      }
    }
    cout << s << endl;
  }
}
Problem p00101 (C++)

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

int main(void) {
  char sentence[1050];
  int n;
  scanf("%d\n", &n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 1050; j++) {
      sentence[j] = getchar();
      if (sentence[j] == '\n') {
        sentence[j] = 0;
        break;
      }
    }
    for (int j = 0; j < 1025; i++) {
      if (sentence[j] == 0)
        break;
      if (!strncmp(sentence + j, "Hoshino", 7)) {
        sentence[j + 6] = 'a';
      }
    }
    puts(sentence);
  }
  return 0;
}

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

int main(void) {
  char sentence[1050];
  int n;
  scanf("%d\n", &n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 1050; j++) {
      sentence[j] = getchar();
      if (sentence[j] == '\n') {
        sentence[j] = 0;
        break;
      }
    }
    for (int j = 0; j < 1025; j++) {
      if (sentence[j] == 0)
        break;
      if (!strncmp(sentence + j, "Hoshino", 7)) {
        sentence[j + 6] = 'a';
      }
    }
    puts(sentence);
  }
  return 0;
}
Problem p00101 (C++)

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

using namespace std;

int main() {
  int n;
  cin >> n;
  cin.ignore();
  while (n--) {
    string s;
    getline(cin, s);
    for (int i = 0; i < s.length() - 6; i++) {
      if (s.substr(i, 7) == "Hoshino")
        s.replace(i, 7, "Hoshina");
    }
    cout << s << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  cin.ignore();
  while (n--) {
    string s;
    getline(cin, s);
    if (s.length() >= 7) {
      for (int i = 0; i < s.length() - 6; i++) {
        if (s.substr(i, 7) == "Hoshino")
          s.replace(i, 7, "Hoshina");
      }
    }
    cout << s << endl;
  }
  return 0;
}
Problem p00101 (C++)

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

int main() {
  const std::string str_false = "Hoshino";
  const std::string str_true = "Hoshina";

  u_int num_of_data;
  std::cin >> num_of_data;
  std::cin.ignore();

  for (u_int i = 0; i < num_of_data; ++i) {
    std::string text;
    getline(std::cin, text);

    u_int index = 0;
    while ((index = text.find(str_false, index)) != std::string::npos) {
      text.replace(index, str_false.size(), str_true);
      index += str_false.size();
    }
    std::cout << text << std::endl;
  }

  return 0;
}

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

int main() {
  const std::string str_false = "Hoshino";
  const std::string str_true = "Hoshina";

  u_int num_of_data;
  std::cin >> num_of_data;
  std::cin.ignore();

  for (u_int i = 0; i < num_of_data; ++i) {
    std::string text;
    getline(std::cin, text);

    int index = 0;
    while ((index = text.find(str_false, index)) != std::string::npos) {
      text.replace(index, str_false.size(), str_true);
      index += str_false.size();
    }
    std::cout << text << std::endl;
  }

  return 0;
}
Problem p00101 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main(void) {
  int n;
  string h = "Hoshino";
  string s;
  cin >> n;
  getline(cin, s);
  stringstream ss(s);
  ss >> n;
  rep(loop, n) {
    getline(cin, s);
    rep(i, s.size() - h.size() + 1) {
      bool same = true;
      rep(j, h.size()) {
        if (s[i + j] != h[j]) {
          same = false;
          break;
        }
      }
      if (same)
        s[i + h.size() - 1] = 'a';
    }
    cout << s << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main(void) {
  int n;
  string h = "Hoshino";
  string s;
  cin >> n;
  getline(cin, s);
  stringstream ss(s);
  ss >> n;
  rep(loop, n) {
    getline(cin, s);
    rep(i, s.size()) {
      if (i + h.size() - 1 >= s.size())
        break;
      bool same = true;
      rep(j, h.size()) {
        if (s[i + j] != h[j]) {
          same = false;
          break;
        }
      }
      if (same)
        s[i + h.size() - 1] = 'a';
    }
    cout << s << endl;
  }
}
Problem p00101 (C++)

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

using namespace std;

int main() {
  int n, i, j;
  ios::sync_with_stdio();
  string s;

  scanf("%d", &n);
  cin.get();
  for (i = 0; i < n; i++) {
    getline(cin, s);

    for (j = 0; s[j + 6] != '\0'; j++) {
      if (s.substr(j, 7) == "Hoshino")
        s[j + 6] = 'a';
    }

    cout << s << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
  int n, i, j;
  ios::sync_with_stdio();
  string s;

  scanf("%d", &n);
  cin.get();
  for (i = 0; i < n; i++) {
    getline(cin, s);

    for (j = 0; j + 6 < s.size(); j++) {
      if (s.substr(j, 7) == "Hoshino")
        s[j + 6] = 'a';
    }

    cout << s << endl;
  }
  return 0;
}
Problem p00101 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {

  int n;
  string s;
  string d = "Hoshina";
  cin >> n;
  cin.ignore();
  while (n--) {
    getline(cin, s);
    while (1) {
      unsigned int loc = s.find("Hoshino");
      if (loc != string::npos)
        s.replace(loc, d.size(), d);
      else
        break;
    }
    cout << s << endl;
  }
}

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

  int n;
  string s;
  string d = "Hoshina";
  cin >> n;
  cin.ignore();
  while (n--) {
    getline(cin, s);
    for (int i = 6; i < s.size(); i++) {
      if (s.substr(i - 6, 7) == "Hoshino")
        s.at(i) = 'a';
    }
    cout << s << endl;
  }
}
Problem p00101 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double ESP = 1e-10;
using namespace std;
int main() {
  int n;
  string s;
  cin >> n;
  getline(cin, s);
  rep(i, n) {
    getline(cin, s);
    rep(j, s.size() - 6) {
      if (s.substr(j, 7) == "Hoshino")
        s[j + 6] = 'a';
    }
    cout << s << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double ESP = 1e-10;
using namespace std;
int main() {
  int n;
  string s;
  cin >> n;
  getline(cin, s);
  rep(i, n) {
    getline(cin, s);
    for (int j = 7; j <= s.size(); j++) {
      if (s.substr(j - 7, 7) == "Hoshino")
        s[j - 1] = 'a';
    }
    cout << s << endl;
  }
}
Problem p00102 (C++)

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

int main(void) {
  int matrix[10][10], i, j, dataset;
  while (scanf("%d", &dataset)) {

    if (dataset == 0)
      break;

    // init add total norm
    for (i = 0; i < dataset + 1; i++) {
      matrix[dataset][i] = 0;
      matrix[i][dataset] = 0;
    }

    // input and calc
    for (i = 0; i < dataset; i++) {
      for (j = 0; j < dataset; j++) {
        scanf("%d", &matrix[i][j]);
        matrix[i][dataset] += matrix[i][j];
      }
    }

    // calc
    for (j = 0; j < dataset + 1; j++) {
      for (i = 0; i < dataset; i++) {
        matrix[dataset][j] += matrix[i][j];
      }
    }

    // output
    for (i = 0; i < dataset + 1; i++) {
      for (j = 0; j < dataset + 1; j++) {
        printf("%5d", matrix[i][j]);
      }
      printf("\n");
    }
  }
}

Fixed submission:
#include <stdio.h>

int main(void) {
  int matrix[11][11], i, j, dataset;
  while (scanf("%d", &dataset)) {

    if (dataset == 0)
      break;

    // init add total norm
    for (i = 0; i < dataset + 1; i++) {
      matrix[dataset][i] = 0;
      matrix[i][dataset] = 0;
    }

    // input and calc
    for (i = 0; i < dataset; i++) {
      for (j = 0; j < dataset; j++) {
        scanf("%d", &matrix[i][j]);
        matrix[i][dataset] += matrix[i][j];
      }
    }

    // calc
    for (j = 0; j < dataset + 1; j++) {
      for (i = 0; i < dataset; i++) {
        matrix[dataset][j] += matrix[i][j];
      }
    }

    // output
    for (i = 0; i < dataset + 1; i++) {
      for (j = 0; j < dataset + 1; j++) {
        printf("%5d", matrix[i][j]);
      }
      printf("\n");
    }
  }
}
Problem p00102 (C++)

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

int main() {
  int n;
  while (std::cin >> n, n) {
    int data[10][10];
    memset(data, 0, sizeof(data));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        std::cin >> data[i][j];
        data[i][n] += data[i][j];
        data[n][j] += data[i][j];
        data[n][n] += data[i][j];
      }
    }
    for (int i = 0; i < n + 1; i++) {
      for (int j = 0; j < n + 1; j++) {
        std::cout << std::setw(5) << std::right << data[i][j];
      }
      std::cout << std::endl;
    }
  }
  return 0;
}

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

int main() {
  int n;
  while (std::cin >> n, n) {
    int data[11][11];
    memset(data, 0, sizeof(data));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        std::cin >> data[i][j];
        data[i][n] += data[i][j];
        data[n][j] += data[i][j];
        data[n][n] += data[i][j];
      }
    }
    for (int i = 0; i < n + 1; i++) {
      for (int j = 0; j < n + 1; j++) {
        std::cout << std::setw(5) << std::right << data[i][j];
      }
      std::cout << std::endl;
    }
  }
  return 0;
}
Problem p00102 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const int N = 10000;
int n, a[N][N];
signed main(void) {
  ios::sync_with_stdio(false);
  while (cin >> n && n) {
    memset(a, 0, sizeof(a));
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        cin >> a[i][j];
    for (int i = 1, sum; i <= n; i++) {
      sum = 0;
      for (int j = 1; j <= n; j++)
        sum += a[i][j];
      a[i][n + 1] = sum;
    }
    for (int j = 1, sum; j <= n; j++) {
      sum = 0;
      for (int i = 1; i <= n; i++)
        sum += a[i][j];
      a[n + 1][j] = sum;
    }
    int sum = 0;
    for (int i = 1; i <= n; i++)
      sum += a[i][n + 1];
    a[n + 1][n + 1] = sum;
    for (int i = 1; i <= n + 1; i++, cout << endl)
      for (int j = 1; j <= n + 1; j++)
        cout << setw(5) << a[i][j];
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
int n, a[N][N];
signed main(void) {
  ios::sync_with_stdio(false);
  while (cin >> n && n) {
    memset(a, 0, sizeof(a));
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        cin >> a[i][j];
    for (int i = 1, sum; i <= n; i++) {
      sum = 0;
      for (int j = 1; j <= n; j++)
        sum += a[i][j];
      a[i][n + 1] = sum;
    }
    for (int j = 1, sum; j <= n; j++) {
      sum = 0;
      for (int i = 1; i <= n; i++)
        sum += a[i][j];
      a[n + 1][j] = sum;
    }
    int sum = 0;
    for (int i = 1; i <= n; i++)
      sum += a[i][n + 1];
    a[n + 1][n + 1] = sum;
    for (int i = 1; i <= n + 1; i++, cout << endl)
      for (int j = 1; j <= n + 1; j++)
        cout << setw(5) << a[i][j];
  }
}
Problem p00102 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

void Solution() {
  int n;
  int a[10][10];

  while (true) {
    cin >> n;

    if (n == 0) {
      break;
    }

    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= n; j++) {
        a[i][j] = 0;
      }
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> a[i][j];
        a[i][n] += a[i][j];
      }
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j <= n; j++) {
        a[n][j] += a[i][j];
      }
    }

    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= n; j++) {
        cout << setw(5) << a[i][j];
      }

      cout << endl;
    }
  }
}

int main() {
  Solution();
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

void Solution() {
  int n;
  int a[11][11];

  while (true) {
    cin >> n;

    if (n == 0) {
      break;
    }

    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= n; j++) {
        a[i][j] = 0;
      }
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> a[i][j];
        a[i][n] += a[i][j];
      }
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j <= n; j++) {
        a[n][j] += a[i][j];
      }
    }

    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= n; j++) {
        cout << setw(5) << a[i][j];
      }

      cout << endl;
    }
  }
}

int main() {
  Solution();
  return 0;
}
Problem p00103 (C++)

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

int main() {
  int hit, out, score, data_set_num;
  std::string event, str;
  std::getline(std::cin, str);
  sscanf(str.c_str(), "%d ", &data_set_num);

  while (data_set_num) {
    std::cin >> event;
    if (event == "HIT") {
      ++hit;
      if (hit == 4) {
        ++score;
        hit = 3;
      }
    } else if (event == "HOMERUN") {
      score += (hit + 1);
      hit = 0;
    } else if (event == "OUT") {
      ++out;
    }

    if (out == 3) {
      std::cout << score << std::endl;
      hit = 0;
      score = 0;
      --data_set_num;
    }
  }

  return 0;
}

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

int main() {
  int hit, out, score, data_set_num;
  std::string event, str;
  std::getline(std::cin, str);
  sscanf(str.c_str(), "%d ", &data_set_num);

  while (data_set_num) {
    std::cin >> event;
    if (event == "HIT") {
      ++hit;
      if (hit == 4) {
        ++score;
        hit = 3;
      }
    } else if (event == "HOMERUN") {
      score += (hit + 1);
      hit = 0;
    } else if (event == "OUT") {
      ++out;
    }

    if (out == 3) {
      std::cout << score << std::endl;
      hit = 0;
      score = 0;
      out = 0;
      --data_set_num;
    }
  }

  return 0;
}
Problem p00103 (C++)

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

int main() {
  int n;
  cin >> n;
  int ini = 0, out = 0, hit = 0, cnt = 0;
  while (ini <= n) {
    string s;
    cin >> s;
    if (s == "OUT") {
      out++;
      if (out == 3) {
        cout << cnt << endl;
        cnt = 0;
        hit = 0;
        out = 0;
        ini++;
      }
    }
    if (s == "HIT") {
      if (hit == 3) {
        cnt++;
      } else {
        hit++;
      }
    }

    if (s == "HOMERUN") {
      cnt += hit + 1;
      hit = 0;
    }
  }
}


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

int main() {
  int n;
  cin >> n;
  int ini = 0, out = 0, hit = 0, cnt = 0;
  while (ini < n) {
    string s;
    cin >> s;
    if (s == "OUT") {
      out++;
      if (out == 3) {
        cout << cnt << endl;
        cnt = 0;
        hit = 0;
        out = 0;
        ini++;
      }
    }
    if (s == "HIT") {
      if (hit == 3) {
        cnt++;
      } else {
        hit++;
      }
    }

    if (s == "HOMERUN") {
      cnt += hit + 1;
      hit = 0;
    }
  }
}
Problem p00103 (C++)

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

int main() {
  int o, i, out = 0, b = 0, p[10];
  string ev;

  cin >> o;

  for (i = 0; i < o; i++) {

    p[i] = 0;

    while (1) {

      cin >> ev;

      if (ev == "HIT") {
        b++;

        if (b == 4) {
          b--;

          p[i]++;
        }
      }

      else if (ev == "HOMERUN") {
        p[i] += b + 1;

        b = 0;
      }

      else if (ev == "OUT") {
        out++;
      }

      if (out == 3)
        break;
    }

    out = 0;
    b = 0;
  }

  for (i = 0; i < o; i++) {
    cout << p[i] << endl;
  }

  return 0;
}

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

int main() {
  int o, i, out = 0, b = 0, p[100];
  string ev;

  cin >> o;

  for (i = 0; i < o; i++) {

    p[i] = 0;

    while (1) {

      cin >> ev;

      if (ev == "HIT") {
        b++;

        if (b == 4) {
          b--;

          p[i]++;
        }
      }

      else if (ev == "HOMERUN") {
        p[i] += b + 1;

        b = 0;
      }

      else if (ev == "OUT") {
        out++;
      }

      if (out == 3)
        break;
    }

    out = 0;
    b = 0;
  }

  for (i = 0; i < o; i++) {
    cout << p[i] << endl;
  }

  return 0;
}
Problem p00103 (C++)

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

int main() {
  int N, m = 0, rn = 0, pn = 0;
  string str;
  cin >> N;
  for (int i = 0; i < N; i++) {
    while (1) {
      cin >> str;
      if (str == "OUT") {
        m++;
        if (m == 3)
          break;
      }
      if (str == "HIT") {
        rn++;
        if (rn == 4) {
          pn++;
          rn = 3;
        }
      }
      if (str == "HOMERUN") {
        pn += rn + 1;
        rn = 0;
      }
    }
    cout << pn << endl;
    rn = 0;
    pn = 0;
  }
  return 0;
}

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

int main() {
  int N, m = 0, rn = 0, pn = 0;
  string str;
  cin >> N;
  for (int i = 0; i < N; i++) {
    while (1) {
      cin >> str;
      if (str == "OUT") {
        m++;
        if (m == 3)
          break;
      }
      if (str == "HIT") {
        rn++;
        if (rn == 4) {
          pn++;
          rn = 3;
        }
      }
      if (str == "HOMERUN") {
        pn += rn + 1;
        rn = 0;
      }
    }
    cout << pn << endl;
    rn = 0;
    pn = 0;
    m = 0;
  }
  return 0;
}
Problem p00104 (C++)

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

struct zahyou {
  int x;
  int y;
};

int main() {

  int tx, ty, count;
  char map[100][100];
  bool flag;
  struct zahyou now;

  while (cin >> tx >> ty, tx && ty) {

    flag = false;
    now.x = 0;
    now.y = 0;
    memset(map, '\0', sizeof(map));

    for (int i = 0; i < ty; i++) {
      for (int j = 0; j < tx; j++) {
        cin >> map[i][j];
      }
    }

    while (1) {

      if (map[now.y][now.x] == '.') {
        cout << now.x << " " << now.y << endl;
        break;
      } else if (map[now.y][now.x] == '1') {
        cout << "LOOP" << endl;
        break;
      }

      if (map[now.y][now.x] == '>') {
        map[now.y][now.x] = '1';
        now.x++;
      } else if (map[now.y][now.x] == '<') {
        map[now.y][now.x] = '1';
        now.x--;
      } else if (map[now.y][now.x] == 'v') {
        map[now.y][now.x] = '1';
        now.y++;
      } else if (map[now.y][now.x] == '^') {
        map[now.y][now.x] = '1';
        now.y--;
      }
    }
  }
}

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

struct zahyou {
  int x;
  int y;
};

int main() {

  int tx, ty, count;
  char map[100][100];
  bool flag;
  struct zahyou now;

  while (cin >> tx >> ty, tx && ty) {

    flag = false;
    now.x = 0;
    now.y = 0;
    memset(map, '\0', sizeof(map));

    for (int i = 0; i < tx; i++) {
      for (int j = 0; j < ty; j++) {
        cin >> map[i][j];
      }
    }

    while (1) {

      if (map[now.y][now.x] == '.') {
        cout << now.x << " " << now.y << endl;
        break;
      } else if (map[now.y][now.x] == '1') {
        cout << "LOOP" << endl;
        break;
      }

      if (map[now.y][now.x] == '>') {
        map[now.y][now.x] = '1';
        now.x++;
      } else if (map[now.y][now.x] == '<') {
        map[now.y][now.x] = '1';
        now.x--;
      } else if (map[now.y][now.x] == 'v') {
        map[now.y][now.x] = '1';
        now.y++;
      } else if (map[now.y][now.x] == '^') {
        map[now.y][now.x] = '1';
        now.y--;
      }
    }
  }
}
Problem p00104 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstring>
#include <iostream>
using namespace std;
char a[8000][8000];
int h, w, loop, cx, cy;
int main() {
  while (true) {
    cin >> h >> w;
    if (!h) {
      break;
    }
    memset(a, ' ', sizeof(a));
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> a[i][j];
      }
    }
    cx = 0;
    cy = 0;
    loop = 0;
    while (true) {
      if (loop > 18000000) {
        cout << "LOOP" << endl;
        break;
      }
      if (a[cy][cx] == '.') {
        cout << cx << ' ' << cy << endl;
        break;
      }
      if (a[cy][cx] == '<') {
        cx--;
      }
      if (a[cy][cx] == '>') {
        cx++;
      }
      if (a[cy][cx] == '^') {
        cy--;
      }
      if (a[cy][cx] == 'v') {
        cy++;
      }
      loop++;
    }
  }
}

Fixed submission:
#include <cstring>
#include <iostream>
using namespace std;
char a[8000][8000];
int h, w, loop, cx, cy;
int main() {
  while (true) {
    cin >> h >> w;
    if (!h) {
      break;
    }
    memset(a, ' ', sizeof(a));
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> a[i][j];
      }
    }
    cx = 0;
    cy = 0;
    loop = 0;
    while (true) {
      if (loop > 15000000) {
        cout << "LOOP" << endl;
        break;
      }
      if (a[cy][cx] == '.') {
        cout << cx << ' ' << cy << endl;
        break;
      }
      if (a[cy][cx] == '<') {
        cx--;
      }
      if (a[cy][cx] == '>') {
        cx++;
      }
      if (a[cy][cx] == '^') {
        cy--;
      }
      if (a[cy][cx] == 'v') {
        cy++;
      }
      loop++;
    }
  }
}
Problem p00104 (C++)

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

int main() {

  int w, h;
  while (cin >> h >> w, w + h) {
    char room[10][10];
    int t = 0;
    int now_x = 0, now_y = 0;

    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> room[i][j];
      }
    }

    while (1) {
      if (room[now_y][now_x] == '.')
        break;
      char c = room[now_y][now_x];
      if (c == '>')
        now_x++;
      if (c == '<')
        now_x--;
      if (c == 'v')
        now_y++;
      if (c == '^')
        now_y--;
      t++;
      if (t > w * h)
        break;
    }

    if (t > w * h)
      cout << "LOOP" << endl;
    else
      cout << now_x << " " << now_y << endl;
  }
}

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

int main() {

  int w, h;
  while (cin >> h >> w, w + h) {
    char room[101][101];
    int t = 0;
    int now_x = 0, now_y = 0;

    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> room[i][j];
      }
    }

    while (1) {
      if (room[now_y][now_x] == '.')
        break;
      char c = room[now_y][now_x];
      if (c == '>')
        now_x++;
      if (c == '<')
        now_x--;
      if (c == 'v')
        now_y++;
      if (c == '^')
        now_y--;
      t++;
      if (t > w * h)
        break;
    }

    if (t > w * h)
      cout << "LOOP" << endl;
    else
      cout << now_x << " " << now_y << endl;
  }
}
Problem p00104 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int H, W, x, y;
  while (cin >> H >> W) {
    if (H == 0 && W == 0)
      break;
    char space[H][W], c;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cin >> space[j][i];
      }
    }
    x = y = 0;
    while (1) {
      c = space[x][y];
      space[x][y] = '0';
      if (c == '>')
        x++;
      else if (c == '<')
        x--;
      else if (c == 'v')
        y++;
      else if (c == '^')
        y--;
      else if (c == '.') {
        cout << x << ' ' << y << endl;
        break;
      } else if (c == '0') {
        cout << "LOOP" << endl;
        break;
      }
    }
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int H, W, x, y;
  while (cin >> H >> W) {
    if (H == 0 && W == 0)
      break;
    char space[W][H], c;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cin >> space[j][i];
      }
    }
    x = y = 0;
    while (1) {
      c = space[x][y];
      space[x][y] = '0';
      if (c == '>')
        x++;
      else if (c == '<')
        x--;
      else if (c == 'v')
        y++;
      else if (c == '^')
        y--;
      else if (c == '.') {
        cout << x << ' ' << y << endl;
        break;
      } else if (c == '0') {
        cout << "LOOP" << endl;
        break;
      }
    }
  }
  return 0;
}
Problem p00104 (C++)

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

using namespace std;

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

string fie[30] = {};

int main() {
  int h, w;
  while (cin >> h >> w) {
    if (w == 0 && h == 0)
      break;

    rep(i, h) { cin >> fie[i]; }

    int y = 0, x = 0;

    int c = 0;
    while (c < 1000000) {
      c++;
      char ch = fie[y][x];
      if (ch == '>') {
        x++;
      } else if (ch == '<') {
        x--;
      } else if (ch == '^') {
        y--;
      } else if (ch == 'v') {
        y++;
      } else
        break;
    }
    if (c == 1000000)
      cout << "LOOP" << endl;
    else
      cout << x << " " << y << endl;
  }
}

Fixed submission:
#include "bits/stdc++.h"

using namespace std;

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

string fie[200] = {};

int main() {
  int h, w;
  while (cin >> h >> w) {
    if (w == 0 && h == 0)
      break;

    rep(i, h) { cin >> fie[i]; }

    int y = 0, x = 0;

    int c = 0;
    while (c < 1000000) {
      c++;
      char ch = fie[y][x];
      if (ch == '>') {
        x++;
      } else if (ch == '<') {
        x--;
      } else if (ch == '^') {
        y--;
      } else if (ch == 'v') {
        y++;
      } else
        break;
    }
    if (c == 1000000)
      cout << "LOOP" << endl;
    else
      cout << x << " " << y << endl;
  }
}
Problem p00104 (C++)

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

#define MAX 10

int main(void) {
  int H, W;
  char tile[MAX][MAX];

  while (1) {

    int x = 0, y = 0;

    for (int i = 0; i < MAX; i++) {
      for (int j = 0; j < MAX; j++) {
        tile[i][j] = '.';
      }
    }

    cin >> H >> W;
    if (H == 0 && W == 0)
      break;

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cin >> tile[i][j];
      }
    }

    int cal = 0, sum = 0;
    cal = H * W;

    // for(int i = 0 ; i < H ; i++) {
    // for(int j = 0 ; j < W ; j++) {
    while (tile[x][y] != '.') {
      if (tile[x][y] == '>')
        y++, sum++;
      else if (tile[x][y] == '<')
        y--, sum++;
      else if (tile[x][y] == '^')
        x--, sum++;
      else if (tile[x][y] == 'v')
        x++, sum++;
      if (sum > cal)
        break;
      // cout << "x = " << x << endl << "y = " << y << endl;
    }
    if (sum <= cal)
      cout << y << ' ' << x << endl;
    else
      cout << "LOOP" << endl;
  }
  return 0;
}

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

#define MAX 100

int main(void) {
  int H, W;
  char tile[MAX][MAX];

  while (1) {

    int x = 0, y = 0;

    for (int i = 0; i < MAX; i++) {
      for (int j = 0; j < MAX; j++) {
        tile[i][j] = '.';
      }
    }

    cin >> H >> W;
    if (H == 0 && W == 0)
      break;

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cin >> tile[i][j];
      }
    }

    int cal = 0, sum = 0;
    cal = H * W;

    // for(int i = 0 ; i < H ; i++) {
    // for(int j = 0 ; j < W ; j++) {
    while (tile[x][y] != '.') {
      if (tile[x][y] == '>')
        y++, sum++;
      else if (tile[x][y] == '<')
        y--, sum++;
      else if (tile[x][y] == '^')
        x--, sum++;
      else if (tile[x][y] == 'v')
        x++, sum++;
      if (sum > cal)
        break;
      // cout << "x = " << x << endl << "y = " << y << endl;
    }
    if (sum <= cal)
      cout << y << ' ' << x << endl;
    else
      cout << "LOOP" << endl;
  }
  return 0;
}
Problem p00104 (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;

char tile[11][11];

void loop(int x, int y) {
  if (tile[x][y] == '.') {
    cout << y << ' ' << x << endl;
    return;
  }
  if (tile[x][y] == '#') {
    cout << "LOOP" << endl;
    return;
  }
  if (tile[x][y] == '>') {
    tile[x][y] = '#';
    loop(x, y + 1);
  }
  if (tile[x][y] == '<') {
    tile[x][y] = '#';
    loop(x, y - 1);
  }
  if (tile[x][y] == '^') {
    tile[x][y] = '#';
    loop(x - 1, y);
  }
  if (tile[x][y] == 'v') {
    tile[x][y] = '#';
    loop(x + 1, y);
  }
}

int main(void) {
  int h, w;
  int x, y;
  int a;
  while (1) {
    x = 0, y = 0;
    cin >> h >> w;
    if (h == 0 && w == 0)
      break;
    for (a = 0; a < h; a++) {
      cin >> tile[a];
    }
    loop(0, 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;

char tile[101][101];

void loop(int x, int y) {
  if (tile[x][y] == '.') {
    cout << y << ' ' << x << endl;
    return;
  }
  if (tile[x][y] == '#') {
    cout << "LOOP" << endl;
    return;
  }
  if (tile[x][y] == '>') {
    tile[x][y] = '#';
    loop(x, y + 1);
  }
  if (tile[x][y] == '<') {
    tile[x][y] = '#';
    loop(x, y - 1);
  }
  if (tile[x][y] == '^') {
    tile[x][y] = '#';
    loop(x - 1, y);
  }
  if (tile[x][y] == 'v') {
    tile[x][y] = '#';
    loop(x + 1, y);
  }
}

int main(void) {
  int h, w;
  int x, y;
  int a;
  while (1) {
    x = 0, y = 0;
    cin >> h >> w;
    if (h == 0 && w == 0)
      break;
    for (a = 0; a < h; a++) {
      cin >> tile[a];
    }
    loop(0, 0);
  }
  return 0;
}
Problem p00104 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  while (1) {
    int w, h;
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;

    vector<string> data;
    for (int i = 0; i < h; i++) {
      string line;
      cin >> line;
      data.push_back(line);
    }

    bool loop_flag = false;
    int x = 0;
    int y = 0;
    while (1) {
      int oldx = x;
      int oldy = y;
      if (data[y][x] == '.')
        break;
      else if (data[y][x] == '>')
        x++;
      else if (data[y][x] == 'v')
        y++;
      else if (data[y][x] == '^')
        y--;
      else if (data[y][x] == '<')
        x--;
      else if (data[y][x] == 'x') {
        loop_flag = true;
        break;
      }
      data[oldy][oldx] = 'x';
    }

    if (loop_flag)
      cout << "LOOP" << endl;
    else
      cout << x << " " << y << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  while (1) {
    int w, h;
    cin >> h >> w;
    if (w == 0 && h == 0)
      break;

    vector<string> data;
    for (int i = 0; i < h; i++) {
      string line;
      cin >> line;
      data.push_back(line);
    }

    bool loop_flag = false;
    int x = 0;
    int y = 0;
    while (1) {
      int oldx = x;
      int oldy = y;
      if (data[y][x] == '.')
        break;
      else if (data[y][x] == '>')
        x++;
      else if (data[y][x] == 'v')
        y++;
      else if (data[y][x] == '^')
        y--;
      else if (data[y][x] == '<')
        x--;
      else if (data[y][x] == 'x') {
        loop_flag = true;
        break;
      }
      data[oldy][oldx] = 'x';
    }

    if (loop_flag)
      cout << "LOOP" << endl;
    else
      cout << x << " " << y << endl;
  }
  return 0;
}
Problem p00105 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
pair<string, int> a[1];
int main() {
  int t = 0, g, i;
  while (cin >> a[t].first >> a[t].second)
    t++;
  sort(a, a + t);
  string f, b = a[0].first;
  cout << b << endl << a[0].second;
  for (i = 1; i < t; i++) {
    bool n = 0;
    f = a[i].first, g = a[i].second;
    if (f == b)
      n = 1;
    if (n)
      cout << " " << g;
    else
      cout << endl << f << endl << g;
    b = f;
  }
  cout << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
pair<string, int> a[100];
int main() {
  int t = 0, g, i;
  while (cin >> a[t].first >> a[t].second)
    t++;
  sort(a, a + t);
  string f, b = a[0].first;
  cout << b << endl << a[0].second;
  for (i = 1; i < t; i++) {
    bool n = 0;
    f = a[i].first, g = a[i].second;
    if (f == b)
      n = 1;
    if (n)
      cout << " " << g;
    else
      cout << endl << f << endl << g;
    b = f;
  }
  cout << endl;
  return 0;
}
Problem p00105 (C++)

Buggy submission (status: Runtime Error):
#define scanf_s scanf
// #define sscanf_s sscanf
// #define gets_s gets
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;
#define MAX 1001
#define _MAX 100
#define HO 6
int main(void) {
  char str[MAX];
  string word[_MAX];
  int pa[_MAX], rank[_MAX], cou, a;
  for (cou = 0; scanf_s("%s %d", str, MAX, &pa[cou]) != EOF; ++cou) {
    string wo(str);
    word[cou] = wo;
    rank[cou] = cou;
  }
  for (int i = 0; i < cou; ++i) {
    for (int j = cou - 1; j > i; --j) {
      if (word[rank[j]] <= word[rank[j - 1]]) {
        if (word[rank[j]] == word[rank[j - 1]]) {
          if (pa[rank[j]] < pa[rank[j - 1]]) {
            a = rank[j];
            rank[j] = rank[j - 1];
            rank[j - 1] = a;
          }
        } else {
          a = rank[j];
          rank[j] = rank[j - 1];
          rank[j - 1] = a;
        }
      }
    }
  }
  for (int i = 0; i < cou; ++i) {
    if (i == 0 || word[rank[i - 1]] != word[rank[i]])
      cout << word[rank[i]] << "\n";
    if (i != 0 && word[rank[i - 1]] == word[rank[i]])
      printf(" ");
    printf("%d", pa[rank[i]]);
    if (i != cou - 1 && word[rank[i + 1]] != word[rank[i]])
      printf("\n");
  }
  printf("\n");
}

Fixed submission:
#define scanf_s scanf
// #define sscanf_s sscanf
// #define gets_s gets
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;
#define MAX 1001
#define _MAX 100
#define HO 6
int main(void) {
  char str[MAX];
  string word[_MAX];
  int pa[_MAX], rank[_MAX], cou, a;
  for (cou = 0; scanf_s("%s %d", str, &pa[cou]) != EOF; ++cou) {
    string wo(str);
    word[cou] = wo;
    rank[cou] = cou;
  }
  for (int i = 0; i < cou; ++i) {
    for (int j = cou - 1; j > i; --j) {
      if (word[rank[j]] <= word[rank[j - 1]]) {
        if (word[rank[j]] == word[rank[j - 1]]) {
          if (pa[rank[j]] < pa[rank[j - 1]]) {
            a = rank[j];
            rank[j] = rank[j - 1];
            rank[j - 1] = a;
          }
        } else {
          a = rank[j];
          rank[j] = rank[j - 1];
          rank[j - 1] = a;
        }
      }
    }
  }
  for (int i = 0; i < cou; ++i) {
    if (i == 0 || word[rank[i - 1]] != word[rank[i]])
      cout << word[rank[i]] << "\n";
    if (i != 0 && word[rank[i - 1]] == word[rank[i]])
      printf(" ");
    printf("%d", pa[rank[i]]);
    if (i != cou - 1 && word[rank[i + 1]] != word[rank[i]])
      printf("\n");
  }
  printf("\n");
}
Problem p00105 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

int main() {
  std::string s;
  int p;
  std::map<std::string, std::vector<int>> m;
  while (std::cin >> s >> p, p != 0) {
    m[s].push_back(p);
  }
  std::map<std::string, std::vector<int>>::iterator m_it = m.begin();
  while (m_it != m.end()) {
    std::cout << (*m_it).first << std::endl;
    std::sort((*m_it).second.begin(), (*m_it).second.end());
    std::vector<int>::iterator v_it = (*m_it).second.begin();
    while (v_it != (*m_it).second.end()) {
      std::cout << *v_it;
      v_it++;
      (v_it == (*m_it).second.end()) ? std::cout << std::endl
                                     : std::cout << " ";
    }
    m_it++;
  }
  return 0;
}
/*
Sample Input
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18
Output for the Sample Input
document
13
easy
9
even
18 25
introduction
3
style
7 12 21
*/

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

int main() {
  std::string s;
  int p;
  std::map<std::string, std::vector<int>> m;
  while (std::cin >> s >> p, !std::cin.eof()) {
    m[s].push_back(p);
  }
  std::map<std::string, std::vector<int>>::iterator m_it = m.begin();
  while (m_it != m.end()) {
    std::cout << (*m_it).first << std::endl;
    std::sort((*m_it).second.begin(), (*m_it).second.end());
    std::vector<int>::iterator v_it = (*m_it).second.begin();
    while (v_it != (*m_it).second.end()) {
      std::cout << *v_it;
      v_it++;
      (v_it == (*m_it).second.end()) ? std::cout << std::endl
                                     : std::cout << " ";
    }
    m_it++;
  }
  return 0;
}
/*
Sample Input
style 12
even 25
introduction 3
easy 9
style 7
document 13
style 21
even 18
Output for the Sample Input
document
13
easy
9
even
18 25
introduction
3
style
7 12 21
*/
Problem p00105 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

int main() {
  std::string s;
  int p;
  std::map<std::string, std::vector<int>> m;
  while (std::cin >> s >> p, p != 0) {
    m[s].push_back(p);
  }
  std::map<std::string, std::vector<int>>::iterator m_it = m.begin();
  while (m_it != m.end()) {
    std::cout << (*m_it).first << std::endl;
    std::sort((*m_it).second.begin(), (*m_it).second.end());
    std::vector<int>::iterator v_it = (*m_it).second.begin();
    while (v_it != (*m_it).second.end()) {
      std::cout << *v_it;
      v_it++;
      (v_it == (*m_it).second.end()) ? std::cout << std::endl
                                     : std::cout << " ";
    }
    m_it++;
  }
  return 0;
}

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

int main() {
  std::string s;
  int p;
  std::map<std::string, std::vector<int>> m;
  while (std::cin >> s >> p, !std::cin.eof()) {
    m[s].push_back(p);
  }
  std::map<std::string, std::vector<int>>::iterator m_it = m.begin();
  while (m_it != m.end()) {
    std::cout << (*m_it).first << std::endl;
    std::sort((*m_it).second.begin(), (*m_it).second.end());
    std::vector<int>::iterator v_it = (*m_it).second.begin();
    while (v_it != (*m_it).second.end()) {
      std::cout << *v_it;
      v_it++;
      (v_it == (*m_it).second.end()) ? std::cout << std::endl
                                     : std::cout << " ";
    }
    m_it++;
  }
  return 0;
}
Problem p00107 (C++)

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

int main() {
  while (1) {
    int d, w, h;
    scanf("%d %d %d", &d, &w, &h);
    if (d == 0 && w == 0 && h == 0)
      break;
    int n;
    scanf("%d", &n);

    int max = (int)fmax((double)d, fmax((double)w, (double)h));
    double a = sqrt(d * d + w * w + h * h - max * max) / 2;

    int i;
    for (i = 0; i < 5; i++) {
      int b;
      scanf("%d", &b);
      // printf("a:%lf b:%d", a, b);
      if ((double)b <= a)
        printf("NA\n");
      else
        printf("OK\n");
    }
  }
  return 0;
}

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

int main() {
  while (1) {
    int d, w, h;
    scanf("%d %d %d", &d, &w, &h);
    if (d == 0 && w == 0 && h == 0)
      break;
    int n;
    scanf("%d", &n);

    int max = (int)fmax((double)d, fmax((double)w, (double)h));
    double a = sqrt(d * d + w * w + h * h - max * max) / 2;

    int i;
    for (i = 0; i < n; i++) {
      int b;
      scanf("%d", &b);
      // printf("a:%lf b:%d", a, b);
      if ((double)b <= a)
        printf("NA\n");
      else
        printf("OK\n");
    }
  }
  return 0;
}