// Arup Guha
// 2/9/06
// A small example that utilizes an array of arrays.
import java.util.*;
import java.io.*;

public class ProcessData {

  public static void main(String[] args) throws IOException {

    // Create the 2D array reference.
    int[][] rawdata;

    Scanner fin = new Scanner(new File("testdata.in"));
 
    // Read in the number of regions in the data file.
    int numregions = fin.nextInt();

    // Allocate space for each array reference, one per region.
    rawdata = new int[numregions][];

    // Read in data for each region, one by one.
    for (int i=0; i<numregions; i++) {

      // Read in the number of samples for this particular region.
      int numsamples = fin.nextInt();

      // Allocate the space for this one array, to hold data for this region.
      rawdata[i] = new int[numsamples];

      // Read in each sample for this region.
      for (int j=0; j<numsamples; j++)
        rawdata[i][j] = fin.nextInt();
    }

    // Print out the standard deviation for each region.
    for (int i=0; i<numregions; i++) {
      System.out.print("Standard Deviation of Data Set "+(i+1));
      System.out.println(": "+ stddev(rawdata[i]));
    }

    fin.close();
  }

  // Returns the average of the values stored in data.
  public static double avg(int[] data) {
    int sum = 0;

    // Add up the sum of the values in data.
    for (int i=0; i<data.length; i++) 
      sum += data[i];

    // Return the average by dividing this by the length of the array.
    return (double)sum/data.length;
  }

  // Calculates the standard deviation of all of the values in data.
  public static double stddev(int[] data) {

    // Calculate the average of all the values.
    double average = avg(data);
    double sum=0;

    // Add up the difference each term and the average squared.
    for (int i=0; i<data.length; i++)
      sum = sum + Math.pow((data[i]-average),2);

    // Divide by the number of terms.
    sum /= data.length;

    // The standard deviation is the square root of that value.
    return Math.sqrt(sum);
  }
}
