import java.applet.*;
import java.awt.*;

class BRun implements Runnable
{
	double x[],y[],xtotal;
	int Nboot,n,N;
	int I[],imin;
	double results[],resmin;
	int nresults,ntop;
	
	Runner R;
	
	final double alpha=0.05;

	public BRun (Runner r, double X[], double Y[], int nn, int NN, double XTotal)
	{	x=new double[X.length];
		for (int i=0; i<X.length; i++) x[i]=X[i];
		y=new double[Y.length];
		for (int i=0; i<Y.length; i++) y[i]=Y[i];
		N=NN; n=nn; xtotal=XTotal; R=r;
	}

	void shuffle (int n, int I[], int N)
	{	int i,j,h;
		for (i=0; i<n; i++)
		{	j=i+(int)(Math.random()*(N-i));
			if (i!=j)
			{	h=I[j]; I[j]=I[i]; I[i]=h;
			}
		}
	}
	
	void shuffle (int n, int I[], int start, int N)
	{	int i,j,h;
		for (i=0; i<n; i++)
		{	j=i+(int)(Math.random()*(N-i));
			if (i!=j)
			{	h=I[start+j]; I[start+j]=I[start+i]; I[start+i]=h;
			}
		}
	}
	
	double sqr (double x)
	{	return x*x;
	}
	
	void bootstr100 ()
	{	int i,j,k;
		double xsum,ysum,mux,h,p,vp,est,ptrue;
		for (k=0; k<100; k++)
		{
			for (i=0; i<Nboot; i++) I[i]=i%n;
			shuffle(N-(Nboot-n),I,Nboot-n,n);
			shuffle(n,I,N);
	
			xsum=0; ysum=0;
			for (j=0; j<n; j++)
			{	xsum+=x[I[j]]; ysum+=y[I[j]];
			}
			if (xsum==0) est=-10;
			else
			{
				p=ysum/xsum;
				xsum=0; ysum=0;
				for (int l=0; l<N; l++) { xsum+=x[I[l]]; ysum+=y[I[l]]; }
				ptrue=ysum/xsum;
				mux=xsum/N;
				h=0;
				for (j=0; j<n; j++)
				{	h+=sqr(y[I[j]]-p*x[I[j]]);
				}
				vp=(1-(double)(n-1)/(N-1))/(n*mux*mux)*h/(n-1);
				if (vp==0) est=-10;
				else est=(p-ptrue)/Math.sqrt(vp);
			}
	
			if (nresults==0)
			{	results[0]=est;
				imin=0; resmin=est; nresults=1;
			}
			else if (nresults<ntop)
			{   results[nresults]=est;
				if (est<resmin) { resmin=est; imin=nresults; }
				nresults++;
			}
			else if (est>resmin)
			{	results[imin]=est;
				resmin=results[0]; imin=0;
				for (j=0; j<ntop; j++)
				{	if (results[j]<resmin)
					{	resmin=results[j]; imin=j;
					}
				}
			}
		}
	}
	
	int iter;
	
	void bootstrap (int n)
	{	iter=n;
		new Thread(this).start();
	}
	
	void bootstrapn (int n)
	{	iter=n;
		run();
	}
	
	public void run ()
	{	int i,f,k,j;
		double xsum,ysum,p,est,h,vp,ptrue,mux;
	
		f=N/n+1;
		Nboot=n*f;
		I=new int[Nboot];
	
		ntop=(int)(iter*100*alpha);
		results=new double[ntop];
		nresults=0;
	
		for (k=0; k<iter; k++) bootstr100();

		xsum=0; ysum=0;
		for (j=0; j<n; j++)
		{	xsum+=x[j]; ysum+=y[j];
		}
		mux=xtotal/N;
		h=0;
		ptrue=ysum/xsum;
		for (j=0; j<n; j++)
		{	h+=sqr(y[j]-ptrue*x[j]);
		}
		vp=(1-(double)(n-1)/(N-1))/(n*mux*mux)*h/(n-1);
	
		R.note(ptrue-Math.sqrt(vp)*resmin);
	}
}

