prithivMLmods/Coder-Stat huggingface dataset:
Problem p02381 (C++)

Buggy submission (status: Time Limit Exceeded):
#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;
}

Fixed submission:
#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;
}
Problem p02381 (C++)

Buggy submission (status: Time Limit Exceeded):
#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;
}

Fixed submission:
#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;
}
Problem p02381 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02381 (C++)

Buggy submission (status: 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;
  }
  return 0;
}


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;
    cin >> n;
  }
  return 0;
}
Problem p02381 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
int main(void) {
  int n, s[101], i;
  double m, a2, a;
  cin >> n;

  while (n != 0) {
    m = 0;
    a2 = 0;
    for (i = 0; i < n; i++) {
      cin >> s[i];
      m += s[i];
    }
    m = m / n;
    for (i = 0; i < n; i++) {
      a2 += (s[i] - m) * (s[i] - m);
    }
    a2 = a2 / n;
    a = sqrt(a2);

    cout << fixed << setprecision(5) << a << endl;

    cin >> n;
  }
  return 0;
}


Fixed submission:
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
int main(void) {
  long int n, s[1001], i;
  double m, a2, a;
  cin >> n;

  while (n != 0) {
    m = 0;
    a2 = 0;
    for (i = 0; i < n; i++) {
      cin >> s[i];
      m += s[i];
    }
    m = m / n;
    for (i = 0; i < n; i++) {
      a2 += (s[i] - m) * (s[i] - m);
    }
    a2 = a2 / n;
    a = sqrt(a2);

    cout << fixed << setprecision(5) << a << endl;

    cin >> n;
  }
  return 0;
}
Problem p02381 (C++)

Buggy submission (status: Runtime Error):
#include <math.h>
#include <stdio.h>
#include <string.h>
#define rep(i, a, n) for (int i = a; i < n; i++)

int main() {
  int n;
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    double s[101] = {0}, ave = 0, a = 0;
    rep(i, 0, n) {
      scanf("%lf", &s[i]);
      ave += s[i];
    }
    ave /= (double)n;
    rep(i, 0, n) { a += pow(s[i] - ave, 2); }
    a /= (double)n;
    a = sqrt(a);
    printf("%.10lf\n", a);
  }
  return 0;
}

Fixed submission:
#include <math.h>
#include <stdio.h>
#include <string.h>
#define rep(i, a, n) for (int i = a; i < n; i++)

int main() {
  int n;
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    double s[1001] = {0}, ave = 0, a = 0;
    rep(i, 0, n) {
      scanf("%lf", &s[i]);
      ave += s[i];
    }
    ave /= (double)n;
    rep(i, 0, n) { a += pow(s[i] - ave, 2); }
    a /= (double)n;
    a = sqrt(a);
    printf("%.10lf\n", a);
  }
  return 0;
}
Problem p02381 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <iostream>
#include <stdio.h>
using namespace std;

int main(void) {
  // Here your code !
  int n, s[100];
  double m, A;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    m = 0;
    A = 0;
    for (int i = 0; i < n; i++) {

      cin >> s[i];
      m = m + s[i];
    }
    m = m / n;

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

      A = A + pow((s[i] - m), 2);
    }
    A = A / n;
    A = sqrt(A);
    printf("%f\n", A);
  }
}

Fixed submission:
#include <cmath>
#include <iostream>
#include <stdio.h>
using namespace std;

int main(void) {
  // Here your code !
  int n, s[1000];
  double m, A;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    m = 0;
    A = 0;
    for (int i = 0; i < n; i++) {

      cin >> s[i];
      m = m + s[i];
    }
    m = m / n;

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

      A = A + pow((s[i] - m), 2);
    }
    A = A / n;
    A = sqrt(A);
    printf("%f\n", A);
  }
}
Problem p02381 (Python)

Buggy submission (status: Runtime Error):
# -*- coding: utf-8 -*-

import math

while True:
    n = int(input())

    if n == 0:
        break

    s = list(map(float, input().split()))
    mean = sum(s) / len(s)

    for i in range(len(s)):
        s[i] = (s[i] - sum) * (s[i] - sum)

    variance = sum(s) / len(s)
    stdev = math.sqrt(variance)

    print(stdev)


Fixed submission:
# -*- coding: utf-8 -*-

import math

while True:
    n = int(input())

    if n == 0:
        break

    s = list(map(float, input().split()))
    mean = sum(s) / len(s)

    for i in range(len(s)):
        s[i] = (s[i] - mean) * (s[i] - mean)

    variance = sum(s) / len(s)
    stdev = math.sqrt(variance)

    print(stdev)
Problem p02381 (C++)

Buggy submission (status: Runtime Error):
#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;
}


Fixed submission:
#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;
}
Problem p02381 (C++)

