Almost Integer Rock Garden


Problem Statement :


ictor is building a Japanese rock garden in his  square courtyard. He overlaid the courtyard with a Cartesian coordinate system so that any point  in the courtyard has coordinates  and . Victor wants to place  stones in the garden according to the following rules:

The center of each stone is located at some point , where  and  are integers .
The coordinates of all twelve stones are pairwise distinct.
The Euclidean distance from the center of any stone to the origin is not an integer.
The sum of Euclidean distances between all twelve points and the origin is an almost integer, meaning the absolute difference between this sum and an integer must be .
Given the values of  and  for the first stone Victor placed in the garden, place the remaining  stones according to the requirements above. For each stone you place, print two space-separated integers on a new line describing the respective  and  coordinates of the stone's location.

Input Format

Two space-separated integers describing the respective values of  and  for the first stone's location.

Output Format

Print  lines, where each line contains two space-separated integers describing the respective values of  and  for a stone's location.



Solution :



title-img


                            Solution in C :

In   C  :






#include <stdio.h>
#include <math.h>

int pnt[][12][16][2]={
{{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-12,-4}, {-12,4}, {-4,-12}, {-4,12}, {4,-12}, {4,12}, {12,-4}, {12,4}, },{{-12,-4}, {-12,4}, {-4,-12}, {-4,12}, {4,-12}, {4,12}, {12,-4}, {12,4}, },{{-11,-1}, {-11,1}, {-1,-11}, {-1,11}, {1,-11}, {1,11}, {11,-1}, {11,1}, },{{-10,-3}, {-10,3}, {-3,-10}, {-3,10}, {3,-10}, {3,10}, {10,-3}, {10,3}, },{{-9,-6}, {-9,6}, {-6,-9}, {-6,9}, {6,-9}, {6,9}, {9,-6}, {9,6}, },{{-12,-3}, {-12,3}, {-3,-12}, {-3,12}, {3,-12}, {3,12}, {12,-3}, {12,3}, },{{-12,-2}, {-12,2}, {-2,-12}, {-2,12}, {2,-12}, {2,12}, {12,-2}, {12,2}, },{{-11,-7}, {-11,7}, {-7,-11}, {-7,11}, {7,-11}, {7,11}, {11,-7}, {11,7}, },{{-11,-1}, {-11,1}, {-1,-11}, {-1,11}, {1,-11}, {1,11}, {11,-1}, {11,1}, },{{-6,-6}, {-6,6}, {6,-6}, {6,6}, },{{-5,-4}, {-5,4}, {-4,-5}, {-4,5}, {4,-5}, {4,5}, {5,-4}, {5,4}, }},
{{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-11,-5}, {-11,5}, {-5,-11}, {-5,11}, {5,-11}, {5,11}, {11,-5}, {11,5}, },{{-11,-3}, {-11,3}, {-9,-7}, {-9,7}, {-7,-9}, {-7,9}, {-3,-11}, {-3,11}, {3,-11}, {3,11}, {7,-9}, {7,9}, {9,-7}, {9,7}, {11,-3}, {11,3}, },{{-11,-2}, {-11,2}, {-10,-5}, {-10,5}, {-5,-10}, {-5,10}, {-2,-11}, {-2,11}, {2,-11}, {2,11}, {5,-10}, {5,10}, {10,-5}, {10,5}, {11,-2}, {11,2}, },{{-10,-1}, {-10,1}, {-1,-10}, {-1,10}, {1,-10}, {1,10}, {10,-1}, {10,1}, },{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-7,-7}, {-7,7}, {7,-7}, {7,7}, },{{-7,-3}, {-7,3}, {-3,-7}, {-3,7}, {3,-7}, {3,7}, {7,-3}, {7,3}, },{{-6,-2}, {-6,2}, {-2,-6}, {-2,6}, {2,-6}, {2,6}, {6,-2}, {6,2}, },{{-3,-2}, {-3,2}, {-2,-3}, {-2,3}, {2,-3}, {2,3}, {3,-2}, {3,2}, },{{-3,-1}, {-3,1}, {-1,-3}, {-1,3}, {1,-3}, {1,3}, {3,-1}, {3,1}, }},
{{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-11,-5}, {-11,5}, {-5,-11}, {-5,11}, {5,-11}, {5,11}, {11,-5}, {11,5}, },{{-9,-3}, {-9,3}, {-3,-9}, {-3,9}, {3,-9}, {3,9}, {9,-3}, {9,3}, },{{-7,-7}, {-7,7}, {7,-7}, {7,7}, },{{-2,-1}, {-2,1}, {-1,-2}, {-1,2}, {1,-2}, {1,2}, {2,-1}, {2,1}, },{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-11,-3}, {-11,3}, {-9,-7}, {-9,7}, {-7,-9}, {-7,9}, {-3,-11}, {-3,11}, {3,-11}, {3,11}, {7,-9}, {7,9}, {9,-7}, {9,7}, {11,-3}, {11,3}, },{{-10,-1}, {-10,1}, {-1,-10}, {-1,10}, {1,-10}, {1,10}, {10,-1}, {10,1}, },{{-8,-4}, {-8,4}, {-4,-8}, {-4,8}, {4,-8}, {4,8}, {8,-4}, {8,4}, },{{-7,-3}, {-7,3}, {-3,-7}, {-3,7}, {3,-7}, {3,7}, {7,-3}, {7,3}, },{{-3,-2}, {-3,2}, {-2,-3}, {-2,3}, {2,-3}, {2,3}, {3,-2}, {3,2}, }},
{{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-11,-3}, {-11,3}, {-9,-7}, {-9,7}, {-7,-9}, {-7,9}, {-3,-11}, {-3,11}, {3,-11}, {3,11}, {7,-9}, {7,9}, {9,-7}, {9,7}, {11,-3}, {11,3}, },{{-9,-3}, {-9,3}, {-3,-9}, {-3,9}, {3,-9}, {3,9}, {9,-3}, {9,3}, },{{-7,-3}, {-7,3}, {-3,-7}, {-3,7}, {3,-7}, {3,7}, {7,-3}, {7,3}, },{{-6,-6}, {-6,6}, {6,-6}, {6,6}, },{{-3,-2}, {-3,2}, {-2,-3}, {-2,3}, {2,-3}, {2,3}, {3,-2}, {3,2}, },{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-11,-5}, {-11,5}, {-5,-11}, {-5,11}, {5,-11}, {5,11}, {11,-5}, {11,5}, },{{-11,-2}, {-11,2}, {-10,-5}, {-10,5}, {-5,-10}, {-5,10}, {-2,-11}, {-2,11}, {2,-11}, {2,11}, {5,-10}, {5,10}, {10,-5}, {10,5}, {11,-2}, {11,2}, },{{-10,-1}, {-10,1}, {-1,-10}, {-1,10}, {1,-10}, {1,10}, {10,-1}, {10,1}, },{{-1,-1}, {-1,1}, {1,-1}, {1,1}, }},
{{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-11,-3}, {-11,3}, {-9,-7}, {-9,7}, {-7,-9}, {-7,9}, {-3,-11}, {-3,11}, {3,-11}, {3,11}, {7,-9}, {7,9}, {9,-7}, {9,7}, {11,-3}, {11,3}, },{{-7,-3}, {-7,3}, {-3,-7}, {-3,7}, {3,-7}, {3,7}, {7,-3}, {7,3}, },{{-7,-1}, {-7,1}, {-5,-5}, {-5,5}, {-1,-7}, {-1,7}, {1,-7}, {1,7}, {5,-5}, {5,5}, {7,-1}, {7,1}, },{{-3,-2}, {-3,2}, {-2,-3}, {-2,3}, {2,-3}, {2,3}, {3,-2}, {3,2}, },{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-11,-5}, {-11,5}, {-5,-11}, {-5,11}, {5,-11}, {5,11}, {11,-5}, {11,5}, },{{-11,-2}, {-11,2}, {-10,-5}, {-10,5}, {-5,-10}, {-5,10}, {-2,-11}, {-2,11}, {2,-11}, {2,11}, {5,-10}, {5,10}, {10,-5}, {10,5}, {11,-2}, {11,2}, },{{-10,-1}, {-10,1}, {-1,-10}, {-1,10}, {1,-10}, {1,10}, {10,-1}, {10,1}, },{{-9,-3}, {-9,3}, {-3,-9}, {-3,9}, {3,-9}, {3,9}, {9,-3}, {9,3}, },{{-2,-2}, {-2,2}, {2,-2}, {2,2}, }},
{{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-11,-3}, {-11,3}, {-9,-7}, {-9,7}, {-7,-9}, {-7,9}, {-3,-11}, {-3,11}, {3,-11}, {3,11}, {7,-9}, {7,9}, {9,-7}, {9,7}, {11,-3}, {11,3}, },{{-9,-3}, {-9,3}, {-3,-9}, {-3,9}, {3,-9}, {3,9}, {9,-3}, {9,3}, },{{-7,-3}, {-7,3}, {-3,-7}, {-3,7}, {3,-7}, {3,7}, {7,-3}, {7,3}, },{{-4,-2}, {-4,2}, {-2,-4}, {-2,4}, {2,-4}, {2,4}, {4,-2}, {4,2}, },{{-3,-2}, {-3,2}, {-2,-3}, {-2,3}, {2,-3}, {2,3}, {3,-2}, {3,2}, },{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-11,-5}, {-11,5}, {-5,-11}, {-5,11}, {5,-11}, {5,11}, {11,-5}, {11,5}, },{{-10,-1}, {-10,1}, {-1,-10}, {-1,10}, {1,-10}, {1,10}, {10,-1}, {10,1}, },{{-7,-7}, {-7,7}, {7,-7}, {7,7}, },{{-6,-3}, {-6,3}, {-3,-6}, {-3,6}, {3,-6}, {3,6}, {6,-3}, {6,3}, }},
{{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-11,-3}, {-11,3}, {-9,-7}, {-9,7}, {-7,-9}, {-7,9}, {-3,-11}, {-3,11}, {3,-11}, {3,11}, {7,-9}, {7,9}, {9,-7}, {9,7}, {11,-3}, {11,3}, },{{-7,-3}, {-7,3}, {-3,-7}, {-3,7}, {3,-7}, {3,7}, {7,-3}, {7,3}, },{{-4,-4}, {-4,4}, {4,-4}, {4,4}, },{{-3,-3}, {-3,3}, {3,-3}, {3,3}, },{{-3,-2}, {-3,2}, {-2,-3}, {-2,3}, {2,-3}, {2,3}, {3,-2}, {3,2}, },{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-12,-7}, {-12,7}, {-7,-12}, {-7,12}, {7,-12}, {7,12}, {12,-7}, {12,7}, },{{-11,-5}, {-11,5}, {-5,-11}, {-5,11}, {5,-11}, {5,11}, {11,-5}, {11,5}, },{{-11,-2}, {-11,2}, {-10,-5}, {-10,5}, {-5,-10}, {-5,10}, {-2,-11}, {-2,11}, {2,-11}, {2,11}, {5,-10}, {5,10}, {10,-5}, {10,5}, {11,-2}, {11,2}, },{{-10,-1}, {-10,1}, {-1,-10}, {-1,10}, {1,-10}, {1,10}, {10,-1}, {10,1}, },{{-9,-3}, {-9,3}, {-3,-9}, {-3,9}, {3,-9}, {3,9}, {9,-3}, {9,3}, }},
{{{-12,-11}, {-12,11}, {-11,-12}, {-11,12}, {11,-12}, {11,12}, {12,-11}, {12,11}, },{{-12,-11}, {-12,11}, {-11,-12}, {-11,12}, {11,-12}, {11,12}, {12,-11}, {12,11}, },{{-10,-8}, {-10,8}, {-8,-10}, {-8,10}, {8,-10}, {8,10}, {10,-8}, {10,8}, },{{-10,-1}, {-10,1}, {-1,-10}, {-1,10}, {1,-10}, {1,10}, {10,-1}, {10,1}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-2,-1}, {-2,1}, {-1,-2}, {-1,2}, {1,-2}, {1,2}, {2,-1}, {2,1}, },{{-12,-1}, {-12,1}, {-9,-8}, {-9,8}, {-8,-9}, {-8,9}, {-1,-12}, {-1,12}, {1,-12}, {1,12}, {8,-9}, {8,9}, {9,-8}, {9,8}, {12,-1}, {12,1}, },{{-11,-9}, {-11,9}, {-9,-11}, {-9,11}, {9,-11}, {9,11}, {11,-9}, {11,9}, },{{-9,-3}, {-9,3}, {-3,-9}, {-3,9}, {3,-9}, {3,9}, {9,-3}, {9,3}, },{{-9,-2}, {-9,2}, {-7,-6}, {-7,6}, {-6,-7}, {-6,7}, {-2,-9}, {-2,9}, {2,-9}, {2,9}, {6,-7}, {6,7}, {7,-6}, {7,6}, {9,-2}, {9,2}, },{{-9,-1}, {-9,1}, {-1,-9}, {-1,9}, {1,-9}, {1,9}, {9,-1}, {9,1}, },{{-6,-6}, {-6,6}, {6,-6}, {6,6}, }},
{{{-11,-10}, {-11,10}, {-10,-11}, {-10,11}, {10,-11}, {10,11}, {11,-10}, {11,10}, },{{-10,-7}, {-10,7}, {-7,-10}, {-7,10}, {7,-10}, {7,10}, {10,-7}, {10,7}, },{{-9,-6}, {-9,6}, {-6,-9}, {-6,9}, {6,-9}, {6,9}, {9,-6}, {9,6}, },{{-9,-5}, {-9,5}, {-5,-9}, {-5,9}, {5,-9}, {5,9}, {9,-5}, {9,5}, },{{-7,-5}, {-7,5}, {-5,-7}, {-5,7}, {5,-7}, {5,7}, {7,-5}, {7,5}, },{{-7,-3}, {-7,3}, {-3,-7}, {-3,7}, {3,-7}, {3,7}, {7,-3}, {7,3}, },{{-11,-5}, {-11,5}, {-5,-11}, {-5,11}, {5,-11}, {5,11}, {11,-5}, {11,5}, },{{-11,-3}, {-11,3}, {-9,-7}, {-9,7}, {-7,-9}, {-7,9}, {-3,-11}, {-3,11}, {3,-11}, {3,11}, {7,-9}, {7,9}, {9,-7}, {9,7}, {11,-3}, {11,3}, },{{-8,-5}, {-8,5}, {-5,-8}, {-5,8}, {5,-8}, {5,8}, {8,-5}, {8,5}, },{{-8,-5}, {-8,5}, {-5,-8}, {-5,8}, {5,-8}, {5,8}, {8,-5}, {8,5}, },{{-8,-5}, {-8,5}, {-5,-8}, {-5,8}, {5,-8}, {5,8}, {8,-5}, {8,5}, },{{-6,-5}, {-6,5}, {-5,-6}, {-5,6}, {5,-6}, {5,6}, {6,-5}, {6,5}, }},
{{{-11,-2}, {-11,2}, {-10,-5}, {-10,5}, {-5,-10}, {-5,10}, {-2,-11}, {-2,11}, {2,-11}, {2,11}, {5,-10}, {5,10}, {10,-5}, {10,5}, {11,-2}, {11,2}, },{{-11,-1}, {-11,1}, {-1,-11}, {-1,11}, {1,-11}, {1,11}, {11,-1}, {11,1}, },{{-10,-8}, {-10,8}, {-8,-10}, {-8,10}, {8,-10}, {8,10}, {10,-8}, {10,8}, },{{-10,-8}, {-10,8}, {-8,-10}, {-8,10}, {8,-10}, {8,10}, {10,-8}, {10,8}, },{{-10,-1}, {-10,1}, {-1,-10}, {-1,10}, {1,-10}, {1,10}, {10,-1}, {10,1}, },{{-3,-2}, {-3,2}, {-2,-3}, {-2,3}, {2,-3}, {2,3}, {3,-2}, {3,2}, },{{-12,-11}, {-12,11}, {-11,-12}, {-11,12}, {11,-12}, {11,12}, {12,-11}, {12,11}, },{{-11,-7}, {-11,7}, {-7,-11}, {-7,11}, {7,-11}, {7,11}, {11,-7}, {11,7}, },{{-11,-4}, {-11,4}, {-4,-11}, {-4,11}, {4,-11}, {4,11}, {11,-4}, {11,4}, },{{-11,-1}, {-11,1}, {-1,-11}, {-1,11}, {1,-11}, {1,11}, {11,-1}, {11,1}, },{{-9,-2}, {-9,2}, {-7,-6}, {-7,6}, {-6,-7}, {-6,7}, {-2,-9}, {-2,9}, {2,-9}, {2,9}, {6,-7}, {6,7}, {7,-6}, {7,6}, {9,-2}, {9,2}, },{{-9,-2}, {-9,2}, {-7,-6}, {-7,6}, {-6,-7}, {-6,7}, {-2,-9}, {-2,9}, {2,-9}, {2,9}, {6,-7}, {6,7}, {7,-6}, {7,6}, {9,-2}, {9,2}, }},
{{{-12,-1}, {-12,1}, {-9,-8}, {-9,8}, {-8,-9}, {-8,9}, {-1,-12}, {-1,12}, {1,-12}, {1,12}, {8,-9}, {8,9}, {9,-8}, {9,8}, {12,-1}, {12,1}, },{{-11,-4}, {-11,4}, {-4,-11}, {-4,11}, {4,-11}, {4,11}, {11,-4}, {11,4}, },{{-10,-8}, {-10,8}, {-8,-10}, {-8,10}, {8,-10}, {8,10}, {10,-8}, {10,8}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-8,-2}, {-8,2}, {-2,-8}, {-2,8}, {2,-8}, {2,8}, {8,-2}, {8,2}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-9,-3}, {-9,3}, {-3,-9}, {-3,9}, {3,-9}, {3,9}, {9,-3}, {9,3}, },{{-9,-3}, {-9,3}, {-3,-9}, {-3,9}, {3,-9}, {3,9}, {9,-3}, {9,3}, },{{-9,-3}, {-9,3}, {-3,-9}, {-3,9}, {3,-9}, {3,9}, {9,-3}, {9,3}, },{{-7,-1}, {-7,1}, {-5,-5}, {-5,5}, {-1,-7}, {-1,7}, {1,-7}, {1,7}, {5,-5}, {5,5}, {7,-1}, {7,1}, },{{-4,-1}, {-4,1}, {-1,-4}, {-1,4}, {1,-4}, {1,4}, {4,-1}, {4,1}, }},
{{{-12,-2}, {-12,2}, {-2,-12}, {-2,12}, {2,-12}, {2,12}, {12,-2}, {12,2}, },{{-11,-2}, {-11,2}, {-10,-5}, {-10,5}, {-5,-10}, {-5,10}, {-2,-11}, {-2,11}, {2,-11}, {2,11}, {5,-10}, {5,10}, {10,-5}, {10,5}, {11,-2}, {11,2}, },{{-10,-6}, {-10,6}, {-6,-10}, {-6,10}, {6,-10}, {6,10}, {10,-6}, {10,6}, },{{-10,-4}, {-10,4}, {-4,-10}, {-4,10}, {4,-10}, {4,10}, {10,-4}, {10,4}, },{{-8,-1}, {-8,1}, {-7,-4}, {-7,4}, {-4,-7}, {-4,7}, {-1,-8}, {-1,8}, {1,-8}, {1,8}, {4,-7}, {4,7}, {7,-4}, {7,4}, {8,-1}, {8,1}, },{{-4,-4}, {-4,4}, {4,-4}, {4,4}, },{{-12,-8}, {-12,8}, {-8,-12}, {-8,12}, {8,-12}, {8,12}, {12,-8}, {12,8}, },{{-9,-3}, {-9,3}, {-3,-9}, {-3,9}, {3,-9}, {3,9}, {9,-3}, {9,3}, },{{-8,-3}, {-8,3}, {-3,-8}, {-3,8}, {3,-8}, {3,8}, {8,-3}, {8,3}, },{{-8,-1}, {-8,1}, {-7,-4}, {-7,4}, {-4,-7}, {-4,7}, {-1,-8}, {-1,8}, {1,-8}, {1,8}, {4,-7}, {4,7}, {7,-4}, {7,4}, {8,-1}, {8,1}, },{{-7,-5}, {-7,5}, {-5,-7}, {-5,7}, {5,-7}, {5,7}, {7,-5}, {7,5}, },{{-5,-2}, {-5,2}, {-2,-5}, {-2,5}, {2,-5}, {2,5}, {5,-2}, {5,2}, }},
{{{-11,-5}, {-11,5}, {-5,-11}, {-5,11}, {5,-11}, {5,11}, {11,-5}, {11,5}, },{{-10,-2}, {-10,2}, {-2,-10}, {-2,10}, {2,-10}, {2,10}, {10,-2}, {10,2}, },{{-10,-2}, {-10,2}, {-2,-10}, {-2,10}, {2,-10}, {2,10}, {10,-2}, {10,2}, },{{-8,-2}, {-8,2}, {-2,-8}, {-2,8}, {2,-8}, {2,8}, {8,-2}, {8,2}, },{{-3,-2}, {-3,2}, {-2,-3}, {-2,3}, {2,-3}, {2,3}, {3,-2}, {3,2}, },{{-3,-1}, {-3,1}, {-1,-3}, {-1,3}, {1,-3}, {1,3}, {3,-1}, {3,1}, },{{-10,-8}, {-10,8}, {-8,-10}, {-8,10}, {8,-10}, {8,10}, {10,-8}, {10,8}, },{{-10,-2}, {-10,2}, {-2,-10}, {-2,10}, {2,-10}, {2,10}, {10,-2}, {10,2}, },{{-9,-5}, {-9,5}, {-5,-9}, {-5,9}, {5,-9}, {5,9}, {9,-5}, {9,5}, },{{-8,-8}, {-8,8}, {8,-8}, {8,8}, },{{-8,-1}, {-8,1}, {-7,-4}, {-7,4}, {-4,-7}, {-4,7}, {-1,-8}, {-1,8}, {1,-8}, {1,8}, {4,-7}, {4,7}, {7,-4}, {7,4}, {8,-1}, {8,1}, },{{-5,-3}, {-5,3}, {-3,-5}, {-3,5}, {3,-5}, {3,5}, {5,-3}, {5,3}, }},
{{{-12,-6}, {-12,6}, {-6,-12}, {-6,12}, {6,-12}, {6,12}, {12,-6}, {12,6}, },{{-12,-6}, {-12,6}, {-6,-12}, {-6,12}, {6,-12}, {6,12}, {12,-6}, {12,6}, },{{-11,-10}, {-11,10}, {-10,-11}, {-10,11}, {10,-11}, {10,11}, {11,-10}, {11,10}, },{{-10,-2}, {-10,2}, {-2,-10}, {-2,10}, {2,-10}, {2,10}, {10,-2}, {10,2}, },{{-9,-9}, {-9,9}, {9,-9}, {9,9}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-10,-2}, {-10,2}, {-2,-10}, {-2,10}, {2,-10}, {2,10}, {10,-2}, {10,2}, },{{-10,-1}, {-10,1}, {-1,-10}, {-1,10}, {1,-10}, {1,10}, {10,-1}, {10,1}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-8,-7}, {-8,7}, {-7,-8}, {-7,8}, {7,-8}, {7,8}, {8,-7}, {8,7}, },{{-5,-2}, {-5,2}, {-2,-5}, {-2,5}, {2,-5}, {2,5}, {5,-2}, {5,2}, },{{-1,-1}, {-1,1}, {1,-1}, {1,1}, }},
{{{-11,-10}, {-11,10}, {-10,-11}, {-10,11}, {10,-11}, {10,11}, {11,-10}, {11,10}, },{{-10,-2}, {-10,2}, {-2,-10}, {-2,10}, {2,-10}, {2,10}, {10,-2}, {10,2}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-8,-7}, {-8,7}, {-7,-8}, {-7,8}, {7,-8}, {7,8}, {8,-7}, {8,7}, },{{-5,-2}, {-5,2}, {-2,-5}, {-2,5}, {2,-5}, {2,5}, {5,-2}, {5,2}, },{{-4,-2}, {-4,2}, {-2,-4}, {-2,4}, {2,-4}, {2,4}, {4,-2}, {4,2}, },{{-11,-2}, {-11,2}, {-10,-5}, {-10,5}, {-5,-10}, {-5,10}, {-2,-11}, {-2,11}, {2,-11}, {2,11}, {5,-10}, {5,10}, {10,-5}, {10,5}, {11,-2}, {11,2}, },{{-11,-2}, {-11,2}, {-10,-5}, {-10,5}, {-5,-10}, {-5,10}, {-2,-11}, {-2,11}, {2,-11}, {2,11}, {5,-10}, {5,10}, {10,-5}, {10,5}, {11,-2}, {11,2}, },{{-10,-10}, {-10,10}, {10,-10}, {10,10}, },{{-10,-2}, {-10,2}, {-2,-10}, {-2,10}, {2,-10}, {2,10}, {10,-2}, {10,2}, },{{-10,-1}, {-10,1}, {-1,-10}, {-1,10}, {1,-10}, {1,10}, {10,-1}, {10,1}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, }},
{{{-12,-6}, {-12,6}, {-6,-12}, {-6,12}, {6,-12}, {6,12}, {12,-6}, {12,6}, },{{-12,-6}, {-12,6}, {-6,-12}, {-6,12}, {6,-12}, {6,12}, {12,-6}, {12,6}, },{{-11,-10}, {-11,10}, {-10,-11}, {-10,11}, {10,-11}, {10,11}, {11,-10}, {11,10}, },{{-10,-10}, {-10,10}, {10,-10}, {10,10}, },{{-5,-2}, {-5,2}, {-2,-5}, {-2,5}, {2,-5}, {2,5}, {5,-2}, {5,2}, },{{-5,-1}, {-5,1}, {-1,-5}, {-1,5}, {1,-5}, {1,5}, {5,-1}, {5,1}, },{{-10,-2}, {-10,2}, {-2,-10}, {-2,10}, {2,-10}, {2,10}, {10,-2}, {10,2}, },{{-10,-1}, {-10,1}, {-1,-10}, {-1,10}, {1,-10}, {1,10}, {10,-1}, {10,1}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-8,-7}, {-8,7}, {-7,-8}, {-7,8}, {7,-8}, {7,8}, {8,-7}, {8,7}, },{{-5,-1}, {-5,1}, {-1,-5}, {-1,5}, {1,-5}, {1,5}, {5,-1}, {5,1}, }},
{{{-12,-10}, {-12,10}, {-10,-12}, {-10,12}, {10,-12}, {10,12}, {12,-10}, {12,10}, },{{-11,-5}, {-11,5}, {-5,-11}, {-5,11}, {5,-11}, {5,11}, {11,-5}, {11,5}, },{{-10,-9}, {-10,9}, {-9,-10}, {-9,10}, {9,-10}, {9,10}, {10,-9}, {10,9}, },{{-6,-6}, {-6,6}, {6,-6}, {6,6}, },{{-6,-3}, {-6,3}, {-3,-6}, {-3,6}, {3,-6}, {3,6}, {6,-3}, {6,3}, },{{-6,-1}, {-6,1}, {-1,-6}, {-1,6}, {1,-6}, {1,6}, {6,-1}, {6,1}, },{{-12,-10}, {-12,10}, {-10,-12}, {-10,12}, {10,-12}, {10,12}, {12,-10}, {12,10}, },{{-12,-10}, {-12,10}, {-10,-12}, {-10,12}, {10,-12}, {10,12}, {12,-10}, {12,10}, },{{-12,-4}, {-12,4}, {-4,-12}, {-4,12}, {4,-12}, {4,12}, {12,-4}, {12,4}, },{{-12,-2}, {-12,2}, {-2,-12}, {-2,12}, {2,-12}, {2,12}, {12,-2}, {12,2}, },{{-11,-4}, {-11,4}, {-4,-11}, {-4,11}, {4,-11}, {4,11}, {11,-4}, {11,4}, },{{-10,-8}, {-10,8}, {-8,-10}, {-8,10}, {8,-10}, {8,10}, {10,-8}, {10,8}, }},
{{{-10,-9}, {-10,9}, {-9,-10}, {-9,10}, {9,-10}, {9,10}, {10,-9}, {10,9}, },{{-10,-9}, {-10,9}, {-9,-10}, {-9,10}, {9,-10}, {9,10}, {10,-9}, {10,9}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-9,-1}, {-9,1}, {-1,-9}, {-1,9}, {1,-9}, {1,9}, {9,-1}, {9,1}, },{{-7,-5}, {-7,5}, {-5,-7}, {-5,7}, {5,-7}, {5,7}, {7,-5}, {7,5}, },{{-6,-1}, {-6,1}, {-1,-6}, {-1,6}, {1,-6}, {1,6}, {6,-1}, {6,1}, },{{-12,-3}, {-12,3}, {-3,-12}, {-3,12}, {3,-12}, {3,12}, {12,-3}, {12,3}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-8,-5}, {-8,5}, {-5,-8}, {-5,8}, {5,-8}, {5,8}, {8,-5}, {8,5}, },{{-7,-2}, {-7,2}, {-2,-7}, {-2,7}, {2,-7}, {2,7}, {7,-2}, {7,2}, },{{-5,-1}, {-5,1}, {-1,-5}, {-1,5}, {1,-5}, {1,5}, {5,-1}, {5,1}, },{{-4,-2}, {-4,2}, {-2,-4}, {-2,4}, {2,-4}, {2,4}, {4,-2}, {4,2}, }},
{{{-12,-10}, {-12,10}, {-10,-12}, {-10,12}, {10,-12}, {10,12}, {12,-10}, {12,10}, },{{-12,-1}, {-12,1}, {-9,-8}, {-9,8}, {-8,-9}, {-8,9}, {-1,-12}, {-1,12}, {1,-12}, {1,12}, {8,-9}, {8,9}, {9,-8}, {9,8}, {12,-1}, {12,1}, },{{-11,-8}, {-11,8}, {-8,-11}, {-8,11}, {8,-11}, {8,11}, {11,-8}, {11,8}, },{{-11,-4}, {-11,4}, {-4,-11}, {-4,11}, {4,-11}, {4,11}, {11,-4}, {11,4}, },{{-8,-2}, {-8,2}, {-2,-8}, {-2,8}, {2,-8}, {2,8}, {8,-2}, {8,2}, },{{-7,-2}, {-7,2}, {-2,-7}, {-2,7}, {2,-7}, {2,7}, {7,-2}, {7,2}, },{{-12,-10}, {-12,10}, {-10,-12}, {-10,12}, {10,-12}, {10,12}, {12,-10}, {12,10}, },{{-12,-10}, {-12,10}, {-10,-12}, {-10,12}, {10,-12}, {10,12}, {12,-10}, {12,10}, },{{-11,-6}, {-11,6}, {-6,-11}, {-6,11}, {6,-11}, {6,11}, {11,-6}, {11,6}, },{{-9,-9}, {-9,9}, {9,-9}, {9,9}, },{{-8,-4}, {-8,4}, {-4,-8}, {-4,8}, {4,-8}, {4,8}, {8,-4}, {8,4}, },{{-8,-1}, {-8,1}, {-7,-4}, {-7,4}, {-4,-7}, {-4,7}, {-1,-8}, {-1,8}, {1,-8}, {1,8}, {4,-7}, {4,7}, {7,-4}, {7,4}, {8,-1}, {8,1}, }},
{{{-12,-8}, {-12,8}, {-8,-12}, {-8,12}, {8,-12}, {8,12}, {12,-8}, {12,8}, },{{-11,-3}, {-11,3}, {-9,-7}, {-9,7}, {-7,-9}, {-7,9}, {-3,-11}, {-3,11}, {3,-11}, {3,11}, {7,-9}, {7,9}, {9,-7}, {9,7}, {11,-3}, {11,3}, },{{-10,-2}, {-10,2}, {-2,-10}, {-2,10}, {2,-10}, {2,10}, {10,-2}, {10,2}, },{{-6,-3}, {-6,3}, {-3,-6}, {-3,6}, {3,-6}, {3,6}, {6,-3}, {6,3}, },{{-3,-2}, {-3,2}, {-2,-3}, {-2,3}, {2,-3}, {2,3}, {3,-2}, {3,2}, },{{-3,-1}, {-3,1}, {-1,-3}, {-1,3}, {1,-3}, {1,3}, {3,-1}, {3,1}, },{{-7,-5}, {-7,5}, {-5,-7}, {-5,7}, {5,-7}, {5,7}, {7,-5}, {7,5}, },{{-7,-1}, {-7,1}, {-5,-5}, {-5,5}, {-1,-7}, {-1,7}, {1,-7}, {1,7}, {5,-5}, {5,5}, {7,-1}, {7,1}, },{{-6,-5}, {-6,5}, {-5,-6}, {-5,6}, {5,-6}, {5,6}, {6,-5}, {6,5}, },{{-6,-4}, {-6,4}, {-4,-6}, {-4,6}, {4,-6}, {4,6}, {6,-4}, {6,4}, },{{-6,-3}, {-6,3}, {-3,-6}, {-3,6}, {3,-6}, {3,6}, {6,-3}, {6,3}, },{{-5,-1}, {-5,1}, {-1,-5}, {-1,5}, {1,-5}, {1,5}, {5,-1}, {5,1}, }},
{{{-11,-11}, {-11,11}, {11,-11}, {11,11}, },{{-10,-10}, {-10,10}, {10,-10}, {10,10}, },{{-10,-9}, {-10,9}, {-9,-10}, {-9,10}, {9,-10}, {9,10}, {10,-9}, {10,9}, },{{-8,-5}, {-8,5}, {-5,-8}, {-5,8}, {5,-8}, {5,8}, {8,-5}, {8,5}, },{{-6,-1}, {-6,1}, {-1,-6}, {-1,6}, {1,-6}, {1,6}, {6,-1}, {6,1}, },{{-5,-3}, {-5,3}, {-3,-5}, {-3,5}, {3,-5}, {3,5}, {5,-3}, {5,3}, },{{-11,-3}, {-11,3}, {-9,-7}, {-9,7}, {-7,-9}, {-7,9}, {-3,-11}, {-3,11}, {3,-11}, {3,11}, {7,-9}, {7,9}, {9,-7}, {9,7}, {11,-3}, {11,3}, },{{-10,-6}, {-10,6}, {-6,-10}, {-6,10}, {6,-10}, {6,10}, {10,-6}, {10,6}, },{{-10,-6}, {-10,6}, {-6,-10}, {-6,10}, {6,-10}, {6,10}, {10,-6}, {10,6}, },{{-9,-5}, {-9,5}, {-5,-9}, {-5,9}, {5,-9}, {5,9}, {9,-5}, {9,5}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-8,-7}, {-8,7}, {-7,-8}, {-7,8}, {7,-8}, {7,8}, {8,-7}, {8,7}, }},
{{{-12,-12}, {-12,12}, {12,-12}, {12,12}, },{{-10,-9}, {-10,9}, {-9,-10}, {-9,10}, {9,-10}, {9,10}, {10,-9}, {10,9}, },{{-9,-5}, {-9,5}, {-5,-9}, {-5,9}, {5,-9}, {5,9}, {9,-5}, {9,5}, },{{-9,-4}, {-9,4}, {-4,-9}, {-4,9}, {4,-9}, {4,9}, {9,-4}, {9,4}, },{{-6,-1}, {-6,1}, {-1,-6}, {-1,6}, {1,-6}, {1,6}, {6,-1}, {6,1}, },{{-5,-3}, {-5,3}, {-3,-5}, {-3,5}, {3,-5}, {3,5}, {5,-3}, {5,3}, },{{-11,-3}, {-11,3}, {-9,-7}, {-9,7}, {-7,-9}, {-7,9}, {-3,-11}, {-3,11}, {3,-11}, {3,11}, {7,-9}, {7,9}, {9,-7}, {9,7}, {11,-3}, {11,3}, },{{-10,-6}, {-10,6}, {-6,-10}, {-6,10}, {6,-10}, {6,10}, {10,-6}, {10,6}, },{{-10,-6}, {-10,6}, {-6,-10}, {-6,10}, {6,-10}, {6,10}, {10,-6}, {10,6}, },{{-9,-9}, {-9,9}, {9,-9}, {9,9}, },{{-8,-7}, {-8,7}, {-7,-8}, {-7,8}, {7,-8}, {7,8}, {8,-7}, {8,7}, },{{-8,-5}, {-8,5}, {-5,-8}, {-5,8}, {5,-8}, {5,8}, {8,-5}, {8,5}, }},
};

