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

Buggy submission (status: Runtime Error):
#include <stdio.h>
const int SIZE = 100;
int data[SIZE];
int sp = 0;
int size() { return sp; }
int empty() { return sp <= 0; }
int top() { return data[sp - 1]; }
void pop() { sp--; }
void push(int v) {
  data[sp] = v;
  sp++;
}
int main() {
  int n, k;
  while (n != EOF) {
    scanf("%d", &n);
    if (n == 0) {
      printf("%d\n", top());
      pop();
    } else {
      push(n);
    }
  }
  return 0;
}

Fixed submission:
#include <stdio.h>
const int SIZE = 100;
int data[SIZE];
int sp = 0;
int size() { return sp; }
int empty() { return sp <= 0; }
int top() { return data[sp - 1]; }
void pop() { sp--; }
void push(int v) {
  data[sp] = v;
  sp++;
}
int main() {
  int n, k;
  while (scanf("%d", &n) != EOF) {
    if (n == 0) {
      printf("%d\n", top());
      pop();
    } else {
      push(n);
    }
  }
  return 0;
}
Problem p00013 (C++)

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

int main() {
  stack<int> R;
  int n;
  int car[10];
  int i = 0;

  while (cin >> n) {
    if (n == 0) {
      car[i] = R.top();
      R.pop();
      i++;
    } else {
      R.push(n);
    }
  }

  for (int j = 0; j < i; j++) {
    cout << car[j] << endl;
  }

  return (0);
}

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

int main() {
  stack<int> R;
  int n;
  int car[1000];
  int i = 0;

  while (cin >> n) {
    if (n == 0) {
      car[i] = R.top();
      R.pop();
      i++;
    } else {
      R.push(n);
    }
  }

  for (int j = 0; j < i; j++) {
    cout << car[j] << endl;
  }

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

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

using namespace std;

int main() {
  int n;
  stack<int> s;
  while (true) {
    cin >> n;

    if (n == 0) {
      cout << s.top() << endl;
      s.pop();
    } else {
      s.push(n);
    }
  }
  return 0;
}

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

using namespace std;

int main() {
  int n;
  stack<int> s;
  while (cin >> n) {
    if (n == 0) {
      cout << s.top() << endl;
      s.pop();
    } else {
      s.push(n);
    }
  }
  return 0;
}
Problem p00013 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int train[10], moving, situation = 0, ans[10], n = 0, ende = 0;
  while (cin >> moving) {
    if (moving != 0) {
      train[situation] = moving;
      situation++;
    } else {
      situation--;
      ans[ende] = train[situation];
      ende++;
    }
  }
  for (int i = 0; i < ende; i++)
    cout << ans[i] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int train[10000], moving, situation = 0, ans[10000], n = 0, ende = 0;
  while (cin >> moving) {
    if (moving != 0) {
      train[situation] = moving;
      situation++;
    } else {
      situation--;
      ans[ende] = train[situation];
      ende++;
    }
  }
  for (int i = 0; i < ende; i++)
    cout << ans[i] << endl;
}
Problem p00013 (C++)

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

int main() {
  int tmp, i = 0, j, k = 0, f[11];
  vector<int> ans;

  while (cin >> tmp) {
    if (tmp == 0) {
      ans[k] = f[i - 1];
      f[i - 1] = '\0';
      i--;
      k++;
    } else {
      f[i] = tmp;
      i++;
    }
  }
  for (j = 0; j < k; j++) {
    cout << ans[j] << endl;
  }
  return 0;
}

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

int main() {
  int tmp, i = 0, j, k = 0, f[11];
  vector<int> ans;

  while (cin >> tmp) {
    if (tmp == 0) {
      ans.push_back(f[i - 1]);
      f[i - 1] = '\0';
      i--;
      k++;
    } else {
      f[i] = tmp;
      i++;
    }
  }
  for (j = 0; j < k; j++) {
    cout << ans[j] << endl;
  }
  return 0;
}
Problem p00013 (C++)

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

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

  while (1) {
    if (cin >> n, n) {
      car.push_back(n);
    } else {
      cout << car.back() << endl;
      car.pop_back();
    }
  }

  return 0;
}

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

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

  while (cin >> n) {
    if (n) {
      car.push_back(n);
    } else {
      cout << car.back() << endl;
      car.pop_back();
    }
  }

  return 0;
}
Problem p00013 (C++)

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

int main(void) {
  stack<int> s;

  int buf;
  while (1) {
    cin >> buf;
    if (buf == 0) {
      cout << s.top() << endl;
      s.pop();
    } else {
      s.push(buf);
    }
  }
}

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

int main(void) {
  stack<int> s;

  int buf;
  while (cin >> buf) {
    if (buf == 0) {
      cout << s.top() << endl;
      s.pop();
    } else {
      s.push(buf);
    }
  }
}
Problem p00013 (C++)

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

stack<int> sta;

int main(void) {
  int a;
  while (1) {
    cin >> a;
    if (a)
      sta.push(a);
    else {
      cout << sta.top() << endl;
      sta.pop();
    }
  }
  return 0;
}

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

stack<int> sta;