Buggy submission (status: Runtime Error):
#include <iomanip>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
  int n;
  double a[101], s, e;
  do {
    cin >> n;
    if (n == 0)
      break;
    s = 0;
    e = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      s += (a[i] / n);
    }
    for (int i = 0; i < n; i++) {
      e += ((a[i] - s) * (a[i] - s)) / n;
    }
    cout << fixed;
    cout << setprecision(8) << sqrt(e) << endl;
  } while (true);
  return 0;
}

Fixed submission:
#include <iomanip>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
  int n;
  double a[1001], s, e;
  do {
    cin >> n;
    if (n == 0)
      break;
    s = 0;
    e = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      s += (a[i] / n);
    }
    for (int i = 0; i < n; i++) {
      e += ((a[i] - s) * (a[i] - s)) / n;
    }
    cout << fixed;
    cout << setprecision(8) << sqrt(e) << endl;
  } while (true);
  return 0;
}
Problem p02381 (C++)

Buggy submission (status: Runtime Error):
#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;
}


Fixed submission:
#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;
}
Problem p02381 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  double point, a, n, s[100], m; // a標準偏差 n学生の数
  while (1) {
    m = 0;
    point = 0;
    cin >> n;
    if (n == 0)
      break;
    a = 0;

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

    m = point / n;

    for (int i = 0; i < n; i++) {
      a += pow(s[i] - m, 2);
    }
    a = sqrt(a / n);
    printf("%f\n", a);
  }

  return 0;
}


Fixed submission:
#include <cmath>
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  double point, a, n, s[1000], m; // a標準偏差 n学生の数
  while (1) {
    m = 0;
    point = 0;
    cin >> n;
    if (n == 0)
      break;
    a = 0;

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

    m = point / n;

    for (int i = 0; i < n; i++) {
      a += pow(s[i] - m, 2);
    }
    a = sqrt(a / n);
    printf("%f\n", a);
  }

  return 0;
}
Problem p02381 (C++)

Buggy submission (status: 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[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;
}


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[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;
}
Problem p02381 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int n, s[100];
  while (1) {
    double a = 0;
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      a += s[i];
    }
    double b = a / n;
    double c = 0;
    for (int i = 0; i < n; i++) {
      c += pow(b - s[i], 2.0);
    }
    double d = 0;
    d = sqrt(c / n);
    printf("%.8f\n", d);
  }
  return 0;
}

Fixed submission:
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int n, s[1001];
  while (1) {
    double a = 0;
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      a += s[i];
    }
    double b = a / n;
    double c = 0;
    for (int i = 0; i < n; i++) {
      c += pow(b - s[i], 2.0);
    }
    double d = 0;
    d = sqrt(c / n);
    printf("%.8f\n", d);
  }
  return 0;
}
Problem p02381 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int n;
  double s[101], sum, dist, m;

  while (1) {
    cin >> n;
    sum = 0.0;
    dist = 0.0;
    if (n == 0)
      break;

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

      sum += s[i];
    }
    m = sum / n;

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

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

  return 0;
}

Fixed submission:
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;

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

  while (1) {
    cin >> n;
    sum = 0.0;
    dist = 0.0;
    if (n == 0)
      break;

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

      sum += s[i];
    }
    m = sum / n;

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

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

  return 0;
}
Problem p02381 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int time;
  double m;
  int s[100];
  double apow;
  while (true) {
    cin >> time;
    if (time == 0)
      break;
    apow = 0;
    m = 0;
    for (int i = 0; i < time; ++i) {
      cin >> s[i];
      m += s[i];
    }
    m /= (double)time;
    for (int i = 0; i < time; ++i) {
      apow += pow((double)s[i] - m, 2.0);
    }
    cout << sqrt(apow / (double)time) << endl;
  }
  return 0;
}

Fixed submission:
#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int time;
  double m;
  int s[1000];
  double apow;
  while (true) {
    cin >> time;
    if (time == 0)
      break;
    apow = 0;
    m = 0;
    for (int i = 0; i < time; ++i) {
      cin >> s[i];
      m += s[i];
    }
    m /= (double)time;
    for (int i = 0; i < time; ++i) {
      apow += pow((double)s[i] - m, 2.0);
    }
    cout << sqrt(apow / (double)time) << endl;
  }
  return 0;
}
Problem p02381 (C++)

Buggy submission (status: Runtime Error):
#include <iomanip>
#include <iostream>
#include <math.h>

#define PI 3.14159265

double standard_deviation(double *s, double m, double n) {
  double sum_ = 0;
  for (int i = 0; i < n; i++) {
    sum_ += pow((s[i] - m), 2);
  }
  return sum_ / n;
}

int main() {
  double n;
  double s[100] = {0};
  double m = 0;

  while (true) {
    m = 0;
    std::cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      std::cin >> s[i];
      m += s[i];
    }
    m /= n;

    std::cout << std::fixed << std::setprecision(8)
              << sqrt(standard_deviation(s, m, n)) << std::endl;
  }

  return 0;
}


Fixed submission:
#include <iomanip>
#include <iostream>
#include <math.h>

#define PI 3.14159265