class Runner
{
	static int n=60,N=1125;
	static double XTotal=395113;
	static double Data[][]=
	{
	{158.40,0},
	{33.99,0},
	{78.40,0},
	{103.52,0},
	{145.60,56},
	{313.60,78.40},
	{74.25,0},
	{368.89,0},
	{65.78,0},
	{109.78,0},
	{428.40,59.12},
	{345.98,0},
	{162.20,0},
	{489.50,0},
	{181.49,0},
	{27.94,0},
	{292.69,0},
	{305.40,0},
	{579.55,0},
	{101.91,0},
	{796.87,78.40},
	{545.36,0},
	{994.50,0},
	{45.55,0},
	{448,0},
	{243.06,0},
	{137.49,0},
	{210.80,65.90},
	{91.10,0},
	{545.62,56},
	{1785.90,28},
	{90.20,0},
	{265.36,0},
	{215.53,0},
	{181.45,0},
	{67,0},
	{123.20,0},
	{78.40,0},
	{51.52,0},
	{203.16,0},
	{133.33,0},
	{22.40,0},
	{579.08,0},
	{150.58,0},
	{89.60,89.60},
	{805,0},
	{826.69,0},
	{1429.77,0},
	{181.99,44.80},
	{259.09,0},
	{266.40,0},
	{298.68,0},
	{564.36,0},
	{33.93,0},
	{56,0},
	{90.38,0},
	{35,0},
	{965.66,313.60},
	{142.76,0},
	{268.85,0}
	};

	BTest R;

	long time;
	
	int Count=0;
	public static int NThreads=1;
	
	public Runner ()
	{	compute();
	}

	public Runner (BTest bt)
	{	R=bt;
		compute();
	}

	void compute ()
	{	int i;
		int res;
		double x[]=new double[n];
		double y[]=new double[n];
		for (i=0; i<n; i++)
		{	x[i]=Data[i][0]; y[i]=Data[i][1];
		}
		time=System.currentTimeMillis();
		Count=NThreads;
		if (NThreads==1)
		{	BRun T=new BRun(this,x,y,n,N,XTotal);
			T.bootstrapn(1000/NThreads);
		}
		else
			for (i=0; i<NThreads; i++)
			{	BRun T=new BRun(this,x,y,n,N,XTotal);
				T.bootstrap(1000/NThreads);
			}
	}

	double Res=0;

	public synchronized void note (double res)
	{	Count--;
		Res+=res;
		if (Count<=0)
		{	int sec=(int)((System.currentTimeMillis()-time)/1000);
			System.out.println("Result : "+Res/NThreads*100);
			if (R!=null)
			{	R.note(sec);
			}
			else
			{	System.out.println("Time: "+sec+" seconds with "+
					NThreads+" thread(s)");
			}
		}
	}
}

public class BTest extends Applet
{
	static public void main (String argv[])
	{   if (argv.length>0 && argv[0].equals("threads")) Runner.NThreads=2;
		Runner R=new Runner();
	}

	TextArea T;
	Checkbox Threads;
	
	public void init ()
	{	setLayout(new BorderLayout());
		T=new TextArea();
		add("Center",T);
		Panel p=new Panel();
		p.add(new Button("Compute"));
		p.add(Threads=new Checkbox("Threads"));
		add("South",p);
	}
	
	boolean Computing=false;
	
	public boolean action (Event e, Object o)
	{	if ("Compute".equals(o) && !Computing)
		{	Runner.NThreads=(Threads.getState())?2:1;
			Computing=true;
			T.setText("Computing, Please Wait!");
			Runner R=new Runner(this);
		}
		return true;
	}
	
	public void note (int seconds)	
	{	T.setText("Time: "+seconds+" seconds with "+
			Runner.NThreads+" thread(s)");
		Computing=false;
	}
}	

