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

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF = 100000000;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
typedef pair<int, int> P;
typedef long long ll;

bool binary_search(int *a, int n, int x) {
  int l = 0, r = n;
  while (r - l > 0) {
    int mid = (l + r) / 2;
    if (a[mid] < x)
      l = mid + 1;
    else if (a[mid] == x)
      return true;
    else
      r = mid;
  }
  // cout<<l<<","<<r<<endl;
  return false;
}

int n;
int S[100005];
int q;
int main() {
  int ans = 0;
  cin >> n;
  rep(i, n) cin >> S[i];
  cin >> q;
  rep(i, q) {
    int t;
    cin >> t;
    if (binary_search(S, n, t))
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF = 100000000;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
typedef pair<int, int> P;
typedef long long ll;

bool binary_search(int *a, int n, int x) {
  int l = 0, r = n;
  while (r - l > 0) {
    int mid = (l + r) / 2;
    if (a[mid] < x)
      l = mid;
    else if (a[mid] == x)
      return true;
    else
      r = mid;
  }
  // cout<<l<<","<<r<<endl;
  return false;
}

int n;
int S[100005];
int q;
int main() {
  int ans = 0;
  cin >> n;
  rep(i, n) cin >> S[i];
  cin >> q;
  rep(i, q) {
    int t;
    cin >> t;
    if (binary_search(S, n, t))
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

//
//  main.cpp
//  binary_search
//
//  Created by ???????????? on 2017/10/06.
//  Copyright ?? 2017 ????????????. All rights reserved.
//

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

using namespace std;

bool binary_search(int A[], int n, int key) {
  int left, mid, right;
  left = 0;
  right = n;
  while (left < right) {
    mid = (left + right) / 2;
    if (A[mid] == key) {
      return true;
    } else if (key < A[mid]) {
      right = mid;
    } else if (key > A[mid]) {
      left = mid + 1;
    }
  }
  return false;
}

int main(int argc, const char *argv[]) {
  int n, i, ct, q, key;

  scanf("%d", &n);
  int S[n];
  for (i = 0; i < n; i++) {
    scanf("%d", &S[i]);
  }

  ct = 0;
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &key);
    bool found = binary_search(S, n, key);
    if (found)
      ct++;
  }
  cout << ct << endl;
  ;
  return 0;
}

Error: TLE

Fixed submission:

//
//  main.cpp
//  binary_search
//
//  Created by ???????????? on 2017/10/06.
//  Copyright ?? 2017 ????????????. All rights reserved.
//

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

using namespace std;

bool binary_search(int A[], int n, int key) {
  int left, mid, right;
  left = 0;
  right = n;
  while (left < right) {
    mid = (left + right) / 2;
    if (A[mid] == key) {
      return true;
    } else if (key < A[mid]) {
      right = mid;
    } else if (key > A[mid]) {
      left = mid;
    }
  }
  return false;
}

int main(int argc, const char *argv[]) {
  int n, i, ct, q, key;

  scanf("%d", &n);
  int S[n];
  for (i = 0; i < n; i++) {
    scanf("%d", &S[i]);
  }

  ct = 0;
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &key);
    bool found = binary_search(S, n, key);
    if (found)
      ct++;
  }
  cout << ct << endl;
  ;
  return 0;
}
Problem p02268 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

int main() {
  int N;
  cin >> N;
  vector<int> ns(N);
  for (int i = 0; i < N; ++i) {
    cin >> ns[i];
  }
  int Q;
  cin >> Q;
  int sum = 0;
  while (Q--) {
    int a;
    cin >> a;
    auto it = lower_bound(ns.begin(), ns.end(), a);
    auto jt = upper_bound(ns.begin(), ns.end(), a);
    sum += min(1, int(jt - it));
  }
  cout << sum << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

bool bs(int val, vector<int> &v) {
  int l = 0, r = v.size() - 1;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (v[mid] == val)
      return true;
    else if (v[mid] > val)
      r = mid;
    else
      l = mid + 1;
  }
  return false;
}

