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 Perl (v5.18.2) (judge verdict: Time Limit Exceeded)

($a,$b,$c,$d,$e,$f)=split(' ', <>);

for ($suma = 0; $suma <= 30; $suma += $a) {
    for ($sumb = $suma; $sumb <= 30; $sumb += $b) {
        $water{$sumb}++;
    }
}

$e30 = $e*30;

for ($sumc = 0; $sumc <= $e30; $sumc += $c) {
    for ($sumd = $sumc; $sumd <= $e30; $sumd += $d) {
        $suger{$sumd}++;
    }
}

$max = -1;
@water = sort{$a<=>$b}(keys %water);
@suger = sort{$a<=>$b}(keys %suger);
for $w (@water) {
    if ($w == 0) {
        next;
    }

    for $s (@suger) {
        if ($s > $w * $e ) {
            last;
        }
        ($s + $w*100 > $f)and last;
        if ($max < $s*100/$w) {
            $resw = $w;
            $ress = $s;
            $max = $s*100/$w;
        }
    }
}
printf("%d %d\n", $ress+$resw*100, $ress);