Fibonacci Pattern

0

0 votes
Easy
Problem

Poltu is pretty much obsessed with fibonacci series which he learned at school recently. What he does now is that he looks out for the fibonacci pattern on everything he looks at, such as sunflower, ice flakes and even human bones. Being so much obsessed with it he started to look out for words falling in that particular sequence in his english literature paper. Can you join his madness?? your task is to verify whether a string given as input, the length of the words, falls in a fibonacci pattern or not.

Fibonacci pattern : 0,1,1,2,3,5,8,13,21,34.......

By definition, the first two numbers in the Fibonacci sequence are either 1 and 1, or 0 and 1, depending on the chosen starting point of the sequence, and each subsequent number is the sum of the previous two. a word shall only be considered as long as there is a continuous stream of alphabets. For eg. ra!hul is 2 words separated by !.

Input :

A sentence S that can have any number of words with special characters also.All test cases has atleast 3 words.

Output :

If it is a fibonacci sentence i.e. it falls in fibonacci sequence then print “YES” else “NO”.

Constraint:

|S|<1000

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

I, am not!

consider the letters only then 1 2 and 3, and these 3 numbers fall in the fibonacci pattern,

so output : YES

Editor Image

?