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

#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;

int main() {
  int n, count = 1, j = 0;
  double m;
  std::vector<double> A(10, 0);
  cin >> n;
  while (n != 0) {
    int s[n];
    m = 0;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      m += s[i];
    }

    m /= (double)n;

    for (int i = 0; i < n; i++)
      A[j] += pow((s[i] - m), 2) / n;

    A[j] = sqrt(A[j]);
    cin >> n;
    if (++j == count * 10) {
      count++;
      A.resize(count * 10);
    }
  }

  for (int i = 0; i < j; i++)
    cout << std::fixed << std::setprecision(8) << A[i] << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;

int main() {
  int n, count = 1, j = 0;
  double m;
  std::vector<double> A(10, 0);
  cin >> n;
  int s[n + 1];
  while (n != 0) {
    m = 0;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      m += s[i];
    }

    m /= (double)n;

    for (int i = 0; i < n; i++)
      A[j] += pow((s[i] - m), 2) / n;

    A[j] = sqrt(A[j]);
    cin >> n;
    j++;
  }

  for (int i = 0; i < j; i++)
    cout << std::fixed << std::setprecision(8) << A[i] << endl;

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

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

int main() {
  double n, m, points[1000], sum, elSum;

  while (true) {
    sum = 0;
    elSum = 0;
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> points[i];
      sum += points[i];
    }

    m = sum / n;

    for (int i = 0; i < n; i++) {
      elSum += pow(points[i] - m, 2);
    }
    cout << fixed << setprecision(6) << sqrt(elSum / n) << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  double n, m, points[1000], sum = 0, elSum = 0;

  while (true) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> points[i];
      sum += points[i];
    }

    m = sum / n;

    for (int i = 0; i < n; i++) {
      elSum += pow(points[i] - m, 2);
    }
    cout << fixed << setprecision(6) << sqrt(elSum / n);
  }

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

#include <cmath>
#include <cstdio>
int s[1000];

int main() {
  int n;
  double m, sum, var, dev;
  while (1) {
    sum = 0.0, var = 0.0, m = 0.0, dev = 0.0;
    scanf("%d", &n);
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      scanf("%d", &s[i]);
      sum += s[i];
    }
    m = sum / n;
    for (int i = 0; i < n; i++)
      var += (s[i] - m) * (s[i] - m);
    dev = sqrt(var / n);
    printf("%.8lf\\n", dev);
  }

  return 0;
}


Error: 0

Fixed submission:

#include <cmath>
#include <cstdio>

int main() {
  double n, s[101], m, sum, var, dev;
  while (1) {
    sum = 0.0, var = 0.0, m = 0.0, dev = 0.0;
    scanf("%lf", &n);
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      scanf("%lf", &s[i]);
      sum += s[i];
    }
    m = sum / n;
    for (int i = 0; i < n; i++)
      var += (s[i] - m) * (s[i] - m);
    dev = sqrt(var / n);
    printf("%.8lf\\n", dev);
  }

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

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

int main() {
  int n, s[1000], i, j;
  double a, m;
  while (1) {
    cin >> n;
    if (!n)
      break;
    m = a = 0;
    for (i = 0; i < n; i++) {
      cin >> s[i];
      m += s[i];
    }
    m /= n;
    for (i = 0; i < n; i++) {
      a += (s[i] - m) * (s[i] - m);
    }
    a = sqrt(a / n);
    cout << fixed << setprecision(6) << a << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, s[100], i, j;
  double a, m;
  while (1) {
    cin >> n;
    if (!n)
      break;
    m = a = 0;
    for (i = 0; i < n; i++) {
      cin >> s[i];
      m += s[i];
    }
    m /= n;
    for (i = 0; i < n; i++) {
      a += (s[i] - m) * (s[i] - m);
    }
    a = sqrt(a / n);
    cout << fixed << setprecision(6) << a << endl;
  }
  return 0;
}
Problem p02381 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    int s[n];
    for (int i = 0; i < n; i++) {
      cin >> s[i];
    }

    int sum = 0;
    for (int i = 0; i < n; i++) {
      sum += s[i];
    }
    double mean = 1.0 * sum / n;
    double var = 0.0;
    for (int i = 0; i < n; i++) {
      var += 1.0 * (s[i] - mean) * (s[i] - mean);
    }
    double SD = sqrt(1.0 * var / n);
    printf("%f\\n", SD);
  }
  return 0;
}


