alexjercan/bugnet huggingface dataset:
Problem p00110 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int int_pow(int n, int m) {
  int ans = 1;
  while (m--)
    ans *= n;
  return ans;
}

int main() {
  while (true) {
    vector<int> n[3];
    char C;
    int r;
    int cnt = 0;
    while (true) {
      r = scanf("%c", &C);
      if (r == EOF)
        return 0;
      if (C == '\\n')
        break;
      else if (C == '+' || C == '=')
        cnt++;
      else if (C == 'X')
        n[cnt].push_back(-1);
      else
        n[cnt].push_back(C - '0');
    }
    bool na = true;
    for (int t = 0; t < 10; t++) {
      int n_[3] = {};
      for (int i = 0; i < 3; i++) {
        if (t == 0 && n[i].size() >= 2 && n[i][0] == -1)
          goto NEXT;
        for (int j = 0; j < n[i].size(); j++) {
          int a = n[i][n[i].size() - j - 1];
          if (a == -1)
            a = t;
          n_[i] += a * int_pow(10, j);
        }
      }
      if (n_[0] + n_[1] == n_[2]) {
        printf("%d\\n", t);
        na = false;
        break;
      }
    NEXT:;
    }
    if (na)
      puts("NA");
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int int_pow(int n, int m) {
  int ans = 1;
  while (m--)
    ans *= n;
  return ans;
}

int main() {
  while (true) {
    vector<int> n[3];
    char C;
    int r;
    int cnt = 0;
    while (r = scanf("%c", &C), C != '\\n') {
      if (r == EOF)
        return 0;
      else if (C == '+' || C == '=')
        cnt++;
      else if (C == 'X')
        n[cnt].push_back(-1);
      else
        n[cnt].push_back(C - '0');
    }
    bool na = true;
    for (int t = 0; t < 9; t++) {
      int n_[3] = {};
      for (int i = 0; i < 3; i++) {
        for (int j = 0; j < n[i].size(); j++) {
          int a = n[i][n[i].size() - j - 1];
          if (a == -1)
            a = t;
          n_[i] += a * int_pow(10, j);
        }
      }
      if (n_[0] + n_[1] == n_[2]) {
        printf("%d\\n", t);
        na = false;
        break;
      }
    }
    if (na)
      puts("NA");
  }
}
Problem p00110 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
// #define int ll

signed main(void) {
  string s;
  while (cin >> s) {
    string a = s.substr(0, s.find("+")),
           b = s.substr(s.find("+") + 1, s.find("=") - s.find("+") - 1),
           c = s.substr(s.find("=") + 1);

    reverse(ALL(a));
    reverse(ALL(b));
    reverse(ALL(c));
    string ans = "-1";
    for (char i = '0'; i <= '9'; ++i) {
      string aa = a, bb = b, cc = c;
      REP(j, a.size()) if (a[j] == 'X') aa[j] = i;
      REP(j, b.size()) if (b[j] == 'X') bb[j] = i;
      REP(j, c.size()) if (c[j] == 'X') cc[j] = i;

      if (i == '0' && aa.size() >= 2 && aa[aa.size() - 1] == '0')
        continue;
      if (i == '0' && bb.size() >= 2 && bb[bb.size() - 1] == '0')
        continue;
      if (i == '0' && cc.size() >= 2 && cc[cc.size() - 1] == '0')
        continue;

      string n = "";
      int ca = 0, m = cc.size();
      REP(i, m) {
        int cu = ca;
        if (i < aa.size())
          cu += (aa[i] - '0');
        if (i < bb.size())
          cu += (bb[i] - '0');
        ca = cu / 10;
        n += (cu % 10 + '0');
      }
      if (ca == 0 && n == cc) {
        ans = i;
      }
    }
    if (ans == "-1")
      cout << "NA" << endl;
    else
      cout << ans << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
// #define int ll

signed main(void) {
  string s;
  while (cin >> s) {
    bool flag = true;
    string a = s.substr(0, s.find("+")),
           b = s.substr(s.find("+") + 1, s.find("=") - s.find("+") - 1),
           c = s.substr(s.find("=") + 1);
    // cout << a << " " << b << " " << c << endl;
    for (char i = '0'; i <= '9'; ++i) {
      string aa = a, bb = b, cc = c;
      REP(j, a.size()) if (a[j] == 'X') aa[j] = i;
      REP(j, b.size()) if (b[j] == 'X') bb[j] = i;
      REP(j, c.size()) if (c[j] == 'X') cc[j] = i;
      int d = stoi(aa), e = stoi(bb), f = stoi(cc);
      // cout << d << " " << e << " " << f << endl;
      if (d + e == f) {
        cout << i << endl;
        flag = false;
        break;
      }
    }
    if (flag)
      cout << "NA" << endl;
  }

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

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

long long int const MOD = 1000000007;

vector<string> split(string s) {
  vector<string> ret;
  string temp;
  replace(s.begin(), s.end(), '+', ' ');
  replace(s.begin(), s.end(), '=', ' ');
  stringstream ss(s);
  while (ss >> temp)
    ret.push_back(temp);
  return ret;
}

bool solve(vector<string> vs, int x) {
  vector<long long int> res(3);
  for (size_t i = 0; i < 3; i++) {
    for (size_t j = 0; j < vs[i].length(); j++) {
      if (vs[i][j] == 'X') {
        if (x == 0 && j == 0 && vs[i].length() != 1)
          return false;
        res[i] = (res[i] * 10 + x) % MOD;
      } else
        res[i] = (res[i] * 10 + (vs[i][j] - '0')) % MOD;
    }
  }
  long long int ra = (res[0] + res[1]) % MOD, rb = res[2];
  return ra == rb;
}

int main() {
  string s;
  while (cin >> s) {
    vector<string> vs = split(s);
    bool ok = false;
    for (int i = 0; i < 10; i++) {
      if (solve(vs, i)) {
        cout << i << endl;
        ok = true;
        break;
      }
    }
    if (!ok)
      cout << "NA" << endl;
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>

char text[130];

bool solve(int s, int t, int x) {
  int cur = s, val = 0, vl = 0, vr = 0;
  while (cur < t) {
    if (text[cur] == 'X')
      val = val * 10 + x;
    else if (text[cur] == '+')
      vl += val, val = 0;
    else if (text[cur] == '=')
      vl += val, val = 0;
    else
      val = val * 10 + (text[cur] - '0');
    cur++;
  }
  vr += val;
  return vl == vr;
}

int main() {
  while (scanf("%s", text)) {
    int N = strlen(text);
    bool ok = false;
    for (int i = 0; i < 10; i++) {
      if (solve(0, N, i)) {
        printf("%d\\n", i);
        ok = true;
      }
    }
    if (!ok)
      printf("NA\\n");
  }
}
Problem p00110 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define rep(i, l, n) for (lint i = l; i < n; i++)
#define rer(i, l, n) for (lint i = l; i <= n; i++)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define pb(a) push_back(a)
#define mk(a, b) make_pair(a, b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

string solve(string s, string t) {
  if (s.size() < t.size())
    swap(s, t);
  for (int i = s.size() - 1, j = t.size() - 1; i >= 0; i--, j--) {
    if (j >= 0)
      s[i] += t[j] - '0';
    if (s[i] > '9') {
      s[i] -= 10;
      if (i == 0)
        s = '1' + s;
      else
        s[i - 1]++;
    }
  }
  return s;
}

int main() {
  string s;
  while (cin >> s) {
    rep(i, 0, 10) {
      string t;
      rep(j, 0, s.size()) {
        if (s[j] == 'X')
          t[j] = '0' + i;
        else
          t[j] = s[j];
      }
      string a, b, c;
      int x, y;
      rep(j, 0, s.size()) {
        if (s[j] == '+')
          x = j;
        if (s[j] == '=')
          y = j;
      }
      rep(j, 0, x) a += t[j];
      rep(j, x + 1, y) b += t[j];
      rep(j, y + 1, s.size()) c += t[j];
      if ((a[0] == '0' && a != "0") || (b[0] == '0' && b != "0") ||
          (c[0] == '0' && c != "0"))
        continue;
      if (solve(a, b) == c) {
        o(i);
        break;
      }
      if (i == 9)
        o("NA");
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define rep(i, l, n) for (lint i = l; i < n; i++)
#define rer(i, l, n) for (lint i = l; i <= n; i++)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define pb(a) push_back(a)
#define mk(a, b) make_pair(a, b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main() {
  string s;
  while (cin >> s) {
    rep(i, 0, 10) {
      string t;
      rep(j, 0, s.size()) {
        if (s[j] == 'X')
          t[j] = '0' + i;
        else
          t[j] = s[j];
      }
      string a, b, c;
      int x, y;
      rep(j, 0, s.size()) {
        if (s[j] == '+')
          x = j;
        if (s[j] == '=')
          y = j;
      }
      rep(j, 0, x) a += t[j];
      rep(j, x + 1, y) b += t[j];
      rep(j, y + 1, s.size()) c += t[j];
      int d = stoi(a), e = stoi(b), f = stoi(c);
      if (d + e == f) {
        o(i);
        break;
      }
      if (i == 9)
        o("NA");
    }
  }
}
Problem p00110 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define INF 999999999
#define int ll

vector<string> split(string s, char ch) {
  vector<string> ret;
  string tmp = "";
  rep(i, s.size()) {
    if (s[i] == ch) {
      ret.pb(tmp);
      tmp = "";
    } else
      tmp += s[i];
  }
  if (tmp.size())
    ret.pb(tmp);
  return ret;
}

string addString(string a, string b) {
  if (a.size() < b.size())
    swap(a, b); // len(a)>len(b)???
  b = string(a.size() - b.size(), '0') +
      b; // b????????????a??¨??????????????????????????????0??§?????????

  string ans =
      string(a.size() + 1, '0'); // a?????????+1 ?????????0??§???????????????
  for (int i = (int)a.size() - 1; i >= 0; i--) { //?¶??????? & ??°????????????
    ans[i + 1] += (a[i] - '0') + (b[i] - '0');
    if (ans[i + 1] >= '0' + 10) {
      ans[i] += 1;
      ans[i + 1] -= 10;
    }
  }
  string ret = ""; //??????????????°???0????¶????
  rep(i, ans.size()) {
    if (ans[i] != '0' || i == ans.size() - 1) {
      ret = ans.substr(i, ans.size() - i);
      break;
    }
  }
  return ret;
}

bool is(string s) {
  rep(i, s.size()) if (s[i] == '+') s[i] = '=';
  vector<string> res = split(s, '=');
  rep(i, res.size()) {
    if (res[i].size() >= 2 && res[i][0] == '0')
      return false;
  }
  if (addString(res[0], res[1]) == res[2])
    return true;
  return false;
}

signed main() {
  string s;
  while (cin >> s) {
    rep(i, 10) {
      string tmp = s;
      rep(j, tmp.size()) if (tmp[j] == 'X') tmp[j] = '0' + i;
      if (is(tmp)) {
        cout << i << endl;
        break;
      }
      if (i == 9)
        cout << "NA" << endl;
    }
  }
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define INF 999999999
#define int ll

vector<string> split(string s, char ch) {
  vector<string> ret;
  string tmp = "";
  rep(i, s.size()) {
    if (s[i] == ch) {
      ret.pb(tmp);
      tmp = "";
    } else
      tmp += s[i];
  }
  if (tmp.size())
    ret.pb(tmp);
  return ret;
}

bool is(string s) {
  rep(i, s.size()) if (s[i] == '+') s[i] = '=';
  vector<string> res = split(s, '=');
  rep(i, res.size()) {
    if (res[i].size() >= 2 && res[i][0] == '0')
      return false;
  }
  int num[3];
  rep(i, 3) num[i] = stoi(res[i]);
  if (num[0] + num[1] == num[2])
    return true;
  return false;
}

signed main() {
  string s;
  while (cin >> s) {
    rep(i, 10) {
      string tmp = s;
      rep(j, tmp.size()) if (tmp[j] == 'X') tmp[j] = '0' + i;
      if (is(tmp)) {
        cout << i << endl;
        break;
      }
      if (i == 9)
        cout << "NA" << endl;
    }
  }
}
Problem p00110 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <sstream>
#include <string>

using namespace std;

long long mstoll(string str) {
  long long ret = 0;
  for (int i = 0; i < str.length(); i++) {
    ret *= 10;
    ret += (str[i] - '0');
  }
  return ret;
}

bool ok(string s) {
  // cout << s << endl;
  for (auto &c : s) {
    if (c == '+' || c == '=') {
      c = ' ';
    }
  }

  stringstream ss(s);
  string a, b, c;
  ss >> a >> b >> c;
  // cout << a << " " << b << " " << c << endl;
  if (a.length() >= 2u && a[0] == '0')
    return false;
  if (b.length() >= 2u && b[0] == '0')
    return false;
  if (c.length() >= 2u && c[0] == '0')
    return false;

  return ((mstoll(a) + mstoll(b)) == mstoll(c));
}

int main(void) {
  string str;

  while (cin >> str) {
    for (int i = 0; i < 10; i++) {
      string s = str;
      for (auto &c : s) {
        if (c == 'X') {
          c = i + '0';
        }
      }
      if (ok(s)) {
        cout << i << endl;
        goto END;
      }
    }
    cout << "NA" << endl;
  END:;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <sstream>
#include <string>

using namespace std;

bool ok(string s) {
  // cout << s << endl;
  for (auto &c : s) {
    if (c == '+' || c == '=') {
      c = ' ';
    }
  }

  stringstream ss(s);
  string a, b, c;
  ss >> a >> b >> c;
  // cout << a << " " << b << " " << c << endl;
  if (a.length() >= 2u && a[0] == '0')
    return false;
  if (b.length() >= 2u && b[0] == '0')
    return false;
  if (c.length() >= 2u && c[0] == '0')
    return false;

  return ((stoi(a) + stoi(b)) == stoi(c));
}

int main(void) {
  string str;

  while (cin >> str) {
    for (int i = 0; i < 10; i++) {
      string s = str;
      for (auto &c : s) {
        if (c == 'X') {
          c = i + '0';
        }
      }
      if (ok(s)) {
        cout << i << endl;
        goto END;
      }
    }
    cout << "NA" << endl;
  END:;
  }

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

#include <algorithm>
#include <iostream>
#include <map>
#include <stdio.h>
using namespace std;
string henkan = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";
map<string, char> sym;

void init() {
  sym["101"] = ' ';
  sym["000000"] = '\\'';
  sym["000011"] = ',';
  sym["10010001"] = '-';
  sym["010001"] = '.';
  sym["000001"] = '?';
  sym["100101"] = 'A';
  sym["10011010"] = 'B';
  sym["0101"] = 'C';
  sym["0001"] = 'D';
  sym["110"] = 'E';
  sym["01001"] = 'F';
  sym["10011011"] = 'G';
  sym["010000"] = 'H';
  sym["0111"] = 'I';
  sym["10011000"] = 'J';
  sym["0110"] = 'K';
  sym["00100"] = 'L';
  sym["10011001"] = 'M';
  sym["10011110"] = 'N';
  sym["00101"] = 'O';
  sym["111"] = 'P';
  sym["10011111"] = 'Q';
  sym["1000"] = 'R';
  sym["00110"] = 'S';
  sym["00111"] = 'T';
  sym["10011100"] = 'U';
  sym["10011101"] = 'V';
  sym["000010"] = 'W';
  sym["10010010"] = 'X';
  sym["10010011"] = 'Y';
  sym["10010000"] = 'Z';
}

string _10to2(int a) {
  string s2;
  for (int i = 0; i < 5; i++) {
    s2 += (a % 2 + '0');
    a /= 2;
  }
  reverse(s2.begin(), s2.end());
  return s2;
}

int main() {
  init();
  string str;
  while (getline(cin, str)) {
    string s = "";
    for (int i = 0; i < (int)str.size(); i++) {
      s += _10to2(henkan.find(str[i]));
    }
    string a = "";
    string tmp = "";
    for (int i = 0; i < (int)s.size(); i++) {
      tmp += s[i];
      if (sym.count(tmp)) {
        a += sym[tmp];
        tmp = "";
      }
    }
    cout << a << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;
string henkan = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";

string henkan2[] = {
    "101",      "000000",   "000011",   "10010001", "010001",   "000001",
    "100101",   "10011010", "0101",     "0001",     "110",      "01001",
    "10011011", "010000",   "0111",     "10011000", "0110",     "00100",
    "10011001", "10011110", "00101",    "111",      "10011111", "1000",
    "00110",    "00111",    "10011100", "10011101", "000010",   "10010010",
    "10010011", "10010000",
};

string ch = " ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ";

string _10to2(int a) {
  string s2;
  for (int i = 0; i < 5; i++) {
    s2 += (a % 2 + '0');
    a /= 2;
  }
  reverse(s2.begin(), s2.end());
  return s2;
}

int main() {
  string str;
  while (cin >> str) {
    string s = "";
    for (int i = 0; i < (int)str.size(); i++) {
      s += _10to2(henkan.find(str[i]));
    }
    string a = "";
    int start = 0;
    for (;;) {
      int f = 0;
      for (int i = 0; i < 32; i++) {
        for (int j = 1;
             j <= (int)henkan2[i].size() || start + j <= (int)s.size(); j++) {
          if (henkan2[i] == s.substr(start, j)) {
            start += j;
            f = 1;
            a += ch[i];
            break;
          }
        }
        if (f == 1)
          break;
      }
      if (f == 0)
        break;
    }
    cout << a << endl;
  }
  return 0;
}
Problem p00112 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    long long need_time[10100] = {0}, total_time[10100] = {0}, total = 0;
    for (int i = 0; i < n; i++) {
      cin >> need_time[i];
    }
    sort(need_time, need_time + n);
    for (int i = 1; i < n; i++) {
      total_time[i] = need_time[i - 1] + total_time[i - 1];
      total += total_time[i];
    }
    cout << total << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    int need_time[500] = {0}, total_time[500] = {0}, total = 0;
    for (int i = 0; i < n; i++) {
      cin >> need_time[i];
    }
    sort(need_time, need_time + n);
    for (int i = 1; i < n; i++) {
      total_time[i] = need_time[i - 1] + total_time[i - 1];
      total += total_time[i];
    }
    cout << total << endl;
  }
  return 0;
}
Problem p00112 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <climits>
#include <iostream>
using namespace std;

typedef long long lli;

int n;
lli a[10000];

int main() {
  while (cin >> n && n) {
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    sort(a, a + n);
    lli res = 0;
    for (int i = 0; i < n; ++i) {
      res += a[i] * (n - i - 1);
    }
    cout << res << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <climits>
#include <iostream>
using namespace std;

typedef long long lli;

int n;
lli a[10000];

int main() {
  while (cin >> n && n) {
    assert(1LL <= n && n <= 10000LL);
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
      assert(0LL <= a[i] && a[i] <= 60LL);
    }
    sort(a, a + n);
    lli res = 0;
    for (int i = 0; i < n; ++i) {
      res += a[i] * (n - i - 1);
    }
    assert(res <= INT_MAX);
    cout << res << endl;
  }
  return 0;
}
Problem p00112 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int main(void) {
  while (1) {
    int n, t[10005];
    long long int w;
    w = 0;
    cin >> n;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> t[i];
    }
    sort(t, t + n);
    for (int i = 0; i < n; i++) {
      w += t[i] * (n - 1 - i);
    }
    cout << w << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main(void) {
  while (1) {
    int n, t[100], w;
    w = 0;
    cin >> n;
    if (n == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> t[i];
    }
    sort(t, t + n);
    for (int i = 0; i < n; i++) {
      w += t[i] * (n - 1 - i);
    }
    cout << w << endl;
  }
  return 0;
}
Problem p00112 (C++) — buggy submission, verdict: Runtime Error

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>

using namespace std;
typedef long long int lint;

lint solve(priority_queue<lint, vector<lint>, greater<lint>> &q) {
  lint ret, sum;

  ret = 0;
  sum = 0;
  while (q.size() != 1) {
    sum += q.top();
    ret += sum;
    q.pop();
  }
  return ret;
}

int main() {

  lint n;
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    priority_queue<lint, vector<lint>, greater<lint>> q;
    int buf;
    for (lint i = 0; i < n; i++) {
      cin >> buf;
      q.push(buf);
    }

    cout << solve(q) << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>

using namespace std;

int solve(priority_queue<int, vector<int>, greater<int>> &q) {
  int ret, sum;

  ret = 0;
  sum = 0;
  while (q.size() != 1) {
    sum += q.top();
    ret += sum;
    q.pop();
  }
  return ret;
}

int main() {

  int n;
  while (cin >> n) {
    priority_queue<int, vector<int>, greater<int>> q;
    int buf;
    for (int i = 0; i < n; i++) {
      cin >> buf;
      q.push(buf);
    }
    cin >> buf;

    cout << solve(q) << endl;
  }

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

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

int main() {
  int n, time[10000];
  long long ans = 0;

  while (cin >> n) {
    if (n == 0)
      break;
    int wait = 0;
    for (int i = 0; i < n; i++)
      cin >> time[i];
    sort(time, time + n);
    for (int i = 0; i < n; i++) {
      ans += wait;
      wait += time[i];
    }
    cout << ans << endl;
    ans = 0;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n, time[1000];
  long long ans = 0;

  while (cin >> n) {
    if (n == 0)
      break;
    int wait = 0;
    for (int i = 0; i < n; i++)
      cin >> time[i];
    sort(time, time + n);
    for (int i = 0; i < n; i++) {
      ans += wait;
      wait += time[i];
    }
    cout << ans << endl;
    ans = 0;
  }
  return 0;
}