int garden[25][25];

int main(void) {
  int x, y;
  int i, j, k, m, c;
  long double d=0;
  scanf("%d%d", &x, &y);
  d+=sqrtl(x*x+y*y);
  garden[x+12][y+12]=1;
  for (i=0; i<sizeof(pnt)/sizeof(pnt[0]); i++) {
    for (j=0; j<12; j++) {
      for (k=0; k<16 && pnt[i][j][k][0]; k++) {
        if (pnt[i][j][k][0]==x && pnt[i][j][k][1]==y)
          break;
      }
      if (k<16 && pnt[i][j][k][0]) {
        for (k=0, c=0; c<11; k++) {
          if (j==k)
            continue;
          for (m=0; m<16 && pnt[i][k][m][0]; m++) {
            if (!garden[pnt[i][k][m][0]+12][pnt[i][k][m][1]+12]) {
              garden[pnt[i][k][m][0]+12][pnt[i][k][m][1]+12]=1;
              printf("%d %d\n", pnt[i][k][m][0], pnt[i][k][m][1]);
//              d+=sqrtl(pnt[i][k][m][0]*pnt[i][k][m][0]+pnt[i][k][m][1]*pnt[i][k][m][1]);
              c++;
              break;
            }
          }
        }
//        printf("%.60Lf\n", d);
        return 0;
      }
    }
  }
  return 0;
}
                        


                        Solution in C++ :