int main() {
  int n, m;
  scanf("%d", &n);
  int v;
  vector<int> s, t;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &v);
    s.push_back(v);
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d", &v);
    t.push_back(v);
  }
  for (int x : t) {
    if (bs(x, s)) {
      ans++;
    }
  }
  printf("%d\\n", ans);
  return 0;
}
Problem p02268 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int Binarysearch(int *, int, int);
#define N 100005

int main() {
  int i, s, array[N], t, m, sum = 0;

  scanf("%d", &s);
  for (i = 0; i < s; i++) {
    scanf("%d", &array[i]);
  }
  scanf("%d", &t);
  for (i = 0; i < t; i++) {
    scanf("%d", &m);
    if (Binarysearch(array, s, m))
      sum++;
  }
  printf("%d\\n", sum);
  return 0;
}

int Binarysearch(int A[], int x, int key) {
  int left = 0, right, mid = 0;
  right = x;
  while (left < right) {
    mid = (left + right) / 2;
    if (key == A[mid])
      return 1;
    else if (key < A[mid])
      right = mid;
    else if (key > A[mid])
      left = mid + 1;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
int Binarysearch(int *, int, int);
#define N 10000

int main() {
  int i, s, array[N], t, m, sum = 0;

  scanf("%d", &s);
  for (i = 0; i < s; i++) {
    scanf("%d", &array[i]);
  }
  scanf("%d", &t);
  for (i = 0; i < t; i++) {
    scanf("%d", &m);
    if (Binarysearch(array, s, m))
      sum++;
  }
  printf("%d\\n", sum);
  return 0;
}

int Binarysearch(int A[], int x, int key) {
  int left = 0, right, mid = 0;
  right = x;
  while (left < right) {
    mid = (left + right) / 2;
    if (key == A[mid])
      return 1;
    else if (key < A[mid])
      right = mid;
    else if (key > A[mid])
      left = mid + 1;
  }
  return 0;
}
Problem p02379 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iomanip>
#include <iostream>

using namespace std;

int main() {
  double x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  cout << fixed << setprecision(7);
  cout << sqrt(pow((x1 - x2), 2) + pow((y1 - y2), 2)) << endl;
  return 0;
}

Error: 1

Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  cout << sqrt(pow(double(x1 - x2), 2.0) + pow(double(y1 - y2), 2.0)) << endl;
  return 1;
}
Problem p02379 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iomanip>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
  double x, y, x1, x2, y1, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  x = fabs(x2 - x1);
  y = fabs(y2 - y1);
  if (x == 0) {
    cout << fixed << setprecision(5) << y << "\\n";
    return 0;
  } else if (y == 0) {
    cout << fixed << setprecision(5) << x << "\\n";
    return 0;
  }

  int c = 0;

  double v = x * x + y * y, d = max(x, y), eps = 0.00001;
  do {
    d = (d + v / d) / 2.0L;
    ++c;
  } while (c < 5);

  cout << fixed << setprecision(5) << d << "\\n";

  return 0;
}

Error: TLE

Fixed submission:

#include <iomanip>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
  double x, y, x1, x2, y1, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  x = x2 - x1;
  y = y2 - y1;
  if (x == 0) {
    cout << fixed << setprecision(5) << fabs(y) << "\\n";
    return 0;
  } else if (y == 0) {
    cout << fixed << setprecision(5) << fabs(x) << "\\n";
    return 0;
  }

  double v = x * x + y * y, d = 1, eps = 0.00001;
  do {
    d = (d + v / d) / 2.0L;
  } while (fabs(v - d * d) > eps);

  cout << fixed << setprecision(5) << d << "\\n";

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

#include <stdio.h>

#ifndef DEBUG
#define fprintf (void)
#endif

double absval(double x);

int main(void) {

  double x1, y1, x2, y2;
  double b = 0;
  int n;
  scanf("%lf", &x1);
  scanf("%lf", &y1);
  scanf("%lf", &x2);
  scanf("%lf", &y2);
  double dx = absval(x1 - x2);
  double dy = absval(y1 - y2);

  double x = dx * dx + dy * dy;
  fprintf(stdout, "%lf\\n", x);

  scanf("%d", &n);

  while (b * b < x) {
    b++;
  }
  while (absval(b * b - x) > 0.0001) {
    b = (b * b + x) / (2 * b);
    fprintf(stdout, "%f\\n", b);
  }
  printf("%f\\n", b);

  return 0;
}

