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

#include <algorithm>
#include <cstdio>
#include <queue>
#define INF 1000000
using namespace std;
typedef pair<int, int> P;
int h, w, n, ans = 0;
bool map[1002][1002];
int x[10], y[10];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {-1, 0, 1, 0};
int main() {
  scanf("%d %d %d", &h, &w, &n);
  fill(map[0], map[0] + 1002 * 1002, false);
  for (int i = 1; i <= h; i++) {
    getchar();
    for (int j = 1; j <= w; j++) {
      char c = getchar();
      if (c != 'X') {
        map[i][j] = true;
        if (c == 'S') {
          x[0] = i;
          y[0] = j;
        } else if (c != '.') {
          x[c - 48] = i;
          y[c - 48] = j;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    int d[1002][1002];
    fill(d[0], d[0] + 1002 * 1002, INF);
    queue<P> q;
    d[x[i]][y[i]] = 0;
    q.push(P(x[i], y[i]));
    while (!q.empty()) {
      P p = q.front();
      int sx = p.first;
      int sy = p.second;
      q.pop();
      if (sx == x[i + 1] && sy == y[i + 1])
        break;
      for (int j = 0; j < 4; j++) {
        if (map[sx + dx[j]][sy + dy[j]] && d[sx + dx[j]][sy + dy[j]] == INF) {
          d[sx + dx[j]][sy + dy[j]] = d[sx][sy] + 1;
          q.push(P(sx + dx[j], sy + dy[j]));
        }
      }
    }
    ans += d[x[i + 1]][y[i + 1]];
  }
  printf("%d\\n", ans);
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <queue>
#define INF 1000000
using namespace std;
typedef pair<int, int> P;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
bool map[1000][1000];
int x[10], y[10];
int ans = 0;
int h, w;
int search(int n) {
  int d[1000][1000];
  fill(d[0], d[0] + 1000 * 1000, INF);
  int sx = x[n], sy = y[n];
  int tx = x[n + 1], ty = y[n + 1];
  queue<P> q;
  q.push(P(sx, sy));
  d[sx][sy] = 0;
  while (!q.empty()) {
    P p = q.front();
    q.pop();
    sx = p.first, sy = p.second;
    if (sx == tx && sy == ty)
      return d[tx][ty];
    for (int i = 0; i < 4; i++) {
      int X = sx + dx[i];
      int Y = sy + dy[i];
      if (map[X][Y] && X >= 0 && X < h && Y >= 0 && Y < w && d[X][Y] == INF) {
        q.push(P(X, Y));
        d[X][Y] = d[sx][sy] + 1;
      }
    }
  }
  return d[tx][ty];
}
int main() {
  int n;
  scanf("%d %d %d", &h, &w, &n);
  fill(map[0], map[0] + 1000 * 1000, false);
  getchar();
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c = getchar();
      if (c != 'X') {
        map[i][j] = true;
        if (c == 'S') {
          x[0] = i, y[0] = j;
        } else {
          int k = (int)c - 48;
          x[k] = i;
          y[k] = j;
        }
      }
    }
    getchar();
  }
  for (int i = 0; i < n; i++) {
    int tmp = search(i);
    ans += tmp;
  }
  printf("%d\\n", ans);
  return 0;
}
Problem p00505 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int san = 0;
int a[3];
int inu = 0;
int saru = 0;
int kiji = 0;

int main() {
  while (true) {
    for (int i = 0; i < 3; i++) {
      cin >> a[i];
    }
    sort(a, a + 3);
    if (a[2] * a[2] < a[1] * a[1] + a[0] * a[0] && a[2] < a[0] + a[1]) {
      san = san + 1;
      saru = saru + 1;
    }
    if (a[2] * a[2] == a[1] * a[1] + a[0] * a[0] && a[2] < a[0] + a[1]) {
      san = san + 1;
      inu = inu + 1;
    }
    if (a[2] * a[2] > a[1] * a[1] + a[0] * a[0] && a[2] < a[0] + a[1]) {
      san = san + 1;
      kiji = kiji + 1;
    }
    if (a[2] >= a[0] + a[1]) {
      break;
    }
  }
  cout << san << " " << inu << " " << saru << " " << kiji << endl;
}

Error: TLE

Fixed submission:

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

int san = 0;
int a[3];
int inu = 0;
int saru = 0;
int kiji = 0;

int main() {
  while (true) {
    for (int i = 0; i < 3; i++) {
      cin >> a[i];
    }
    sort(a, a + 3);
    if (a[3] * a[3] < a[2] * a[2] + a[1] * a[1] && a[3] < a[1] + a[2]) {
      san = san + 1;
      saru = saru + 1;
    }
    if (a[3] * a[3] == a[2] * a[2] + a[1] * a[1] && a[3] < a[1] + a[2]) {
      san = san + 1;
      inu = inu + 1;
    }
    if (a[3] * a[3] > a[2] * a[2] + a[1] * a[1] && a[3] < a[1] + a[2]) {
      san = san + 1;
      kiji = kiji + 1;
    }
    if (a[3] > a[1] + a[2]) {
      break;
    }
  }
  cout << san << " " << inu << " " << saru << " " << kiji << endl;
}
Problem p00505 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {

  int a, b, c;
  int s, ch, e, d;
  s = ch = e = d = 0;
  int tmp, hantei;
  while (1) {
    cin >> a >> b >> c;
    if (a > b) {
      if (a > c) {
        tmp = a;
        a = c;
        c = tmp;
      }
    } else {
      if (b > c) {
        tmp = b;
        b = c;
        c = tmp;
      }
    }
    if (c >= a + b)
      break;
    s++;
    hantei = c * c - a * a - b * b;
    if (hantei > 0) {
      d++;
    } else if (hantei < 0) {
      e++;
    } else {
      ch++;
    }
  }

  cout << s << " " << ch << " " << e << " " << d << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {

  int a, b, c;
  int s, ch, e, d;
  s = ch = e = d = 0;

  while (1) {
    cin >> a >> b >> c;
    if (a == 0)
      break;
    s++;
    a = a * a;
    b = b * b;
    c = c * c;
    int hantei;
    if (a > b) {
      if (a > c) {
        hantei = a - b - c;
      } else {
        hantei = c - a - b;
      }
    } else {
      if (b > c) {
        hantei = b - a - c;
      } else {
        hantei = c - a - b;
      }
    }
    if (hantei > 0) {
      d++;
    } else if (hantei < 0) {
      e++;
    } else {
      ch++;
    }
  }

  cout << s << " " << ch << " " << e << " " << d << endl;

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

#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i, n) for (int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001   // 1e9+1

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
//---------------------------
int a[3], b[4];

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  while (true) {
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    if (a[2] >= a[0] + a[1])
      break;
    b[0]++;
    int rec = a[2] * a[2] - a[1] * a[1] - a[0] * a[0];
    if (rec == 0)
      b[1]++;
    if (rec > 0)
      b[3]++;
    if (rec < 0)
      b[2]++;
  }
  REP(i, 4) { cout << b[i] << " \\n"[i == 3]; }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i, n) for (int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001   // 1e9+1

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
//---------------------------
int a[3], b[4];

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  while (true) {
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    if (a[2] == a[0] + a[1])
      break;
    b[0]++;
    int rec = a[2] * a[2] - a[1] * a[1] - a[0] * a[0];
    if (rec == 0)
      b[1]++;
    if (rec > 0)
      b[3]++;
    if (rec < 0)
      b[2]++;
  }
  REP(i, 4) { cout << b[i] << " \\n"[i == 3]; }
  return 0;
}
Problem p00505 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int a[3], p, q, r;
int main() {
  while (true) {
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    if (a[0] + a[1] <= a[2]) {
      cout << p + q + r << ' ' << p << ' ' << q << ' ' << r << endl;
      break;
    }
    if (a[0] * a[0] + a[1] * a[1] == a[2] * a[2]) {
      p++;
    }
    if (a[0] * a[0] + a[1] * a[1] > a[2] * a[2]) {
      q++;
    }
    if (a[0] * a[0] + a[1] * a[1] < a[2] * a[2]) {
      r++;
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int a[3], p, q, r;
int main() {
  while (true) {
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    if (a[0] + a[1] <= a[2]) {
      cout << p + q + r << ' ' << p << ' ' << q << ' ' << r << ' ' << endl;
    }
    if (a[0] * a[0] + a[1] * a[1] == a[2] * a[2]) {
      p++;
    }
    if (a[0] * a[0] + a[1] * a[1] > a[2] * a[2]) {
      q++;
    }
    if (a[0] * a[0] + a[1] * a[1] < a[2] * a[2]) {
      r++;
    }
  }
}
Problem p00505 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int a[3];
  bool b = true;
  unsigned w, x, y, z;
  x = 0;
  y = 0;
  z = 0;
  while (cin >> a[0] >> a[1] >> a[2]) {
    if (b) {
      sort(a, a + 3);
      if (a[0] + a[1] < a[2])
        b = false;
      else if (a[0] * a[0] + a[1] * a[1] == a[2] * a[2])
        x++;
      else if (a[0] * a[0] + a[1] * a[1] < a[2] * a[2])
        z++;
      else
        y++;
    }
  }
  cout << x + y + z << ' ' << x << ' ' << y << ' ' << z << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int a[3];
  bool b = true;
  int w, x, y, z;
  while (cin) {
    if (b) {
      w++;
      sort(a, a + 3);
      if (a[0] + a[1] < a[2]) {
        b = false;
      } else if (a[0] * a[0] + a[1] * a[1] == a[2] * a[2])
        x++;
      else if (a[0] * a[0] + a[1] * a[1] < a[2] * a[2])
        y++;
      else
        z++;
    }
  }
  cout << w << ' ' << x << ' ' << y << ' ' << z << endl;
}
Problem p00559 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, s, t, a, b, l, r, x;
  long long ans = 0;
  cin >> n >> q >> s >> t;
  vector<long long> vec;
  for (int i = 0; i <= n; i++) {
    cin >> a;
    if (i != 0) {
      vec.push_back(a - b);
      if (vec[i - 1] > 0)
        ans -= vec[i - 1] * s;
      else
        ans -= vec[i - 1] * t;
    }
    b = a;
  }
  vec.push_back(0);
  for (int i = 0; i < q; i++) {
    cin >> l >> r >> x;
    if (vec[l - 1] > 0)
      ans += vec[l - 1] * s;
    else
      ans += vec[l - 1] * t;
    if (vec[r] > 0)
      ans += vec[r] * s;
    else
      ans += vec[r] * t;
    vec[l - 1] += x;
    if (r != n)
      vec[r] -= x;
    if (vec[l - 1] > 0)
      ans -= vec[l - 1] * s;
    else
      ans -= vec[l - 1] * t;
    if (vec[r] > 0)
      ans -= vec[r] * s;
    else
      ans -= vec[r] * t;
    cout << ans << endl;
  }
  return (0);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, s, t;
  long long a[200000];
  vector<long long> vec;
  cin >> n >> q >> s >> t;
  for (int i = 0; i <= n; i++)
    cin >> a[i];
  int l, r, x;
  long long ans;
  for (int i = 0; i < q; i++) {
    cin >> l >> r >> x;
    ans = 0;
    for (int j = l; j <= r; j++)
      a[j] += x;
    for (int i = 0; i <= n; i++) {
      if (i != 0) {
        if (a[i - 1] < a[i])
          ans -= s * (a[i] - a[i - 1]);
        if (a[i - 1] > a[i])
          ans += t * (a[i - 1] - a[i]);
      }
    }
    cout << ans << endl;
  }
  return (0);
}
Problem p00559 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i, N) for (int i = 0; i < N; ++i)
typedef long long int LL;

LL N, Q, S, T, A[212345], L[212345], R[212345], X[212345];
LL dif[212345], ans;

int main() {
  in >> N >> Q >> S >> T;
  rep(i, N + 1) { in >> A[i]; }
  rep(i, Q) { in >> L[i] >> R[i] >> X[i]; }

  rep(i, N) {
    if (A[i] < A[i + 1]) {
      ans -= S * (A[i + 1] - A[i]);
    } else {
      ans += T * (A[i] - A[i + 1]);
    }
    dif[i] = A[i + 1] - A[i];
  }
  rep(i, Q) {
    LL prev = -(dif[L[i] - 1] > 0 ? dif[L[i] - 1] * S : dif[L[i] - 1] * T);
    dif[L[i] - 1] += X[i];
    LL now = -(dif[L[i] - 1] > 0 ? dif[L[i] - 1] * S : dif[L[i] - 1] * T);
    ans += (now - prev);
    if (R[i] < N) {
      prev = -(dif[R[i]] > 0 ? dif[R[i]] * S : dif[R[i]] * T);
      dif[R[i]] -= X[i];
      now = -(dif[R[i]] > 0 ? dif[R[i]] * S : dif[R[i]] * T);
      ans += (now - prev);
    }
    out << ans << std::endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i, N) for (int i = 0; i < N; ++i)
typedef long long int LL;

LL N, Q, S, T, A[212345], L[212345], R[212345], X[212345];
LL ans;

int main() {
  in >> N >> Q >> S >> T;
  rep(i, N + 1) { in >> A[i]; }
  rep(i, Q) { in >> L[i] >> R[i] >> X[i]; }

  rep(i, Q) {
    ans = 0;
    for (int j = L[i]; j <= R[i]; ++j) {
      A[j] += X[i];
    }
    rep(j, N) {
      if (A[j] < A[j + 1]) {
        ans -= S * (A[j + 1] - A[j]);
      } else {
        ans += T * (A[j] - A[j + 1]);
      }
    }
    out << ans << std::endl;
  }
  return 0;
}
Problem p00559 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int N, Q, S, T, L, R, X;
long long d[200009], ret;
void change_d(int pos, int x) {
  if (pos < N) {
    if (d[pos] > 0)
      ret += 1LL * S * d[pos];
    if (d[pos] < 0)
      ret += 1LL * T * d[pos];
  }
  d[pos] += x;
  if (pos < N) {
    if (d[pos] > 0)
      ret -= 1LL * S * d[pos];
    if (d[pos] < 0)
      ret -= 1LL * T * d[pos];
  }
}
void change(int l, int r, int x) {
  change_d(l - 1, x);
  change_d(r - 1, -x);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> N >> Q >> S >> T;
  for (int i = 0; i <= N; i++) {
    cin >> X;
    if (i >= 1)
      change(i, i + 1, X);
  }
  for (int i = 0; i < Q; i++) {
    cin >> L >> R >> X;
    change(L, R + 1, X);
    cout << ret << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int N, Q, S, T, L, R, X, d[100009];
ll ret;
void change_d(int pos, int x) {
  if (pos < N) {
    if (d[pos] > 0)
      ret += 1LL * S * d[pos];
    if (d[pos] < 0)
      ret += 1LL * T * d[pos];
  }
  d[pos] += x;
  if (pos < N) {
    if (d[pos] > 0)
      ret -= 1LL * S * d[pos];
    if (d[pos] < 0)
      ret -= 1LL * T * d[pos];
  }
}
void change(int l, int r, int x) {
  change_d(l - 1, x);
  change_d(r - 1, -x);
}
int main() {
  cin >> N >> Q >> S >> T;
  for (int i = 0; i <= N; i++) {
    cin >> X;
    if (i >= 1)
      change(i, i + 1, X);
  }
  for (int i = 0; i < Q; i++) {
    cin >> L >> R >> X;
    change(L, R + 1, X);
    cout << ret << endl;
  }
  return 0;
}
Problem p00559 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(void) {
  ll N, Q, S, T;
  cin >> N >> Q >> S >> T;
  vector<ll> A(N + 1);
  vector<ll> B(N);
  for (ll i = 0; i <= N; i++) {
    cin >> A[i];
  }

  for (ll i = 1; i <= N; i++) {
    B[i - 1] = A[i] - A[i - 1];
  }

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    if (B[i] > 0) {
      ans -= B[i] * S;
    } else {
      ans -= B[i] * T;
    }
  }

  for (int i = 0; i < Q; i++) {
    ll l, r, x;
    cin >> l >> r >> x;
    l--;

    if (B[l] > 0)
      ans += B[l] * S;
    else
      ans += B[l] * T;

    if (r != N) {
      if (B[r] > 0)
        ans += B[r] * S;
      else
        ans += B[r] * T;
    }

    B[l] += x;
    if (r != N)
      B[r] -= x;
    if (B[l] > 0) {
      ans -= B[l] * S;
    } else {
      ans -= B[l] * T;
    }

    if (r != N) {
      if (B[r] > 0) {
        ans -= B[r] * S;
      } else {
        ans -= B[r] * T;
      }
    }

    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(void) {
  ll N, Q, S, T;
  cin >> N >> Q >> S >> T;
  vector<ll> A(N + 1);
  vector<ll> B(N);
  for (ll i = 0; i <= N; i++) {
    cin >> A[i];
  }

  for (ll i = 1; i <= N; i++) {
    B[i - 1] = A[i] - A[i - 1];
  }

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    if (B[i] > 0) {
      ans -= B[i] * S;
    } else {
      ans -= B[i] * T;
    }
  }

  for (int i = 0; i < Q; i++) {
    ll l, r, x;
    cin >> l >> r >> x;
    l--;

    if (B[l] > 0)
      ans += B[l] * S;
    else
      ans += B[l] * T;

    if (r != N) {
      if (B[r] > 0)
        ans += B[r] * S;
      else
        ans += B[r] * T;
    }

    B[l] += x;
    B[r] -= x;
    if (B[l] > 0) {
      ans -= B[l] * S;
    } else {
      ans -= B[l] * T;
    }

    if (r != N) {
      if (B[r] > 0) {
        ans -= B[r] * S;
      } else {
        ans -= B[r] * T;
      }
    }

    cout << ans << endl;
  }
  return 0;
}
Problem p00559 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, Q;
  long long S, T;

  cin >> N >> Q >> S >> T;

  vector<long long> A;

  for (int i = 0; i <= N; ++i) {
    long long temp, before;
    cin >> temp;
    if (i == 0) {
      A.push_back(temp);
      before = temp;
    } else {
      A.push_back(temp - before);
      before = temp;
    }
  }

  long long temp = 0;

  for (int i = 1; i <= N; ++i) {
    if (A[i] > 0)
      temp -= S * A[i];
    else
      temp -= T * A[i];
  }

  for (int j = 0; j < Q; ++j) {
    long long l, r, x, a;
    cin >> l >> r >> x;

    a = A[l];
    if (a > 0)
      temp += S * a;
    else
      temp += T * a;

    A[l] += x;
    if (A[l] > 0)
      temp -= S * A[l];
    else
      temp -= T * A[l];

    if (r < N) {
      a = A[r + 1];
      if (a > 0)
        temp += S * a;
      else
        temp += T * a;

      A[r + 1] -= x;
      if (A[r + 1] > 0)
        temp -= S * A[r + 1];
      else
        temp -= T * A[r + 1];
    }

    cout << temp << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, Q;
  long long S, T;
  cin >> N >> Q >> S >> T;

  vector<int> A(N + 1);
  for (int i = 0; i <= N; ++i)
    cin >> A[i];

  long long t = 0;

  for (int i = 0; i < N; ++i) {
    if (A[i + 1] > A[i])
      t -= S * (A[i + 1] - A[i]);
    else
      t -= T * (A[i + 1] - A[i]);
  }

  for (int j = 0; j < Q; ++j) {
    int l, r, x;
    cin >> l >> r >> x;
    if (x > 0) {
      if (A[l] >= A[l - 1])
        t -= x * S;
      else if (A[l] + x <= A[l - 1])
        t -= x * T;
      else
        t -= T * (A[l - 1] - A[l]) + S * (x + A[l] - A[l - 1]);
      if (r < N) {
        if (A[r] >= A[r + 1])
          t += x * T;
        else if (A[r] + x <= A[r + 1])
          t += x * S;
        else
          t += S * (A[r + 1] - A[r]) + T * (x + A[r] - A[r + 1]);
      }
    } else {
      if (A[l] <= A[l - 1])
        t += (-x) * T;
      else if (A[l] + x >= A[l - 1])
        t += (-x) * S;
      else
        t += S * (A[l] - A[l - 1]) + T * (A[l - 1] - x - A[l]);
      if (r < N) {
        if (A[r] <= A[r + 1])
          t -= (-x) * S;
        else if (A[r] + x >= A[r + 1])
          t -= (-x) * T;
        else
          t -= T * (A[r] - A[r + 1]) + S * (A[r + 1] - x - A[r]);
      }
    }

    for (int i = l; i <= r; ++i)
      A[i] += x;

    cout << t << endl;
  }

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

#include <iostream>
using namespace std;

int main() {
  int a, b;
  while (cin >> a >> b) {
    cout << a + b << endl;
  }
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::substr: __pos (which is 1) > this->size() (which is 0)


Fixed submission:

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

struct Node {
  Node *left;
  Node *right;
  Node() { left = NULL, right = NULL; }
};

int findcc(string s) {
  int dd = 0;
  for (int i = 0; i < s.length(); ++i) {
    if (s[i] == '(')
      dd++;
    else if (s[i] == ')')
      dd--;
    else if (s[i] == ',' && dd == 1)
      return i;
  }
  return -1;
}

Node *parse(string s) {
  Node *r = new Node();
  int ff = findcc(s);
  if (ff != 1)
    r->left = parse(s.substr(1, ff - 1));
  if (ff != s.length() - 2) {
    string tmp = s.substr(ff + 1);
    r->right = parse(tmp.substr(0, tmp.length() - 1));
  }
  return r;
}

Node *intersect(Node *r1, Node *r2) {
  Node *ret = new Node();
  if (r1->left != NULL && r2->left != NULL)
    ret->left = intersect(r1->left, r2->left);

  if (r1->right != NULL && r2->right != NULL)
    ret->right = intersect(r1->right, r2->right);

  return ret;
}

Node *uni(Node *r1, Node *r2) {
  if (r1 == NULL && r2 == NULL)
    return NULL;

  Node *ret = new Node();
  ret->left =
      uni(((r1 == NULL) ? NULL : r1->left), (r2 == NULL) ? NULL : r2->left);
  ret->right =
      uni(((r1 == NULL) ? NULL : r1->right), (r2 == NULL) ? NULL : r2->right);
  return ret;
}

string toStr(Node *tree) {
  string res = "(";
  if (tree->left != NULL)
    res += toStr(tree->left);
  res += ",";
  if (tree->right != NULL)
    res += toStr(tree->right);
  res += ")";
  return res;
}

void treedel(Node *node) {
  if (node->left != NULL)
    treedel(node->left);
  if (node->right != NULL)
    treedel(node->right);
  delete node;
  return;
}

int main() {
  string op, t1, t2;
  while (cin >> op >> t1 >> t2) {
    Node *r1 = parse(t1);
    Node *r2 = parse(t2);
    Node *ans;
    if (op == "i")
      ans = intersect(r1, r2);
    else if (op == "u")
      ans = uni(r1, r2);

    cout << toStr(ans) << endl;
    treedel(r1);
    treedel(r2);
    treedel(ans);
  }
}
Problem p00586 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>

using namespace std;

int main() {

  int a, b;

  while (scanf("%d %d", &a, &b) != EOF)
    printf("%d\\n", a + b);

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {

  int a, b;
  while (cin >> a >> b, a, b)
    cout << a + b << endl;

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

#include <iostream>
#include <string>

using namespace std;

int main() {
  int a, b;
  while (std::cin >> a >> b) {
    std::cout << a + b << '\\n';
  }
}


Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  while (1) {
    int a, b;
    std::cin >> a >> b;
    std::cout << a + b << '\\n';
  }
}
Problem p00586 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int a, b, c;
  while (scanf("%d %d", &a, &b) == 2) {
    cout << a + b << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int a, b;
  while (scanf("%d %d", &a, &b)) {
    for (int i = 0; i < b; i++)
      a++;
    cout << a << endl;
  }

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

#include <stdio.h>

int main() {
  int a, b;
  while (scanf("%d %d", &a, &b) != EOF) {
    printf("%d\\n", a + b);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  int a, b;
  while (scanf("%d %d", &a, &b)) {
    printf("%d\\n", a + b);
  }
  return 0;
}
Problem p00586 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int a, b;
  while (cin >> a >> b)
    cout << a + b << endl;
}


Error: 1

Fixed submission:

#include <cstdio>
int a, b;
int main() {
  int a, b;
  while (~scanf("%d %d", &a, &b))
    printf("%d\\n", a + b);
  return 1;
}
Problem p00586 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int a, b;

int main() {
  while (cin >> a >> b) {
    int c = 0;
    while (c < 10000000 && c + c / 2 != 2)
      c++;
    cout << a + b + c % 9 - 1 << endl;
  }
}

Error: TLE

Fixed submission:

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

int a, b;

int main() {
  while (cin >> a >> b) {
    int c = 0;
    while (c < 100000000 && c + c / 2 != 2)
      c++;
    cout << a + b + c % 9 - 1 << endl;
  }
}