double standard_deviation(double *s, double m, double n) {
  double sum_ = 0;
  for (int i = 0; i < n; i++) {
    sum_ += pow((s[i] - m), 2);
  }
  return sum_ / n;
}

int main() {
  double n;
  double s[1000] = {0};
  double m = 0;

  while (true) {
    m = 0;
    std::cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      std::cin >> s[i];
      m += s[i];
    }
    m /= n;

    std::cout << std::fixed << std::setprecision(8)
              << sqrt(standard_deviation(s, m, n)) << std::endl;
  }

  return 0;
}
Problem p02381 (C++)

Buggy submission (status: 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[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;
}

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[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;
}
Problem p02381 (C++)

Buggy submission (status: Time Limit Exceeded):
#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;
}

Fixed submission:
#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;
}
Problem p02381 (C++)

Buggy submission (status: Runtime Error):
// class point	の練習（クラスの高度な実装）
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <vector>

typedef long long llong;
using namespace std;

int main() {
  int n;
  int score[150];
  double mean, var;
  while (1) {
    scanf("%d", &n);
    if (!n)
      break;
    mean = 0;
    var = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &score[i]);
      mean += (double)score[i];
    }
    mean /= n;
    for (int i = 0; i < n; i++) {
      var += ((double)score[i] - mean) * ((double)score[i] - mean);
    }
    var /= n;
    cout << fixed << setprecision(10) << sqrt(var) << endl;
  }
  return 0;
}


Fixed submission:
// class point	の練習（クラスの高度な実装）
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <vector>

typedef long long llong;
using namespace std;

int main() {
  int n;
  int score[1100];
  double mean, var;
  while (1) {
    scanf("%d", &n);
    if (!n)
      break;
    mean = 0;
    var = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &score[i]);
      mean += (double)score[i];
    }
    mean /= n;
    for (int i = 0; i < n; i++) {
      var += ((double)score[i] - mean) * ((double)score[i] - mean);
    }
    var /= n;
    cout << fixed << setprecision(10) << sqrt(var) << endl;
  }
  return 0;
}
Problem p02381 (C++)

Buggy submission (status: 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[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;
}


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[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;
}
Problem p02381 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <time.h>
#include <valarray>
#include <vector>

using namespace std;

int main(void) {
  long double s[500], Hei, kari;

  long int n;

  for (long int A = 0; A < 1000; A++) {
    cin >> n;

    if (n == 0) {
      break;
    }

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

    for (long int i = 0; i < n; i++) {
      kari += (s[i] - Hei / n) * (s[i] - Hei / n);
    }

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

    Hei = 0;
    kari = 0;
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <time.h>
#include <valarray>
#include <vector>

using namespace std;

int main(void) {
  long double s[1000], Hei, kari;

  long int n;

  for (long int A = 0; A < 1000; A++) {
    cin >> n;

    if (n == 0) {
      break;
    }

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

    for (long int i = 0; i < n; i++) {
      kari += (s[i] - Hei / n) * (s[i] - Hei / n);
    }

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

    Hei = 0;
    kari = 0;
  }
}
Problem p02381 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <math.h>
#include <stdio.h>
#include <string.h>

#define PI 3.1415926

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

    scanf("%d", &n);
    if (n == 0) {
      break;
    }
    for (int i = 1; i <= n; i++) {
      scanf("%d", &s[i]);
      sum += s[i];
    }

    sum /= n;

    for (int i = 1; i <= n; i++) {
      a2 += (s[i] - sum) * (s[i] - sum);
    }
    printf("%f\n", sqrt(a2 / n));
    sum = 0;
    a2 = 0;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <math.h>
#include <stdio.h>
#include <string.h>

#define PI 3.1415926

int main() {
  int n, s[2000];
  double sum = 0;
  double a2 = 0;
  while (1) {

    scanf("%d", &n);
    if (n == 0) {
      break;
    }
    for (int i = 1; i <= n; i++) {
      scanf("%d", &s[i]);
      sum += s[i];
    }

    sum /= n;

    for (int i = 1; i <= n; i++) {
      a2 += (s[i] - sum) * (s[i] - sum);
    }
    printf("%f\n", sqrt(a2 / n));
    sum = 0;
    a2 = 0;
  }
  return 0;
}
Problem p02381 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  // int n,vol,s[100];
  double a, n, vol, s[100], avg;
  while (true) {

    cin >> n;
    if (n == 0)
      break;
    vol = 0;
    a = 0;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      vol += s[i];
    }
    avg = vol / n;
    for (int i = 0; i < n; i++) {
      a += pow(s[i] - avg, 2.0);
    }
    a /= n;
    printf("%lf\n", sqrt(a));
  }
  return 0;
}


Fixed submission:
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  // int n,vol,s[100];
  double a, n, vol, s[1000], avg;
  while (true) {

    cin >> n;
    if (n == 0)
      break;
    vol = 0;
    a = 0;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      vol += s[i];
    }
    avg = vol / n;
    for (int i = 0; i < n; i++) {
      a += pow(s[i] - avg, 2.0);
    }
    a /= n;
    printf("%lf\n", sqrt(a));
  }
  return 0;
}
Problem p02381 (C++)

