alexjercan/bugnet huggingface dataset:
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main(void) {
  int n;

  cin >> n;
  while (n--) {
    int len, big;
    string val[2];
    bool crr = false;

    for (int j = 0; j < 2; j++) {
      cin >> val[j];
      reverse(val[j].begin(), val[j].end());
    }

    big = val[0].size() >= val[1].size() ? 0 : 1;
    val[1 - big].append((len = val[big].size()) - val[1 - big].size(), '0');

    if (len <= 80) {
      for (int j = 0; j < len; j++) {
        val[0][j] += val[1][j] + crr - 0x60;
        crr = val[0][j] / 10;
        val[0][j] %= 10;
        val[0][j] += 0x30;
      }

      if (crr) {
        val[0].append(1, '1');
        len++;
      }
    }

    if (len <= 80)
      reverse(val[0].begin(), val[0].end());
    else
      val[0] = "overflow";

    cout << val[0] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string.h>

using namespace std;

int main(void) {
  int n;

  cin >> n;
  for (int i = 0; i < n; i++) {
    int len, mlen = 0;
    char val[2][128] = {0}, tmp[128], crr = 0;

    for (int j = 0; j < 2; j++) {
      cin >> tmp;
      len = strlen(tmp);
      mlen = mlen > len ? mlen : len;
      for (int k = 0; k < len; k++)
        val[j][len - 1 - k] = tmp[k] - 0x30;
    }

    if (mlen <= 80)
      for (int j = 0; j < mlen; j++) {
        val[0][j] += val[1][j] + crr;
        crr = val[0][j] / 10;
        val[0][j] %= 10;

        if (j == mlen - 1 && crr)
          mlen++;
      }

    if (mlen <= 80) {
      for (int j = 0; j < mlen; j++)
        tmp[j] = val[0][mlen - 1 - j] + 0x30;
      tmp[mlen] = '\\0';
    } else
      strcpy(tmp, "overflow");

    cout << tmp << endl;
  }

  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a, t) for (int a = 0; a < t; ++a)
#define forever while (true)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define pb push_back
#define int_maxvalue numeric_limits<int>::max()
ll mod = 1e9 + 7;
string Addition(string a, string b) {
  string ans = "";
  int bef = 0;
  int be1 = 0;
  for (int i = a.length() - 1; i >= 0; i--) {
    int added = stoi(a.substr(i, 1)) + stoi(b.substr(i, 1)) + be1;

    if (added >= 10) {
      bef = 1;
      added -= 10;
    } else {
      bef = 0;
    }

    ans = to_string(added) + ans;
    /*/
    stringstream ss;
    ss << added;

    ans = ss.str() + ans;*/
    be1 = bef;
    if (i == 0) {
      break;
    }
  }
  if (be1 == 1) {
    ans = "1" + ans;
  }
  return ans;
}
int main() {
  int n;
  cin >> n;
  rep(o1, n) {
    string a, b;
    cin >> a >> b;
    if (a.length() < b.length()) {
      swap(a, b);
    }
    string b1 = b;
    for (int i = 0; i < a.length() - b1.length(); ++i) {
      b = '0' + b;
    }
    string ans = Addition(a, b);
    if (ans.length() > 80) {
      cout << "overflow" << endl;
    } else {
      cout << ans << endl;
    }
  }
  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;
int main() {
  char a1, a2;
  long long a, b, c;
  int kaisu = 0;
  cin >> kaisu;
  for (int i = 0; i < kaisu; i++) {
    cin >> a;
    cin >> b;
    a1 = (long long)log10(a) + 1;
    ;
    a2 = (long long)log10(b) + 1;
    ;
    if (a1 + a2 >= 80) {
      printf("overflow");
    } else {
      c = a + b;
      printf(c + "\\n");
    }
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

#define PI 3.141592653

int main() {
  string A, B;
  int n, Ak, Bk, ans[81];

  scanf("%d", &n);

  for (int i = 0; i < n; i++) {

    for (int j = 0; j < 80; j++) {
      ans[j] = 0;
    }

    cin >> A >> B;

    if (A == B && A == "0") {
      printf("0\\n");
      continue;
    }

    Ak = (int)A.size();
    Bk = (int)B.size();

    if (Ak > 80 || Bk > 80) {
      puts("overflow");
      continue;
    }

    for (int j = 0; j < max(Ak, Bk); j++) {
      if (j < min(Ak, Bk))
        ans[79 - j] += (A[Ak - 1 - j] - '0') + (B[Bk - 1 - j] - '0');
      else if (j < Ak)
        ans[79 - j] += A[Ak - 1 - j] - '0';
      else if (j < Bk)
        ans[79 - j] += B[Bk - 1 - j] - '0';

      if (ans[79 - j] >= 10) {
        if (j == 79) {
          break;
        }
        ans[79 - j - 1]++;
        ans[79 - j] -= 10;
      }
    }

    if (ans[0] >= 10) {
      puts("overflow");
    } else {
      bool f = false;
      for (int j = 0; j < 80; j++) {
        if (ans[j] > 0 || f) {
          printf("%1d", ans[j]);
          f = true;
        }
      }
      printf("\\n");
    }
  }

  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

#define PI 3.141592653

int main() {
  string A, B;
  int n, Ak, Bk, ans[81];

  scanf("%d", &n);

  for (int i = 0; i < n; i++) {

    for (int j = 0; j < 80; j++) {
      ans[j] = 0;
    }

    cin >> A >> B;

    Ak = (int)A.size();
    Bk = (int)B.size();

    for (int i = 0; i < max(Ak, Bk); i++) {
      if (i < min(Ak, Bk))
        ans[79 - i] += (A[Ak - 1 - i] - '0') + (B[Bk - 1 - i] - '0');
      else if (i < Ak)
        ans[79 - i] += A[Ak - 1 - i] - '0';
      else if (i < Bk)
        ans[79 - i] += B[Bk - 1 - i] - '0';

      if (ans[79 - i] >= 10) {
        if (i == 79) {
          break;
        }
        ans[79 - i - 1]++;
        ans[79 - i] -= 10;
      }
    }

    if (ans[79 - i] >= 10) {
      puts("overflow");
    } else {
      bool f = false;
      for (int i = 0; i < 80; i++) {
        if (ans[i] || f) {
          printf("%1d", ans[i]);
          f = true;
        }
      }
      printf("\\n");
    }
  }

  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int k, a, b, c, d, i, j, s;
  stack<int> st[3];
  char n[2][1000];
  cin >> d;
  for (d; d > 0; d--) {
    n[0][81] = '*';
    n[1][81] = '*';
    cin >> n[0] >> n[1];
    if (n[0][81] != '*' || n[1][81] != '*') {
      cout << "overflow" << endl;
      continue;
    }
    for (i = 0; i < 2; i++)
      for (j = 0; n[i][j] != '\\0'; j++)
        st[i].push(n[i][j] - '0');
    k = 0;
    c = 0;
    while (!st[0].empty() || !st[1].empty()) {
      if (!st[0].empty()) {
        a = st[0].top();
        st[0].pop();
      } else
        a = 0;
      if (!st[1].empty()) {
        b = st[1].top();
        st[1].pop();
      } else
        b = 0;
      s = a + b + c;
      k++;
      if (s > 9) {
        c = 1;
        s -= 10;
      } else
        c = 0;
      st[2].push(s);
    }
    if ((c == 1 && k == 80) || k > 80) {
      cout << "overflow" << endl;
      while (!st[2].empty())
        st[2].pop();
    } else {
      if (c == 1)
        cout << 1;
      while (!st[2].empty()) {
        cout << st[2].top();
        st[2].pop();
      }
      cout << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int k, a, b, c, d, i, j, s;
  stack<int> st[3];
  char n[2][81];
  cin >> d;
  for (d; d > 0; d--) {
    cin >> n[0] >> n[1];
    for (i = 0; i < 2; i++)
      for (j = 0; n[i][j] != '\\0'; j++)
        st[i].push(n[i][j] - '0');
    k = 0;
    c = 0;
    while (!st[0].empty() || !st[1].empty()) {
      if (!st[0].empty()) {
        a = st[0].top();
        st[0].pop();
      } else
        a = 0;
      if (!st[1].empty()) {
        b = st[1].top();
        st[1].pop();
      } else
        b = 0;
      s = a + b + c;
      k++;
      if (s > 9) {
        c = 1;
        s -= 10;
      } else
        c = 0;
      st[2].push(s);
    }
    if ((c == 1 && k == 80) || k > 80) {
      cout << "overflow" << endl;
      while (!st[2].empty())
        st[2].pop();
    } else {
      if (c == 1)
        cout << 1;
      while (!st[2].empty()) {
        cout << st[2].top();
        st[2].pop();
      }
      cout << endl;
    }
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string a, b, c;
    char tmp;
    cin >> a >> b;
    if (a.size() > 80 || b.size() > 80) {
      cout << "overflow" << endl;
      continue;
    }
    if (a.size() < b.size()) {
      swap(a, b);
    }
    for (int k = 0; k < a.size(); k++)
      c[k] = '0';
    for (int k = 0; k < b.size(); k++) {
      c[k] = b[b.size() - 1 - k];
    }
    b.resize(a.size());
    for (int k = 0; k < a.size(); k++) {
      b[k] = c[k];
      c[k] = a[k];
    }
    for (int k = 0; k < a.size(); k++) {
      a[a.size() - k - 1] = c[k];
    }

    tmp = '0';
    for (int k = 0; k < a.size(); k++) {
      c[k] = a[k] + b[k] + tmp - '0' - '0';
      if (c[k] > '9') {
        tmp = '1';
        c[k] = c[k] - ':' + '0';
      } else {
        tmp = '0';
      }
    }
    if ((a.size() <= 80 && tmp == '0') || (a.size() < 80 && tmp == '1')) {
      if (tmp == '1')
        cout << tmp;
      for (int k = a.size() - 1; k >= 0; k--) {
        cout << c[k];
      }
      cout << endl;
    } else {
      cout << "overflow" << endl;
    }
  }
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#define N 1000
using namespace std;
int main() {

  int n, anum, bnum;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string a, b, c, tmp;
    cin >> a >> b;
    if (a.size() < b.size()) {
      swap(a, b);
    }
    for (int k = 0; k < a.size(); k++)
      c[k] = '0';
    for (int k = 0; k < b.size(); k++) {
      c[k] = b[b.size() - 1 - k];
    }
    for (int k = 0; k < a.size(); k++) {
      b[k] = c[k];
      c[k] = a[k];
    }
    for (int k = 0; k < a.size(); k++) {
      a[a.size() - k - 1] = c[k];
      tmp[k] = '0';
    }

    // for(int k = 0;k <= a.size();k++)
    //	cout << a[k] ;
    // cout << endl;
    // for(int k = 0;k <= a.size();k++)
    //	cout << b[k] ;
    // cout << endl;

    for (int k = 0; k < a.size(); k++) {
      //  cout << a[k] << b[k] << " " <<tmp[k] << endl;
      c[k] = a[k] + b[k] + tmp[k] - '0' - '0';

      if (c[k] > '9') {
        tmp[k + 1] = '1';
        c[k] = c[k] - ':' + '0';
      }
    }

    if (a.size() < 80 && tmp[a.size()] == '1') {
      cout << tmp[a.size()];
      for (int k = a.size() - 1; k >= 0; k--) {
        cout << c[k]; // cout << tmp[0];
      }

      cout << endl;
    } else {
      cout << "overflow" << endl;
    }
  }
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

// 0015 National Budget
// 80ÜÅÌ2ÂÌ®Ì«µZÊðoÍ¹æ
// 1sÚÉf[^Zbgnª^¦çêé
// ^¦çê½â»Ìaª80ð´¦½êAoverflowÆoÍµÄ­¾³¢

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

int main(void) {
  int n;
  cin >> n;
  while (n--) {
    const int N = 80;
    int i;
    string a, b;
    // 0ú»@æ­í©çÈ¢ÌÅKÉå«­
    char c[N + 10] = "";

    cin >> a >> b;

    // vZµâ·¢æ¤É½]
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());

    int aSize, bSize;
    aSize = a.size();
    bSize = b.size();

    // Ü¸ÍAcÉ»ÌÜÜlðüêÄ¢­
    for (int i = 0; i < min(max(aSize, bSize), N + 1); i++) {
      int s = 0;
      if (i < aSize)
        s += a[i] - '0';
      if (i < bSize)
        s += b[i] - '0';

      c[i] += s;
      c[i + 1] += c[i] / 10;
      c[i] %= 10;
    }

    // ã©ç©Ä¢ÁÄA0ÈOÌ¶ª»ê½ç¶»·é
    bool isAnswer = false;
    for (i = sizeof(c) - 1; i >= 0; i--) {
      if (c[i])
        isAnswer = true;
      if (isAnswer)
        c[i] += '0';
    }
    // ½]µÄ®¬
    reverse(c, c + strlen(c));

    // àµà80¶ÚªNULL¶Å êÎI[o[t[
    if (c[N])
      cout << "overflow" << endl;
    // dlãA¦ª0ÈçNULL¶ÅÜéÌÅËÁÞ
    else if (c[0] == '\\0')
      cout << '0' << endl;
    else
      cout << c << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

// 0015 National Budget
// 80ÜÅÌ2ÂÌ®Ì«µZÊðoÍ¹æ
// 1sÚÉf[^Zbgnª^¦çêé
// ^¦çê½â»Ìaª80ð´¦½êAoverflowÆoÍµÄ­¾³¢

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

int main(void) {
  int n;
  cin >> n;
  while (n--) {
    const int N = 3;
    int i;
    string a, b;
    // 0ú»
    char c[N + 2] = "";

    cin >> a >> b;

    // vZµâ·¢æ¤É½]
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());

    int aSize, bSize;
    aSize = a.size();
    bSize = b.size();

    // Ü¸ÍAcÉ»ÌÜÜlðüêÄ¢­
    for (int i = 0; i < min(max(aSize, bSize), N + 1); i++) {
      int s = 0;
      if (i < aSize)
        s += a[i] - '0';
      if (i < bSize)
        s += b[i] - '0';

      c[i] += s;
      c[i + 1] += c[i] / 10;
      c[i] %= 10;
    }

    // ã©ç©Ä¢ÁÄA0ÈOÌ¶ª»ê½ç¶»·é
    bool isAnswer = false;
    for (i = sizeof(c) - 1; i >= 0; i--) {
      if (c[i])
        isAnswer = true;
      if (isAnswer)
        c[i] += '0';
    }
    // ½]µÄ®¬
    reverse(c, c + strlen(c));

    // àµà80¶ÚªNULL¶Å êÎI[o[t[
    if (c[N])
      cout << "overflow" << endl;
    // dlãA¦ª0ÈçNULL¶ÅÜéÌÅËÁÞ
    else if (c[0] == '\\0')
      cout << '0' << endl;
    else
      cout << c << endl;
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
#include <string.h>

int n;
char a[1000];
int temp[1000], temp2[1000], temp3[1000];

int main() {
  std::cin >> n;

  while (n--) {
    memset(temp, -1, sizeof(temp));
    memset(temp2, -1, sizeof(temp2));
    memset(temp3, 0, sizeof(temp3));

    std::cin >> a;

    for (int i = 0; i < strlen(a); i++) {
      temp[strlen(a) - i - 1] = a[i] - '0';
    }

    std::cin >> a;

    for (int i = 0; i < strlen(a); i++) {
      temp2[strlen(a) - i - 1] = a[i] - '0';
    }

    int p = 0, f = 0;
    while (1) {
      if (temp[p] != -1 && temp2[p] != -1) {
        temp3[p] = (temp[p] + temp2[p] + f) % 10;
        f = (temp[p] + temp2[p] + f) / 10;
      } else if (temp[p] != -1) {
        temp3[p] = (temp[p] + f) % 10;
        f = (temp[p] + f) / 10;
      } else if (temp2[p] != -1) {
        temp3[p] = (temp2[p] + f) % 10;
        f = (temp2[p] + f) / 10;
      } else
        break;

      p++;
    }

    if (p + f > 80) {
      std::cout << "overflow" << std::endl;
      continue;
    }

    if (f)
      std::cout << -temp[p];

    for (int i = p - 1; i >= 0; i--) {
      std::cout << temp3[i];
    }
    std::cout << std::endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <string.h>

int n;
char a[256], b[256];
int temp[100], temp2[100];

int main() {
  std::cin >> n;

  while (n--) {
    memset(temp, 0, sizeof(temp));
    memset(temp2, 0, sizeof(temp2));

    std::cin >> a >> b;

    int maxlen = std::max(strlen(a), strlen(b));

    if (maxlen > 79) {
      std::cout << "overflow" << std::endl;
      continue;
    }

    for (int i = 0; i < strlen(a); i++) {
      temp[strlen(a) - i - 1] = a[i] - '0';
    }

    for (int i = 0; i < strlen(b); i++) {
      temp2[strlen(b) - i - 1] = b[i] - '0';
    }

    for (int i = 0; i < maxlen; i++) {
      temp[i + 1] += (temp[i] + temp2[i]) / 10;
      temp[i] = (temp[i] + temp2[i]) % 10;
    }

    if (temp[maxlen]) {
      if (maxlen + 1 > 79) {
        std::cout << "overflow" << std::endl;
        continue;
      }

      std::cout << temp[maxlen];
    }

    for (int i = maxlen - 1; i >= 0; i--) {
      std::cout << temp[i];
    }
    std::cout << std::endl;
  }

  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

// AOJ 0015
#include <algorithm>
#include <iostream>
#include <string>
#define rep(i, a) for (int i = 0; i != (a); ++i)

int N;
std::string a, b;

int main() {
  std::cin >> N;
  while (N--) {
    std::cin >> a >> b;
    int asz = a.size(), bsz = b.size(), sz = std::max(asz, bsz);
    if (asz > 80 || bsz > 80) {
      std::cout << "overflow" << std::endl;
      continue;
    }

    std::reverse(a.begin(), a.end());
    std::reverse(b.begin(), b.end());

    a.resize(80);
    b.resize(80);

    std::string ans;
    int c = 0;
    rep(i, sz) {
      if (i >= asz)
        a[i] = '0';
      if (i >= bsz)
        b[i] = '0';

      int t = int(a[i]) + b[i] + c - 2 * '0';
      c = 0;

      if (t >= 10)
        c = 1, t %= 10;
      ans += char(t + '0');
    }

    if (c)
      ans += '1';

    if (ans.size() > 80)
      std::cout << "overflow" << std::endl;
    else {
      rep(i, ans.size()) std::cout << ans[ans.size() - 1 - i];
      std::cout << std::endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

// AOJ 0015
#include <algorithm>
#include <iostream>
#include <string>
#define rep(i, a) for (int i = 0; i != (a); ++i)

int N;
std::string a, b;

int main() {
  std::cin >> N;
  while (N--) {
    std::cin >> a >> b;
    std::reverse(a.begin(), a.end());
    std::reverse(b.begin(), b.end());

    int asz = a.size(), bsz = b.size(), sz = std::max(asz, bsz);

    a.resize(80);
    b.resize(80);

    std::string ans;
    int c = 0;
    rep(i, sz) {
      if (i >= asz)
        a[i] = '0';
      if (i >= bsz)
        b[i] = '0';

      int t = int(a[i]) + b[i] + c - 2 * '0';
      c = 0;

      if (t >= 10)
        c = 1, t %= 10;
      ans += char(t + '0');
    }

    if (c)
      ans += '1';

    if (ans.size() > 80)
      std::cout << "overflow" << std::endl;
    else {
      rep(i, ans.size()) std::cout << ans[ans.size() - 1 - i];
      std::cout << std::endl;
    }
  }

  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <stdio.h>
#include <string.h>
#include <vector>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << x << endl;
using namespace std;

const int MAX = 81;

int main() {
  int n;
  cin >> n;
  while (n--) {
    vector<int> ans;
    string input1, input2;
    int len1, len2, up = 0;

    cin >> input1 >> input2;
    len1 = input1.length() - 1;
    len2 = input2.length() - 1;
    reverse(input1.begin(), input1.end());
    reverse(input2.begin(), input2.end());

    rep(i, MAX) {
      int add = up;
      if (i <= len1) {
        add += input1[i] - '0';
      }
      if (i <= len2) {
        add += input2[i] - '0';
      }
      if (!(add == 0 && i > len1 && i > len2))
        ans.push_back(add % 10);
      up = add / 10;
      if (i > len1 && i > len2)
        break;
    }

    if (ans.size() > 80) {
      cout << "overflow" << endl;
    } else {
      vector<int>::iterator it;
      it = ans.end();
      while (ans.size() != 0) {
        --it;
        cout << *it;
        ans.pop_back();
      }
      cout << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <stdio.h>
#include <string.h>
#include <vector>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << x << endl;
using namespace std;

int main() {
  char in1[81], in2[81];
  int n;
  cin >> n;
  rep(k, n) {
    cin >> in1 >> in2;
    if (strlen(in1) > 80 || strlen(in2) > 80) {
      cout << "overflow" << endl;
      continue;
    }
    int ans[81] = {0};
    int j = 0;
    for (int i = strlen(in1); i > 0; i--) {
      ans[81 - i] += in1[j] - '0';
      j++;
    }
    j = 0;
    for (int i = strlen(in2); i > 0; i--) {
      ans[81 - i] += in2[j] - '0';
      j++;
    }
    for (int i = 80; i >= 0; i--) {
      if (ans[i] >= 10) {
        ans[i] -= 10;
        ans[i - 1]++;
      }
    }
    if (ans[0] != 0) {
      cout << "overflow" << endl;
      continue;
    }
    int len = 80 - max(strlen(in1), strlen(in2)) + 1;
    if (ans[len - 1] != 0)
      cout << ans[len - 1];
    range(i, len, 81) { cout << ans[i]; }
    cout << endl;
  }
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(T) T.begin(), T.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--) {
    vi res(81);

    rep(i, 2) {
      string in;
      cin >> in;
      if (in.size() > 80) {
        res[80] = 1;
        continue;
      }
      rep(j, in.size() + 1) {
        if (j != in.size())
          res[j] += in.at(in.size() - j - 1) - '0';
        for (int l = 0; res[j + l] > 9; l++)
          res[j + l + 1]++, res[j + l] %= 10;
      }
    }

    if (res[80]) {
      cout << "overflow" << endl;
      continue;
    }

    bool ok = false;
    for (int i = 79; i >= 0; i--) {
      if (!ok)
        if (res[i] || !i)
          ok = true;
      if (ok)
        cout << res[i];
    }
    cout << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(T) T.begin(), T.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--) {
    vi res(82);

    rep(i, 2) {
      string in;
      cin >> in;
      rep(j, in.size() + 1) {
        if (j != in.size())
          res[j] += in[in.size() - j - 1] - '0';
        for (int l = 0; res[j + l] > 9; l++)
          res[j + l + 1]++, res[j + l] %= 10;
      }
    }

    if (res[80]) {
      cout << "overflow" << endl;
      continue;
    }

    bool ok = false;
    for (int i = 79; i >= 0; i--) {
      if (!ok)
        if (res[i])
          ok = true;
      if (ok)
        cout << res[i];
    }
    cout << endl;
  }

  return 0;
}