In   C  ++  :







#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

inline int pack(int x,int y){
  return (x+25)*64 + (y+25);
}
inline void unpack(int p,int &x,int &y){
  x = (p/64)-25;
  y = (p%64)-25;
}

map<double,vi> mp;
vector<double> V;
int n;
map<double,int> rev;

vector<vi> answers;
vi ids;

void appen(int a,int b,int c,int d,int e,int f,int g,int h,int i,int j,int k,int l){
  vi v;
  v.push_back(a);
  v.push_back(b);
  v.push_back(c);
  v.push_back(d);
  v.push_back(e);
  v.push_back(f);
  v.push_back(g);
  v.push_back(h);
  v.push_back(i);
  v.push_back(j);
  v.push_back(k);
  v.push_back(l);
  int demi = answers.size();
  answers.push_back(v);
  double sum = 0.0;
  REP(z,v.size()){
    ids[v[z]] = demi;
    sum += V[v[z]];
  }
  // printf("%.15f\n",sum);
}

int main(){
  FOR(x,-12,13)FOR(y,-12,13){
    int dst = x*x + y*y;
    double sq = sqrt(dst);
    int sqi = sq;
    if(sqi!=sq)mp[sq].push_back(pack(x,y));
  }
  {
    map<double,vi>::iterator iter = mp.begin();
    while(iter != mp.end()){
      double d = iter->first;
      V.push_back(d);
      iter++;
    }
  }
  n = V.size();
  REP(i,n)rev[V[i]] = i;
  // go
  ids.assign(n,-1);
  appen(0,1,3,25,41,43,62,8,10,20,34,39);
  appen(2,1,3,25,41,43,62,6,8,20,34,39);
  appen(4,13,27,65,8,45,49,25,28,37,43,51);
  appen(5,30,31,45,22,31,46,13,16,31,52,54);
  appen(7,1,3,25,8,15,34,16,20,39,43,62);
  appen(9,10,41,48,21,24,62,21,25,30,38,44);
  appen(11,37,43,67,12,35,44,29,31,44,53,57);
  appen(14,21,44,66,21,36,37,3,36,37,54,62);
  appen(17,1,3,25,41,43,62,4,8,16,20,34);
  appen(18,8,27,31,7,12,57,25,29,31,50,57);
  appen(19,15,43,59,33,47,59,4,7,30,32,59);
  appen(23,1,30,66,46,54,61,27,28,31,33,66);
  appen(26,1,3,25,34,43,62,1,8,16,20,39);
  appen(40,11,38,43,26,36,65,0,3,27,59,62);
  appen(42,44,48,49,18,30,66,18,28,31,40,61);
  appen(55,0,24,40,49,54,55,27,29,40,48,49);
  appen(56,3,6,25,0,34,43,0,8,20,39,62);
  appen(58,45,53,65,26,51,65,18,21,22,46,65);
  appen(60,26,34,63,31,33,41,9,15,31,34,37);
  appen(64,12,35,37,43,44,60,11,29,31,44,57);

  int xx,yy;
  scanf("%d%d",&xx,&yy);
  double vv = sqrt(xx*xx+yy*yy);
  int id = ids[rev[vv]];
  vi vec = answers[id];
  vi head(n,0);
  bool poyo = false;
  REP(i,vec.size()){
    double ww = V[vec[i]];
    if(!poyo && ww==vv){
      poyo = true;
      continue;
    }
    while(true){
      int po = mp[ww][head[vec[i]]++];
      int xxx,yyy;
      unpack(po,xxx,yyy);
      if(xx==xxx && yy==yyy)continue;
      printf("%d %d\n",xxx,yyy);
      break;
    }
  }
  return 0;
}
                    


                        Solution in Java :