Buggy submission (status: 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[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;
}

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[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;
}
Problem p02381 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int n;
  const int max_n = 100;
  double a[max_n];
  while (cin >> n, n) {
    double s = 0.0;
    double sum = 0.0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      sum += a[i];
    }
    double m = sum / n;
    for (int i = 0; i < n; i++) {
      s += pow(a[i] - m, 2);
    }
    s /= n;
    s = sqrt(s);
    printf("%.6f\n", s);
  }
  return 0;
}

Fixed submission:
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int n;
  const int max_n = 1000;
  double a[max_n];
  while (cin >> n, n) {
    double s = 0.0;
    double sum = 0.0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      sum += a[i];
    }
    double m = sum / n;
    for (int i = 0; i < n; i++) {
      s += pow(a[i] - m, 2);
    }
    s /= n;
    s = sqrt(s);
    printf("%.6f\n", s);
  }
  return 0;
}
Problem p02381 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02381 (C++)

Buggy submission (status: Runtime Error):
#include <iomanip>
#include <iostream>
#include <math.h>

using namespace std;

int main() {
  double n, a[100], sum, sig;
  while (1) {
    sum = 0;
    sig = 0;
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      sum += a[i];
    }
    for (int i = 0; i < n; i++) {
      sig += pow(a[i] - sum / n, 2);
    }
    cout << fixed << setprecision(6) << sqrt(sig / n) << endl;
  }
  return 0;
}

Fixed submission:
#include <iomanip>
#include <iostream>
#include <math.h>

using namespace std;

int main() {
  double n, a[1000], sum, sig;
  while (1) {
    sum = 0;
    sig = 0;
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      sum += a[i];
    }
    for (int i = 0; i < n; i++) {
      sig += pow(a[i] - sum / n, 2);
    }
    cout << fixed << setprecision(6) << sqrt(sig / n) << endl;
  }
  return 0;
}
Problem p02382 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;

  vector<int> x(3, 0), y(3, 0);

  for (int i = 0; i < n; ++i)
    cin >> x[i];

  for (int i = 0; i < n; ++i)
    cin >> y[i];

  // ???????????????????????¢(p = 1)
  double md = 0.0;
  double p = 1.0;
  for (int i = 0; i < n; ++i)
    md += pow(abs(x[i] - y[i]), p);
  md = pow(md, 1 / p);

  // ???????????????????????¢(p = 2)
  double ed = 0.0;
  p = 2.0;
  for (int i = 0; i < n; ++i)
    ed += pow(abs(x[i] - y[i]), p);
  ed = pow(ed, 1 / p);

  // p = 3?????¨???
  double td = 0.0;
  p = 3.0;
  for (int i = 0; i < n; ++i)
    td += pow(abs(x[i] - y[i]), p);
  td = pow(td, 1 / p);

  // ?????§????????§????????¢(p = ???)
  double cd = 0.0;
  for (int i = 0; i < n; ++i)
    if (abs(x[i] - y[i]) > cd)
      cd = abs(x[i] - y[i]);

  cout << setprecision(16) << md << endl;
  cout << ed << endl;
  cout << td << endl;
  cout << cd << endl;

  return 0;
}

Fixed submission:
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;

  vector<int> x(n, 0), y(n, 0);

  for (int i = 0; i < n; ++i)
    cin >> x[i];

  for (int i = 0; i < n; ++i)
    cin >> y[i];

  // ???????????????????????¢(p = 1)
  double md = 0.0;
  double p = 1.0;
  for (int i = 0; i < n; ++i)
    md += pow(abs(x[i] - y[i]), p);
  md = pow(md, 1 / p);

  // ???????????????????????¢(p = 2)
  double ed = 0.0;
  p = 2.0;
  for (int i = 0; i < n; ++i)
    ed += pow(abs(x[i] - y[i]), p);
  ed = pow(ed, 1 / p);

  // p = 3?????¨???
  double td = 0.0;
  p = 3.0;
  for (int i = 0; i < n; ++i)
    td += pow(abs(x[i] - y[i]), p);
  td = pow(td, 1 / p);

  // ?????§????????§????????¢(p = ???)
  double cd = 0.0;
  for (int i = 0; i < n; ++i)
    if (abs(x[i] - y[i]) > cd)
      cd = abs(x[i] - y[i]);

  cout << setprecision(16) << md << endl;
  cout << ed << endl;
  cout << td << endl;
  cout << cd << endl;

  return 0;
}
Problem p02382 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int n;
double x[100], y[100];

double distance(double p) {
  double sum = 0;
  for (int i = 0; i < n; i++) {
    double w = abs(x[i] - y[i]);
    sum += pow(w, p);
  }
  return pow(sum, 1.0 / p);
}

