2480.Magic Numbers

Time Limit: 1s Memory Limit: 256MB

A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.

You're given a number. Determine if it is a magic number or not.

Input Format(From the terminal/stdin)

The first line of input contains an integer n, (1 \le n \le 109). This number doesn't contain leading zeros.

Output Format(To the terminal/stdout)

Print "YES" if n is a magic number or print "NO" if it's not.

Sample Input 1

Copy
114114
      \n

Sample Output 1

Copy
YES
   \n

Sample Input 2

Copy
1111
    \n

Sample Output 2

Copy
YES
   \n

Sample Input 3

Copy
441231
      \n

Sample Output 3

Copy
NO
  \n

Submit

请先 登录

© 2025 FAQs