#include <math.h>
#include <stdio.h>
 
double avg (double x[], int n)
{
  int i;
  double sx = 0.0;
 
  for (i=0; i < n; i++) {
    sx += x[i];
  }
  return sx / n;
}
 
double std (double x[], int n, double mean)
{
  int i;
  double sx = 0.0;
 
  for (i=0; i < n; i++) {
    sx += (x[i] - mean) * (x[i] - mean);
  }
 
  return sqrt (sx / n);
}
 
main (int argc, char *argv[])
{
  int space = 1024;
  double *x = (double *) malloc (space * sizeof (double));
  double m, s;
  int i = 0;
  FILE *fp;

  if (argc == 1) {
    fp = stdin;
  } else if (argc == 2) {
    fp = fopen (argv[1], "r");
    if (fp == NULL) {
      printf ("Unable to open file %s.\n", argv[1]);
      exit (1);
    }
  } else {
    printf ("Usage: avgsd [filename].\n");
    exit (1);
  }
 
  while (fscanf (fp, "%lf", &x[i]) == 1) {
    i++;
    if (i == space) {
      space *= 2;
      x = (double *) realloc ((void *) x, space * sizeof (double));
    }
  }

  m = avg (x, i);
  s = std (x, i, m);
  printf ("%lf\t%lf\t%lf\n", m, s, s/m);
  /*  printf ("%lf\t%lf\t%lf\n", m, s, s/sqrt((double)i) ); */

  return (0);
}
