BEENUMS - Beehive Numbers

no tags 

A beehive is an enclosed structure in which some honey bee species live and raise their young. In this problem we consider a two-dimensional sketch of the beehives. Each beehive is composed of a certain number of cells, where each cell is a regular hexagon. Each cell may have some neighbors, which are other cells that share a side with that cell. A cell with exactly 6 neighbors is an internal cell, while a cell with fewer neighbors is an external one. Notice that an external cell can always be changed to internal by adding some neighbor cells.

We are interested in a particular class of beehives. This class of valid beehives is defined recursively as follows: a) a single cell is a valid beehive; and b) given a valid beehive B, if we add the minimum number of cells such that each external cell of B becomes an internal cell, the result is a valid beehive.

The number of cells in a valid beehive is called a beehive number. Given an integer N, you must decide whether it is a beehive number.

Input

Each test case is described using a single line. The line contains an integer N (1 ≤ N ≤ 109). The end of input is indicated with a line containing a single −1.

Output

For each test case, output a single line containing an uppercase “Y” if N is a beehive number, or an uppercase “N” otherwise.

Example

Input:
43
1
7
19
15
-1

Output:
N
Y
Y
Y
N

hide comments
Arnab Mitra: 2015-06-04 14:35:02

AC in 1 go :D The required series is very simple. Use the sample input to itself to derive it.

Rishabh Joshi: 2015-05-30 17:33:01

was getting TLE.
I was using unsigned long long and checking for (n==-1)
Lesson learnt - never use ull unless absolute necessary.

Last edit: 2015-05-30 21:18:25
Chisty: 2015-04-17 18:09:23

Solved it. But the problem statement is very confusing. :(

burninggoku: 2015-04-07 21:56:10

my 22.76 th!!!woow

MKM: 2015-04-04 20:52:29

and this brings up the century!!

arjun: 2015-03-25 14:37:50

Observe the Input Pattern!
and obtain a logic from it.
Thats it.

pingal tirkey: 2015-03-17 15:56:58

Easy one my 50th :)

[Mayank Pratap]: 2015-03-09 16:40:57

Try to find a formula...Intermidiate Maths comes to rescue ... My 47th .. :)

codedog: 2015-01-29 23:19:29

I didn't understand the problem. What is the value of min no. of cells to add?

confusedSoul: 2015-01-19 18:02:03

Time Limit Updated, no more brute force -_-


Added by:Pablo Ariel Heiber
Date:2010-09-26
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 NODEJS OBJC VB.NET
Resource:FCEyN UBA ICPC Selection 2010