int main(void) {
  int a;
  while (scanf("%d", &a) != EOF) {
    if (a)
      sta.push(a);
    else {
      cout << sta.top() << endl;
      sta.pop();
    }
  }
  return 0;
}
Problem p00013 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int a[10], i = 0, n;
  while (scanf("%d", n) == 1) {
    if (n != 0) {
      a[i] = n;
      i++;
    } else {
      i--;
      cout << a[i] << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int a[10], i = 0, n;
  while (scanf("%d", &n) == 1) {
    if (n != 0) {
      a[i] = n;
      i++;
    } else {
      i--;
      cout << a[i] << endl;
    }
  }
  return 0;
}
Problem p00013 (C++)

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

using namespace std;

int main() {
  int a;

  stack<int> syaryo;

  while (cin >> a) {
    cin >> a;

    if (a != 0) {
      syaryo.push(a);
    }

    else {
      cout << syaryo.top() << endl;
      syaryo.pop();
    }
  }

  return 0;
}

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

using namespace std;

int main() {
  int a;

  stack<int> syaryo;

  while (cin >> a) {

    if (a != 0) {
      syaryo.push(a);
    }

    else {
      cout << syaryo.top() << endl;
      syaryo.pop();
    }
  }

  return 0;
}
Problem p00013 (C++)

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

int main() {

  int c[10], e[10], m, n = 0, k = 0;
  for (int i = 0; i < 10; i++) {
    c[i] = 0;
    e[i] = 0;
  }

  while (cin >> m) {
    if (m == 0) {
      e[k] = c[n - 1];
      k++;
      c[n - 1] = 0;
      n--;
    } else {
      c[n] = m;
      n++;
    }
  }

  for (int i = 0; i < k; i++)
    cout << e[i] << endl;

  return 0;
}

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

int main() {

  int c[256], e[256], m, n = 0, k = 0;
  for (int i = 0; i < 10; i++) {
    c[i] = 0;
    e[i] = 0;
  }

  while (cin >> m) {
    if (m == 0) {
      e[k] = c[n - 1];
      k++;
      c[n - 1] = 0;
      n--;
    } else {
      c[n] = m;
      n++;
    }
  }

  for (int i = 0; i < k; i++)
    cout << e[i] << endl;

  return 0;
}
Problem p00013 (C++)

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

using namespace std;

int main() {
  int in[10];
  int i = 0;

  while (scanf("%d", &in[i])) {
    if (in[i] == 0) {
      i--;
      printf("%d\n", in[i]);
    } else {
      i++;
    }
  }
}

Fixed submission:
#include <cstdio>

using namespace std;

int main() {
  int in[10];
  int i = 0;

  while (scanf("%d", &in[i]) != EOF) {
    if (in[i] == 0) {
      i--;
      printf("%d\n", in[i]);
    } else {
      i++;
    }
  }
}
Problem p00013 (C++)

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

struct stack {
  int element;
  struct stack *next;
};
int top(struct stack *s) { return s->element; }
struct stack *pop(struct stack *s) {
  struct stack *p, *q;
  q = s;
  p = s->next;
  free(q);
  s = p;
  return s;
}
struct stack *push(struct stack *s, int x) {
  struct stack *p, *q;
  q = s;
  p = (struct stack *)malloc(sizeof(struct stack));
  p->element = x;
  p->next = q;
  s = p;
  return s;
}

int main() {
  struct stack *S = NULL;
  int num;
  while (1) {
    cin >> num;
    if (num == 0) {
      cout << top(S) << endl;
      S = pop(S);
    } else {
      S = push(S, num);
    }
  }
  return 0;
}

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

struct stack {
  int element;
  struct stack *next;
};
int top(struct stack *s) { return s->element; }
struct stack *pop(struct stack *s) {
  struct stack *p, *q;
  q = s;
  p = s->next;
  free(q);
  s = p;
  return s;
}
struct stack *push(struct stack *s, int x) {
  struct stack *p, *q;
  q = s;
  p = (struct stack *)malloc(sizeof(struct stack));
  p->element = x;
  p->next = q;
  s = p;
  return s;
}

int main() {
  struct stack *S = NULL;
  int num;
  while (cin >> num) {
    if (num == 0) {
      cout << top(S) << endl;
      S = pop(S);
    } else {
      S = push(S, num);
    }
  }
  return 0;
}
Problem p00013 (C++)

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

int main() {
  int g[10];
  int i = 0;
  int t;
  while (scanf("%d", &t)) {
    if (t) {
      g[i] = t;
      i++;
    } else {
      i--;
      printf("%d\n", g[i]);
    }
  }
  return 0;
}

Fixed submission:
#include <cstdio>

int main() {
  int g[10];
  int i = 0;
  int t;
  while (scanf("%d", &t) + 1) {
    if (t) {
      g[i] = t;
      i++;
    } else {
      i--;
      printf("%d\n", g[i]);
    }
  }
  return 0;
}
Problem p00014 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define fi first
#define se second
using namespace std;
bool value(int y, int x, int R, int C) {
  return 0 <= y && y < R && 0 <= x && x < C;
}
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vi> vvi;
double pie = acos(-1);
int INF = 10000009;
int dx[4] = {0, -1, 0, 1};
int dy[4] = {-1, 0, 1, 0};
int main() {
  int d;
  while (true) {
    cin >> d;
    int S = 0;
    for (int i = 1; i * d <= 600 - d; i++) {
      int x = i * d;
      x = x * x;
      x *= d;
      S += x;
    }
    cout << S << endl;
    S = 0;
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define fi first
#define se second
using namespace std;
bool value(int y, int x, int R, int C) {
  return 0 <= y && y < R && 0 <= x && x < C;
}
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vi> vvi;
double pie = acos(-1);
int INF = 10000009;
int dx[4] = {0, -1, 0, 1};
int dy[4] = {-1, 0, 1, 0};
int main() {
  int d;
  while (cin >> d) {
    int S = 0;
    for (int i = 1; i * d <= 600 - d; i++) {
      int x = i * d;
      x = x * x;
      x *= d;
      S += x;
    }
    cout << S << endl;
    S = 0;
  }
}
Problem p00014 (C++)

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

using namespace std;

double y(double x) {
  double y;
  y = x * x;
  return y;
}

int main() {
  int i, d, s;
  while (cin >> d) {
    s = 0;
    for (i = 0; i < 600; i += d) {
      s += d * y(i);
    }
    cout << s << endl;
  }
  while (1)
    ;
  return 0;
}

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

using namespace std;

double y(double x) {
  double y;
  y = x * x;
  return y;
}

int main() {
  int i, d, s;
  while (cin >> d) {
    s = 0;
    for (i = 0; i < 600; i += d) {
      s += d * y(i);
    }
    cout << s << endl;
  }
  return 0;
}
Problem p00014 (C++)

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

int main(void) {
  int n;
  while (cin >> n, n) {
    long long res = 0;
    for (int i = 0; i < 600; i += n) {
      res += n * i * i;
    }
    cout << res << endl;
  }
  return 0;
}

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

int main(void) {
  int n;
  while (cin >> n) {
    long long res = 0;
    for (int i = 0; i < 600; i += n) {
      res += n * i * i;
    }
    cout << res << endl;
  }
  return 0;
}
Problem p00014 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int w;
  while (scanf("%d", &w) && w) {

    int i;
    long long area = 0;
    for (i = w; i < 600; i += w) {
      area += w * i * i;
    }
    printf("%lld\n", area);
  }
}

Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int w;
  while (scanf("%d", &w) != EOF) {

    int i;
    long long area = 0;
    for (i = w; i < 600; i += w) {
      area += w * i * i;
    }
    printf("%lld\n", area);
  }
}
Problem p00015 (C++)

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

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    char str1[82];
    char str2[82];
    string ans = "";
    cin >> str1;
    cin >> str2;
    int m1 = strlen(str1) - 1, m2 = strlen(str2) - 1, pre = 0;
    int m = max(m1, m2);
    for (int j = 0; j <= m; j++) {
      int sum = pre;
      sum += (m1 >= 0) ? str1[m1--] - '0' : 0;
      sum += (m2 >= 0) ? str2[m2--] - '0' : 0;
      pre = sum / 10;
      sum -= pre * 10;
      ans += '0' + sum;
    }
    if (pre > 0)
      ans += '0' + pre;
    reverse(ans.begin(), ans.end());
    if (ans.length() > 80)
      cout << "overflow" << endl;
    else
      cout << ans << endl;
  }
}

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

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    char str1[1000];
    char str2[1000];
    string ans = "";
    cin >> str1;
    cin >> str2;
    int m1 = strlen(str1) - 1, m2 = strlen(str2) - 1, pre = 0;
    int m = max(m1, m2);
    for (int j = 0; j <= m; j++) {
      int sum = pre;
      sum += (m1 >= 0) ? str1[m1--] - '0' : 0;
      sum += (m2 >= 0) ? str2[m2--] - '0' : 0;
      pre = sum / 10;
      sum -= pre * 10;
      ans += '0' + sum;
    }
    if (pre > 0)
      ans += '0' + pre;
    reverse(ans.begin(), ans.end());
    if (ans.length() > 80)
      cout << "overflow" << endl;
    else
      cout << ans << endl;
  }
}
Problem p00015 (C++)

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

