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 Java8 (OpenJDK 1.8.0) (judge verdict: Runtime Error)

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

/**
 * お遊び
 *
 * @author s-sugimoto
 */
public class Main {

	/**
	 * 隠蔽
	 */
	private Main() {
	}

	/**
	 * メイン
	 *
	 * @param args 起動引数
	 */
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		// 100A
		int a = scanner.nextInt();
		// 100B
		int b = scanner.nextInt();
		// C
		int c = scanner.nextInt();
		// D
		int d = scanner.nextInt();
		// 砂糖は100GあたりEとけるらしい
		int e = scanner.nextInt();
		// 砂糖と水の質量の合計がF
		int f = scanner.nextInt();

		int satoumizu = 0;
		int satou = 0;
		double noudo = 0;
		for (int i = 0; i * a * 100 < f; i++) {

			for (int j = 0; (i * a + j * b) * 100 < f; j++) {
				// まず水の量だけ弾いた残りの容量
				int withoutWater = f - (i * a + j * b) * 100;
				// 溶かすことのできる砂糖の量
				int satouLimit = (i * a + j * b) * e;
				for (int k = 0; k * c <= satouLimit && satouLimit <= withoutWater; k++) {
					int dsSatouLimitCount = (satouLimit - k * c) / d;
					if (i + j != 0 && k + dsSatouLimitCount != 0) {
						double newnoudo = k * c + dsSatouLimitCount * d / ((i * a + j * b) * 100 + k * c + dsSatouLimitCount * d);
						if (noudo < newnoudo) {
							satoumizu = i * a * 100 + j * b * 100 + k * c + dsSatouLimitCount * d;
							satou = k * c + dsSatouLimitCount * d;
							noudo = newnoudo;
						}
					}
				}
			}
		}

		System.out.println(satoumizu + " " + satou);
	}

}