double absval(double x) {
  if (x < 0) {
    return -x;
  } else {
    return x;
  }
}

Error: TLE

Fixed submission:

#include <stdio.h>

#ifndef DEBUG
#define fprintf (void)
#endif

double absval(double x);

int main(void) {

  double x1, y1, x2, y2;
  double b = 0;
  int n;
  scanf("%lf", &x1);
  scanf("%lf", &y1);
  scanf("%lf", &x2);
  scanf("%lf", &y2);
  double dx = absval(x1 - x2);
  double dy = absval(y1 - y2);

  double x = dx * dx + dy * dy;
  fprintf(stdout, "%lf\\n", x);

  scanf("%d", &n);

  while (b * b < x) {
    b++;
  }
  while (absval(b * b - x) > 0.000001) {
    b = (b * b + x) / (2 * b);
    fprintf(stdout, "%f\\n", b);
  }
  printf("%f\\n", b);

  return 0;
}

double absval(double x) {
  if (x < 0) {
    return -x;
  } else {
    return x;
  }
}
Problem p02379 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  double x1, x2, y1, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  double d = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  printf("%lf\\n", d);
  return 0;
}

Error: -11

Fixed submission:

#include <cmath>
#include <cstdio>

int main() {
  double x1, x2, y1, y2;
  scanf("%lf %lf %lf %lf", x1, y1, x2, y2);
  double d = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  printf("%lf\\n", d);
  return 0;
}
Problem p02379 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iomanip>
#include <iostream>

using namespace std;