using namespace std;

int main() {
  int n, l1, l2, i;
  string a, b;
  char ans[80];
  int ia, ib, sum;
  cin >> n;
  while (n--) {
    cin >> a >> b;
    if (a.length() > 80 || b.length() > 80) {
      cout << "overflow" << endl;
      continue;
    }
    if (a.length() == 80 || b.length() == 80) {
      if ((int)a[0] - '0' + (int)b[0] - '0' > 9) {
        cout << "overflow" << endl;
        continue;
      }
    }
    if (a.length() < b.length()) {
      swap(a, b);
    }
    l1 = a.length();
    l2 = b.length();
    for (i = 0; i < 80; i++)
      ans[i] = 0;
    for (i = 1; i < l2 + 1; i++) {
      ia = (int)a[l1 - i] - (int)'0';
      ib = (int)b[l2 - i] - (int)'0';
      sum = ia + ib;
      ans[80 - i] += sum + '0';
    }
    for (i = l2 + 1; i < l1 + 1; i++) {
      ans[80 - i] = a[l1 - i];
    }
    for (i = 79; i >= 0; i--) {
      if (ans[i] - '0' > 9 && ans[i] != 0) {
        ans[i] = ans[i] - 10;
        if (ans[i - 1] == 0)
          ans[i - 1] += 49;
        else
          ans[i - 1] += 1;
      }
    }
    for (i = 0; i < 80; i++) {
      if (ans[i] != 0) {
        cout << (int)ans[i] - '0';
      }
    }
    cout << endl;
  }
  while (1)
    ;
  return 0;
}

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

using namespace std;

int main() {
  int n, l1, l2, i;
  string a, b;
  char ans[80];
  int ia, ib, sum;
  cin >> n;
  while (n--) {
    cin >> a >> b;
    if (a.length() > 80 || b.length() > 80) {
      cout << "overflow" << endl;
      continue;
    }
    if (a.length() == 80 || b.length() == 80) {
      if ((int)a[0] - '0' + (int)b[0] - '0' > 9) {
        cout << "overflow" << endl;
        continue;
      }
    }
    if (a.length() < b.length()) {
      swap(a, b);
    }
    l1 = a.length();
    l2 = b.length();
    for (i = 0; i < 80; i++)
      ans[i] = 0;
    for (i = 1; i < l2 + 1; i++) {
      ia = (int)a[l1 - i] - (int)'0';
      ib = (int)b[l2 - i] - (int)'0';
      sum = ia + ib;
      ans[80 - i] += sum + '0';
    }
    for (i = l2 + 1; i < l1 + 1; i++) {
      ans[80 - i] = a[l1 - i];
    }
    for (i = 79; i >= 0; i--) {
      if (ans[i] - '0' > 9 && ans[i] != 0) {
        ans[i] = ans[i] - 10;
        if (ans[i - 1] == 0)
          ans[i - 1] += 49;
        else
          ans[i - 1] += 1;
      }
    }
    for (i = 0; i < 80; i++) {
      if (ans[i] != 0) {
        cout << (int)ans[i] - '0';
      }
    }
    cout << endl;
  }
  return 0;
}
Problem p00015 (C++)

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

int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    char c1[80], c2[80];
    scanf("%s", &c1);
    scanf("%s", &c2);
    string s1, s2;
    s1 = c1, s2 = c2;
    if (s1 == "0" && s2 == "0") {
      printf("0\n");
      continue;
    }
    reverse(s1.begin(), s1.end());
    reverse(s2.begin(), s2.end());
    int n = max(s1.size(), s2.size()) + 1;
    for (int i = s1.size(); i < n; i++) {
      s1 += '0';
    }
    for (int i = s2.size(); i < n; i++) {
      s2 += '0';
    }
    string res;
    int b = 0;
    for (int i = 0; i < max(s1.size(), s2.size()); i++) {
      int u = s1[i] - '0' + s2[i] - '0' + b;
      b = (u >= 10);
      u %= 10;
      res += u + '0';
    }

    reverse(res.begin(), res.end());
    string res2;
    int j = 0;
    while (res[j] == '0')
      j++;
    for (; j < res.size(); j++) {
      res2 += res[j];
    }

    if (res2.size() > 80) {
      printf("overflow\n");
    } else {
      printf("%s\n", res2.c_str());
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <list>
#include <queue>
#include <stack>
#include <vector>
using namespace std;

int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    char c1[1000], c2[1000];
    scanf("%s", &c1);
    scanf("%s", &c2);
    string s1, s2;
    s1 = c1, s2 = c2;
    if (s1 == "0" && s2 == "0") {
      printf("0\n");
      continue;
    }
    reverse(s1.begin(), s1.end());
    reverse(s2.begin(), s2.end());
    int n = max(s1.size(), s2.size()) + 1;
    for (int i = s1.size(); i < n; i++) {
      s1 += '0';
    }
    for (int i = s2.size(); i < n; i++) {
      s2 += '0';
    }
    string res;
    int b = 0;
    for (int i = 0; i < max(s1.size(), s2.size()); i++) {
      int u = s1[i] - '0' + s2[i] - '0' + b;
      b = (u >= 10);
      u %= 10;
      res += u + '0';
    }

    reverse(res.begin(), res.end());
    string res2;
    int j = 0;
    while (res[j] == '0')
      j++;
    for (; j < res.size(); j++) {
      res2 += res[j];
    }

    if (res2.size() > 80) {
      printf("overflow\n");
    } else {
      printf("%s\n", res2.c_str());
    }
  }
  return 0;
}
Problem p00015 (C++)

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

