CF936E Iqea
Description
Gridland is placed on infinite grid and has a shape of figure consisting of cells. Every cell of Gridland is a city. Two cities that are placed in adjacent cells are connected by the road of length $ 1 $ . It's possible to get from any city to any other city using roads. The distance between two cities is the minimum total road length on path from one city to another. It's possible to get from any cell that doesn't belong to Gridland to any other cell that doesn't belong to Gridland by using only cells which don't belong to Gridland. In other words, Gridland is connected and complement of Gridland is also connected.
At the moment no city in Gridland has Iqea famous shop. But Iqea has great plans for building shops in Gridland. For customers' convenience Iqea decided to develop an application. Using this application everyone can learn the distance to the nearest Iqea. You are to develop this application.
You are asked to process two types of queries:
- new Iqea shop has been opened in the city with coordinates $ (x,y) $ ;
- customer wants to know the distance to the nearest already opened Iqea shop from his city located in a cell with coordinates $ (x,y) $ .
Pay attention that customer can move only by roads and can never leave Gridland on his way to the shop.
Input Format
The first line contains one integer $ n $ — number of cities in Gridland ( $ 1
Output Format
For every query of second type output single integer — minimum distance to the nearest Iqea shop. If no Iqea shop has been already opened, output $ -1 $ .