In  Java  :









import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

import static java.lang.Math.sqrt;

public class Solution {

    static final Map<Integer, List<Integer>> squaresMap = new TreeMap<>();
    static final int[] squares = new int[68];
    static final int[] counts = new int[68];
    static final double[] roots = new double[300];

    static {
        Map<Integer, List<Integer>> localSquareMap = squaresMap;
        for (int x = 1; x <= 12; x++) {
            for (int y = 1; y <= 12; y++) {
                int sq = x * x + y * y;
                double distance = sqrt(sq);
                if (distance != (int) distance) {
                    List<Integer> list = localSquareMap.get(sq);
                    if (list == null) {
                        localSquareMap.put(sq, list = new ArrayList<>(3));
                    }
                    list.add(x * 16 + y);
                }
            }
        }

        int[] localSquares = squares;
        int index = 0;
        for (Map.Entry<Integer, List<Integer>> entry : localSquareMap.entrySet()) {
            localSquares[index] = entry.getKey();
            counts[index] = entry.getValue().size();
            roots[localSquares[index]] = sqrt(localSquares[index]);
            index++;
        }
    }

    static final long[] squaresSerialized = new long[942415];
    static final double[] distancesUnsorted = new double[squaresSerialized.length];
    static final double[] distancesSorted = new double[squaresSerialized.length];
    static int count = 0;