Error: -11

Fixed submission:

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

int main() {
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    int s[n];
    for (int i; i < n; i++) {
      cin >> s[i];
    }

    int sum = 0;
    for (int i; i < n; i++) {
      sum += s[i];
    }
    double mean = 1.0 * sum / n;
    double var = 0.0;
    for (int i; i < n; i++) {
      var += 1.0 * (s[i] - mean) * (s[i] - mean);
    }
    double SD = sqrt(1.0 * var / n);
    printf("%f\\n", SD);
  }
  return 0;
}
Problem p02381 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  float m, tmp;
  int s[1000] = {};
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    m = 0;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      m += s[i];
    }
    m /= n;
    tmp = 0;
    for (int i = 0; i < n; i++) {
      tmp += (s[i] - m) * (s[i] - m);
    }
    cout << sqrt(tmp / n) << endl;
  }
}


Error: WA

Fixed submission:

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

int main() {
  int n;
  float m, tmp;
  int s[100] = {};
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    m = 0;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      m += s[i];
    }
    m /= n;
    tmp = 0;
    for (int i = 0; i < n; i++) {
      tmp += (s[i] - m) * (s[i] - m);
    }
    cout << sqrt(tmp / n) << endl;
  }
}
Problem p02381 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, s[1010];
  double ave, sum, alpha;
  while (1) {
    ave = 0;
    sum = 0;
    alpha = 0;
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      sum += s[i];
    }
    ave = sum / n;

    for (int i = 0; i < n; i++) {
      alpha += (s[i] - ave) * (s[i] - ave);
    }
    alpha /= n;
    alpha = sqrt(alpha);
    cout << fixed << setprecision(6) << alpha << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, s[110];
  double ave, sum, alpha;
  while (1) {
    ave = 0;
    sum = 0;
    alpha = 0;
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      sum += s[i];
    }
    ave = sum / n;

    for (int i = 0; i < n; i++) {
      alpha += (s[i] - ave) * (s[i] - ave);
    }
    alpha /= n;
    alpha = sqrt(alpha);
    cout << fixed << setprecision(6) << alpha << endl;
  }
  return 0;
}
Problem p02381 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>

using namespace std;

int main() {

  int n, s[1000];
  double m, a2;
  while (1) {
    scanf("%d\\n", &n);
    if (n == 0)
      return 0;
    m = 0;
    a2 = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &s[i]);
      m += s[i];
    }
    m /= n;
    for (int i = 0; i < n; i++) {
      a2 += pow(s[i] - m, 2);
    }
    printf("%.8lf\\n", sqrt(a2 / n));
  }
}


Error: 0

Fixed submission:

#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>

using namespace std;

int main() {

  int n, s[100];
  double m, a2;
  while (1) {
    scanf("%d\\n", &n);
    if (n == 0)
      return 0;
    m = 0;
    a2 = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &s[i]);
      m += s[i];
    }
    m /= n;
    for (int i = 0; i < n; i++) {
      a2 += pow(s[i] - m, 2);
    }
    printf("%.8lf\\n", sqrt(a2 / n));
  }
}
Problem p02381 (C++) — buggy submission, verdict: Time Limit Exceeded

//
//  main.cpp
//  ITP1_10-C
//
//  Created by Saicj on 2015/08/05.
//  Copyright (c) 2015??´ saicj. All rights reserved.
//