int main() {
  cout << fixed << setprecision(12);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> y[i];
  }
  cout << distance(1) << endl;
  cout << distance(2) << endl;
  cout << distance(3) << endl;
  double mx = 0;
  for (int i = 0; i, n; i++) {
    mx = max(mx, abs(x[i] - y[i]));
  }
  cout << mx << endl;
  return 0;
}


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

int n;
double x[100], y[100];

double distance(double p) {
  double sum = 0;
  for (int i = 0; i < n; i++) {
    double w = abs(x[i] - y[i]);
    sum += pow(w, p);
  }
  return pow(sum, 1.0 / p);
}

int main() {
  cout << fixed << setprecision(12);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> y[i];
  }
  cout << distance(1) << endl;
  cout << distance(2) << endl;
  cout << distance(3) << endl;
  double mx = 0;
  for (int i = 0; i < n; i++) {
    mx = max(mx, abs(x[i] - y[i]));
  }
  cout << mx << endl;
  return 0;
}
Problem p02383 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
#include <vector>

using namespace std;

struct Dice {
  vector<int> faces;

  Dice(vector<int> &f) : faces(f) {}

  int top() { return faces.front(); }

  void roll(char direction) {
    int tmp;
    switch (direction) {
    case 'E': // 1,4,6,3 -> 4,6,3,1
      tmp = faces[0];
      faces[0] = faces[3];
      faces[3] = faces[5];
      faces[5] = faces[2];
      faces[2] = tmp;
      break;
    case 'N': // 1,2,6,5 -> 2,6,5,1
      tmp = faces[0];
      faces[0] = faces[1];
      faces[1] = faces[5];
      faces[5] = faces[4];
      faces[4] = tmp;
      break;
    case 'S': // 1,5,6,2 -> 5,6,2,1
      tmp = faces[0];
      faces[0] = faces[4];
      faces[4] = faces[5];
      faces[5] = faces[1];
      faces[1] = tmp;
      break;
    case 'W': // 1,3,6,4 -> 3,6,4,1
      tmp = faces[0];
      faces[0] = faces[2];
      faces[2] = faces[5];
      faces[5] = faces[3];
      faces[3] = tmp;
      break;
    }
  }
};

