Under construction

Still being built. Things may change

All Squares

Time limit1sMemory limit128 MB

Summary
Given starting size k, count the nested corner squares whose border or interior holds the query point.
Level

Medium5 of 10

Topics
Recursion, Geometry
Solved
No attempts yet

Problem

Geometrically every square has one well defined centre point. On a grid that holds only when the sides of the square span an odd number of points. Every odd number can be written as 2k+12k+1, so a square whose sides are 2k+12k+1 points long is said to have size kk.

A pattern of squares is built with these rules.

  1. The largest square has size kk, so its sides are 2k+12k+1 points long, and it sits at the centre of a grid of size 1024, whose sides are 2049 points long.
  2. The smallest permissible square has size 1 and the largest has size 512, so 1≤k≤5121 \le k \le 512.
  3. A square of size s>1s > 1 has a square of size s/2s / 2 centred on each of its 4 corners. The division is integer division, so 9/2=49 / 2 = 4. A square of size 1 puts nothing on its corners.
  4. The top left corner of the grid has coordinates (0,0)(0, 0).

A value of kk therefore fixes one pattern. The picture below shows the pattern for k=15k = 15.

Any point of the grid is surrounded by zero or more squares. A point lying on the border of a square counts as surrounded by that square.

Read a value of kk and the coordinates of a point, then report how many squares surround the point.

Input

Each line of input holds 3 integers: kk, the xx coordinate of the point, and the yy coordinate of the point, with 1≤k≤5121 \le k \le 512 and 0≤x,y≤20480 \le x, y \le 2048. The input ends with a line holding three zeroes, 0 0 0, which is not a query.

Output

Print one line for every query line of the input. Each line holds the number of squares that surround the given point.

Examples2

  1. Example 1

    Input
    500 113 941
    0 0 0
    
    Expected output
    5
    
  2. Example 2

    Input
    15 1024 1024
    15 1024 1039
    15 1035 1035
    15 1024 1041
    0 0 0
    
    Expected output
    1
    1
    4
    0