int main() {
  int n;
  cin >> n;
  while (n-- > 0) {
    string num1, num2;
    cin >> num1 >> num2;
    int sum[101];
    int degit = 0;
    for (int i = 0; i < 101; i++)
      sum[i] = 0;
    for (int i = 0; i < num1.size(); i++) {
      sum[100 - i] = num1[num1.size() - i - 1] - '0';
    }
    int d;
    for (int i = 0; i < num1.size() || i < num2.size() || degit != 0; i++) {
      int now;
      if (i < num2.size()) {
        now =
            sum[100 - i] + (int)num2[num2.size() - i - 1] - (int)('0') + degit;
      } else {
        now = sum[100 - i] + degit;
      }
      sum[100 - i] = (now % 10);
      if (now >= 10)
        degit = 1;
      else
        degit = 0;
      d = i;
    }
    if (d < 80) {
      for (int i = 100 - d; i < 101; i++)
        cout << sum[i];
      cout << endl;
    } else {
      cout << "overflow" << endl;
    }
  }
}

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

int main() {
  int n;
  cin >> n;
  while (n-- > 0) {
    string num1, num2;
    cin >> num1 >> num2;
    if (num1.size() > 80 || num2.size() > 80) {
      cout << "overflow" << endl;
      continue;
    }
    int sum[101];
    int degit = 0;
    for (int i = 0; i < 101; i++)
      sum[i] = 0;
    for (int i = 0; i < num1.size(); i++) {
      sum[100 - i] = num1[num1.size() - i - 1] - '0';
    }
    int d;
    for (int i = 0; i < num1.size() || i < num2.size() || degit != 0; i++) {
      int now;
      if (i < num2.size()) {
        now =
            sum[100 - i] + (int)num2[num2.size() - i - 1] - (int)('0') + degit;
      } else {
        now = sum[100 - i] + degit;
      }
      sum[100 - i] = (now % 10);
      if (now >= 10)
        degit = 1;
      else
        degit = 0;
      d = i;
    }
    if (d < 80) {
      for (int i = 100 - d; i < 101; i++)
        cout << sum[i];
      cout << endl;
    } else {
      cout << "overflow" << endl;
    }
  }
}
Problem p00015 (C++)

Buggy submission (status: Runtime Error):
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    char num[2][90];
    int ans[90], up = 0, t, l;
    cin >> num[0] >> num[1];
    int a = strlen(num[0]), b = strlen(num[1]), max = (b > a) ? b : a,
        min = (b > a) ? a : b;
    for (l = 0; l < max; l++) {
      if (l < min) {
        t = (int)num[0][a - l - 1] + (int)num[1][b - l - 1] - 48 * 2 + up;
      } else if (a < b) {
        t = (int)num[1][b - l - 1] - 48 + up;
      } else {
        t = (int)num[0][a - l - 1] - 48 + up;
      }
      if (t > 9) {
        t -= 10;
        up = 1;
      } else {
        up = 0;
      }
      ans[l] = t;
    }
    if (up == 1) {
      ans[max] = 1;
      l++;
    }
    if (l <= 80)
      for (int m = l - 1; m >= 0; m--) {
        cout << ans[m];
      }
    else {
      cout << "overflow";
    }
    cout << endl;
  }
  return 0;
}

Fixed submission:
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    char num[2][900];
    int ans[900], up = 0, t, l;
    cin >> num[0] >> num[1];
    int a = strlen(num[0]), b = strlen(num[1]), max = (b > a) ? b : a,
        min = (b > a) ? a : b;
    for (l = 0; l < max; l++) {
      if (l < min) {
        t = (int)num[0][a - l - 1] + (int)num[1][b - l - 1] - 48 * 2 + up;
      } else if (a < b) {
        t = (int)num[1][b - l - 1] - 48 + up;
      } else {
        t = (int)num[0][a - l - 1] - 48 + up;
      }
      if (t > 9) {
        t -= 10;
        up = 1;
      } else {
        up = 0;
      }
      ans[l] = t;
    }
    if (up == 1) {
      ans[max] = 1;
      l++;
    }
    if (l <= 80)
      for (int m = l - 1; m >= 0; m--) {
        cout << ans[m];
      }
    else {
      cout << "overflow";
    }
    cout << endl;
  }
  return 0;
}
Problem p00015 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstring>
#define MAX_NUM 100

using namespace std;

void array_add(int *a, int *b) {
  int i;
  for (i = MAX_NUM - 1; i > 0; i--) {
    a[i] = a[i] + b[i];
    a[i - 1] = a[i - 1] + a[i] / 10;
    a[i] %= 10;
  }
}

