c 1$B9TL\$K%G!<%??t!"(B2$B9TL\0J9_$K(Bx,y$B%G!<%?$,JB$s$G$$$k%U%!%$%k(B
c ($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
         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
c
        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 )
c         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))
c
         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
         end