    static int privateCounter = 0;
    static void iter(int index, int number, int[] four) {
        if (number == 4) {
            int localCount = Solution.count;
            squaresSerialized[Solution.count] = serialize(four);
            double distance = getDistance(four);
            distancesUnsorted[Solution.count] = distancesSorted[Solution.count] = distance - (int) distance;
            Solution.count = localCount + 1;
        } else {
            int[] localSquares = Solution.squares;
            if (index == localSquares.length) return;
            int[] localCounts = Solution.counts;
            if (localCounts[index] != 0) {
                localCounts[index]--;
                four[number] = localSquares[index];
                iter(index, number + 1, four);
                localCounts[index]++;
            }
            iter(index + 1, number, four); // skip current number
        }
    }

    private static double getDistance(int[] four) {
        return roots[four[0]] + roots[four[1]] + roots[four[2]] + roots[four[3]];
    }

    private static long serialize(int[] four) {
        return (((long) four[0]) << 48) + (((long) four[1]) << 32)
             + (((long) four[2]) << 16) + (((long) four[3]));
    }

    static int originalX;
    static int originalY;

    static void solve(int index, int number, int[] four) {
        if (number == 4) {
            if (privateCounter++ % 7 != 0) return;
            double originalDistance = getDistance(four);
            for (int k = count - 1; k >= 0; k -= 31) {
                double candidateDistance = distancesSorted[k];
                double distanceToSearch = originalDistance + candidateDistance;
                distanceToSearch -= (int) distanceToSearch;
                distanceToSearch = 1 - distanceToSearch;
                int i = Arrays.binarySearch(distancesSorted, 0, count, distanceToSearch);
                if (i >= 0) {
                    double result = originalDistance + candidateDistance + distancesSorted[i];
                    result -= (int) result;
                    if (result < 1e-12 || result > (1 - 1e-12)) {
                        printAnswer(four, distancesSorted[k], distancesSorted[i]);
                    }
                } else {
                    i = -1 - i;

                    if (i < count) {
                        double result = originalDistance + candidateDistance + distancesSorted[i];
                        result -= (int) result;
                        if (result < 1e-12 || result > (1 - 1e-12)) {
                            printAnswer(four, distancesSorted[k], distancesSorted[i]);
                        }
                    }

                    if (i > 0) {
                        double result = originalDistance + candidateDistance + distancesSorted[i - 1];
                        result -= (int) result;
                        if (result < 1e-12 || result > (1 - 1e-12)) {
                            printAnswer(four, distancesSorted[k], distancesSorted[i - 1]);
                        }
                    }
                }
            }
        } else {
            if (index == squares.length) return;
            solve(index + 1, number, four); // skip current number
            if (counts[index] != 0) {
                counts[index]--;
                four[number] = squares[index];
                solve(index, number + 1, four);
                counts[index]++;
            }
        }
    }

