Problem:
Score : 100 points

Problem Statement

We have an N \times N square grid.

We will paint each square in the grid either black or white.

If we paint exactly A squares white, how many squares will be painted black?

Constraints

1 \leq N \leq 100

0 \leq A \leq N^2

Inputs

Input is given from Standard Input in the following format:

N
A

Outputs

Print the number of squares that will be painted black.

Sample Input 1

3
4

Sample Output 1

5

There are nine squares in a 3 \times 3 square grid.
Four of them will be painted white, so the remaining five squares will be painted black.

Sample Input 2

19
100

Sample Output 2

261

Sample Input 3

10
0

Sample Output 3

100

As zero squares will be painted white, all the squares will be painted black.

Solution in Ruby (2.3.3) (judge verdict: Runtime Error)

a, b, c, d, e, f = gets.chomp.split(' ').map(&:to_f)
max = 0
limit = e/(100+e)
a *= 100
b *= 100
result = [0, 0]
for i in 0..(f/a)
  for j in 0..(f-a*i)/b
    w = (a*i+b*j).to_f
    for k in 0..(f-w)/c
      for l in 0..(f-w-c*k)/d
        next if i+j==0 || k+l==0
        s = (c*k+d*l).to_f
        con = s/(s+w)
        next if limit < con
        if max < con
          max = con
          result[0] = s+w
          result[1] = s
        end
      end
    end
  end
end

result.map!(&:to_i)
if result[1] > 0
  puts "#{result[0]} #{result[1]}"
else
  puts "#{a.to_i} #{result[1]}"
end