int main(void) {
  int n, i, j, len1, len2, val1[MAX_NUM], val2[MAX_NUM];
  char c;
  scanf("%d%*c", &n);
  for (i = 0; i < n; i++) {
    for (j = 0; (c = getchar()) != '\n'; j++) {
      val1[j] = c - '0';
    }
    len1 = j;
    for (j = 0; (c = getchar()) != '\n'; j++) {
      val2[j] = c - '0';
    }
    len2 = j;
    for (j = MAX_NUM - 1; j > MAX_NUM - 1 - len1; j--) {
      val1[j] = val1[len1 - 1 + (j - (MAX_NUM - 1))];
    }
    for (; j >= 0; j--) {
      val1[j] = 0;
    }
    val1[MAX_NUM] = 0;
    for (j = MAX_NUM - 1; j > MAX_NUM - 1 - len2; j--) {
      val2[j] = val2[len2 - 1 + (j - (MAX_NUM - 1))];
    }
    for (; j >= 0; j--) {
      val2[j] = 0;
    }
    array_add(val1, val2);
    for (j = 0; val1[j] == 0 && j < MAX_NUM; j++)
      ;
    if (j <= MAX_NUM - 81)
      printf("overflow");
    else if (j == MAX_NUM)
      printf("0");
    else {
      for (; j < MAX_NUM; j++) {
        printf("%d", val1[j]);
      }
    }
    printf("\n");
  }
  return 0;
}

Fixed submission:
#include <cstdio>
#include <cstring>
#define MAX_NUM 32767

using namespace std;

void array_add(int *a, int *b) {
  int i;
  for (i = MAX_NUM - 1; i > 0; i--) {
    a[i] = a[i] + b[i];
    a[i - 1] = a[i - 1] + a[i] / 10;
    a[i] %= 10;
  }
}

int main(void) {
  int n, i, j, len1, len2, val1[MAX_NUM], val2[MAX_NUM];
  char c;
  scanf("%d%*c", &n);
  for (i = 0; i < n; i++) {
    for (j = 0; (c = getchar()) != '\n'; j++) {
      val1[j] = c - '0';
    }
    len1 = j;
    for (j = 0; (c = getchar()) != '\n'; j++) {
      val2[j] = c - '0';
    }
    len2 = j;
    for (j = MAX_NUM - 1; j > MAX_NUM - 1 - len1; j--) {
      val1[j] = val1[len1 - 1 + (j - (MAX_NUM - 1))];
    }
    for (; j >= 0; j--) {
      val1[j] = 0;
    }
    val1[MAX_NUM] = 0;
    for (j = MAX_NUM - 1; j > MAX_NUM - 1 - len2; j--) {
      val2[j] = val2[len2 - 1 + (j - (MAX_NUM - 1))];
    }
    for (; j >= 0; j--) {
      val2[j] = 0;
    }
    array_add(val1, val2);
    for (j = 0; val1[j] == 0 && j < MAX_NUM; j++)
      ;
    if (j <= MAX_NUM - 81)
      printf("overflow");
    else if (j == MAX_NUM)
      printf("0");
    else {
      for (; j < MAX_NUM; j++) {
        printf("%d", val1[j]);
      }
    }
    printf("\n");
  }
  return 0;
}
Problem p00015 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a[80];
    string sa1, sa2, s1 = "", s2 = "";
    for (int i = 0; i < 80; i++)
      a[i] = 0;
    cin >> sa1 >> sa2;
    for (int j = 0; j < 80 - sa1.length(); j++) {
      s1 += '0';
    }
    s1 += sa1;
    for (int j = 0; j < 80 - sa2.length(); j++) {
      s2 += '0';
    }
    s2 += sa2;
    for (int i = 0; i < 80; i++) {
      a[i] += (s1[i] - '0') + (s2[i] - '0');
    }
    for (int i = 79; i >= 1; i--) {
      a[i - 1] += a[i] / 10;
      a[i] %= 10;
    }
    if (a[0] >= 10) {
      printf("overflow\n");
      continue;
    }
    int x = 0;
    while (a[x] == 0)
      x++;
    for (int i = x; i <= 79; i++) {
      cout << a[i];
    }
    if (x == 80)
      printf("0\n");
    else
      printf("\n");
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a[80];
    string sa1, sa2, s1 = "", s2 = "";
    for (int i = 0; i < 80; i++)
      a[i] = 0;
    cin >> sa1 >> sa2;
    if (sa1.length() > 80 || sa2.length() > 80) {
      printf("overflow\n");
      continue;
    }
    for (int j = 0; j < 80 - sa1.length(); j++) {
      s1 += '0';
    }
    s1 += sa1;
    for (int j = 0; j < 80 - sa2.length(); j++) {
      s2 += '0';
    }
    s2 += sa2;
    for (int i = 0; i < 80; i++) {
      a[i] += (s1[i] - '0') + (s2[i] - '0');
    }
    for (int i = 79; i >= 1; i--) {
      a[i - 1] += a[i] / 10;
      a[i] %= 10;
    }
    if (a[0] >= 10) {
      printf("overflow\n");
      continue;
    }
    int x = 0;
    while (a[x] == 0)
      x++;
    for (int i = x; i <= 79; i++) {
      cout << a[i];
    }
    if (x == 80)
      printf("0\n");
    else
      printf("\n");
  }
  return 0;
}
Problem p00015 (C++)

Buggy submission (status: Runtime Error):
// 2012/10/28 Tazoe

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

int main() {
  int N;
  cin >> N;

  for (int i = 0; i < N; i++) {
    string S1, S2;
    cin >> S1;
    cin >> S2;

    if (S1.size() < S2.size()) {
      string tmp = S1;
      S1 = S2;
      S2 = tmp;
    }

    int A[80];
    int C = 0;
    for (int j = 0; j < S1.size(); j++) {
      int tmp = (int)(S1[S1.size() - 1 - j] - '0') + C;
      if (j < S2.size()) {
        tmp += (int)(S2[S2.size() - 1 - j] - '0');
      }

      A[j] = tmp % 10;
      C = tmp / 10;
    }

    if (S1.size() == 80 && C == 1) {
      cout << "overflow" << endl;
    } else {
      if (C == 1) {
        cout << C;
      }
      for (int j = S1.size() - 1; j >= 0; j--) {
        cout << A[j];
      }
      cout << endl;
    }
  }

  return 0;
}

Fixed submission:
// 2012/10/28 Tazoe

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