    private static final List<String> result = new ArrayList<>(12);
    private static void printAnswer(int[] original, double candidateDistance, double distance) {
        result.add(originalX + " " + originalY);
        addToResult(original[1]);
        addToResult(original[2]);
        addToResult(original[3]);


        for (int i = 0; i < count; i++) {
            if (Math.abs(distancesUnsorted[i] - candidateDistance) < 1e-13) {
                long four = squaresSerialized[i];
                addToResult((int) ((four >>> 48) & 0xFFFF));
                addToResult((int) ((four >>> 32) & 0xFFFF));
                addToResult((int) ((four >>> 16) & 0xFFFF));
                addToResult((int) (four & 0xFFFF));
                break;
            }
        }

        for (int i = 0; i < count; i++) {
            if (Math.abs(distancesUnsorted[i] - distance) < 1e-13) {
                long four = squaresSerialized[i];
                addToResult((int) ((four >>> 48) & 0xFFFF));
                addToResult((int) ((four >>> 32) & 0xFFFF));
                addToResult((int) ((four >>> 16) & 0xFFFF));
                addToResult((int) (four & 0xFFFF));
                break;
            }
        }
        for (String s : result.subList(1, result.size())) {
            System.out.println(s);
        }

        System.out.flush();
        System.exit(1);
    }