int main() {
  vector<int> faces;
  for (int i = 0; i < 6; ++i) {
    int x;
    cin >> x;
    faces.push_back(x);
  }

  Dice dice(faces);
  string s;
  cin >> s;

  // cerr << s << endl;
  for (string::iterator it = s.begin(); it != s.end(); ++it) {
    dice.roll(*it);
    cerr << *it << "->" << dice.top() << endl;
  }
  cout << dice.top() << endl;

  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
#include <vector>

using namespace std;

struct Dice {
  vector<int> faces;

  Dice(vector<int> &f) : faces(f) {}

  int top() { return faces.front(); }

  void roll(char direction) {
    int tmp;
    switch (direction) {
    case 'E': // 1,4,6,3 -> 4,6,3,1
      tmp = faces[0];
      faces[0] = faces[3];
      faces[3] = faces[5];
      faces[5] = faces[2];
      faces[2] = tmp;
      break;
    case 'N': // 1,2,6,5 -> 2,6,5,1
      tmp = faces[0];
      faces[0] = faces[1];
      faces[1] = faces[5];
      faces[5] = faces[4];
      faces[4] = tmp;
      break;
    case 'S': // 1,5,6,2 -> 5,6,2,1
      tmp = faces[0];
      faces[0] = faces[4];
      faces[4] = faces[5];
      faces[5] = faces[1];
      faces[1] = tmp;
      break;
    case 'W': // 1,3,6,4 -> 3,6,4,1
      tmp = faces[0];
      faces[0] = faces[2];
      faces[2] = faces[5];
      faces[5] = faces[3];
      faces[3] = tmp;
      break;
    }
  }
};

int main() {
  vector<int> faces;
  for (int i = 0; i < 6; ++i) {
    int x;
    cin >> x;
    faces.push_back(x);
  }

  Dice dice(faces);
  string s;
  cin >> s;

  // cerr << s << endl;
  for (string::iterator it = s.begin(); it != s.end(); ++it) {
    dice.roll(*it);
    // cerr << *it << "->" << dice.top() << endl;
  }
  cout << dice.top() << endl;

  return 0;
}
Problem p02384 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
#define rep2(x, from, to) for (int x = (from); (x) < (to); (x)++)
#define rep(x, to) rep2(x, 0, to)
int main() {
  int a[6], head, down;
  rep(i, 6) { cin >> a[i]; }
  int s[6][6];
  s[0][0] = -1, s[0][1] = 2, s[0][2] = 4, s[0][3] = 1, s[0][4] = 3,
  s[0][5] = -1;
  s[1][0] = 3, s[1][1] = -1, s[1][2] = 0, s[1][3] = 5, s[1][4] = -1,
  s[1][5] = 2;
  s[2][0] = 1, s[2][1] = 5, s[2][2] = -1, s[2][3] = -1, s[2][4] = 0,
  s[2][5] = 4;
  rep2(i, 3, 6) {
    rep(j, 6) { s[i][j] = s[5 - i][5 - j]; }
  }
  int q;
  cin >> q;
  rep(i, q) {
    cin >> head >> down;
    cout << a[s[head - 1][down - 1]] << endl;
  }
  return 0;
}


Fixed submission:
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
#define rep2(x, from, to) for (int x = (from); (x) < (to); (x)++)
#define rep(x, to) rep2(x, 0, to)
int main() {
  int a[6], head, down;
  rep(i, 6) { cin >> a[i]; }
  int s[6][6];
  s[0][0] = -1, s[0][1] = 2, s[0][2] = 4, s[0][3] = 1, s[0][4] = 3,
  s[0][5] = -1;
  s[1][0] = 3, s[1][1] = -1, s[1][2] = 0, s[1][3] = 5, s[1][4] = -1,
  s[1][5] = 2;
  s[2][0] = 1, s[2][1] = 5, s[2][2] = -1, s[2][3] = -1, s[2][4] = 0,
  s[2][5] = 4;
  rep2(i, 3, 6) {
    rep(j, 6) { s[i][j] = s[5 - i][5 - j]; }
  }
  int q;
  cin >> q;
  rep(i, q) {
    cin >> head >> down;
    int b, c;
    rep(i, 6) {
      if (a[i] == head)
        b = i;
      else if (a[i] == down)
        c = i;
    }
    cout << a[s[b][c]] << endl;
  }
  return 0;
}
Problem p02384 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <iostream>

using namespace std;

struct dice {
  int q1, q2, q3, q4, q5, q6;
};

void mN(dice &d) {
  int tmp = d.q1;
  d.q1 = d.q2;
  d.q2 = d.q6;
  d.q6 = d.q5;
  d.q5 = tmp;
}

void mE(dice &d) {
  int tmp = d.q1;
  d.q1 = d.q4;
  d.q4 = d.q6;
  d.q6 = d.q3;
  d.q3 = tmp;
}
void mW(dice &d) {
  int tmp = d.q1;
  d.q1 = d.q3;
  d.q3 = d.q6;
  d.q6 = d.q4;
  d.q4 = tmp;
}
void mS(dice &d) {
  int tmp = d.q1;
  d.q1 = d.q5;
  d.q5 = d.q6;
  d.q6 = d.q2;
  d.q2 = tmp;
}

void spin(dice &d) {
  int tmp = d.q2;
  d.q2 = d.q3;
  d.q3 = d.q5;
  d.q5 = d.q4;
  d.q4 = tmp;
}

int main() {
  dice z;
  int q;

  scanf(" %d %d %d %d %d %d", &z.q1, &z.q2, &z.q3, &z.q4, &z.q5, &z.q6);
  scanf(" %d", &q);

  for (int i = 0; i < q; ++i) {
    int a, b;
    dice x = z;

    scanf(" %d %d", &a, &b);

    if (a == 3 || a == 4)
      mE(x);
    while (a != x.q1)
      mN(x);
    while (b != x.q2)
      spin(x);

    printf("%d\n", x.q3);
  }

  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>

using namespace std;

struct dice {
  int q1, q2, q3, q4, q5, q6;
};

void mN(dice &d) {
  int tmp = d.q1;
  d.q1 = d.q2;
  d.q2 = d.q6;
  d.q6 = d.q5;
  d.q5 = tmp;
}

void mE(dice &d) {
  int tmp = d.q1;
  d.q1 = d.q4;
  d.q4 = d.q6;
  d.q6 = d.q3;
  d.q3 = tmp;
}
void mW(dice &d) {
  int tmp = d.q1;
  d.q1 = d.q3;
  d.q3 = d.q6;
  d.q6 = d.q4;
  d.q4 = tmp;
}
void mS(dice &d) {
  int tmp = d.q1;
  d.q1 = d.q5;
  d.q5 = d.q6;
  d.q6 = d.q2;
  d.q2 = tmp;
}

void spin(dice &d) {
  int tmp = d.q2;
  d.q2 = d.q3;
  d.q3 = d.q5;
  d.q5 = d.q4;
  d.q4 = tmp;
}

int main() {
  dice z;
  int q;

  scanf(" %d %d %d %d %d %d", &z.q1, &z.q2, &z.q3, &z.q4, &z.q5, &z.q6);
  scanf(" %d", &q);

  for (int i = 0; i < q; ++i) {
    int a, b;
    dice x = z;

    scanf(" %d %d", &a, &b);

    if (a == x.q3 || a == x.q4)
      mE(x);
    while (a != x.q1)
      mN(x);
    while (b != x.q2)
      spin(x);

    printf("%d\n", x.q3);
  }

  return 0;
}
Problem p02384 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int dice(int a, int b) {
  int count = 0;
  string tpat[3];
  tpat[0] = "12651";
  tpat[1] = "23542";
  tpat[2] = "13641";
  int ret[3];
  ret[0] = 3;
  ret[1] = 1;
  ret[2] = 5;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 4; j++) {
      if (tpat[i][j] - '0' == a && tpat[i][j + 1] - '0' == b) {
        return ret[i];
      }
    }
  }
  tpat[0] = "15621";
  tpat[1] = "24532";
  tpat[2] = "14631";
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 4; j++) {
      if (tpat[i][j] - '0' == a && tpat[i][j + 1] - '0' == b) {
        return 7 - ret[i];
      }
    }
  }
}