int main() {
  int N;
  cin >> N;

  for (int i = 0; i < N; i++) {
    string S1, S2;
    cin >> S1;
    cin >> S2;

    if (S1.size() < S2.size()) {
      string tmp = S1;
      S1 = S2;
      S2 = tmp;
    }

    if (S1.size() > 80) {
      cout << "overflow" << endl;
      continue;
    }

    int A[80];
    int C = 0;
    for (int j = 0; j < S1.size(); j++) {
      int tmp = (int)(S1[S1.size() - 1 - j] - '0') + C;
      if (j < S2.size()) {
        tmp += (int)(S2[S2.size() - 1 - j] - '0');
      }

      A[j] = tmp % 10;
      C = tmp / 10;
    }

    if (S1.size() == 80 && C == 1) {
      cout << "overflow" << endl;
    } else {
      if (C == 1) {
        cout << C;
      }
      for (int j = S1.size() - 1; j >= 0; j--) {
        cout << A[j];
      }
      cout << endl;
    }
  }

  return 0;
}
Problem p00015 (C++)

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

int charToInt(char);
string sumStr(string, string);

int charToInt(char c) { return (int)c - (int)'0'; }

string sumStr(string a, string b) {
  int pa = a.length() - 1, pb = b.length() - 1;
  string str(83, '0');
  int pstr = str.length() - 1;
  int next = 0;
  while (pa >= 0 && pb >= 0) {
    int temp = charToInt(a[pa]) + charToInt(b[pb]) + next;
    next = temp / 10;
    str[pstr] = (char)(temp % 10 + (int)'0');

    pa--;
    pb--;
    pstr--;
  }
  while (pa >= 0) {
    int temp = charToInt(a[pa]) + next;
    next = temp / 10;
    str[pstr] = (char)(temp % 10 + (int)'0');

    pa--;
    pstr--;
  }
  while (pb >= 0) {
    int temp = charToInt(b[pb]) + next;
    next = temp / 10;
    str[pstr] = (char)(temp % 10 + (int)'0');

    pb--;
    pstr--;
  }
  str[pstr] = (char)(next + (int)'0');

  for (int i = 0; i < str.length(); i++) {
    if (str[i] != '0') {
      return str.substr(i, str.length() - i);
    }
  }
  return "0";
}

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    bool overflow = false;
    int data[N][8];
    string sum;
    for (int j = 0; j < 2; j++) {
      string str;
      cin >> str;

      if (!overflow) {
        if (j == 0)
          sum = str;
        else
          sum = sumStr(sum, str);
        if (sum.length() > 80)
          overflow = true;
      }
    }

    if (overflow)
      cout << "overflow" << endl;
    else
      cout << sum << endl;
  }
  return 0;
}

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

int charToInt(char);
string sumStr(string, string);

int charToInt(char c) { return (int)c - (int)'0'; }

string sumStr(string a, string b) {
  int pa = a.length() - 1, pb = b.length() - 1;
  string str(83, '0');
  int pstr = str.length() - 1;
  int next = 0;
  while (pa >= 0 && pb >= 0) {
    int temp = charToInt(a[pa]) + charToInt(b[pb]) + next;
    next = temp / 10;
    str[pstr] = (char)(temp % 10 + (int)'0');

    pa--;
    pb--;
    pstr--;
  }
  while (pa >= 0) {
    int temp = charToInt(a[pa]) + next;
    next = temp / 10;
    str[pstr] = (char)(temp % 10 + (int)'0');

    pa--;
    pstr--;
  }
  while (pb >= 0) {
    int temp = charToInt(b[pb]) + next;
    next = temp / 10;
    str[pstr] = (char)(temp % 10 + (int)'0');

    pb--;
    pstr--;
  }
  str[pstr] = (char)(next + (int)'0');

  for (int i = 0; i < str.length(); i++) {
    if (str[i] != '0') {
      return str.substr(i, str.length() - i);
    }
  }
  return "0";
}

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    bool overflow = false;
    int data[N][8];
    string sum;
    for (int j = 0; j < 2; j++) {
      string str;
      cin >> str;
      if (str.length() > 80)
        overflow = true;
      if (!overflow) {
        if (j == 0)
          sum = str;
        else
          sum = sumStr(sum, str);
        if (sum.length() > 80)
          overflow = true;
      }
    }

    if (overflow)
      cout << "overflow" << endl;
    else
      cout << sum << endl;
  }
  return 0;
}
Problem p00015 (C++)

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

int main(void) {
  int N;
  scanf("%d", &N);

  int i, j, k;
  for (i = 0; i < N; ++i) {

    int digits[2][80];
    for (j = 0; j < 2; ++j) {
      for (k = 0; k < 80; ++k) {
        digits[j][k] = 0;
      }
    }

    int overflow = 0;

    for (j = 0; j < 2; ++j) {
      char digit[256];
      scanf("%s", digit);
      getchar();

      if (overflow || strlen(digit) > 80) {
        overflow = 1;
      } else {
        for (k = 0; k < strlen(digit); ++k) {
          digits[j][k] = digit[strlen(digit) - 1 - k] - '0';
        }
      }
    }

    if (!overflow) {
      int sum[81];
      for (j = 0; j < 81; ++j) {
        sum[j] = 0;
      }

      for (j = 0; j < 80; ++j) {
        for (k = 0; k < 2; ++k) {
          sum[j] += digits[k][j];
        }
        sum[j + 1] += sum[j] / 10;
        sum[j] %= 10;
      }

      if (sum[80] > 0) {
        overflow = 1;
      } else {
        int available = 0;
        for (j = 80; j >= 0; --j) {
          if (available || sum[j] != 0 || j == 0) {
            available = 1;
            printf("%d", sum[j]);
          }
        }
        printf("\n");
      }
    }

    if (overflow) {
      printf("overflow\n");
    }
  }

  return 0;
}

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

