! 1$B9TL\$K%G!<%??t!"(B2$B9TL\0J9_$K(Bx,y$B%G!<%?$,JB$s$G$$$k%U%!%$%k(B
! ($BNc$($P(Bhoge.d)$B$r:n$k!#(Bkaiki<hoge.d $B$H<B9T!#(B
        program kaiki
        implicit real*8 (a-h, o-z)
        dimension x(1000),y(1000)
         print*,'x,y$B$N%G!<%?$+$i(By=ax+b$B$N2s5"D>@~$r5a$a$k(B'
        read(*,*) n
         sx=0.d0
         sy=0.d0
         sxy=0.d0
         sx2=0.d0
         sy2=0.d0
         sxxyy=0.d0
        do i=1,n
!         print*,i
         read(*,*) x(i),y(i)
         sx=sx+x(i)
         sy=sy+y(i)
         sxy=sxy+x(i)*y(i)
         sx2=sx2+x(i)**2
         sy2=sy2+y(i)**2
        end do
!
! x(i),y(i)$B$N:GBgCM(Bxmax,ymax$B$H:G>.CM(Bxmin,ymin$B$r5a$a$k(B
               xmax=x(1)
               ymax=y(1)
               xmin=x(1)
               ymin=y(1)
               do i=1,n
               if (x(i).gt.xmax) xmax= x(i)
               if (y(i).gt.ymax) ymax= y(i)
               if (x(i).lt.xmin) xmin= x(i)
               if (y(i).lt.ymin) ymin= y(i)
               end do
!        
!        
!        
        xm=sx/n
        ym=sy/n
        do i=1,n
         sxxyy=sxxyy+(x(i)-xm)*(y(i)-ym)
        end do
         a=(n*sxy-sx*sy)/(n*sx2-sx**2)
         b=(sx2*sy-sxy*sx)/(n*sx2-sx**2)
         hen=sqrt( (sy2-b*sy-a*sxy)/n )
!         hensa=sqrt((sy2-n*ym**2-a*sxxyy)/n)
         r2=sxxyy**2/((sx2-n*xm**2)*(sy2-n*ym**2))
         r=sxxyy/sqrt((sx2-n*xm**2)*(sy2-n*ym**2))
!
         print*, 'a=',a
         print*, 'b=',b
         print*, 'r**2=',r2
         print*, 'r=',r
         print*,'x$B$NJ?6Q(B',xm
         xb=sx2/n-xm**2
         print*,'x$B$NJ,;6!"I8=`JP:9(B',xb,sqrt(xb)
         print*,'y$B$NJ?6Q(B',ym
         yb=sy2/n-ym**2
         print*,'y$B$NJ,;6!"I8=`JP:9(B',yb,sqrt(yb)
         print*, '$B2s5"@~$KBP$9$kJQ?t(By$B$NI8=`JP:9(B',hen
         cv=sqrt(yb)/ym
         print*,'$BJQF078?t(B(y$BJP:9(B/y$BJ?6Q(B)',cv
!
! $B2s5"D>@~$N(B2$BE@%G!<%?$r=PNO(B
         yxmin=a*xmin+b
         yxmax=a*xmax+b
         xymin=(ymin-b)/a
         xymax=(ymax-b)/a
         open(7,file='k.d')
!         write(7,*) xmin,yxmin
!         write(7,*) xmax,yxmax
         write(7,*) xymin,ymin
         write(7,*) xymax,ymax
         close(7)
!
         end