    private static void addToResult(int square) {
        for (int pair : squaresMap.get(square)) {
            int x = pair / 16;
            int y = pair % 16;

            String s = x + " " + y;
            if (!result.contains(s)) {
                result.add(s);
                return;
            }
            s = y + " " + x;
            if (!result.contains(s)) {
                result.add(s);
                return;
            }

            x = -x;
            s = x + " " + y;
            if (!result.contains(s)) {
                result.add(s);
                return;
            }
            s = y + " " + x;
            if (!result.contains(s)) {
                result.add(s);
                return;
            }

            y = -y;
            s = x + " " + y;
            if (!result.contains(s)) {
                result.add(s);
                return;
            }
            s = y + " " + x;
            if (!result.contains(s)) {
                result.add(s);
                return;
            }

            x = -x;
            s = x + " " + y;
            if (!result.contains(s)) {
                result.add(s);
                return;
            }
            s = y + " " + x;
            if (!result.contains(s)) {
                result.add(s);
                return;
            }
        }
    }

    public static void main(String[] args) {
        iter(0, 0, new int[4]);
        Arrays.sort(distancesSorted, 0, count);

        originalX = readInt();
        originalY = readInt();

        int square = originalX * originalX + originalY * originalY;
        int[] four = new int[4];
        four[0] = square;
        counts[Arrays.binarySearch(squares, square)] = 0;
        solve(0, 1, four);
    }

    private static int readInt() {
        try {
            int c = in.read();
            while (c <= 32) {
                c = in.read();
            }
            boolean minus = false;
            if (c == '-') {
                minus = true;
                c = in.read();
            }
            int result = (c - '0');
            c = in.read();
            while (c >= '0') {
                result = result * 10 + (c - '0');
                c = in.read();
            }
            return minus ? -result : result;
        } catch (IOException e) {
            return -1; // should not happen
        }
    }

    private static long readLong() {
        try {
            int c = in.read();
            while (c <= 32) {
                c = in.read();
            }
            boolean minus = false;
            if (c == '-') {
                minus = true;
                c = in.read();
            }
            long result = (c - '0');
            c = in.read();
            while (c >= '0') {
                result = result * 10 + (c - '0');
                c = in.read();
            }
            return minus ? -result : result;
        } catch (IOException e) {
            return -1; // should not happen
        }
    }

    private static double readDouble() {
        return Double.parseDouble(readWord(SMALL_CHAR_BUFFER));
    }

    private static String readWord(char[] buffer) {
        try {
            int c = in.read();
            while (c <= 32) {
                c = in.read();
            }
            int length = 0;
            while (c > 32) {
                buffer[length] = (char) c;
                c = in.read();
                length++;
            }
            return String.valueOf(buffer, 0, length);
        } catch (IOException ex) {
            throw new RuntimeException(ex); // should not happen
        }
    }

    private static String readLine(char[] buffer) {
        try {
            int c = in.read();
            while (c <= 32) {
                c = in.read();
            }
            int length = 0;
            while (c != '\n' && c != '\r' && c != -1) {
                buffer[length] = (char) c;
                c = in.read();
                length++;
            }
            return String.valueOf(buffer, 0, length);
        } catch (IOException ex) {
            throw new RuntimeException(ex); // should not happen
        }
    }