int main(void) {
  int N;
  scanf("%d", &N);

  int i, j, k;
  for (i = 0; i < N; ++i) {

    int digits[2][80];
    for (j = 0; j < 2; ++j) {
      for (k = 0; k < 80; ++k) {
        digits[j][k] = 0;
      }
    }

    int overflow = 0;

    for (j = 0; j < 2; ++j) {
      char digit[256];
      scanf("%256s", digit);
      getchar();

      if (overflow || strlen(digit) > 80) {
        overflow = 1;
      } else {
        for (k = 0; k < strlen(digit); ++k) {
          digits[j][k] = digit[strlen(digit) - 1 - k] - '0';
        }
      }
    }

    if (!overflow) {
      int sum[81];
      for (j = 0; j < 81; ++j) {
        sum[j] = 0;
      }

      for (j = 0; j < 80; ++j) {
        for (k = 0; k < 2; ++k) {
          sum[j] += digits[k][j];
        }
        sum[j + 1] += sum[j] / 10;
        sum[j] %= 10;
      }

      if (sum[80] > 0) {
        overflow = 1;
      } else {
        int available = 0;
        for (j = 80; j >= 0; --j) {
          if (available || sum[j] != 0 || j == 0) {
            available = 1;
            printf("%d", sum[j]);
          }
        }
        printf("\n");
      }
    }

    if (overflow) {
      printf("overflow\n");
    }
  }

  return 0;
}
Problem p00015 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    // char s[100] = "abc";
    string a, b;

    cin >> a >> b;
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    while (a.size() < 100)
      a += "0";
    while (b.size() < 100)
      b += "0";
    string ans = "";
    int carry = 0;
    for (int i = 0; i < 100; i++) {
      int d = (a[i] - '0') + (b[i] - '0') + carry;
      ans += d % 10 + '0';
      carry = d / 10;
    }
    reverse(ans.begin(), ans.end());
    if (ans.find_first_not_of('0') < 20) {
      cout << "overflow" << endl;
      continue;
    }
    ans = ans.substr(ans.find_first_not_of('0'));

    cout << ans << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    // char s[100] = "abc";
    string a, b;

    cin >> a >> b;
    if (a == b) {
      if (a == "0") {
        cout << "0" << endl;
        continue;
      }
    }
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    while (a.size() < 100)
      a += "0";
    while (b.size() < 100)
      b += "0";
    string ans = "";
    int carry = 0;
    for (int i = 0; i < 100; i++) {
      int d = (a[i] - '0') + (b[i] - '0') + carry;
      ans += d % 10 + '0';
      carry = d / 10;
    }
    reverse(ans.begin(), ans.end());
    if (ans.find_first_not_of('0') < 20) {
      cout << "overflow" << endl;
      continue;
    }
    ans = ans.substr(ans.find_first_not_of('0'));

    cout << ans << endl;
  }

  return 0;
}
Problem p00015 (C++)

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

int main(void) {
  int N, j, k = 0;
  cin >> N;
  char strA[300], strB[300];
  while (1) {
    k++;
    if (k == N + 1) {
      break;
    }
    cin >> strA >> strB;
    int ans[81] = {0};
    ans[0] = 11111;
    if (strlen(strA) > 80 || strlen(strB) > 80) {
      cout << "overflow" << endl;
      continue;
    }
    int a[81] = {0}, b[81] = {0};
    if (strA[strlen(strA) - 1] == '0' && strB[strlen(strB) - 1] == '0') {
      cout << 0 << endl;
      continue;
    }
    j = strlen(strA) - 1;
    for (int i = 80; j >= 0; i--) {
      a[i] = (int)strA[j] - 48;
      j--;
    }
    j = strlen(strB) - 1;
    for (int i = 80; j >= 0; i--) {
      b[i] = (int)strB[j] - 48;
      j--;
    }
    for (int i = 80; i != 0; i--) {
      ans[i] = ans[i] + a[i] + b[i];
      if (ans[i] >= 10) {
        ans[i] = ans[i] - 10;
        ans[i - 1]++;
      }
    }
    if (ans[0] != 11111) {
      cout << "overflow" << endl;
      continue;
    }
    for (int i = 1; i < 81; i++) {
      if (ans[i] != 0) {
        j = i;
        break;
      }
    }
    char c[3];
    for (int i = j; i < 81; i++) {
      printf("%c", ans[i] + 48);
    }
    cout << '\n';
  }
  return 0;
}

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

int main(void) {
  int N, j, k = 0;
  cin >> N;
  char strA[100000], strB[100000];
  while (1) {
    k++;
    if (k == N + 1) {
      break;
    }
    cin >> strA >> strB;
    int ans[81] = {0};
    ans[0] = 11111;
    if (strlen(strA) > 80 || strlen(strB) > 80) {
      cout << "overflow" << endl;
      continue;
    }
    int a[81] = {0}, b[81] = {0};
    if (strA[strlen(strA) - 1] == '0' && strB[strlen(strB) - 1] == '0') {
      cout << 0 << endl;
      continue;
    }
    j = strlen(strA) - 1;
    for (int i = 80; j >= 0; i--) {
      a[i] = (int)strA[j] - 48;
      j--;
    }
    j = strlen(strB) - 1;
    for (int i = 80; j >= 0; i--) {
      b[i] = (int)strB[j] - 48;
      j--;
    }
    for (int i = 80; i != 0; i--) {
      ans[i] = ans[i] + a[i] + b[i];
      if (ans[i] >= 10) {
        ans[i] = ans[i] - 10;
        ans[i - 1]++;
      }
    }
    if (ans[0] != 11111) {
      cout << "overflow" << endl;
      continue;
    }
    for (int i = 1; i < 81; i++) {
      if (ans[i] != 0) {
        j = i;
        break;
      }
    }
    char c[3];
    for (int i = j; i < 81; i++) {
      printf("%c", ans[i] + 48);
    }
    cout << '\n';
  }
  return 0;
}
Problem p00015 (C++)

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

int N, ans[82], a, b, la, lb, up, deg;
string sta, stb;

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> sta >> stb;
    la = sta.size();
    lb = stb.size();
    up = 0;
    deg = 1;
    for (int i = 0; i < max(la, lb) + 1; i++) {
      if (i >= la)
        a = '0';
      else
        a = sta[la - 1 - i];
      if (i >= lb)
        b = '0';
      else
        b = stb[lb - 1 - i];
      if (a + b + up > 105) {
        ans[i] = a + b + up - 10 - 96;
        up = 1;
      } else {
        ans[i] = a + b + up - 96;
        up = 0;
      }
      if (ans[i] != 0)
        deg = i + 1;
    }
    if (deg > 80)
      cout << "overflow" << endl;
    else {
      for (int i = 0; i < deg; i++)
        cout << ans[deg - 1 - i];
      cout << endl;
    }
  }
}

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

