Option Strict On
Imports System.IO
Module Module1

    Sub Main()
        Dim N As Integer
        Dim reader As StreamReader = New StreamReader("inputdata.csv")
        N = Integer.Parse(reader.ReadLine())
        Dim x(N - 1) As Double
        Dim y(N - 1) As Double
        For i As Integer = 0 To N - 1
            Dim line As String = reader.ReadLine()
            Dim semicolon As Integer = line.IndexOf(";")
            x(i) = Double.Parse(line.Substring(0, semicolon))
            y(i) = Double.Parse(line.Substring(semicolon + 1))
        Next i
        Dim Xmean As Double = 0
        Dim Ymean As Double = 0
        For i As Integer = 0 To N - 1
            Xmean = Xmean + x(i)
            Ymean = Ymean + y(i)
        Next i
        Xmean = Xmean / N
        Ymean = Ymean / N
        Dim num As Double = 0
        Dim denom As Double = 0
        For i As Integer = 0 To N - 1
            num = num + (x(i) - Xmean) * (y(i) - Ymean)
            denom = denom + (x(i) - Xmean) ^ 2
        Next i
        Dim A As Double = num / denom
        Dim B As Double = Ymean - A * Xmean
        Console.WriteLine("Уравнение прямой:  Y = {0:F4} * X + {1:F4}", A, B)
        Console.WriteLine()
        Console.WriteLine("  Xi         Yi          A * Xi + B        Delta")
        For i As Integer = 0 To N - 1
            Console.WriteLine(" {0,10}  {1,10:F4}  {2,10:F4}  {3,10:F4}", x(i), y(i), A * x(i) + B, y(i) - A * x(i) - B)
        Next i
        reader.Close()
        Console.ReadLine()
    End Sub

End Module
