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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <ostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define INF 1000000000
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rev(i, a, b) for (int i = (a)-1; i >= b; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef queue<int> qi;
typedef queue<pair<int, int>> qpii;
typedef vector<int> vi;
typedef vector<int, int> vii;
typedef vector<string> vs;
typedef vector<pair<int, int>> vpii;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

map<string, int> d;

void bfs() {
  int dn[4] = {4, -4, -1, 1};
  queue<string> qs;

  qs.push("01234567");
  d["01234567"] = 0;

  while (qs.size()) {
    string s = qs.front();
    qs.pop();
    int n = s.find("0");
    rep(i, 0, 4) {
      int ne = n + dn[i];
      if (0 <= ne && ne < 8) {
        if ((n == 4 && ne == 3) || (n == 3 && ne == 4))
          continue;
        string ss = s;

        char tmp = ss[n];
        ss[n] = ss[ne];
        ss[ne] = tmp;

        if (d.find(ss) == d.end()) {
          qs.push(ss);
          d[ss] = d[s] + 1;
        }
      }
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  bfs();

  while (1) {
    string in = "";
    char num;
    rep(i, 0, 8) {
      if (cin >> num)
        in += num;
      else
        break;
    }
    cout << d[in] << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <ostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define INF 1000000000
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rev(i, a, b) for (int i = (a)-1; i >= b; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef queue<int> qi;
typedef queue<pair<int, int>> qpii;
typedef vector<int> vi;
typedef vector<int, int> vii;
typedef vector<string> vs;
typedef vector<pair<int, int>> vpii;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

map<string, int> d;

void bfs() {
  int dn[4] = {4, -4, -1, 1};
  queue<string> qs;

  qs.push("01234567");
  d["01234567"] = 0;

  while (qs.size()) {
    string s = qs.front();
    qs.pop();
    int n = s.find("0");
    rep(i, 0, 4) {
      int ne = n + dn[i];
      if (0 <= ne && ne < 8) {
        if ((n == 4 && ne == 3) || (n == 3 && ne == 4))
          continue;
        string ss = s;

        char tmp = ss[n];
        ss[n] = ss[ne];
        ss[ne] = tmp;

        if (d.find(ss) == d.end()) {
          qs.push(ss);
          d[ss] = d[s] + 1;
        }
      }
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  bfs();

  while (1) {
    string in = "";
    char num;
    rep(i, 0, 8) {
      if (cin >> num)
        in += num;
      else
        return 0;
    }
    cout << d[in] << endl;
  }

  return 0;
}
Problem p00123 (C++)

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

using namespace std;

int main() {
  double t1, t2;
  while (scanf("%lf %lf\n", &t1, &t2) != EOF) {
    printf("%lf %lf\n", t1, t2);
    const double bound_1[7] = {35.5, 37.5, 40, 43, 50, 55, 70};
    const double bound_2[7] = {71, 77, 83, 89, 105, 116, 148};
    const string c[7] = {"AAA", "AA", "A", "B", "C", "D", "E"};
    int i = 0, num;
    while (1) {
      if (t1 < bound_1[i] && t2 < bound_2[i]) {
        cout << c[i] << endl;
        break;
      }
      if (i > 7) {
        printf("NA\n");
        break;
      }
      i++;
    }
    /* for( int i = 0; i < 7; i++ )
    {
        if( t1 > bound_1[i] )
        {
            num1 = i;
        }
        if( t2 > bound_2[i] )
        {
            num2 = i;
        }
    } */
  }
  return 0;
}


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

using namespace std;

int main() {
  double t1, t2;
  while (scanf("%lf %lf\n", &t1, &t2) != EOF) {
    const double bound_1[100] = {35.5, 37.5, 40, 43, 50, 55, 70};
    const double bound_2[100] = {71, 77, 83, 89, 105, 116, 148};
    const string c[100] = {"AAA", "AA", "A", "B", "C", "D", "E"};
    int i = 0, num;
    while (1) {
      if (t1 < bound_1[i] && t2 < bound_2[i]) {
        cout << c[i] << endl;
        break;
      }
      if (i > 7) {
        printf("NA\n");
        break;
      }
      i++;
    }
    /* for( int i = 0; i < 7; i++ )
    {
        if( t1 > bound_1[i] )
        {
            num1 = i;
        }
        if( t2 > bound_2[i] )
        {
            num2 = i;
        }
    } */
  }
  return 0;
}
Problem p00123 (C++)

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

int main(void) {
  double a, b;
  while (scanf("%lf%lf", &a, &b)) {
    if (a < 35.5 && b < 71)
      printf("AAA\n");
    else if (a < 37.5 && b < 77)
      printf("AA\n");
    else if (a < 40 && b < 83)
      printf("A\n");
    else if (a < 43 && b < 89)
      printf("B\n");
    else if (a < 50 && b < 105)
      printf("C\n");
    else if (a < 55 && b < 116)
      printf("D\n");
    else if (a < 70 && b < 148)
      printf("E\n");
    else
      printf("NA\n");
  }
  return 0;
}

Fixed submission:
#include <stdio.h>

int main(void) {
  double a, b;
  while (scanf("%lf%lf", &a, &b) != EOF) {
    if (a < 35.5 && b < 71)
      printf("AAA\n");
    else if (a < 37.5 && b < 77)
      printf("AA\n");
    else if (a < 40 && b < 83)
      printf("A\n");
    else if (a < 43 && b < 89)
      printf("B\n");
    else if (a < 50 && b < 105)
      printf("C\n");
    else if (a < 55 && b < 116)
      printf("D\n");
    else if (a < 70 && b < 148)
      printf("E\n");
    else
      printf("NA\n");
  }
  return 0;
}
Problem p00123 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
int main() {
  float hideo, ruio;
  while (scanf("%f %f", &hideo, &ruio)) {
    if (hideo < 35.50 && ruio < 71.00) {
      printf("AAA\n");
    } else if (hideo < 37.50 && ruio < 77.00) {
      printf("AA\n");
    } else if (hideo < 40.00 && ruio < 83.00) {
      printf("A\n");
    } else if (hideo < 43.00 && ruio < 89.00) {
      printf("B\n");
    } else if (hideo < 50.00 && ruio < 105.00) {
      printf("C\n");
    } else if (hideo < 55.00 && ruio < 116.00) {
      printf("D\n");
    } else if (hideo < 70.00 && ruio < 148.00) {
      printf("E\n");
    } else {
      printf("NA\n");
    }
  }
  return 0;
}

Fixed submission:
#include <stdio.h>
int main() {
  float hideo, ruio;
  while (scanf("%f %f", &hideo, &ruio) != EOF) {
    if (hideo < 35.50 && ruio < 71.00) {
      printf("AAA\n");
    } else if (hideo < 37.50 && ruio < 77.00) {
      printf("AA\n");
    } else if (hideo < 40.00 && ruio < 83.00) {
      printf("A\n");
    } else if (hideo < 43.00 && ruio < 89.00) {
      printf("B\n");
    } else if (hideo < 50.00 && ruio < 105.00) {
      printf("C\n");
    } else if (hideo < 55.00 && ruio < 116.00) {
      printf("D\n");
    } else if (hideo < 70.00 && ruio < 148.00) {
      printf("E\n");
    } else {
      printf("NA\n");
    }
  }
  return 0;
}
Problem p00123 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define INF 114514
using namespace std;

int main() {
  double fh, om;
  while (scanf("%lf %lf", &fh, &om)) {
    if (fh < 35.5 && om < 71.0) {
      puts("AAA");
    } else if (fh < 37.5 && om < 77.0) {
      puts("AA");
    } else if (fh < 40.0 && om < 83.0) {
      puts("A");
    } else if (fh < 43.0 && om < 89.0) {
      puts("B");
    } else if (fh < 50.0 && om < 105.0) {
      puts("C");
    } else if (fh < 55.0 && om < 116.0) {
      puts("D");
    } else if (fh < 70.0 && om < 148.0) {
      puts("E");
    } else {
      puts("NA");
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define INF 114514
using namespace std;

int main() {
  double fh, om;
  while (cin >> fh >> om) {
    if (fh < 35.5 && om < 71.0) {
      puts("AAA");
    } else if (fh < 37.5 && om < 77.0) {
      puts("AA");
    } else if (fh < 40.0 && om < 83.0) {
      puts("A");
    } else if (fh < 43.0 && om < 89.0) {
      puts("B");
    } else if (fh < 50.0 && om < 105.0) {
      puts("C");
    } else if (fh < 55.0 && om < 116.0) {
      puts("D");
    } else if (fh < 70.0 && om < 148.0) {
      puts("E");
    } else {
      puts("NA");
    }
  }
  return 0;
}
Problem p00124 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string>
using namespace std;
string a[10];
int p[10];
int main() {
  int n, b, z, c;
  bool first = true;
  while (true) {
    cin >> n;
    if (!first)
      cout << endl;
    first = false;
    for (int i = 0; i < n; i++) {
      cin >> a[i] >> b >> z >> c;
      p[i] = b * 3 + c * 1;
    }
    for (int i = 0; i < n - 1; i++) {
      for (int j = n - 1; j > i; j--) {
        if (p[j] > p[j - 1]) {
          string tmps = a[j];
          a[j] = a[j - 1];
          a[j - 1] = tmps;
          int tmp = p[j];
          p[j] = p[j - 1];
          p[j - 1] = tmp;
        }
      }
    }
    for (int i = 0; i < n; i++)
      cout << a[i] << "," << p[i] << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
string a[10];
int p[10];
int main() {
  int n, b, z, c;
  bool first = true;
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    if (!first)
      cout << endl;
    first = false;
    for (int i = 0; i < n; i++) {
      cin >> a[i] >> b >> z >> c;
      p[i] = b * 3 + c * 1;
    }
    for (int i = 0; i < n - 1; i++) {
      for (int j = n - 1; j > i; j--) {
        if (p[j] > p[j - 1]) {
          string tmps = a[j];
          a[j] = a[j - 1];
          a[j - 1] = tmps;
          int tmp = p[j];
          p[j] = p[j - 1];
          p[j - 1] = tmp;
        }
      }
    }
    for (int i = 0; i < n; i++)
      cout << a[i] << "," << p[i] << endl;
  }
  return 0;
}
Problem p00127 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s, r;
  int i;
  const char *a[7] = {
      "afkpuz", "bglqv.", "chmrw?", "dinsx!", "ejoty ",
  };
  while (cin >> s) {
    r = "";
    for (i = 0; i + 1 < s.size(); i += 2) {
      if (s[i] > '6' || s[i + 1] > '5')
        break;
      r += a[s[i + 1] - '1'][s[i] - '1'];
    }
    if (i != s.size())
      cout << "NA" << endl;
    else
      cout << r << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s, r;
  int i;
  const char *a[7] = {
      "afkpuz", "bglqv.", "chmrw?", "dinsx!", "ejoty ",
  };
  while (cin >> s) {
    r = "";
    for (i = 0; i + 1 < s.size(); i += 2) {
      if (s[i] > '6' || s[i + 1] > '5' || s[i] < '1' || s[i + 1] < '1')
        break;
      r += a[s[i + 1] - '1'][s[i] - '1'];
    }
    if (i != s.size())
      cout << "NA" << endl;
    else
      cout << r << endl;
  }
  return 0;
}
Problem p00127 (C++)

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

using namespace std;

int main(void) {
  string str;

  string hyo[] = {"abcde", "fghij", "klmno", "pqrst", "uvwxy", "z.?! "};

  while (cin >> str) {
    if (str.size() % 2) {
      cout << "NA" << endl;
      continue;
    }

    string out = "";

    for (int i = 0, len = str.size(); i < len; i += 2) {
      int x, y;

      y = str[i] - '1';
      x = str[i + 1] - '1';

      out += hyo[y][x];
    }

    cout << out << endl;
  }

  return 0;
}

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

using namespace std;

int main(void) {
  string str;

  string hyo[] = {"abcde", "fghij", "klmno", "pqrst", "uvwxy", "z.?! "};

  while (cin >> str) {
    if (str.size() % 2) {
      cout << "NA" << endl;
      continue;
    }

    string out = "";

    for (int i = 0, len = str.size(); i < len; i += 2) {
      int x, y;

      y = str[i] - '1';
      x = str[i + 1] - '1';

      if (0 > x || x > 4 || 0 > y || y > 5) {
        out = "NA";
        break;
      }

      out += hyo[y][x];
    }

    cout << out << endl;
  }

  return 0;
}
Problem p00127 (C++)

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

const string hyou[] = {"afkpuz", "bglqv.", "chmrw?", "dinsx!", "ejoty "};
int main() {
  string in;
  while (cin >> in) {
    cin.ignore();
    if (in.size() % 2 == 1) {
      cout << "NA" << endl;
      continue;
    }
    bool flag = true;
    string ans = "";
    for (int i = 0; i < in.size() - 1; i += 2) {
      if (!('1' <= in[i + 1] && in[i + 1] <= '6') ||
          !('1' <= in[i] && in[i] <= '5')) {
        flag = false;
        break;
      }
      ans += hyou[in[i + 1] - '0' - 1][in[i] - '0' - 1];
    }
    if (flag)
      cout << ans << endl;
    else
      cout << "NA" << endl;
  }
  return 0;
}

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

const string hyou[] = {"afkpuz", "bglqv.", "chmrw?", "dinsx!", "ejoty "};
int main() {
  string in;
  while (cin >> in) {
    cin.ignore();
    if (in.size() % 2 == 1) {
      cout << "NA" << endl;
      continue;
    }
    bool flag = true;
    string ans = "";
    for (int i = 0; i < in.size() - 1; i += 2) {
      if (!('1' <= in[i + 1] && in[i + 1] <= '5') ||
          !('1' <= in[i] && in[i] <= '6')) {
        flag = false;
        break;
      }
      ans += hyou[in[i + 1] - '0' - 1][in[i] - '0' - 1];
    }
    if (flag)
      cout << ans << endl;
    else
      cout << "NA" << endl;
  }
  return 0;
}
Problem p00127 (C++)

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

int main() {
  string str;
  vector<string> vs = {"abcde", "fghij", "klmno", "pqrst", "uvwxy", "z.?! "};
  while (cin >> str) {
    if (str.size() % 2) {
      cout << "NA" << endl;
      continue;
    }
    string ans;
    for (int i = 0; i < str.size(); i += 2) {
      int a = str[i] - '0' - 1;
      int b = str[i + 1] - '0' - 1;

      if (a < 6 && b < 5) {
        ans += vs[a][b];
      } else {
        ans = "NA";
        break;
      }
    }

    cout << ans << endl;
  }

  return 0;
}

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

int main() {
  string str;
  vector<string> vs = {"abcde", "fghij", "klmno", "pqrst", "uvwxy", "z.?! "};
  while (cin >> str) {
    if (str.size() % 2) {
      cout << "NA" << endl;
      continue;
    }
    string ans;
    for (int i = 0; i < str.size(); i += 2) {
      int a = str[i] - '0' - 1;
      int b = str[i + 1] - '0' - 1;

      if (0 <= a && a < 6 && 0 <= b && b < 5) {
        ans += vs[a][b];
      } else {
        ans = "NA";
        break;
      }
    }

    cout << ans << endl;
  }

  return 0;
}
Problem p00127 (C++)

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctype.h>
#include <exception>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)

using namespace std;
typedef long long int lint;

vector<string> keys;
vector<char> vals;
map<string, char> encoder;

bool AOJ0127() {
  string str, ret;
  cin >> str;

  if (str.size() % 2) {
    cout << "NA" << endl;
    return true;
  }

  REP(i, str.size() / 2) {
    string buf = str.substr(2 * i, 2);
    if (encoder.find(buf) == encoder.end()) {
      cout << "NA" << endl;
      return true;
    }
    ret.push_back(encoder[buf]);
  }
  cout << ret << endl;

  return true;
}

int main() {
  FOR(i, 1, 7) {
    FOR(j, 1, 6) {
      string key;
      key.push_back('0' + i);
      key.push_back('0' + j);
      keys.push_back(key);
    }
  }

  for (char c = 'a'; c <= 'z'; c++) {
    vals.push_back(c);
  }
  vals.push_back('.');
  vals.push_back('?');
  vals.push_back('!');
  vals.push_back(' ');

  REP(i, keys.size()) { encoder[keys[i]] = vals[i]; }

  while (AOJ0127()) {
  }

  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctype.h>
#include <exception>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)

using namespace std;
typedef long long int lint;

vector<string> keys;
vector<char> vals;
map<string, char> encoder;

bool AOJ0127() {
  string str, ret;
  if (!(cin >> str))
    return false;

  if (str.size() % 2) {
    cout << "NA" << endl;
    return true;
  }

  REP(i, str.size() / 2) {
    string buf = str.substr(2 * i, 2);
    if (encoder.find(buf) == encoder.end()) {
      cout << "NA" << endl;
      return true;
    }
    ret.push_back(encoder[buf]);
  }
  cout << ret << endl;

  return true;
}

int main() {
  FOR(i, 1, 7) {
    FOR(j, 1, 6) {
      string key;
      key.push_back('0' + i);
      key.push_back('0' + j);
      keys.push_back(key);
    }
  }

  for (char c = 'a'; c <= 'z'; c++) {
    vals.push_back(c);
  }
  vals.push_back('.');
  vals.push_back('?');
  vals.push_back('!');
  vals.push_back(' ');

  REP(i, keys.size()) { encoder[keys[i]] = vals[i]; }

  while (AOJ0127()) {
  }

  return 0;
}
Problem p00127 (C++)

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

int main() {
  string map[6];
  map[0] = "abcde";
  map[1] = "fghij";
  map[2] = "klmno";
  map[3] = "pqrst";
  map[4] = "uvwxy";
  map[5] = "z.?! ";
  string str;
  while (cin >> str) {
    int num[1000] = {0};
    int len = str.size();
    if (len % 2 == 1) {
      cout << "NA" << endl;
      continue;
    }
    for (int i = 0; i < len; i += 2) {
      for (int j = i; j < i + 2; j++) {
        string tmp = "";
        tmp += str[j];
        istringstream ss(tmp);
        ss >> num[j];
        // cout << num[j] << endl;
      }
    }
    for (int i = 0; i < len; i += 2) {
      cout << map[num[i] - 1][num[i + 1] - 1];
    }
    cout << endl;
  }
}

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

int main() {
  string map[6];
  map[0] = "abcde";
  map[1] = "fghij";
  map[2] = "klmno";
  map[3] = "pqrst";
  map[4] = "uvwxy";
  map[5] = "z.?! ";
  string str;
  while (cin >> str) {
    int num[1000] = {0};
    int len = str.size();
    bool flag = false;
    for (int i = 0; i < len; i += 2) {
      if (str[i] <= '0' || str[i] > '6') {
        flag = true;
        break;
      } else if (str[i + 1] <= '0' || str[i + 1] > '5') {
        flag = true;
        break;
      }
    }
    if (len % 2 == 1 || flag) {
      cout << "NA" << endl;
      continue;
    }
    for (int i = 0; i < len; i += 2) {
      for (int j = i; j < i + 2; j++) {
        string tmp = "";
        tmp += str[j];
        istringstream ss(tmp);
        ss >> num[j];
        // cout << num[j] << endl;
      }
    }
    for (int i = 0; i < len; i += 2) {
      cout << map[num[i] - 1][num[i + 1] - 1];
    }
    cout << endl;
  }
}
Problem p00128 (C++)

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

int main() {
  string s;
  string soro[10] = {"* = ****", "* =* ***", "* =** **", "* =*** *",
                     "* =**** ", " *= ****", " *=* ***", " *=** **",
                     " *=*** *", " *=**** "};
  bool flag = true;
  while (cin >> s) {
    vector<char> c;
    for (int i = 0; i < s.size(); i++) {
      c.push_back('0');
    }
    for (int i = 0; i < s.size(); i++) {
      c.push_back(s[i]);
    }
    if (flag) {
      flag = false;
    } else {
      cout << endl;
    }

    for (int i = 0; i < 8; i++) {
      for (int j = 0; j < 5; j++) {
        cout << soro[c[j] - '0'][i];
      }
      cout << endl;
    }
  }
  return 0;
}


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

int main() {
  string s;
  string soro[10] = {"* = ****", "* =* ***", "* =** **", "* =*** *",
                     "* =**** ", " *= ****", " *=* ***", " *=** **",
                     " *=*** *", " *=**** "};
  bool flag = true;
  while (cin >> s) {
    vector<char> c;
    for (int i = 0; i < 5 - s.size(); i++) {
      c.push_back('0');
    }
    for (int i = 0; i < s.size(); i++) {
      c.push_back(s[i]);
    }
    if (flag) {
      flag = false;
    } else {
      cout << endl;
    }

    for (int i = 0; i < 8; i++) {
      for (int j = 0; j < 5; j++) {
        cout << soro[c[j] - '0'][i];
      }
      cout << endl;
    }
  }
  return 0;
}
Problem p00128 (C++)

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

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)
#define rreps(v, f, l) for (int v = (l), v##_ = (f); v >= v##_; --v)
#define rrep(v, n) rreps(v, 0, n - 1)
#define rlep(v, n) rreps(v, 1, n)
#define show_a(a, size)                                                        \
  rep(a##_it, size) std::cout << a[a##_it] << " \n"[a##_it == a##_it_ - 1];
#define show_v(v) show_a(v, v.size())
#define debug(x) std::cerr << #x << " = " << (x) << "\n";

using namespace std;

typedef long long int lint;

static inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
static inline lint inl() {
  lint x;
  scanf("%lld", &x);
  return x;
}

int main() {
  bool is_first = true;
  int n;
  while (~scanf("%d", &n)) {
    if (is_first)
      is_first = false;
    else
      puts("");
    char snum[8];
    sprintf(snum, "%05d", n);
    debug(snum);
    rep(i, 5) printf("%c", " *"[snum[i] < '5']);
    puts("");
    rep(i, 5) printf("%c", "* "[snum[i] < '5']);
    puts("");
    puts("=====");
    rep(i, 5) {
      rep(j, 5) { printf("%c", " *"[i != (snum[j] - '0') % 5]); }
      puts("");
    }
  }
  return (0);
}

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

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)
#define rreps(v, f, l) for (int v = (l), v##_ = (f); v >= v##_; --v)
#define rrep(v, n) rreps(v, 0, n - 1)
#define rlep(v, n) rreps(v, 1, n)
#define show_a(a, size)                                                        \
  rep(a##_it, size) std::cout << a[a##_it] << " \n"[a##_it == a##_it_ - 1];
#define show_v(v) show_a(v, v.size())
#define debug(x) std::cerr << #x << " = " << (x) << "\n";

using namespace std;

typedef long long int lint;

static inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
static inline lint inl() {
  lint x;
  scanf("%lld", &x);
  return x;
}

int main() {
  bool is_first = true;
  int n;
  while (~scanf("%d", &n)) {
    if (is_first)
      is_first = false;
    else
      puts("");
    char snum[8];
    sprintf(snum, "%05d", n);
    rep(i, 5) printf("%c", " *"[snum[i] < '5']);
    puts("");
    rep(i, 5) printf("%c", "* "[snum[i] < '5']);
    puts("");
    puts("=====");
    rep(i, 5) {
      rep(j, 5) { printf("%c", " *"[i != (snum[j] - '0') % 5]); }
      puts("");
    }
  }
  return (0);
}
Problem p00128 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int i, j = 0, n[5];
  string s;
  char x[5], l[2] = {' ', '*'};
  while (cin >> i) {
    if (j)
      cout << endl;
    sprintf(x, "%05d", i);
    for (j = 5; j-- > 0;)
      n[j] = x[j] - '0';
    s = "";
    while (j++ < 1) {
      for (i = 0; i < 5; i++)
        s += l[j + (n[i] < 5) & 1];
      s += "\n";
    }
    for (j = 5; j-- > 0;)
      s += "=";
    s += "\n";
    while (j++ < 4) {
      for (i = 0; i < 5; i++)
        s += l[n[i] % 5 != j];
      s += "\n";
    }
    cout << s;
  }
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int i, j = 0, n[5];
  string s, l[2] = {" ", "*"};
  char x[6];
  while (cin >> i) {
    if (j)
      cout << endl;
    sprintf(x, "%05d", i);
    for (j = 5; j-- > 0;)
      n[j] = x[j] - '0';
    s = "";
    while (j++ < 1) {
      for (i = 0; i < 5; i++)
        s += l[j + (n[i] < 5) & 1];
      s += "\n";
    }
    for (j = 5; j-- > 0;)
      s += "=";
    s += "\n";
    while (j++ < 4) {
      for (i = 0; i < 5; i++)
        s += l[n[i] % 5 != j];
      s += "\n";
    }
    cout << s;
  }
  return 0;
}
Problem p00129 (C++)

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

struct Wall {
  int x, y, r;
};

bool inside(Wall w, double x, double y) {
  return w.r * w.r >= (w.x - x) * (w.x - x) + (w.y - y) * (w.y - y);
}

int main() {
  int n, wx, wy, r, m, tx, ty, sx, sy;
  while (cin >> n, n) {
    vector<Wall> w;
    for (int i = 0; i < n; ++i) {
      cin >> wx >> wy >> r;
      w.push_back((Wall){wx, wy, r});
    }
    cin >> m;
    for (int i = 0; i < m; ++i) {
      cin >> tx >> ty >> sx >> sy;
      bool safe = false;
      for (int j = 0; j < n && !safe; ++j) {
        int k = inside(w[j], tx, ty) + inside(w[j], sx, sy);
        if (k == 0) {
          double dx, dy, x, y, minx, maxx, miny, maxy;
          dx = (sx - tx) / 100000.0;
          dy = (sy - ty) / 100000.0;
          x = tx;
          y = ty;
          minx = min(sx, tx);
          maxx = max(sx, tx);
          miny = min(sy, ty);
          maxy = max(sy, ty);
          while (!safe && minx <= x && x <= maxx && miny <= y && y <= maxy) {
            if (inside(w[j], x, y)) {
              safe = true;
              break;
            }
            x += dx;
            y += dy;
          }
        } else if (k == 1) {
          safe = true;
        }
      }
      cout << (safe ? "Safe" : "Danger") << endl;
    }
  }
  return 0;
}

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

struct Wall {
  int x, y, r;
};

bool inside(Wall w, double x, double y) {
  return w.r * w.r >= (w.x - x) * (w.x - x) + (w.y - y) * (w.y - y);
}

int main() {
  int n, wx, wy, r, m, tx, ty, sx, sy;
  while (cin >> n, n) {
    vector<Wall> w;
    for (int i = 0; i < n; ++i) {
      cin >> wx >> wy >> r;
      w.push_back((Wall){wx, wy, r});
    }
    cin >> m;
    for (int i = 0; i < m; ++i) {
      cin >> tx >> ty >> sx >> sy;
      bool safe = false;
      for (int j = 0; j < n && !safe; ++j) {
        int k = inside(w[j], tx, ty) + inside(w[j], sx, sy);
        if (k == 0) {
          double dx, dy, x, y, minx, maxx, miny, maxy;
          dx = (sx - tx) / 10000.0;
          dy = (sy - ty) / 10000.0;
          x = tx;
          y = ty;
          minx = min(sx, tx);
          maxx = max(sx, tx);
          miny = min(sy, ty);
          maxy = max(sy, ty);
          while (!safe && minx <= x && x <= maxx && miny <= y && y <= maxy) {
            if (inside(w[j], x, y)) {
              safe = true;
              break;
            }
            x += dx;
            y += dy;
          }
        } else if (k == 1) {
          safe = true;
        }
      }
      cout << (safe ? "Safe" : "Danger") << endl;
    }
  }
  return 0;
}
Problem p00130 (C++)

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define COUNT(i, n) for (int i = 1; i <= n; i++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for (ITER(c) it = (c).begin(); it != (c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))

using namespace std;

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

const int INF = 1 << 24;

int main(void) {
  int n;
  cin >> n;

  while (n--) {
    string in, res;
    cin >> in;
    res = in.at(0);

    COUNT(i, in.size() - 3) {
      i += 2;
      string cur = in.substr(i, 1);

      if (~res.find(cur))
        continue;
      switch (in.at(i - 2)) {
      case '-':
        res = res + cur;
        break;
      case '<':
        res = cur + res;
        break;
      }
    }
    cout << res << endl;
  }

  return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define COUNT(i, n) for (int i = 1; i <= n; i++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for (ITER(c) it = (c).begin(); it != (c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))

using namespace std;

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

const int INF = 1 << 24;

int main(void) {
  int n;
  cin >> n;

  while (n--) {
    string in, res;
    cin >> in;
    res = in.at(0);

    for (int i = 3; i < in.size(); i += 3) {
      string cur = in.substr(i, 1);

      if (~res.find(cur))
        continue;
      switch (in.at(i - 2)) {
      case '-':
        res = res + cur;
        break;
      case '<':
        res = cur + res;
        break;
      }
    }
    cout << res << endl;
  }

  return 0;
}
Problem p00134 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int n, s[1000], i, j, b;
  long long int av = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> s[i];
    av = s[i] + av;
  }
  cout << av / n << endl;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n, i, b, s[100010];
  long long int av = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> s[i];
    av = s[i] + av;
  }
  cout << av / n << endl;
}
Problem p00135 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int a, b, n;
double d, e, f;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d:%d", a, b);
    d = b * 6;
    e = 1.0 * (a * 30 + b) / 2.0;
    f = abs(d - e);
    if (f > 180) {
      f = 360 - f;
    }
    if (f < 30) {
      cout << "alert" << endl;
    } else if (f < 90) {
      cout << "warning" << endl;
    } else {
      cout << "safe" << endl;
    }
  }
}

Fixed submission:
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int a, b, n;
double d, e, f;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d:%d", &a, &b);
    f = abs(a * 30 - b * 11.0 / 2.0);
    if (f > 180) {
      f = 360 - f;
    }
    if (f < 30) {
      cout << "alert" << endl;
    } else if (f < 90) {
      cout << "warning" << endl;
    } else {
      cout << "safe" << endl;
    }
  }
}
Problem p00137 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main() {
  long n, m, i, j;
  string s, t;
  stringstream ss;
  string::size_type k;
  char mm[9];
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> m;
    cout << "Case " << i + 1 << ":" << endl;
    for (j = 0; j < 10; j++) {
      sprintf(mm, "%08d", m * m);
      s = string(mm);
      t = s.substr(2, 4);
      k = t.find_first_not_of('0');
      cout << t.substr(k) << endl;
      ss.str("");
      ss.clear();
      ss << t;
      ss >> m;
    }
  }
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main() {
  long n, m, i, j;
  string s, t;
  stringstream ss;
  string::size_type k;
  char mm[9];
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> m;
    cout << "Case " << i + 1 << ":" << endl;
    for (j = 0; j < 10; j++) {
      sprintf(mm, "%08d", m * m);
      s = string(mm);
      t = s.substr(2, 4);
      k = t.find_first_not_of('0');
      if (k == string::npos)
        cout << '0' << endl;
      else
        cout << t.substr(k) << endl;
      ss.str("");
      ss.clear();
      ss << t;
      ss >> m;
    }
  }
  return 0;
}
Problem p00138 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

typedef long long ll;
const double Eps = 1e-6;

using namespace std;

int main() {
  pair<double, int> runners[24];
  for (int i = 0; i < 24; ++i) {
    int a;
    double b;
    scanf("%d %lf", &a, &b);
    runners[i] = make_pair(b, a);
  }
  for (int i = 0; i < 3; ++i) {
    sort(runners + i * 8, runners + 8 + i * 8);
    printf("%d %.2f\n", runners[0 + i * 8].second, runners[0 + i * 8]);
    printf("%d %.2f\n", runners[1 + i * 8].second, runners[1 + i * 8]);
    runners[0 + i * 8].first = runners[1 + i * 8].first = 1e10;
  }
  sort(runners, runners + 24);
  printf("%d %.2f\n", runners[0].second, runners[0].first);
  printf("%d %.2f\n", runners[1].second, runners[1].first);

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

typedef long long ll;
const double Eps = 1e-6;

using namespace std;

int main() {
  pair<double, int> runners[24];
  for (int i = 0; i < 24; ++i) {
    int a;
    double b;
    scanf("%d %lf", &a, &b);
    runners[i] = make_pair(b, a);
  }
  for (int i = 0; i < 3; ++i) {
    sort(runners + i * 8, runners + 8 + i * 8);
    printf("%d %.2f\n", runners[0 + i * 8].second, runners[0 + i * 8].first);
    printf("%d %.2f\n", runners[1 + i * 8].second, runners[1 + i * 8].first);
    runners[0 + i * 8].first = runners[1 + i * 8].first = 1e10;
  }
  sort(runners, runners + 24);
  printf("%d %.2f\n", runners[0].second, runners[0].first);
  printf("%d %.2f\n", runners[1].second, runners[1].first);

  return 0;
}
Problem p00140 (C++)

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

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define PB push_back
#define p(a, b) g.PB(pii(a, b))
#define INF (1 << 29)

typedef pair<int, int> pii;
typedef vector<pii> vp;

int main() {
  vp g; // pos to
  REP(i, 9) p(i, i + 1);
  p(9, 10);
  REP(i, 4) p(5 - i, i + 11);
  p(1, 0);

  int n;
  cin >> n;
  while (n--) {
    int prev[2][10], miner[2], tmp[2];
    int a, b;
    scanf("%d %d", &a, &b);

    tmp[0] = tmp[1] = INF;
    REP(i, g.size()) if (g[i].first == a) {
      if (tmp[0] == INF)
        tmp[0] = i;
      else
        tmp[1] = i;
    }

    miner[0] = miner[1] = INF;
    REP(i, 2) {
      if (tmp[i] == INF)
        break;

      queue<int> que; // pos
      que.push(tmp[i]);

      miner[i] = 0;
      while (true) {
        int pos = g[que.front()].first;
        int to = g[que.front()].second;
        que.pop();

        prev[i][miner[i]++] = pos;
        if (pos == b)
          break;

        que.push(to);
      }
    }

    int ans = miner[0] < miner[1] ? 0 : 1;
    REP(i, miner[ans]) {
      if (i != 0)
        printf(" ");
      printf("%d", prev[ans][i]);
    }
    cout << endl;
  }
  return 0;
}

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

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define PB push_back
#define p(a, b) g.PB(pii(a, b))
#define INF (1 << 29)

typedef pair<int, int> pii;
typedef vector<pii> vp;

int main() {
  vp g; // pos to
  REP(i, 9) p(i, i + 1);
  p(9, 10);
  REP(i, 4) p(5 - i, i + 11);
  p(1, 0);

  int n;
  cin >> n;
  while (n--) {
    int prev[2][20], miner[2], tmp[2];
    int a, b;
    scanf("%d %d", &a, &b);

    tmp[0] = tmp[1] = INF;
    REP(i, g.size()) if (g[i].first == a) {
      if (tmp[0] == INF)
        tmp[0] = i;
      else
        tmp[1] = i;
    }

    miner[0] = miner[1] = INF;
    REP(i, 2) {
      if (tmp[i] == INF)
        break;

      queue<int> que; // pos
      que.push(tmp[i]);

      miner[i] = 0;
      while (true) {
        int pos = g[que.front()].first;
        int to = g[que.front()].second;
        que.pop();

        prev[i][miner[i]++] = pos;
        if (pos == b)
          break;

        que.push(to);
      }
    }

    int ans = miner[0] < miner[1] ? 0 : 1;
    REP(i, miner[ans]) {
      if (i != 0)
        printf(" ");
      printf("%d", prev[ans][i]);
    }
    cout << endl;
  }
  return 0;
}
Problem p00140 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(), x.end()
#define mp make_pair
#define pb push_back

#define INF 1000010

using namespace std;

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

int main() {
  int n;
  cin >> n;
  for (int k = 0; k < n; k++) {

    int e1, e2;
    bool isFirst = false;
    cin >> e1 >> e2;

    if (e1 > e2)
      isFirst = true;

    for (int i = 0;; i++) {
      if (busstop[i] == e1) {
        if (isFirst) {
          isFirst = !isFirst;
          continue;
        }
        for (int j = i;; j++) {
          if (busstop[j] == e2) {
            cout << " " << busstop[j];
            goto end_state;
          } else {
            if (j == i)
              cout << busstop[j];
            else
              cout << " " << busstop[j];
          }
        }
      }
    }
  end_state:
    cout << endl;
  }
}

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

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(), x.end()
#define mp make_pair
#define pb push_back

#define INF 1000010

using namespace std;

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

int main() {
  int n;
  cin >> n;
  for (int k = 0; k < n; k++) {

    int e1, e2;
    bool isFirst = false;
    cin >> e1 >> e2;

    if (e1 > e2)
      isFirst = true;

    for (int i = 0;; i++) {
      if (busstop[i] == e1) {
        if (isFirst) {
          isFirst = !isFirst;
          continue;
        }
        for (int j = i;; j++) {
          if (busstop[j] == e2) {
            cout << " " << busstop[j];
            goto end_state;
          } else {
            if (j == i)
              cout << busstop[j];
            else
              cout << " " << busstop[j];
          }
        }
      }
    }
  end_state:
    cout << endl;
  }
}
Problem p00140 (C++)

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

using namespace std;

int main() {

  int n;

  int a, b;

  cin >> n;

  for (int loop = 0; loop < n; loop++) {
    cin >> a >> b;
    if (a == b) {
      printf("%d\n", b);
    } else if (a < b) {
      for (int i = a; i < b; i++) {
        printf("%d ", i);
      }
      printf("%d\n", b);
    } else if (a <= 5) {
      for (int i = a; i > b; i--) {
        printf("%d ", i);
      }
      printf("%d\n", b);
    } else if (b <= 5) {
      for (int i = a; i <= 9; i++) {
        printf("%d ", i);
      }
      for (int i = 5; i > b; i++) {
        printf("%d ", i);
      }
      printf("%d\n", b);
    } else {
      for (int i = a; i <= 9; i++) {
        printf("%d ", i);
      }
      printf("5 4 3 2 1 0 1 2 3 4 5 ");
      for (int i = 6; i < b; i++) {
        printf("%d ", i);
      }
      printf("%d\n", b);
    }
  }

  return 0;
}

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

using namespace std;

int main() {

  int n;

  int a, b;

  cin >> n;

  for (int loop = 0; loop < n; loop++) {
    cin >> a >> b;
    if (a == b) {
      printf("%d\n", b);
    } else if (a < b) {
      for (int i = a; i < b; i++) {
        printf("%d ", i);
      }
      printf("%d\n", b);
    } else if (a <= 5) {
      for (int i = a; i > b; i--) {
        printf("%d ", i);
      }
      printf("%d\n", b);
    } else if (b <= 5) {
      for (int i = a; i <= 9; i++) {
        printf("%d ", i);
      }
      for (int i = 5; i > b; i--) {
        printf("%d ", i);
      }
      printf("%d\n", b);
    } else {
      for (int i = a; i <= 9; i++) {
        printf("%d ", i);
      }
      printf("5 4 3 2 1 0 1 2 3 4 5 ");
      for (int i = 6; i < b; i++) {
        printf("%d ", i);
      }
      printf("%d\n", b);
    }
  }

  return 0;
}
Problem p00141 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
bool vis[30][30], na[30][30];
int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0};
int ex[] = {-1, 1, 0, 0}, ey[] = {0, 0, -1, 1};
int n;
void DFS(int y, int x, int k) {
  vis[y][x] = true;
  na[y][x] = true;
  int xx, yy;
  bool done = false;
  for (int i = 0; i < 4; i++) {
    xx = x + dx[k], yy = y + dy[k];
    bool ok = false;
    if (0 <= xx && xx < n && 0 <= yy && yy < n) {
      if (na[yy][xx] == false) {
        ok = true;
      }
    }
    if (ok) {
      done = true;
      break;
    }
    k = (k + 1) % 4;
  }
  if (!done)
    return;
  for (int i = 0; i < 2; i++) {
    int r = i + (k % 2) * 2;
    int nx = x + ex[r], ny = y + ey[r];
    if (0 <= nx && nx < n && 0 <= ny && ny < n) {
      na[ny][nx] = true;
    }
  }
  DFS(yy, xx, k);
}
int main() {
  int q;
  cin >> q;
  for (int u = 0; u < q; u++) {
    if (u)
      cout << endl;
    cin >> n;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        vis[i][j] = false;
        na[i][j] = false;
      }
    }
    DFS(n - 1, 0, 0);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++)
        cout << (vis[i][j] ? "#" : " ");
      cout << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
bool vis[110][110], na[110][110];
int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0};
int ex[] = {-1, 1, 0, 0}, ey[] = {0, 0, -1, 1};
int n;
void DFS(int y, int x, int k) {
  vis[y][x] = true;
  na[y][x] = true;
  int xx, yy;
  bool done = false;
  for (int i = 0; i < 4; i++) {
    xx = x + dx[k], yy = y + dy[k];
    bool ok = false;
    if (0 <= xx && xx < n && 0 <= yy && yy < n) {
      if (na[yy][xx] == false) {
        ok = true;
      }
    }
    if (ok) {
      done = true;
      break;
    }
    k = (k + 1) % 4;
  }
  if (!done)
    return;
  for (int i = 0; i < 2; i++) {
    int r = i + (k % 2) * 2;
    int nx = x + ex[r], ny = y + ey[r];
    if (0 <= nx && nx < n && 0 <= ny && ny < n) {
      na[ny][nx] = true;
    }
  }
  DFS(yy, xx, k);
}
int main() {
  int q;
  cin >> q;
  for (int u = 0; u < q; u++) {
    if (u)
      cout << endl;
    cin >> n;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        vis[i][j] = false;
        na[i][j] = false;
      }
    }
    DFS(n - 1, 0, 0);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++)
        cout << (vis[i][j] ? "#" : " ");
      cout << endl;
    }
  }
  return 0;
}
Problem p00142 (C++)

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

int ok(int n) {
  if (n < 2)
    return 0;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}
int main() {
  int n;
  while (cin >> n, n) {
    set<int> r;
    for (int i = 1; i < n; i++)
      r.insert((i * i) % n);
    vector<int> wow;
    for (set<int>::iterator it = r.begin(); it != r.end(); ++it)
      wow.push_back(*it);
    map<int, int> mp;
    for (int i = 0; i < wow.size(); i++) {
      for (int j = 0; j < wow.size(); j++) {
        if (i == j)
          continue;
        int g = wow[i] - wow[j];
        if (g < 0)
          g += n;
        if (g > (n - 1) / 2)
          g = n - g;
        mp[g]++;
      }
    }
    for (int i = 1; i <= (n - 1) / 2; i++)
      cout << mp[i] << endl;
  }
}

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

int ok(int n) {
  if (n < 2)
    return 0;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}
int main() {
  int n;
  while (cin >> n, n) {
    set<int> r;
    for (int i = 1; i < n; i++)
      r.insert((i * i) % n);
    vector<int> wow;
    for (set<int>::iterator it = r.begin(); it != r.end(); ++it)
      wow.push_back(*it);
    int mp[10001] = {0};
    for (int i = 0; i < wow.size(); i++) {
      for (int j = 0; j < wow.size(); j++) {
        if (i == j)
          continue;
        int g = wow[i] - wow[j];
        if (g < 0)
          g += n;
        if (g > (n - 1) / 2)
          g = n - g;
        mp[g]++;
      }
    }
    for (int i = 1; i <= (n - 1) / 2; i++)
      cout << mp[i] << endl;
  }
}
Problem p00142 (C++)

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

using namespace std;

int main() {
  int ans[5001], m[10001], f[10001], n, i, j, k, c;
  while (cin >> n) {
    if (n == 0)
      break;
    c = 0;
    for (i = 0; i < 10001; i++)
      ans[i] = f[i] = 0;
    for (i = 1; i <= (n - 1) / 2; i++) {
      k = (i * i) % n;
      if (f[k] == 0) {
        f[k] = 1;
        m[c++] = k;
      }
    }
    for (i = 0; i < c - 1; i++)
      for (j = i + 1; j < c; j++) {
        k = m[j] - m[i];
        k = k < 0 ? k + n : k;
        k = k > (n - 1) / 2 ? n - k : k;
        ans[k]++;
      }
    for (i = 1; i <= (n - 1) / 2; i++)
      cout << ans[i] * 2 << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
  int ans[10001], m[10001], f[10001], n, i, j, k, c;
  while (cin >> n) {
    if (n == 0)
      break;
    c = 0;
    for (i = 0; i < 10001; i++)
      ans[i] = f[i] = 0;
    for (i = 1; i <= (n - 1) / 2; i++) {
      k = (i * i) % n;
      if (f[k] == 0) {
        f[k] = 1;
        m[c++] = k;
      }
    }
    for (i = 0; i < c - 1; i++)
      for (j = i + 1; j < c; j++) {
        k = m[j] - m[i];
        k = k < 0 ? k + n : k;
        k = k > (n - 1) / 2 ? n - k : k;
        ans[k]++;
      }
    for (i = 1; i <= (n - 1) / 2; i++)
      cout << ans[i] * 2 << endl;
  }
  return 0;
}