Problems > The King's Options

The King's Options

Difficulty: 900 2000 ms 128 MB

math

A king stands at (R, C) on an N×N board. How many squares can it move to (its 8-neighbourhood clipped to the board)?

Input: one line with three integers N R C.

Output: the number of legal king moves.

Constraints:

  • 1 ≤ N ≤ 109
  • 1 ≤ R, C ≤ N

Sample Tests

Input 1
8 1 1
Output 1
3
Input 2
8 4 4
Output 2
8

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.