#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, const char *argv[]) {

  double n;

  double num;

  while (true) {

    cin >> n;

    std::vector<double> nums(n);

    if (n == 0) {
      break;
    }

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

      cin >> num;
      nums[i] = num;
    }

    //        cout << "nums[0]" << nums[0] << endl;

    double sum = 0;

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

    //        cout << sum << endl;

    double m = sum / n;

    //        cout << "m:" << m << endl;

    double mSum = 0;
    for (int i = 0; i < n; i++) {
      mSum += pow(nums[i] - m, 2);

      //            cout << i << ":" << mSum << endl;
    }

    //        cout << "mSum:" << mSum << endl;

    double result = sqrt(mSum / n);

    printf("%.8lf \\n", result);
  }

  return 0;
}

Error: TLE

Fixed submission:

//
//  main.cpp
//  ITP1_10-C
//
//  Created by Saicj on 2015/08/05.
//  Copyright (c) 2015??´ saicj. All rights reserved.
//

#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, const char *argv[]) {

  int n;
  cin >> n;

  int num;

  std::vector<int> nums;

  while (n != 0) {

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

      cin >> num;
      nums.push_back(num);
    }

    int sum = 0;

    for (int i = 0; i < nums.size(); i++) {
      sum += nums[i];
    }

    int m = sum / nums.size();

    //        cout << m << endl;

    int mSum = 0;
    for (int i; i < n; i++) {
      mSum += pow(nums[i] - m, 2);
    }

    double result = sqrt(mSum / n);

    cout << result << endl;

    nums.clear();
  }

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

#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
  int i, n;
  double sum = 0;
  double a, average;
  while (1) {
    sum = 0;
    int s[1001] = {};
    average = 0;
    cin >> n;
    if (n == 0) {
      break;
    }
    for (i = 0; i < n; i++) {
      cin >> s[i];
      sum += s[i];
    }
    average = sum / (double)n;
    sum = 0;
    for (i = 0; i < n; i++) {
      sum += pow(((double)s[i] - average), 2.0);
    }
    a = sqrt(sum / (double)n);
    cout << fixed << setprecision(4) << a << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
  int i, n, s[100];
  int sum = 0;
  double a;
  while (n != 0) {
    cin >> n;
    for (i = 0; i < n; i++) {
      cin >> s[i];
      sum += s[i];
    }
    double average = sum / n;
    sum = 0;
    for (i = 1; i < n; i++) {
      sum += pow(s[i] - average, 2.0);
    }
    a = sqrt(sum / n);
    cout << fixed << setprecision(4) << a << endl;
  }
  return 0;
}
Problem p02381 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
double f(double x) { return x * x; }

int main(void) {
  double s[1001], n, m, sum, ans;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      sum += s[i];
    }
    m = sum / n;
    ans = 0;
    for (int i = 0; i < n; i++) {
      ans += f(s[i] - m);
    }
    cout << fixed << setprecision(8) << sqrt(ans / n) << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
double f(double x) { return x * x; }

int main(void) {
  double s[101], n, m, sum, a;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      sum += s[i];
    }
    m = sum / n;
    sum = 0;
    for (int i = 0; i < n; i++) {
      sum += f(s[i] - m);
    }
    a = sum / n;
    cout << fixed << setprecision(8) << sqrt(a) << endl;
  }

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

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

using namespace std;

int main() {
  int n;

  while (true) {
    cin >> n;
    if (n == 0)
      break;

    double *s = new double[n];
    double m = 0.0;
    for (int i = 0; i < n; i++) {
      int temp;
      cin >> temp;
      m += temp;
      s[i] = temp;
    }
    m = m / static_cast<double>(n);

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

    a = a / static_cast<double>(n);
    cout << fixed << setprecision(8) << sqrt(a) << "\\n";

    delete[] s;
  }

  return 0;
}

Error: -6
free(): double free detected in tcache 2


Fixed submission:

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

using namespace std;

