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

#include <algorithm>
#include <iostream>
#include <map>
#include <utility>
#include <vector>

using namespace std;

struct Cell {
  int e;
  int a;
};

double solve(vector<Cell> &cel, int pos, vector<int> &vs, int money,
             vector<map<int, double>> &mem) {
  double retval = 0;
  int vl = vs.size();
  int cl = cel.size();
  if (!mem[pos].empty() && (mem[pos].find(money) != mem[pos].end())) {
    return mem[pos][money];
  }
  if (pos >= cl)
    return money;
  for (int i = 0; i < vl; ++i) {
    int v = vs[i];
    if (pos + v >= cl) {
      retval += money;
      continue;
    }
    Cell &cur = cel[pos + v];
    if (cur.e == 0)
      retval += solve(cel, pos + v, vs, money, mem);
    else if (cur.e == 1)
      retval += solve(cel, pos + v + cur.a, vs, money, mem);
    else if (cur.e == 2)
      retval += solve(cel, pos + v, vs, money + cur.a, mem);
    else if (cur.e == 3)
      retval +=
          solve(cel, pos + v, vs, (money > cur.a) ? money - cur.a : 0, mem);
  }
  mem[pos][money] = retval / vl;
  return mem[pos][money];
}

int main() {
  while (1) {
    int x, y, z;
    int i;
    int vl;
    cin >> x >> y >> z;
    if (x == 0 && y == 0 && z == 0)
      break;
    vector<int> vs(x);
    vector<Cell> cells(y);
    vector<map<int, double>> mem(y + 100);
    for (i = 0; i < x; ++i) {
      cin >> vs[i];
    }
    for (i = 0; i < z; ++i) {
      int n;
      cin >> n;
      cin >> cells[n].e;
      cin >> cells[n].a;
    }
    cout << (int)solve(cells, 0, vs, 0, mem) << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <utility>
#include <vector>

using namespace std;

struct Cell {
  int e;
  int a;
};

double solve(vector<Cell> &cel, int pos, vector<int> &vs, int money,
             vector<map<int, double>> &mem) {
  double retval = 0;
  int vl = vs.size();
  int cl = cel.size();
  if (!mem[pos].empty() && (mem[pos].find(money) != mem[pos].end())) {
    return mem[pos][money];
  }
  if (pos >= cl)
    return money;
  for (int i = 0; i < vl; ++i) {
    int v = vs[i];
    if (pos + v >= cl) {
      retval += money;
      continue;
    }
    Cell &cur = cel[pos + v];
    if (cur.e == 0)
      retval += solve(cel, pos + v, vs, money, mem);
    else if (cur.e == 1)
      retval += solve(cel, pos + v + cur.a, vs, money, mem);
    else if (cur.e == 2)
      retval += solve(cel, pos + v, vs, money + cur.a, mem);
    else if (cur.e == 3)
      retval +=
          solve(cel, pos + v, vs, (money > cur.a) ? money - cur.a : 0, mem);
  }
  mem[pos][money] = retval / vl;
  return mem[pos][money];
}

int main() {
  while (1) {
    int x, y, z;
    int i;
    int vl;
    cin >> x >> y >> z;
    if (x == 0 && y == 0 && z == 0)
      break;
    vector<int> vs(x);
    vector<Cell> cells(y);
    vector<map<int, double>> mem(y);
    for (i = 0; i < x; ++i) {
      cin >> vs[i];
    }
    for (i = 0; i < z; ++i) {
      int n;
      cin >> n;
      cin >> cells[n].e;
      cin >> cells[n].a;
    }
    cout << (int)solve(cells, 0, vs, 0, mem) << endl;
  }
}
Problem p00232 (C++) — buggy submission, verdict: Runtime Error

// AOJ 0232
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <map>
#include <utility>
#define rep(i, a) for (int i = 0; i < (a); ++i)

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

int X, Y, Z;
int V[4];
std::map<int, P> evnts;
double dp[51][5001][2];

double rec(int pos, int sum, bool eof) {
  double &ret = dp[pos][sum][eof];

  if (ret >= 0)
    return ret;

  ret = 0;

  if (pos == Y)
    return ret = sum;

  if (evnts.count(pos) && !eof) {
    int a = evnts[pos].second;

    switch (evnts[pos].first) {
    case 1:
      return ret = rec(std::min(Y, pos + a), sum, true);
    case 2:
      return ret = rec(pos, sum + a, true);
    case 3:
      return ret = rec(pos, std::max(0, sum - a), true);
    }
  }

  rep(i, X) ret += rec(std::min(Y, pos + V[i]), sum, false) / X;

  return ret;
}

int main() {
  while (scanf("%d%d%d", &X, &Y, &Z), X | Y | Z) {
    evnts.clear();

    rep(i, X) scanf("%d", V + i);
    int sum = 0;
    rep(i, Z) {
      int N, E, A;
      scanf("%d%d%d", &N, &E, &A);
      evnts[N] = P(E, A);
      if (E == 2)
        sum += A;
    }

    rep(i, Y + 1) rep(j, sum + 1) rep(l, 2) dp[i][j][l] = -1.0;
    printf("%d\\n", (int)rec(0, 0, false));
  }

  return 0;
}

Error: 0

Fixed submission:

// AOJ 0232
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <map>
#include <utility>
#define rep(i, a) for (int i = 0; i < (a); ++i)

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

int X, Y, Z;
int V[4];
std::map<int, P> evnts;
double dp[50][5001][2];

double rec(int pos, int sum, bool eof) {
  double &ret = dp[pos][sum][eof];

  if (ret >= 0)
    return ret;

  ret = 0;

  if (pos == Y)
    return ret = sum;

  if (evnts.count(pos) && !eof) {
    int a = evnts[pos].second;

    switch (evnts[pos].first) {
    case 1:
      return ret = rec(std::min(Y, pos + a), sum, true);
    case 2:
      return ret = rec(pos, sum + a, true);
    case 3:
      return ret = rec(pos, std::max(0, sum - a), true);
    }
  }

  rep(i, X) ret += rec(std::min(Y, pos + V[i]), sum, false) / X;

  return ret;
}

int main() {
  while (scanf("%d%d%d", &X, &Y, &Z), X | Y | Z) {
    evnts.clear();

    rep(i, X) scanf("%d", V + i);
    int sum = 0;
    rep(i, Z) {
      int N, E, A;
      scanf("%d%d%d", &N, &E, &A);
      evnts[N] = P(E, A);
      if (E == 2)
        sum += A;
    }

    rep(i, Y + 1) rep(j, sum + 1) rep(l, 2) dp[i][j][l] = -1.0;
    printf("%d\\n", (int)rec(0, 0, false));
  }

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

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
double ans, dp[51][3000];
int X, Y, Z;

int dice[4], t[51], u[51], N;
void init();
double dfs(int, int);

int main() {
  while (cin >> X >> Y >> Z && X) {
    init();
    for (int i = 0; i < X; i++)
      cin >> dice[i];
    for (int i = 0; i < Z; i++) {
      cin >> N;
      cin >> t[N] >> u[N];
    }
    cout << (int)dfs(0, 0) << endl;
  }
  return 0;
}

void init() {
  for (int i = 0; i < 51; i++) {
    for (int j = 0; j < 3000; j++)
      dp[i][j] = -1.0;
    t[i] = u[i] = 0;
  }
}

double dfs(int pos, int cnt) {
  if (pos >= Y)
    return (double)cnt;
  if (dp[pos][cnt] != -1.0)
    return dp[pos][cnt];
  double res = 0;
  for (int i = 0; i < X; i++) {
    int npos = pos + dice[i];
    if (t[npos] == 1)
      res += dfs(npos + u[npos], cnt);
    else if (t[npos] == 2)
      res += dfs(npos, cnt + u[npos]);
    else
      res += dfs(npos, max(0, cnt - u[npos]));
  }
  return dp[pos][cnt] = res / (double)X;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
double ans, dp[51][3000];
int X, Y, Z;

int dice[4], t[51], u[51], N;
void init();
double dfs(int, int);

int main() {
  while (cin >> X >> Y >> Z && X) {
    init();
    for (int i = 0; i < X; i++)
      cin >> dice[i];
    for (int i = 0; i < Z; i++) {
      cin >> N;
      cin >> t[N] >> u[N];
    }
    cout << (int)dfs(0, 0) << endl;
  }
  return 0;
}

void init() {
  for (int i = 0; i < 51; i++) {
    for (int j = 0; j < 3000; j++)
      dp[i][j] = -1.0;
    t[i] = u[i] = 0;
  }
}

double dfs(int pos, int cnt) {
  if (pos >= Y)
    return (double)cnt;
  if (dp[pos][cnt] != -1.0)
    return dp[pos][cnt];
  double res = 0;
  for (int i = 0; i < X; i++) {
    int npos = pos + dice[i];
    if (t[npos] == 1)
      res += dfs(npos + u[npos], cnt);
    else if (t[npos] == 2)
      res += dfs(npos, cnt + u[npos]);
    else
      res += dfs(npos, max(0, cnt - u[npos]));
  }
  return res / (double)X;
}
Problem p00233 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
using namespace std;
typedef long long ll;

string minu(ll n, int base) {
  string res;
  if (n == 0)
    return "0";
  ll a, b;
  int t = 0;
  for (; n; t++) {
    t = t & 1;
    a = n / base;
    b = n - a * base;
    if (b < 0 && t == 0) {
      b += base;
      a -= 1;
    } else if (t == 1 && b > 0) {
      b -= base;
      a += 1;
    }
    if (b < 0)
      b = -b;
    res = " " + res;
    res[0] = b + '0';
    n = a;
  }

  return res;
}

int main() {
  ll value;
  while (cin >> value, value) {
    cout << minu(value, 10) << endl;
  }
  return 0;
}

Error: -8

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define F first
#define S second
using namespace std;
typedef unsigned long long ll;
typedef pair<ll, int> P;
ll p, q;
bool ch;
bool flag;
string result;
string result2;
map<ll, bool> index;
int debug;

P dfs(ll value) {
  if (!value) {
    ch = true;
    flag = false;
    return P(-(1 << 29), 0);
  }
  // cout<< "value = " << value << " : " << result << endl;
  assert(value >= 0);
  if (index[value])
    return P(value, 0);
  index[value] = true;
  if (value < q) {
    result += "0";
    P res = dfs(value * 10);
    if (flag)
      res.second++;
    if (res.first == value)
      flag = false;
    return res;
  } else {
    ll v = value / q;
    if (v >= 9)
      v = 9;

    result += (char)('0' + v);

    P res = dfs(10 * (value - q * v));
    if (flag)
      res.second++;
    if (res.first == value)
      flag = false;
    return res;
  }
}

int main() {

  while (cin >> p >> q) {
    ch = false;
    debug = 0;
    result2.clear();
    result.clear();
    index.clear();
    flag = true;
    P pes = dfs(p);
    reverse(result2.begin(), result2.end());
    cout << result.substr(1) << endl;
    if (!ch) {
      // string res = result.substr(1);
      // cout << result2.substr(1) << endl;
      string resu2;
      rep(i, result.size() - pes.second - 1) resu2 += " ";
      rep(i, pes.second) resu2 += "^";
      resu2 += string(result.size() - pes.second - 1, ' ');

      cout << resu2 << endl;
    }
  }
  return 0;
}
Problem p00233 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

typedef long long BigInt;

int main() {
  vector<BigInt> min_n, max_n, base;
  min_n.push_back(0);
  max_n.push_back(9);
  base.push_back(1);
  while (not(min_n[base.size() - 1] <= -(1LL << 31) and
             max_n[base.size() - 1] <= (1LL << 31))) {
    int p = base.size();
    base.push_back(base[p - 1] * 10);
    if (p % 2 == 0) {
      max_n.push_back(max_n[p - 1] + 9 * base[p]);
      min_n.push_back(min_n[p - 1]);
    } else {
      max_n.push_back(max_n[p - 1]);
      min_n.push_back(min_n[p - 1] - 9 * base[p]);
    }
  }
  while (true) {
    BigInt n;
    int p = 0;
    string md = "";
    cin >> n;
    if (n == 0) {
      return 0;
    }
    while (not(min_n[p] <= n and n <= max_n[p])) {
      ++p;
    }
    while (p > 0) {
      for (int d = 0; d < 10; ++d) {
        BigInt r = n + (p % 2 == 0 ? -1 : 1) * base[p] * d;
        if (min_n[p - 1] <= r and r <= max_n[p - 1]) {
          n = r;
          md += '0' + d;
          break;
        }
      }
      --p;
    }
    if (0 <= n and n < 10) {
      md += '0' + n;
    } else {
      md += '0';
    }
    cout << md << endl;
  }
}

Error: WA

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

typedef long long BigInt;

int main() {
  vector<BigInt> min_n, max_n, base;
  min_n.push_back(0);
  max_n.push_back(9);
  base.push_back(1);
  while (not(min_n[base.size() - 1] <= -(1LL << 31) and
             max_n[base.size() - 1] <= (1LL << 31))) {
    int p = base.size();
    base.push_back(base[p - 1] * 10);
    if (p % 2 == 0) {
      max_n.push_back(max_n[p - 1] + 9 * base[p]);
      min_n.push_back(min_n[p - 1]);
    } else {
      max_n.push_back(max_n[p - 1]);
      min_n.push_back(min_n[p - 1] - 9 * base[p]);
    }
  }
  while (true) {
    BigInt n;
    int p = 0;
    string md = "";
    cin >> n;
    if (n == 0) {
      return 0;
    }
    while (not(min_n[p] <= n and n <= max_n[p])) {
      ++p;
    }
    cerr << p << endl;
    while (p > 0) {
      for (int d = 0; d < 10; ++d) {
        BigInt r = n + (p % 2 == 0 ? -1 : 1) * base[p] * d;
        if (min_n[p - 1] <= r and r <= max_n[p - 1]) {
          n = r;
          md += '0' + d;
          break;
        }
      }
      --p;
    }
    if (0 <= n and n < 10) {
      md += '0' + n;
    } else {
      md += '0';
    }
    cout << md << endl;
    return 0;
  }
}
Problem p00233 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

long long llpow(long long t, long long a) {
  long long ret = 1;
  for (int i = 0; i < a; ++i) {
    ret *= t;
  }
  return ret;
}

int len;
int ans[32];
#define POSITIVE 1
#define NEGATIVE 2

long long lim(int type, int a) {
  if (type == POSITIVE) {
    long long ret = 0;
    for (int i = a - 1; i >= 0; --i) {
      if (i % 2 == 0)
        ret += 9 * llpow(10, i);
    }
    return ret;
  } else {
    long long ret = 0;
    for (int i = a - 1; i >= 0; --i) {
      if (i % 2 == 1)
        ret += 9 * llpow(10, i);
    }
    return ret;
  }
}

void solve(long long n) {
  if (n == 0)
    return;
  int a = 0;
  if (n > 0) {
    long long L = 9;
    while (true) {
      if (n <= L)
        break;
      L = 100 * L + 9;
      a += 2;
    }
  } else {
    long long L = -90;
    a = 1;
    while (true) {
      if (n >= L)
        break;
      L = 100 * L - 90;
      a += 2;
    }
  }
  len = max(a, len);
  long long B = llpow(-10, a);
  if (B < 0) {
    int t = 0;
    while (true) {
      if (t * B <= n) {
        break;
      }
      ++t;
    }
    if (t * B + lim(POSITIVE, a) < n)
      --t;
    n -= t * B;
    ans[a] = t;
    solve(n);
  } else {
    int t = 0;
    while (true) {
      if (t * B >= n) {
        break;
      }
      ++t;
    }
    if (t * B - lim(NEGATIVE, a) > n)
      --t;
    n -= t * B;
    ans[a] = t;
    solve(n);
  }
  return;
}

int main() {
  long long n;
  while (EOF != scanf("%lld", &n)) {
    if (n == 0)
      break;
    len = 0;
    for (int i = 0; i < 32; ++i) {
      ans[i] = 0;
    }
    solve(n);
    for (int i = len; i >= 0; --i) {
      printf("%d", ans[i]);
    }
    putchar('\\n');
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdlib>
#include <iostream>

using namespace std;

long long llpow(long long t, long long a) {
  long long ret = 1;
  for (int i = 0; i < a; ++i) {
    ret *= t;
  }
  return ret;
}

int main() {
  while (true) {
    long long n;
    scanf("%Ld", &n);
    if (n == 0)
      break;
    int a = 0;
    if (n > 0) {
      long long L = 9;
      while (true) {
        if (n <= L)
          break;
        L = 100 * L + L;
        a += 2;
      }
    } else {
      long long L = -90;
      a = 1;
      while (true) {
        if (n >= L)
          break;
        L = 100 * L + L;
        a += 2;
      }
    }
    long long s = 0;
    for (int la = a; la >= 0; --la) {
      long long B = llpow(-10, la);
      // cout << "B:"<<B<<endl;
      if (la % 2 == 1) {
        int t = 0;
        s += t * B;
        while (true) {
          if (s <= n) {
            break;
          }
          s += B;
          ++t;
        }
        cout << t;
      } else {
        int t = 0;
        s += t * B;
        while (true) {
          if (s >= n) {
            break;
          }
          s += B;
          ++t;
        }
        cout << t;
      }
    }
    cout << endl;
  }
  return 0;
}
Problem p00233 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

int n;
int pw[10] = {1,      10,      100,      1000,      10000,
              100000, 1000000, 10000000, 100000000, 1000000000};

int solve() {
  int tmp = n;
  int ans = 0;
  for (int i = 0;; i++) {
    if (tmp % -10 < 0) {
      ans += (10 + tmp % -10) * pw[i];
      tmp -= 10;
    } else
      ans += tmp % -10 * pw[i];
    tmp = tmp / (-10);
    if (!tmp)
      break;
  }
  return ans;
}

int main() {
  while (true) {
    std::cin >> n;
    if (!n)
      return 0;
    std::cout << solve() << std::endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>

int n;
int mt[10] = {1,       -10,     100,       -1000,     10000,
              -100000, 1000000, -10000000, 100000000, -1000000000};
int pow[10] = {1,      10,      100,      1000,      10000,
               100000, 1000000, 10000000, 100000000, 1000000000};
int nin[10] = {0, 0, -90, 0, -9090, 0, -909090, 0, -90909090, 0};

int solve() {
  int k, ans = 0;
  bool flag = false;
  for (k = 0; n / pow[k] != 0; k++)
    ;
  if (k % 2 == 0 && n < 0 && n < nin[k])
    flag = true;
  if (n > 0)
    k = 2 * k - 2;
  else if (k % 2 == 0)
    k--;
  if (flag)
    k += 2;
  int i = 1;
  int tmp, temp = 0;
  for (; k >= 0; k--) {
    i = 0;
    while (true) {
      tmp = i * mt[k];
      if ((temp + tmp <= n && k % 2 != 0) || (temp + tmp >= n && k % 2 == 0)) {
        temp += tmp;
        if (tmp < 0)
          tmp = -tmp;
        ans += tmp;
        break;
      }
      i++;
    }
    if (temp == n)
      break;
  }
  return ans;
}

int main() {
  while (true) {
    std::cin >> n;
    if (!n)
      return 0;
    std::cout << solve() << std::endl;
  }
}
Problem p00233 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

void solve(int n) {
  if (!n)
    return;
  if (n % (-10) < 0)
    solve((n - 10) / (-10));
  else
    solve(n / (-10));
  if (n % (-10) < 0)
    cout << 10 + n % (-10);
  else
    cout << n % (-10);
}

int main() {
  int n;
  while (true) {
    cin >> n;
    if (!n)
      return 0;
    solve(n);
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>

int n;
int mt[10] = {1,       -10,     100,       -1000,     10000,
              -100000, 1000000, -10000000, 100000000, -1000000000};
int pow[10] = {1,      10,      100,      1000,      10000,
               100000, 1000000, 10000000, 100000000, 1000000000};
int nin[10] = {0,     100,     -90,     909,       -9090,
               90909, -909090, 9090909, -90909090, 909090909};

int solve() {
  int k, ans = 0;
  bool flag = false;
  int i = 1;
  int tmp, temp = 0;
  for (k = 0; n / pow[k] != 0; k++)
    ;
  if ((k % 2 == 0 && n < nin[k] && n < 0) ||
      (k % 2 != 0 && n > nin[k] && n > 0))
    flag = true;
  if (k % 2 == 0 && n < 0)
    k--;
  if (flag) {
    ans = pow[k + 2] + 9 * pow[k + 1];
    temp = mt[k + 2] + 9 * mt[k + 1];
  } else if (n > 0 && k > 1) {
    if (k % 2 != 0)
      k--;
    ans = mt[k];
    temp = mt[k];
    k--;
  }

  for (; k >= 0; k--) {
    i = 0;
    while (true) {
      tmp = i * mt[k];
      if (temp + tmp - n < pow[k] && temp + tmp - n > -pow[k]) {
        temp += tmp;
        if (tmp < 0)
          tmp = -tmp;
        ans += tmp;
        break;
      }
      i++;
    }
    if (temp == n)
      break;
  }
  return ans;
}

int main() {
  while (true) {
    std::cin >> n;
    if (!n)
      return 0;
    std::cout << solve() << std::endl;
  }
}
Problem p00233 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
vector<pair<long long, long long>> v1, v2;
long long power[16], power2[16];
long long solve(long long F, int p) {
  long long sum = 0;
  for (int i = p; i < p + 6; i++)
    sum += power[i] * ((F / power2[i - p]) % 10);
  return sum;
}
int main() {
  power[0] = 1;
  for (int i = 1; i < 16; i++)
    power[i] = power[i - 1] * (-10);
  power2[0] = 1;
  for (int i = 1; i < 16; i++)
    power2[i] = power2[i - 1] * (+10);
  for (int i = 0; i < 10000; i++) {
    v1.push_back(make_pair(solve(i, 0), i));
  }
  for (int i = -999999; i < 1000000; i++) {
    v2.push_back(make_pair(solve(i, 4), i));
  }
  sort(v2.begin(), v2.end());
  while (true) {
    long long r;
    cin >> r;
    if (r == 0)
      break;
    for (int i = 0; i < 10000; i++) {
      long long pos1 =
          lower_bound(v2.begin(), v2.end(), make_pair((r - v1[i].first), 0LL)) -
          v2.begin();
      if (pos1 < v2.size() && v2[pos1].first == (r - v1[i].first)) {
        cout << i + v2[pos1].second * 10000 << endl;
      }
    }
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
vector<pair<long long, long long>> v1, v2;
long long power[16], power2[16];
long long solve(long long F, int p) {
  long long sum = 0;
  for (int i = p; i < p + 6; i++)
    sum += power[i] * ((F / power2[i - p]) % 10);
  return sum;
}
int main() {
  power[0] = 1;
  for (int i = 1; i < 16; i++)
    power[i] = power[i - 1] * (-10);
  power2[0] = 1;
  for (int i = 1; i < 16; i++)
    power2[i] = power2[i - 1] * (+10);
  for (int i = 0; i < 10000; i++) {
    v1.push_back(make_pair(solve(i, 0), i));
  }
  for (int i = -9999999; i < 10000000; i++) {
    v2.push_back(make_pair(solve(i, 4), i));
  }
  sort(v2.begin(), v2.end());
  while (true) {
    long long r;
    cin >> r;
    if (r == 0)
      break;
    for (int i = 0; i < 10000; i++) {
      long long pos1 =
          lower_bound(v2.begin(), v2.end(), make_pair((r - v1[i].first), 0LL)) -
          v2.begin();
      if (pos1 < v2.size() && v2[pos1].first == (r - v1[i].first)) {
        cout << i + v2[pos1].second * 1000000 << endl;
      }
    }
  }
  return 0;
}
Problem p00233 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
typedef long long ll;

int main() {
  ll a;
  while (cin >> a, a) {
    ll ans = 0, k = 1;
    while (a) {
      int b = 10 * (a % 10 < 0);
      ans += (b + a % 10) * k;
      (a -= b) /= -10;
      k *= 10;
    }
    cout << ans << endl;
  }
}

Error: -6
4d51e075-7106-43e3-ad3c-74f4fd4015d0.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p00233/C++/s167716711.cpp:32: int main(): Assertion `a>-100000000LL' failed.


Fixed submission:

#include <cassert>
#include <iostream>
using namespace std;
typedef long long ll;

int rec(ll a) {
  if (0 <= a && a < 10)
    return a;
  if (a > 0) {
    ll k = 1;
    for (;;) {
      for (ll i = 1; i < 10LL; i++) {
        if (a - i * k < k / 10)
          return i * k + rec(a - i * k);
      }
      k *= 100;
    }
  } else {
    a *= -1;
    ll k = 10;
    for (;;) {
      for (ll i = 1; i < 10LL; i++) {
        if (a - i * k < k / 10)
          return i * k + rec(-a + i * k);
      }
      k *= 100;
    }
  }
}

int main() {
  ll a;
  while (cin >> a) {
    if (a == 0)
      break;
    assert(a > -100000000LL);
    cout << rec(a) << endl;
  }
}
Problem p00233 (C++) — buggy submission, verdict: Runtime Error

#include <cassert>
#include <iostream>
using namespace std;
int ans[100];
int main() {
  while (1) {
    long long n;
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < 100; i++)
      ans[i] = 0;
    for (int i = 0; i < 100; i++) {
      int a = n % 10;
      n /= 10;
      if (i && ans[i - 1] == 10) {
        if (i % 2 == 1)
          a++;
        else
          a--;
        ans[i - 1] -= 10;
      }
      if (i % 2 == 1)
        a *= -1;
      if (a >= 0)
        ans[i] += a;
      else
        ans[i] += (10 + a), ans[i + 1]++;
    }

    long long c = 0;
    for (int i = 99; i >= 0; i--) {
      c = c * 10LL + (long long)ans[i];
      // cout<<ans[i]<<endl;
    }
    cout << c << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cassert>
#include <iostream>
using namespace std;
int ans[100];
int main() {
  while (1) {
    long long n;
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < 100; i++)
      ans[i] = 0;
    for (int i = 0; i < 100; i++) {
      if (n == 0)
        break;
      int a = n % 10;
      n /= 10;
      if (i % 2 == 1)
        a *= -1;

      if (a >= 0)
        ans[i] += a;
      else
        ans[i] += (10 + a), ans[i + 1]++;
    }
    for (int i = 0; i < 99; i++) {
      if (ans[i] >= 10)
        assert(0);
    }
    long long c = 0;
    for (int i = 99; i >= 0; i--)
      c = c * 10LL + (long long)ans[i];
    cout << c << endl;
  }
  return 0;
}