Module VBModule
 
    Sub Main()
        Dim n As Integer = CInt(Console.Readline())
        Dim str As String() = Console.Readline().Split(" ")
        Dim i, avg As Integer = 0
        
        for i = 0 to UBound(str)
          avg+= CInt(str(i))
        Next
        Dim a1 As Integer = Math.Floor(avg / n)
        Dim c1 As Integer = 0
        
        for i= 0 to ubound(str)
          c1 += (Cint(str(i)) - a1)*(Cint(str(i)) - a1)
        next
        
        Dim a2 As Integer = Math.Ceiling(avg/n)
        Dim c2 As Integer = 0
        
        for i= 0 to ubound(str)
          c2 += (Cint(str(i)) - a2)*(Cint(str(i)) - a2)
        next
        
        if c2>c1 then Console.writeline(c1.toString()) else console.writeline(c2.tostring())
        
        
    End Sub
  
End Module