int main() {
  int n;

  while (true) {
    cin >> n;
    if (n == 0)
      break;

    vector<double> s;
    double m = 0.0;
    for (int i = 0; i < n; i++) {
      int temp;
      cin >> temp;
      m += temp;
      s.push_back(temp);
    }
    m = m / static_cast<double>(n);

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

    a = a / static_cast<double>(n);
    cout << fixed << setprecision(8) << sqrt(a) << "\\n";

    s.~vector();
  }

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

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

using namespace std;
int main() {
  int n;
  while (cin >> n, n != 0) {
    double ave, hensa[99], sum = 0, s[999];
    for (int i = 0; n > i; i++) {
      cin >> s[i];
      sum += s[i];
    }
    ave = sum / n;
    sum = 0;
    for (int i = 0; n > i; i++) {
      sum += (s[i] - ave) * (s[i] - ave);
    }
    printf("%.6f\\n", sqrt(sum / n));
  }
}


Error: TLE

Fixed submission:

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

using namespace std;
int main() {
  int n, s[99];
  double ave, hensa[99], sum = 0;
  cin >> n;
  while (n != 0) {
    for (int i = 0; n > i; i++) {
      cin >> s[i];
      sum += s[i];
    }
    ave = sum / n;
    sum = 0;
    for (int i = 0; n > i; i++) {
      sum += (s[i] - ave) * (s[i] - ave);
    }
    printf("%.6f\\n", sqrt(sum / n));
  }
}
Problem p02381 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, s[1000];

  while (cin >> n, n) {
    for (int i = 0; i < n; i++) {
      cin >> s[i];
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
      sum += s[i];
    }
    double m = 1.0 * sum / n;

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

    double a = sqrt(t / n);
    printf("%.6f\\n", a);
  }

  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int n, s[100];

  while (cin >> n, n) {
    for (int i = 0; i < n; i++) {
      cin >> s[i];
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
      sum += s[i];
    }
    double m = 1.0 * sum / n;

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

    double a = sqrt(t / n);
    printf("%.6f\\n", a);
  }

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

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#define REP(i, j, n) for (int i = j; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())

using namespace std;

int main() {
  float n, sum = 0, avr, bunsan1 = 0, bunsan2;

  for (;;) {
    cin >> n;
    vector<int> v(n);
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> v[i];
      sum += v[i];
    }
    avr = sum / n;

    for (int i = 0; i < n; i++) {
      bunsan1 += (avr - v[i]) * (avr - v[i]);
    }
    bunsan2 = bunsan1 / n;

    printf("%f\\n", sqrt(bunsan2));
    sum = 0;
    bunsan1 = 0;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#define REP(i, j, n) for (int i = j; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())

using namespace std;

int main() {
  float n, sum = 0, avr, bunsan1 = 0, bunsan2;
  vector<int> v(n);

  for (;;) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> v[i];
      sum += v[i];
    }
    avr = sum / n;

    for (int i = 0; i < n; i++) {
      bunsan1 += (avr - v[i]) * (avr - v[i]);
    }
    bunsan2 = bunsan1 / n;

    cout << sqrt(bunsan2) << endl;
    sum = 0;
    bunsan1 = 0;
  }
  return 0;
}
Problem p02381 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  cout << fixed << setprecision(12);
  int n;
  int s[1000];
  double sum, ans;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    sum = 0;
    ans = 0;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      sum += s[i];
    }
    sum /= n;
    for (int i = 0; i < n; i++) {
      ans += pow(sum - s[i], 2);
    }
    ans = sqrt(ans / n);
    cout << ans << endl;
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  cout << fixed << setprecision(12);
  int n;
  int s[100];
  double sum, ans;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    sum = 0;
    ans = 0;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      sum += s[i];
    }
    sum /= n;
    for (int i = 0; i < n; i++) {
      ans += pow(sum - s[i], 2);
    }
    ans = sqrt(ans / n);
    cout << ans << endl;
  }
  return 0;
}
Problem p02381 (C++) — buggy submission, verdict: Runtime Error

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

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

  while (1) {
    cin >> n;

    if (n == 0)
      break;

    double all = 0, z = 0;

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

    m = all / n;

    for (int i = 0; i < n; i++) {
      z += pow(s[i] - m, 2);
    }

    a = sqrt(z / n);

    printf("%f\\n", a);
    // printf("test all=%.10f m=%.10f z=%.10f\\n",all,m,z); //test
  }

  return 0;
}