int main(int argc, char const *argv[]) {
  int d[6];
  for (int i = 0; i < 6; i++) {
    cin >> d[i];
  }
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    cout << d[dice(a, b) - 1] << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int dice(int a, int b) {
  int count = 0;
  string tpat[3];
  tpat[0] = "12651";
  tpat[1] = "23542";
  tpat[2] = "13641";
  int ret[3];
  ret[0] = 3;
  ret[1] = 1;
  ret[2] = 5;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 4; j++) {
      if (tpat[i][j] - '0' == a && tpat[i][j + 1] - '0' == b) {
        return ret[i];
      }
    }
  }
  tpat[0] = "15621";
  tpat[1] = "24532";
  tpat[2] = "14631";
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 4; j++) {
      if (tpat[i][j] - '0' == a && tpat[i][j + 1] - '0' == b) {
        return 7 - ret[i];
      }
    }
  }
}

int main(int argc, char const *argv[]) {
  int d[6];
  for (int i = 0; i < 6; i++) {
    cin >> d[i];
  }
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    int a1, b1;
    for (int i = 0; i < 6; i++) {
      if (d[i] == a)
        a1 = i;
      if (d[i] == b)
        b1 = i;
    }
    cout << d[dice(a1 + 1, b1 + 1) - 1] << endl;
  }
  return 0;
}
Problem p02385 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

int memo[7][7] = {-1};
int x[3][5] = {{1, 2, 6, 5, 1}, {1, 3, 6, 4, 1}, {2, 3, 5, 4, 2}};
int sides[3][2] = {{4, 3}, {2, 5}, {6, 1}};

int main() {
  int dice_a[7], dice_b[7];
  int top, front, q;
  char command;

  for (int i = 1; i < 7; i++)
    std::cin >> dice_a[i];
  for (int i = 1; i < 7; i++)
    std::cin >> dice_b[i];

  for (int j = 0; j < 3; j++) {
    for (int i = 1; i < 5; i++) {
      memo[dice_a[x[j][i]]][dice_a[x[j][i - 1]]] = dice_a[sides[j][0]];
      memo[dice_a[x[j][i - 1]]][dice_a[x[j][i]]] = dice_a[sides[j][1]];
    }
  }

  if (memo[dice_b[1]][dice_b[2]] == dice_b[3] &&
      memo[dice_b[2]][dice_b[1]] == dice_b[4]) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  return 0;
}


Fixed submission:
#include <iostream>

int memo[101][101] = {-1};
int x[3][5] = {{1, 2, 6, 5, 1}, {1, 3, 6, 4, 1}, {2, 3, 5, 4, 2}};
int sides[3][2] = {{4, 3}, {2, 5}, {6, 1}};

int main() {
  int dice_a[7], dice_b[7];
  int top, front, q;
  char command;

  for (int i = 1; i < 7; i++)
    std::cin >> dice_a[i];
  for (int i = 1; i < 7; i++)
    std::cin >> dice_b[i];

  for (int j = 0; j < 3; j++) {
    for (int i = 1; i < 5; i++) {
      memo[dice_a[x[j][i]]][dice_a[x[j][i - 1]]] = dice_a[sides[j][0]];
      memo[dice_a[x[j][i - 1]]][dice_a[x[j][i]]] = dice_a[sides[j][1]];
    }
  }

  if (memo[dice_b[1]][dice_b[2]] == dice_b[3] &&
      memo[dice_b[2]][dice_b[1]] == dice_b[4]) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  return 0;
}
Problem p02385 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

class dice {

public:
  int _1, _2, _3, _4, _5, _6, sus;

  void moveN() {
    sus = _1;
    _1 = _2;
    _2 = _6;
    _6 = _5;
    _5 = sus;
  }

  void moveE() {
    sus = _1;
    _1 = _4;
    _4 = _6;
    _6 = _3;
    _3 = sus;
  }

  void moveW() {
    sus = _1;
    _1 = _3;
    _3 = _6;
    _6 = _4;
    _4 = sus;
  }

  void moveS() {
    sus = _1;
    _1 = _5;
    _5 = _6;
    _6 = _2;
    _2 = sus;
  }

  void spin() {
    sus = _2;
    _2 = _3;
    _3 = _5;
    _5 = _4;
    _4 = sus;
  }
};

