import java.io.*;
import java.util.Scanner;
import java.util.Arrays;


public class Statistic
{   
	 //"gravitational_beale.txt"
	 //"gravitational_goldstein.txt"
	 //"gravitational_boha1.txt"
	 //"gravitational_boha2.txt"
	 //"gravitational_boha3.txt"
	 //"gravitational_booth.txt"
	 //"gravitational_branin.txt"
	 //"gravitational_colville.txt"
	 //"gravitational_easom.txt"
	 //"gravitational_himmelblau.txt"
	 //"gravitational_griewank.txt"
	 //"gravitational_matyas.txt"
	 //"gravitational_mich.txt"
	 //"gravitational_shekel.txt"
	 //"gravitational_trid.txt"
	 //"gravitational_zakharov.txt"
	 //"gravitational_levy.txt"
	 //"gravitational_solomons.txt"
	 //"gravitational_quartic.txt"
	 
	 
	 
	/* double [] readfile()
	 {
	  double depo[]=new double[20];
	  try{   
	  Scanner scan=new Scanner(new File("gravitational_quartic.txt"));
	  int t=0;
	  while(scan.hasNextLine())
	  {
	  depo[t]=Double.parseDouble(scan.nextLine());t++;	  
	  if(t==20){break;}
	  }
	  scan.close();
      }catch(FileNotFoundException f){};
      return depo; 
	 }*/
	
	
	
	
      double mean_dev()
     {
	  double a[][]=Text.readDouble("hybridsearch2_f77.txt");
	  int n=a.length;double s1=0.0;
	  for(int i=0;i<n;i++)
	  {s1+=a[i][0];}
	  double ret=s1/(double)n;
	  return ret;
	 }
     
     double maxvalue()
     {
	  double a[][]=Text.readDouble("hybridsearch2_f77.txt");
      double b[]=new double[a.length];
	  for(int i=0;i<a.length;i++)
      {b[i]=a[i][0];}
	  double[] maxv=getmaxval_index(b);
	  return maxv[0];   
	 }
	 
	 double[] getmaxval_index(double a[])
	 {
	 double m=0.0;
	 double b[]=new double[a.length];
	 for(int i=0;i<a.length;i++)
	 {b[i]=a[i];}
	 double maxval=a[0];
	 for(int j=0;j<a.length;j++)
	 {if(a[j]>maxval){maxval=a[j];}}
	 for(int i=0;i<b.length;i++)
	 {if(b[i]==maxval){m=i;break;}}
	 double dep2[]=new double[2];
	 dep2[0]=maxval;
	 dep2[1]=m;
	 return dep2;	 
	 }
	 
	 double[] getminval_index(double[] a)
	 {
	 double m=0.0;	 
	 double b[]=new double[a.length];
	 for(int i=0;i<a.length;i++)
	 {b[i]=a[i];}  
	 double minval=a[0];
	 for(int i=0;i<a.length;i++)
	 {if(a[i]<minval){minval=a[i];}}
	 for(int i=0;i<a.length;i++)
	 {if(b[i]==minval){m=i;break;}};
	 double[] dep=new double[2];
	 dep[0]=minval;
	 dep[1]=m;
	 return dep;	 
	 }
	 
	 double minvalue()
     {
	  double a[][]=Text.readDouble("hybridsearch2_f77.txt");
       double b[]=new double[a.length];
	  for(int i=0;i<a.length;i++)
      {b[i]=a[i][0];}
	  double[] minv=getminval_index(b);
      return minv[0];   
	 }
	 
	 void minvariables()
	 {
	  double a[][]=Text.readDouble("hybridsearch2_f77.txt");
       double b[]=new double[a.length];
	  for(int i=0;i<a.length;i++)
      {b[i]=a[i][0];}
      double[] minv=getminval_index(b);
      int k=(int)minv[1];
      for(int j=1;j<a[0].length;j++)
      {System.out.println("x["+j+"] = "+a[k][j]);}	 
	 	 
	 }
	 
	 double standart_dev()
	 {
	  double mean=mean_dev();
	  double a[][]=Text.readDouble("hybridsearch2_f77.txt");
	  int n=a.length;
	  double s1=0.0;
	  for(int i=0;i<n;i++)
	  {s1+=(a[i][0]-mean)*(a[i][0]-mean);}
      return Math.sqrt(s1/(double)n);	 
	}
	
	double median()
	{
		double a[][]=Text.readDouble("hybridsearch2_f77.txt");
	    int n=a.length;
		double d3[]=new double[a.length];
	    for(int i=0;i<a.length;i++)
        {d3[i]=a[i][0];}
	    Arrays.sort(d3);
		double med=0.0;
		int m=n/2;
		if((n%2)==1)
		{med=d3[m];return med;}
		if((n%2)==0)
		{med=(d3[m-1]+d3[m])/2.0;return med;}
		return med;
	}
	
	 
	 
	 
	 
	 public static void main(String args[])
	 {
	     Statistic ss=new Statistic();	 
		 double cc=ss.mean_dev();
		 double maxx=ss.maxvalue();
		 double minx=ss.minvalue();
		 double stand=ss.standart_dev();
		 double med=ss.median();
		 System.out.println("Mean dev = "+cc);
		 System.out.println("Standart dev = "+stand);
		 System.out.println("Maxvalue = "+maxx);
		 System.out.println("Minvalue = "+minx);
		 System.out.println("Median = "+med);
		 ss.minvariables();
		 
     }









}