int main() {
  double x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  x1 -= x2;
  y1 -= y2;
  cout << fixed << setprecision(5) << sqrt(x1 * x1 + y1 * y1) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iomanip>
#include <iostream>

using namespace std;

double sqrt(double x) {
  double dx, ans = x;
  for (;;) {
    dx = (ans - x / ans) / 2;
    ans -= dx;
    if (dx < 0.00001)
      break;
  }
  return ans;
}

int main() {
  double x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  x1 -= x2;
  y1 -= y2;
  cout << fixed << setprecision(5) << sqrt(x1 * x1 + y1 * y1) << endl;
  return 0;
}
Problem p02379 (C++) — buggy submission, verdict: Runtime Error

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

#define FOR(i, a, b) for (long long int i = (a); i < (b); i++)
#define REP(i, n) for (long long int i = 0; i < (n); i++)

int main() {
  long double x1, x2, y1, y2, d;
  cin >> x1 >> y1 >> x2 >> y2;
  d = powl(powl(x1 - x2, 2.0) + powl(y1 - y2, 2.0), 0.5);
  cout << fixed << d << "\\n";
  return 0;
}

Error: -11

Fixed submission:

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

#define FOR(i, a, b) for (long long int i = (a); i < (b); i++)
#define REP(i, n) for (long long int i = 0; i < (n); i++)

int main() {
  long double x1, x2, y1, y2, d;
  scanf("%lf %lf %lf %lf", x1, y1, x2, y2);
  d = powl(powl(x1 - x2, 2.0) + powl(y1 - y2, 2.0), 0.5);
  printf("%.10lf\\n", d);
  return 0;
}
Problem p02381 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

using namespace std;

void Solution() {
  while (1) {
    int n;
    long int s[1000] = {0};
    double m;
    long int sum = 0;
    double aa = 0;

    cin >> n;

    if (n == 0)
      break;

    for (int i = 0; i < n; i++) {
      cin >> s[i];
    }

    for (int i = 0; i < n; i++) {
      sum += s[i];
    }

    m = (double)sum / n; // type change !

    for (int i = 0; i < n; i++) {
      aa += (s[i] - m) * (s[i] - m);
    }

    cout << fixed << setprecision(4) << sqrt(aa / n) << endl;
  }
}

int main() {
  Solution();
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

using namespace std;

void Solution() {
  while (1) {
    int n;
    int s[100] = {0};
    double m;
    long int sum = 0;
    double aa = 0;

    cin >> n;

    if (n == 0)
      break;

    for (int i = 0; i < n; i++) {
      cin >> s[i];
    }

    for (int i = 0; i < n; i++) {
      sum += s[i];
    }

    m = (double)sum / n; // type change !

    for (int i = 0; i < n; i++) {
      aa += (s[i] - m) * (s[i] - m);
    }

    cout << fixed << setprecision(8) << sqrt(aa / n) << endl;
  }
}

int main() {
  Solution();
  return 0;
}
Problem p02381 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>

#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

int main() {

  while (1) {
    int num = 0, i = 0;
    double ave = 0, sum = 0, ans = 0;
    double s[1000] = {0};

    cin >> num;
    if (num == 0)
      break;
    for (i = 0; i < num; i++) {
      cin >> s[i];
      ave += s[i];
    }
    ave = ave / num;
    for (i = 0; i < num; i++) {
      sum += ((s[i] - ave) * (s[i] - ave));
    }
    sum = sum / num;
    ans = sqrt(sum);
    cout << fixed << ans << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>

#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

int main() {

  while (1) {
    int num = 0, i = 0;
    double ave = 0, sum = 0, ans = 0;
    double s[101] = {0};

    cin >> num;
    if (num == 0)
      break;
    for (i = 0; i < num; i++) {
      cin >> s[i];
      ave += s[i];
    }
    ave = ave / num;
    //
    for (i = 0; i < num; i++) {
      sum += ((s[i] - ave) * (s[i] - ave));
    }
    sum = sum / num;
    ans = sqrt(sum);
    cout << fixed << setprecision(8) << ans << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n) {
    int s[n];
    double sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      sum += s[i];
    }
    double ave = sum / n;
    sum = 0.0;
    for (int i = 0; i < n; i++)
      sum += (s[i] - ave) * (s[i] - ave);
    cout << sqrt(sum / n) << endl;
    cin >> n;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n) {
    int s[n];
    double sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      sum += s[i];
    }
    double ave = sum / n;
    sum = 0.0;
    for (int i = 0; i < n; i++)
      sum += (s[i] - ave) * (s[i] - ave);
    cout << sqrt(sum / n) << endl;
  }
  return 0;
}
Problem p02381 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;

int main() {
  int n;
  double s[1005];
  while (cin >> n && n != 0) {
    double sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      sum += s[i];
    }
    double avg = sum / n;
    sum = 0;
    for (int i = 0; i < n; i++) {
      sum += (s[i] - avg) * (s[i] - avg);
    }
    if (sum == 0) {
      printf("%lf\\n", sum);
    } else {
      printf("%lf\\n", sqrt(sum / n));
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;

int main() {
  int n;
  double s[105];
  while (cin >> n && n != 0) {
    double sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      sum += s[i];
    }
    double avg = sum / n;
    sum = 0;
    for (int i = 0; i < n; i++) {
      sum += (s[i] - avg) * (s[i] - avg);
    }
    if (sum == 0) {
      printf("%lf\\n", sum);
    } else {
      printf("%lf\\n", sqrt(sum / n));
    }
  }
  return 0;
}
Problem p02381 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>

#define REP(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)

using namespace std;

int main() {
  int n, s[1000], i;
  double m, d;

  cout.precision(8);
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    m = 0;
    d = 0;
    rep(i, n) {
      cin >> s[i];
      m += s[i];
    }
    m = m / n;
    rep(i, n) d += pow(s[i] - m, 2.0);
    d = sqrt(d / n);
    cout << fixed << d << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>

#define REP(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)

using namespace std;

int main() {
  int n, s[100], i;
  double m, d;

  cout.precision(8);
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    m = 0;
    d = 0;
    rep(i, n) {
      cin >> s[i];
      m += s[i];
    }
    m = m / n;
    rep(i, n) d += pow(s[i] - m, 2.0);
    d = sqrt(d / n);
    cout << fixed << d << endl;
  }
  return 0;
}
Problem p02381 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int n;
  int S[1000];
  double sum = 0;
  double std = 0;
  double deviate = 0;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++)
      cin >> S[i];
    for (int i = 0; i < n; i++) {
      sum += S[i];
    }
    for (int i = 0; i < n; i++) {
      deviate += (S[i] - sum / n) * (S[i] - sum / n);
    }

    printf("%lf\\n", sqrt(deviate / n));
    sum = 0;
    std = 0;
    deviate = 0;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int n;
  int S[100];
  double sum = 0;
  double std = 0;
  double deviate = 0;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++)
      cin >> S[i];
    for (int i = 0; i < n; i++) {
      sum += S[i];
    }
    for (int i = 0; i < n; i++) {
      deviate += (S[i] - sum / n) * (S[i] - sum / n);
    }

    printf("%lf\\n", sqrt(deviate / n));
    sum = 0;
    std = 0;
    deviate = 0;
  }

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265358979