int N, ans[82], a, b, la, lb, up, deg;
string sta, stb;

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> sta >> stb;
    la = sta.size();
    lb = stb.size();
    up = 0;
    deg = 1;
    for (int i = 0; i < max(la, lb) + 1; i++) {
      if (i >= la)
        a = '0';
      else
        a = sta[la - 1 - i];
      if (i >= lb)
        b = '0';
      else
        b = stb[lb - 1 - i];
      if (min(a, b) > 80) {
        cout << "overflow" << endl;
        continue;
      }
      if (a + b + up > 105) {
        ans[i] = a + b + up - 10 - 96;
        up = 1;
      } else {
        ans[i] = a + b + up - 96;
        up = 0;
      }
      if (ans[i] != 0)
        deg = i + 1;
    }
    if (deg > 80)
      cout << "overflow" << endl;
    else {
      for (int i = 0; i < deg; i++)
        cout << ans[deg - 1 - i];
      cout << endl;
    }
  }
}
Problem p00016 (C++)

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

int main() {
  int dis1, rad1, dis2 = 0, rad2 = 0;
  double x = 0, y = 0, PI = 3.141592653589793;
  scanf("%d , %d", &dis1, &rad1);
  y += dis1;
  rad2 = rad1;
  while (scanf("%d , %d", &dis1, &rad1)) {
    if (dis1 != 0) {
      x += dis1 * sin(rad2 * PI / 180);
      y += dis1 * cos(rad2 * PI / 180);
      rad2 += rad1;
    } else {
      cout << int(x) << endl;
      cout << int(y) << endl;
    }
  }
  return 0;
}

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

int main() {
  int dis1, rad1, dis2 = 0, rad2 = 0;
  double x = 0, y = 0, PI = 3.141592653589793;
  scanf("%d , %d", &dis1, &rad1);
  y += dis1;
  rad2 = rad1;
  while (scanf("%d , %d", &dis1, &rad1)) {
    if (dis1 != 0) {
      x += dis1 * sin(rad2 * PI / 180);
      y += dis1 * cos(rad2 * PI / 180);
      rad2 += rad1;
    } else {
      cout << int(x) << endl;
      cout << int(y) << endl;
      break;
    }
  }
  return 0;
}
Problem p00016 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <vector>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a) (a).begin(), (a).end()
#define REP(i, n) for (int i = 0; i < (n); ++i)
const double EPS = 1e-10;
const double PI = acos(-1.0);
#define dump(x)                                                                \
  cerr << "  (L" << __LINE__ << ") " << #x << " = " << (x) << endl;
#define dumpv(x)                                                               \
  cerr << "  (L" << __LINE__ << ") " << #x << " = ";                           \
  REP(q, (x).size()) cerr << (x)[q] << " ";                                    \
  cerr << endl;
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &d) {
  return s << "(" << d.first << "," << d.second << ")";
}

int main() {
  double x = 0.0, y = 0.0;
  double angle = 90;

  while (true) {
    int a, b;
    scanf("%d,%d", &a, &b);
    if (a == 0 && b == 0)
      break;

    double theta = PI * angle / 180.0;
    dump(theta);
    x += a * cos(theta);
    y += a * sin(theta);
    angle -= b;
  }

  printf("%d\n%d\n", (int)x, (int)y);
}

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a) (a).begin(), (a).end()
#define REP(i, n) for (int i = 0; i < (n); ++i)
const double EPS = 1e-10;
const double PI = acos(-1.0);
#define dump(x)                                                                \
  cerr << "  (L" << __LINE__ << ") " << #x << " = " << (x) << endl;
#define dumpv(x)                                                               \
  cerr << "  (L" << __LINE__ << ") " << #x << " = ";                           \
  REP(q, (x).size()) cerr << (x)[q] << " ";                                    \
  cerr << endl;
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &d) {
  return s << "(" << d.first << "," << d.second << ")";
}

int main() {
  double x = 0.0, y = 0.0;
  double angle = 90;

  while (true) {
    int a, b;
    scanf("%d,%d", &a, &b);
    if (a == 0 && b == 0)
      break;

    double theta = PI * angle / 180.0;
    x += a * cos(theta);
    y += a * sin(theta);
    angle -= b;
  }

  printf("%d\n%d\n", (int)x, (int)y);
}
Problem p00016 (C++)

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

int main() {
  int d, t;
  double x = 0, y = 0;
  double angle = 90;
  while (1) {
    cin >> d >> t;
    if (d == 0 && t == 0)
      break;
    x += d * cos(angle / 180 * acos(-1));
    y += d * sin(angle / 180 * acos(-1));
    angle -= t;
  }
  cout << (int)x << endl;
  cout << (int)y << endl;
}

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

int main() {
  int d, t;
  double x = 0, y = 0;
  double angle = 90;
  while (1) {
    char c;
    cin >> d >> c >> t;
    if (d == 0 && t == 0)
      break;
    x += d * cos(angle / 180 * acos(-1));
    y += d * sin(angle / 180 * acos(-1));
    angle -= t;
  }
  cout << (int)x << endl;
  cout << (int)y << endl;
}
Problem p00016 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <fstream>
#include <iostream>
#include <math.h>
#include <queue>
#include <utility>
#include <vector>
#define PI 3.141592
using namespace std;

int main() {
  ifstream cin("../test.txt");
  double x, y, ca, a, l;
  x = 0;
  y = 0;
  ca = PI / 2;
  char c;
  while (true) {
    cin >> l >> c >> a; // 進む距離と回転角度
    if (l == 0 && a == 0)
      break;

    x += l * cos(ca);
    y += l * sin(ca);

    ca -= a * PI / 180.0;
  }

  cout << (int)x << endl;
  cout << (int)y << endl;
}

Fixed submission:
#include <algorithm>
#include <fstream>
#include <iostream>
#include <math.h>
#include <queue>
#include <utility>
#include <vector>
#define PI 3.141592
using namespace std;

int main() {
  // ifstream cin("../test.txt");
  double x, y, ca, a, l;
  x = 0;
  y = 0;
  ca = PI / 2;
  char c;
  while (true) {
    cin >> l >> c >> a; // 進む距離と回転角度
    if (l == 0 && a == 0)
      break;

    x += l * cos(ca);
    y += l * sin(ca);

    ca -= a * PI / 180.0;
  }

  cout << (int)x << endl;
  cout << (int)y << endl;
}