int main() {

  dice d1;
  dice d2;

  int i;

  cin >> d1._1 >> d1._2 >> d1._3 >> d1._4 >> d1._5 >> d1._6;
  cin >> d2._1 >> d2._2 >> d2._3 >> d2._4 >> d2._5 >> d2._6;

  if (d1._3 == d2._1 || d1._4 == d2._1)
    d1.moveE();
  for (i = 0; i < 4; i++) {
    if (d2._1 == d1._1)
      break;
    d1.moveN();
  }
  for (i = 0; i < 4 || d2._2 != d1._2; i++) {
    if (d2._2 == d1._2)
      break;
    d1.spin();
  }

  if (d1._1 == d2._1 && d1._2 == d2._2 && d1._3 == d2._3 && d1._4 == d2._4 &&
      d1._5 == d2._5 && d1._6 == d2._6)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;

class dice {

public:
  int _1, _2, _3, _4, _5, _6, sus;

  void moveN() {
    sus = _1;
    _1 = _2;
    _2 = _6;
    _6 = _5;
    _5 = sus;
  }

  void moveE() {
    sus = _1;
    _1 = _4;
    _4 = _6;
    _6 = _3;
    _3 = sus;
  }

  void moveW() {
    sus = _1;
    _1 = _3;
    _3 = _6;
    _6 = _4;
    _4 = sus;
  }

  void moveS() {
    sus = _1;
    _1 = _5;
    _5 = _6;
    _6 = _2;
    _2 = sus;
  }

  void spin() {
    sus = _2;
    _2 = _3;
    _3 = _5;
    _5 = _4;
    _4 = sus;
  }
};

int main() {

  dice d1;
  dice d2;

  int i;

  cin >> d1._1 >> d1._2 >> d1._3 >> d1._4 >> d1._5 >> d1._6;
  cin >> d2._1 >> d2._2 >> d2._3 >> d2._4 >> d2._5 >> d2._6;

  if (d1._3 == d2._1 || d1._4 == d2._1)
    d1.moveE();
  for (i = 0; i < 4; i++) {
    if (d2._1 == d1._1)
      break;
    d1.moveN();
  }
  for (i = 0; i < 4; i++) {
    if (d2._2 == d1._2)
      break;
    d1.spin();
  }

  if (d1._1 == d2._1 && d1._2 == d2._2 && d1._3 == d2._3 && d1._4 == d2._4 &&
      d1._5 == d2._5 && d1._6 == d2._6)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}
Problem p02385 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
using namespace std;

int main() {
  int d1[7], d2[7];
  scanf("%d %d %d %d %d %d", &d1[0], &d1[1], &d1[2], &d1[3], &d1[4], &d1[5]);
  scanf("%d %d %d %d %d %d", &d2[0], &d2[1], &d2[2], &d2[3], &d2[4], &d2[5]);

  for (int i = 0; i < 4; i++) {
    int tmp1 = d1[0];
    d1[0] = d1[2];
    d1[2] = d1[5];
    d1[5] = d1[3];
    d1[3] = tmp1;
    for (int j = 0; j < 4; j++) {
      int tmp2 = d1[0];
      d1[0] = d1[1];
      d1[1] = d1[5];
      d1[5] = d1[4];
      d1[4] = tmp2;
      for (int k = 0; k < 4; k++) {
        int tmp3 = d1[1];
        d1[1] = d1[2];
        d1[2] = d1[4];
        d1[4] = d1[3];
        d1[3] = tmp3;
        int chk = 0;
        for (int p = 0; p < 6; p++) {
          if (d1[p] != d2[p]) {
            break;
          } else {
            chk++;
          }
          if (chk == 6) {
            printf("Yes\n");
            return 1;
          }
        }
      }
    }
  }
  printf("No\n");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
using namespace std;

int main() {
  int d1[7], d2[7];
  scanf("%d %d %d %d %d %d", &d1[0], &d1[1], &d1[2], &d1[3], &d1[4], &d1[5]);
  scanf("%d %d %d %d %d %d", &d2[0], &d2[1], &d2[2], &d2[3], &d2[4], &d2[5]);

  for (int i = 0; i < 4; i++) {
    int tmp1 = d1[0];
    d1[0] = d1[2];
    d1[2] = d1[5];
    d1[5] = d1[3];
    d1[3] = tmp1;
    for (int j = 0; j < 4; j++) {
      int tmp2 = d1[0];
      d1[0] = d1[1];
      d1[1] = d1[5];
      d1[5] = d1[4];
      d1[4] = tmp2;
      for (int k = 0; k < 4; k++) {
        int tmp3 = d1[1];
        d1[1] = d1[2];
        d1[2] = d1[4];
        d1[4] = d1[3];
        d1[3] = tmp3;
        int chk = 0;
        for (int p = 0; p < 6; p++) {
          if (d1[p] != d2[p]) {
            break;
          } else {
            chk++;
          }
          if (chk == 6) {
            printf("Yes\n");
            return 0;
          }
        }
      }
    }
  }
  printf("No\n");
  return 0;
}