    private static InputStream in = new BufferedInputStream(System.in);
    private static final char[] SMALL_CHAR_BUFFER = new char[32];
}
                    


                        Solution in Python : 
                            
In   Python3 :








__author__ = 'Ward'
import math
import sys

solutions = []
solutions.append({(7,11),(11,1),(-2,12),(5,4),(12,-3),(10,3),(9,6),(-12,-7),(1,11),(-6,-6),(12,-4),(4,12)})
solutions.append({(-12, 8), (9, -6), (10, 5), (-5, 1), (3, 3), (3, 1), (-10, -2), (2, 1), (7, 5), (2, 2), (6, 5), (9, 7)})
solutions.append({(10, 5), (-2, 1), (3, 3), (3, 1), (10, 2), (-7, -5), (12, 8), (2, 2), (6, -5), (5, 1), (-9, 6), (9, 7)})
solutions.append({(10, 2), (-2, 2), (12, 6), (3, -1), (-11, 3), (-7, -5), (2, 2), (5, 1), (9, 6), (1, 1), (6, 5), (12, 8)})
solutions.append({(9, 7), (3, 2), (-10, 2), (-5, 1), (7, 1), (7, -5), (3, 1), (-9, -6), (4, 2), (9, 6), (6, 5), (8, 4)})
solutions.append({(7, 3), (-12, -7), (6, -3), (11, 5), (12, 7), (9, 3), (7, 7), (-12, 7), (-3, 2), (10, 1), (4, 2), (9, 7)})
solutions.append({(7, 3), (10, 8), (-5, 1), (11, 4), (9, 1), (10, 6), (-11, -2), (12, 11), (6, -6), (12, 10), (-11, 7), (10, 9)})
solutions.append({(9, 7), (-9, -1), (12, 7), (-10, 4), (-3, 1), (11, 1), (12, 8), (8, -4), (12, 10), (10, 3), (1, 1), (5, 3)})
solutions.append({(11, 7), (3, 2), (10, 8), (11, 4), (9, 2), (-11, 1), (11, 2), (-7, 6), (-11, -1), (10, -8), (10, 1), (12, 11)})
solutions.append({(10, 8), (8, 3), (10, 5), (8, 1), (10, 6), (12, 6), (-11, 8), (-10, 5), (11, -5), (10, 3), (-11, -8), (12, 8)})
solutions.append({(12, 2), (8, 3), (-4, 4), (10, 4), (8, 1), (-10, -5), (10, 6), (9, 3), (7, 5), (-12, 8), (7, -4), (5, 2)})
solutions.append({(-9, 4), (11, 4), (12, 1), (8, 2), (7, 1), (-10, -8), (3, 1), (9, -4), (12, 4), (9, 4), (-12, 4), (4, 1)})
solutions.append({(10, 8), (12, 1), (11, 4), (5, 5), (-9, -4), (3, 1), (9, -4), (-6, 2), (6, 2), (9, 4), (-12, 4), (12, 3)})
solutions.append({(9, 7), (-12, 12), (-9, 5), (6, 1), (10, 6), (-10, -6), (9, -9), (8, 7), (9, 4), (8, 5), (10, 9), (5, 3)})
solutions.append({(-9, 4), (10, 10), (6, 1), (10, 6), (-11, -3), (10, -6), (8, 7), (-11, 11), (9, 5), (8, 5), (10, 9), (5, 3)})
solutions.append({(6, 4), (9, 7), (5, 5), (3, 1), (3, -2), (-7, -5), (-3, 2), (-12, 6), (5, 1), (9, 6), (6, 5), (10, 2)})
solutions.append({(8, -7), (3, 2), (5, 1), (-9, -1), (10, 7), (9, 2), (-7, 5), (11, 3), (-11, 4), (6, 2), (12, 10), (11, 6)})
solutions.append({(11, 4), (8, 2), (-12, -10), (11, 8), (8, 1), (9, 8), (9, 9), (-12, 10), (-7, 2), (12, -10), (11, 6), (8, 4)})
solutions.append({(10, 8), (12, 1), (9, 1), (7, 6), (9, 3), (11, 9), (2, 1), (-12, 11), (9, -4), (12, 11), (-6, 6), (-10, -1)})
solutions.append({(7, 3), (11, 10), (11, 5), (10, 7), (-8, -5), (-8, 5), (11, 3), (8, -5), (7, 5), (9, 5), (-9, 6), (6, 5)})
solutions.append({(12, 2), (9, 2), (10, 7), (-9, -4), (11, 9), (10, 6), (-12, 11), (9, -3), (8, 8), (11, 1), (-7, 2), (7, 2)})

solutions2 = []
for sol in solutions:
    solutions2.append(list(map(lambda p:(p[0],-p[1]) , sol)))
solutions += solutions2

solutions2 = []
for sol in solutions:
    solutions2.append(list(map(lambda p:(-p[0],p[1]) , sol)))
solutions += solutions2

solutions2 = []
for sol in solutions:
    solutions2.append(list(map(lambda p:(p[1],p[0]) , sol)))
solutions += solutions2

X,Y = map(int,sys.stdin.readline().split())

for sol in solutions:
    if (X,Y) in sol:
        for p in sol:
            if p != (X,Y):
                print(p[0],p[1])
        break
                    


View More Similar Problems

Waiter

You are a waiter at a party. There is a pile of numbered plates. Create an empty answers array. At each iteration, i, remove each plate from the top of the stack in order. Determine if the number on the plate is evenly divisible ith the prime number. If it is, stack it in pile Bi. Otherwise, stack it in stack Ai. Store the values Bi in from top to bottom in answers. In the next iteration, do the

View Solution →

Queue using Two Stacks

A queue is an abstract data type that maintains the order in which elements were added to it, allowing the oldest elements to be removed from the front and new elements to be added to the rear. This is called a First-In-First-Out (FIFO) data structure because the first element added to the queue (i.e., the one that has been waiting the longest) is always the first one to be removed. A basic que

View Solution →

Castle on the Grid

You are given a square grid with some cells open (.) and some blocked (X). Your playing piece can move along any row or column until it reaches the edge of the grid or a blocked cell. Given a grid, a start and a goal, determine the minmum number of moves to get to the goal. Function Description Complete the minimumMoves function in the editor. minimumMoves has the following parameter(s):

View Solution →

Down to Zero II

You are given Q queries. Each query consists of a single number N. You can perform any of the 2 operations N on in each move: 1: If we take 2 integers a and b where , N = a * b , then we can change N = max( a, b ) 2: Decrease the value of N by 1. Determine the minimum number of moves required to reduce the value of N to 0. Input Format The first line contains the integer Q.

View Solution →

Truck Tour

Suppose there is a circle. There are N petrol pumps on that circle. Petrol pumps are numbered 0 to (N-1) (both inclusive). You have two pieces of information corresponding to each of the petrol pump: (1) the amount of petrol that particular petrol pump will give, and (2) the distance from that petrol pump to the next petrol pump. Initially, you have a tank of infinite capacity carrying no petr

View Solution →

Queries with Fixed Length

Consider an -integer sequence, . We perform a query on by using an integer, , to calculate the result of the following expression: In other words, if we let , then you need to calculate . Given and queries, return a list of answers to each query. Example The first query uses all of the subarrays of length : . The maxima of the subarrays are . The minimum of these is . The secon

View Solution →