using namespace std;
typedef pair<int, int> P;

int main(void) {
  int n;
  while (cin >> n, n) {
    int s[1001];
    double alpha = 0, ave = 0;
    FOR(i, 1, n) {
      cin >> s[i];
      ave += s[i];
    }
    ave /= n;
    FOR(i, 1, n) { alpha += (s[i] - ave) * (s[i] - ave); }
    alpha /= n;
    alpha = sqrt(alpha);
    printf("%.10lf\\n", alpha);
  }
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265358979

using namespace std;
typedef pair<int, int> P;

int main(void) {
  int n;
  while (cin >> n, n) {
    int s[101];
    double alpha = 0, ave = 0;
    FOR(i, 1, n) {
      cin >> s[i];
      ave += s[i];
    }
    ave /= n;
    FOR(i, 1, n) { alpha += (s[i] - ave) * (s[i] - ave); }
    alpha /= n;
    alpha = sqrt(alpha);
    printf("%.10lf\\n", alpha);
  }
  return 0;
}
Problem p02381 (C++) — buggy submission, verdict: Runtime Error

#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>
using namespace std;
#define MPI 3.14159265358979323846

int main() {
  while (true) {
    int n, s[1001], sum = 0;
    double a = 0, m;
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      sum += s[i];
    }
    m = (double)sum / (double)n;
    for (int i = 0; i < n; i++) {
      a += pow(s[i] - m, 2) / (double)n;
    }
    printf("%.8f\\n", sqrt(a));
  }
  return 0;
}


Error: 0

Fixed submission:

#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>
using namespace std;
#define MPI 3.14159265358979323846

int main() {
  while (true) {
    int n, s[101], sum = 0;
    double a = 0, m;
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      sum += s[i];
    }
    m = (double)sum / (double)n;
    for (int i = 0; i < n; i++) {
      a += pow(s[i] - m, 2) / (double)n;
    }
    printf("%.8f\\n", sqrt(a));
  }
  return 0;
}
Problem p02381 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  // Your code here!
  long double a, b, c = 0, d, e, f, g = 0;
  int A[1000];
  while (1) {

    cin >> b;
    if (b == 0) {
      break;
    }
    for (int i = 0; i < b; i++) {
      cin >> A[i];
      c += A[i];
    }
    c = c / b;
    for (int i = 0; i < b; i++) {
      g += pow((A[i] - c), 2) / b;
    }
    g = sqrt(g);
    // cout<<printf("%.10lf\\n", sqrt(e))<<endl;
    // e=sqrt(e);
    //  cout << f << endl;
    std::cout << setprecision(16) << g << endl;
    c = 0;
    g = 0;
    A[1000] = 0;
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  // Your code here!
  long double a, b, c = 0, d, e, f, g = 0;
  int A[500];
  while (1) {

    cin >> b;
    if (b == 0) {
      break;
    }
    for (int i = 0; i < b; i++) {
      cin >> A[i];
      c += A[i];
    }
    c = c / b;
    for (int i = 0; i < b; i++) {
      g += pow((A[i] - c), 2) / b;
    }
    g = sqrt(g);
    // cout<<printf("%.10lf\\n", sqrt(e))<<endl;
    // e=sqrt(e);
    //  cout << f << endl;
    std::cout << setprecision(16) << g << endl;
    c = 0;
    g = 0;
    A[500] = 0;
  }
  return 0;
}