Error: WA

Fixed submission:

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

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

  while (1) {
    cin >> n;

    if (n == 0)
      break;

    double all = 0, z = 0;

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

    m = all / n;

    for (int i = 0; i < n; i++) {
      z += pow(s[i] - m, 2);
    }

    a = sqrt(z / n);

    printf("%f\\n", a);
    // printf("test all=%.10f m=%.10f z=%.10f\\n",all,m,z); //test
  }

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

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

using namespace std;

int main() {
  while (1) {
    int n;
    cin >> n;
    if (n == 0) {
      break;
    }

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

    double m = total / n;

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

    double a = sqrt(a_2);
    printf("%.4f\\n", a);
  }

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  while (1) {
    int n;
    cin >> n;
    if (n == 0) {
      break;
    }

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

    double m = total / n;

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

    double a = sqrt(a_2);
    printf("%.4f\\n", a);
  }

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

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

int main() {
  while (1) {
    long long n, sum = 0, s[1001];
    double sum2 = 0;

    cin >> n;
    if (n == 0)
      break;

    for (int i = 1; i <= n; i++) {
      cin >> s[i];
      sum += s[i];
    }
    double m = (double)sum / n;

    for (int i = 1; i <= n; i++) {
      sum2 += (s[i] - m) * (s[i] - m);
    }
    double a2 = (double)sum2 / n;

    printf("%lf\\n", sqrt(a2));
  }

  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  while (1) {
    long long n, sum = 0, s[101];
    double sum2 = 0;

    cin >> n;
    if (n == 0)
      break;

    for (int i = 1; i <= n; i++) {
      cin >> s[i];
      sum += s[i];
    }
    double m = (double)sum / n;

    for (int i = 1; i <= n; i++) {
      sum2 += (s[i] - m) * (s[i] - m);
    }
    double a2 = (double)sum2 / n;

    printf("%lf\\n", sqrt(a2));
  }

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

#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;
int main() {
  int n;
  while (1) {
    cin >> n;
    double a[n];
    if (n == 0)
      break;
    double b = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      b += a[i];
    }
    double m = b / n;
    double c = 0;
    for (int j = 0; j < n; j++) {
      c += pow(m - a[j], 2) / n;
    }
    printf("%.8f\\n", sqrt(c));
  }
}


Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  while (1) {
    if (n == 0)
      break;
    int b = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      b += a[i];
    }
    double m = b / n;
    int c = 0;
    for (int j = 0; j < n; j++) {
      c += pow(m - a[j], 2);
    }
    double x = c / n;
    printf("%.8f\\n", sqrt(x));
  }
}
Problem p02381 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int q = 0;
  while (1) {
    double n;
    double date[1000];
    double sum = 0;
    double var = 0;
    string haki;
    cin >> n;
    getline(cin, haki);
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> date[i];
      sum += date[i];
    }
    double ave = sum / n;
    for (int i = 0; i < n; i++) {
      var += pow(date[i] - ave, 2);
    }
    cout << fixed << pow(var / n, 0.5) << endl;
    q++;
    if (q > 10)
      break;
  }
  return 0;
}


Error: WA

Fixed submission:

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

int main() {
  int q = 0;
  while (1) {
    double n;
    double date[100];
    double sum = 0;
    double var = 0;
    string haki;
    cin >> n;
    getline(cin, haki);
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> date[i];
      sum += date[i];
    }
    double ave = sum / n;
    for (int i = 0; i < n; i++) {
      var += pow(date[i] - ave, 2);
    }
    cout << fixed << pow(var / n, 0.5) << endl;
    q++;
    if (q > 10)
      break;
  }
  return 0;
}