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-----

The first line of input contains an integer n, (1 ≤ n ≤ 10^9). This number doesn't contain leading zeros.


-----Output-----

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


-----Examples-----
Input
114114

Output
YES

Input
1111

Output
YES

Input
441231

Output
NO

Source: codeforces | Difficulty: EASY
Tags: Complete search

Greedy algorithms


Solutions:
import re
n = input()
print('YES' if re.match('(14?4?)*$', n) else 'NO')


list1 = list(str(input()))
list1 = [int(a) for a in list1]
flag1 = 0
flag2 = 0
j = 0
for j in list1:
	if j != 1 and j != 4:
		print('NO')
		flag1 = 1
		flag2 = 1
		break
if flag1 != 1:
	i = 0
	while i in range(0, len(list1)):
		if list1[i] == 1:
			if list1[i] == 1 and i < len(list1) - 1:
				if list1[i + 1] == 4:
					if i + 2 < len(list1) and list1[i + 2] == 4:
						i += 2
					else:
						i += 1
			i += 1
		else:
			print('NO')
			flag2 = 1
			break
if flag2 != 1:
	print('YES')


s = input()
l = []
i = 0
while True:
	if i < len(s) - 2:
		if s[i] == '1':
			if s[i + 1] == '4':
				if s[i + 2] == '4':
					i = i + 3
					l.append(1)
				else:
					i = i + 2
					l.append(1)
			else:
				i = i + 1
				l.append(1)
		else:
			print('NO')
			l.append(0)
			break
	if i == len(s) - 2:
		if s[i] == '1':
			if s[i + 1] == '4':
				l.append(1)
				break
			else:
				i = i + 1
				l.append(1)
		else:
			l.append(0)
			print('NO')
			break
	if i == len(s) - 1:
		if s[i] == '1':
			l.append(1)
			break
		else:
			print('NO')
			l.append(0)
			break
	if i == len(s):
		break
if 0 not in l:
	print('YES')


s = str(input())
s1 = ''
k = 0
for i in range(len(s)):
	if s[i] == '4':
		s1 = s1 + '0'
	elif s[i] == '1':
		s1 += '1'
	else:
		s1 += '2'
s1 = s1.replace('100', '*')
s1 = s1.replace('10', '*')
s1 = s1.replace('1', '*')
if len(s1) != s1.count('*'):
	print('NO')
else:
	print('YES')


number = input('')
n = len(number)
i = 0
while i < n:
	if number[i:i + 3] == '144':
		i += 3
		flag = True
	elif number[i:i + 2] == '14':
		i += 2
		flag = True
	elif number[i] == '1':
		i += 1
		flag = True
	else:
		flag = False
		print('NO')
		break
if flag:
	print('YES')


a = input()
a = a.replace('144', 'i')
a = a.replace('14', 'i')
a = a.replace('1', 'i')
if len(a) == a.count('i'):
	print('YES')
else:
	print('NO')


string = list(input())
string.reverse()
answer = True
temp = string.copy()
while answer:
	if len(temp) != 0:
		for i in range(0, len(temp)):
			if temp[i] == '1':
				temp.pop(i)
				break
			elif temp[i] == '4':
				if i + 1 < len(temp):
					if temp[i + 1] == '1':
						temp.pop(i)
						temp.pop(i)
						break
					elif i + 2 < len(temp):
						if temp[i + 1] == '4' and temp[i + 2] == '1':
							temp.pop(i)
							temp.pop(i)
							temp.pop(i)
							break
						else:
							answer = False
							break
					else:
						answer = False
						break
				else:
					answer = False
					break
			else:
				answer = False
				break
	else:
		break
if answer:
	print('YES')
else:
	print('NO')


ans = True
s = 2
for c in input().strip():
	if c == '1':
		s = 0
	elif c == '4':
		s += 1
		if s >= 3:
			ans = False
	else:
		ans = False
print('YES' if ans else 'NO')


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
n = input()
l = len(n)
a = list(n)
s = []
i = 0
flag = True
while i < l:
	if i < l - 2 and a[i] == '1' and (a[i + 1] == '4') and (a[i + 2] == '4'):
		i += 3
	elif i < l - 1 and a[i] == '1' and (a[i + 1] == '4'):
		i += 2
	elif a[i] == '1':
		i += 1
	else:
		flag = False
		break
if flag == True:
	print('YES')
else:
	print('NO')


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def vars():
	return map(int, input().split())

def array():
	return list(map(int, input().split()))

def main():
	s = input()
	f = 0
	res = 'YES'
	for i in range(len(s)):
		if i == 0 and s[i] == '4':
			res = 'NO'
			break
		elif s[i] == '4':
			f += 1
		elif s[i] == '1':
			if f > 2:
				res = 'NO'
				break
			f = 0
		else:
			res = 'NO'
			break
	if f > 2:
		res = 'NO'
	print(res)
t = 1
for _ in range(t):
	main()


n = input()
status = True
for i in range(len(n)):
	if n[i] == '1':
		continue
	elif n[i] == '4':
		if i == 0:
			status = False
			break
		elif n[i - 1] == '1':
			continue
		elif n[i - 1] == '4':
			if n[i - 2] == '1':
				continue
			else:
				status = False
				break
		else:
			status = False
			break
	else:
		status = False
		break
if status:
	print('YES')
else:
	print('NO')


n = input()
n = n.replace('144', ' ')
n = n.replace('14', ' ')
n = n.replace('1', ' ')
if set(n) == {' '}:
	print('YES')
else:
	print('NO')


s = input()
i = 0
while i < len(s):
	if s[i:i + 3] == '144':
		i += 3
	elif s[i:i + 2] == '14':
		i += 2
	elif s[i] == '1':
		i += 1
	else:
		print('NO')
		break
else:
	print('YES')


s = input()
while s:
	if s.startswith('144'):
		s = s[3:]
	elif s.startswith('14'):
		s = s[2:]
	elif s.startswith('1'):
		s = s[1:]
	else:
		print('NO')
		exit()
print('YES')


n = input()
check = 'YES'
for i in range(len(n)):
	if n[i] not in {'1', '4'}:
		check = 'NO'
	elif n[i] == '4':
		if i == 0:
			check = 'NO'
		elif i == 1:
			if n[0] != '1':
				check = 'NO'
		elif n[i - 1:i + 1] != '14' and n[i - 2:i + 1] != '144':
			check = 'NO'
print(check)


s = input().rstrip()
good = '14'
for j in s:
	if j not in good:
		print('NO')
		return
cur = ''
for i in range(len(s)):
	if s[i] == '1':
		cur = '1'
	else:
		cur += '4'
		if cur == '14' and i != len(s) - 1 and (s[i + 1] == '4'):
			continue
		if cur != '14' and cur != '144':
			print('NO')
			return
		else:
			cur = ''
print('YES')


m = input()
m = m.replace('144', 'A')
m = m.replace('14', 'A')
m = m.replace('1', 'A')
if m.isalpha():
	print('YES')
else:
	print('NO')


import sys
input = sys.stdin.readline

def I():
	return input().strip()

def II():
	return int(input().strip())

def LI():
	return [*map(int, input().strip().split())]
import string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter, OrderedDict
from itertools import permutations, combinations, groupby, count, filterfalse
from operator import itemgetter
for _ in range(1):
	n = II()
	lst = str(n)
	f = 0
	if len(lst) == 3:
		if lst != '144' and lst != '114' and (lst != '111') and (lst != '141'):
			print('NO')
			continue
		else:
			print('YES')
			continue
	if len(lst) == 2:
		if lst != '11' and lst != '14':
			print('NO')
			continue
		else:
			print('YES')
			continue
	if len(lst) == 1:
		if lst == '1':
			print('YES')
			continue
		else:
			print('NO')
			continue
	if lst[0] == '4':
		print('NO')
		continue
	for i in range(len(lst) - 3):
		if lst[i] != '4' and lst[i] != '1':
			print('NO')
			f = 1
			break
		if lst[i] == '1':
			if lst[i + 1] == '4':
				if lst[i + 2] == '4':
					if lst[i + 3] == '4':
						print('NO')
						f = 1
						break
					elif lst[i + 1] != '1' and lst[i + 1] != '4':
						print('NO')
						f = 1
						break
				elif lst[i + 1] != '1' and lst[i + 1] != '4':
					print('NO')
					f = 1
					break
			elif lst[i + 1] != '1' and lst[i + 1] != '4':
				print('NO')
				f = 1
				break
	if f == 0:
		print('YES')


number = input()
l = len(number)
if number[0] != '1':
	print('NO')
elif number.count('1') + number.count('4') != l:
	print('NO')
elif number.count('444') != 0:
	print('NO')
else:
	print('YES')


s = str(input())
x = s.split('1')
l = [i for i in x if i != '']
l = [i for i in l if i != '4']
l = [i for i in l if i != '44']
if l == [] and s.startswith('1'):
	print('YES')
else:
	print('NO')


s = input()
if s.find('444') != -1 or s[0] == '4':
	print('NO')
	exit(0)
for i in s:
	if i != '1' and i != '4':
		print('NO')
		exit(0)
print('YES')


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
s = input()
f = 0
for i in range(0, len(s)):
	if s[i] == '1':
		pass
	elif s[i] == '4':
		if i - 1 >= 0:
			if s[i - 1] == '1':
				pass
			else:
				f = 1
			if s[i - 1] == '4':
				if s[i - 2] == '1':
					f = 0
					pass
				else:
					f = 1
		else:
			f = 1
	else:
		f = 1
		break
	if f == 1:
		break
if f == 1:
	print('NO')
else:
	print('YES')


n = list(input())
broken = False
i = 0
while i < len(n):
	if len(n) - i > 2 and n[i] == '1' and (n[i + 1] == '4') and (n[i + 2] == '4'):
		i += 3
	elif len(n) - i > 1 and n[i] == '1' and (n[i + 1] == '4'):
		i += 2
	elif n[i] == '1':
		i += 1
	else:
		broken = True
		break
if broken:
	print('NO')
else:
	print('YES')


n = int(input())
flag = 0
while n > 0:
	if n % 1000 == 144:
		flag = 1
		n = n // 1000
	elif n % 100 == 14:
		flag = 1
		n = n // 100
	elif n % 10 == 1:
		flag = 1
		n = n // 10
	else:
		flag = 0
		break
if flag == 1:
	print('YES')
else:
	print('NO')


import sys
input = sys.stdin.readline
from math import log2, log, ceil

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return res

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, size, link):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
string = input().strip()
string = string.replace('144', ' ')
string = string.replace('14', ' ')
string = string.replace('1', ' ')
string = string.replace(' ', '')
if len(string) == 0:
	print('YES')
else:
	print('NO')


num = input()

def isMagic(num):
	for i in range(0, len(num)):
		if num[i] != '1' and num[i] != '4':
			return False
	if num[0] == '4':
		return False
	check4 = ''.join(num.split('444'))
	if check4 != num:
		return False
	return True
if isMagic(num):
	print('YES')
else:
	print('NO')


a = input()
i = 0
flag = 0
while i < len(a):
	if i + 3 <= len(a):
		k = a[i:i + 3]
		if k == '144':
			i += 3
			continue
		k = a[i:i + 2]
		if k == '14':
			i += 2
			continue
		k = a[i:i + 1]
		if k == '1':
			i += 1
			continue
		else:
			flag = 1
			print('NO')
			break
	elif i + 2 == len(a):
		k = a[i:i + 2]
		if k == '14':
			i += 2
			continue
		k = a[i:i + 1]
		if k == '1':
			i += 1
			continue
		else:
			flag = 1
			print('NO')
			break
	elif i + 1 == len(a):
		k = a[i]
		if k == '1':
			i += 1
			continue
		else:
			flag = 1
			print('NO')
			break
if flag == 0:
	print('YES')


a = list(input())
b = '14'
for i in range(len(a)):
	if a[i] not in b:
		print('NO')
		exit()
for i in range(len(a) - 2):
	if a[i] == a[i + 1] == a[i + 2] == '4':
		print('NO')
		exit()
if a[0] != '4':
	print('YES')
else:
	print('NO')


def isgood(n):
	if n == '1' or n == '14' or n == '144':
		return True
	if n.startswith('144'):
		return isgood(n[3:])
	if n.startswith('14'):
		return isgood(n[2:])
	if n.startswith('1'):
		return isgood(n[1:])
	return False
n = input()
if isgood(n):
	print('YES')
else:
	print('NO')


s = input()
if len(s) == s.count('1') + s.count('4') and s[0] == '1' and ('444' not in s):
	print('YES')
else:
	print('NO')


data = input()
data = data.replace('144', 'a')
data = data.replace('14', 'a')
data = data.replace('1', 'a')
data = data.replace('a', '')
if len(data) == 0:
	print('YES')
else:
	print('NO')


s = input()
if '444' in s or s.count('1') + s.count('4') < len(s) or s[0] == '4':
	print('NO')
else:
	print('YES')


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import bisect as bi
import heapq

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def main():
	try:
		l = list(input())
		n = len(l)
		i = 0
		(no1, no4) = (0, 0)
		flag = 0
		for i in range(n):
			if l[i] != '1' and l[i] != '4':
				flag = 1
				break
			else:
				if l[i] == '1':
					if no1 != 0 and no4 != 0:
						no1 = 0
						no4 = 0
					no1 += 1
				if l[i] == '4':
					no4 += 1
					if no1 != 0:
						if no4 > 2:
							flag = 1
							break
					else:
						flag = 1
						break
		if flag:
			no()
		else:
			yes()
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


s = input()
flag = True
i = 0
length = len(s)
while i < length:
	if i < length - 2 and s[i:i + 3] == '144':
		i = i + 3
	elif i < length - 1 and s[i:i + 2] == '14':
		i = i + 2
	elif s[i:i + 1] == '1':
		i += 1
	else:
		flag = False
		print('NO')
		break
if flag:
	print('YES')


number = input()
state = 0
magic_number = True
for char in number:
	if state == 0:
		if char != '1':
			magic_number = False
			break
		else:
			state = 1
	elif state == 1:
		if char != '1':
			if char != '4':
				magic_number = False
				break
			else:
				state = 2
	elif char == '1':
		state = 1
	elif char == '4':
		state = 0
	else:
		magic_number = False
		break
print('YES') if magic_number else print('NO')


n = int(input())
k = -1
while n:
	if n % 10 != 1 and n % 100 != 14 and (n % 1000 != 144):
		print('NO')
		k = 0
		break
	n = n // 10
if k == -1:
	print('YES')


import re
n = input()
matches = re.fullmatch('^(1|14|144)*', n)
if matches == None:
	print('NO')
elif matches.string == n:
	print('YES')


string = input()
e = ''
i = 0
while True:
	if string[i:i + 3] == '144':
		e = e + string[i:i + 3]
		i = i + 3
		continue
	elif string[i:i + 2] == '14':
		e = e + string[i:i + 2]
		i = i + 2
		continue
	elif string[i:i + 1] == '1':
		e = e + string[i:i + 1]
		i = i + 1
		continue
	else:
		if e == string:
			print('YES')
			break
		print('NO')
		break


magic = list(input())
ans = 'YES'
if magic.count('1') + magic.count('4') == len(magic) and magic[0] == '1':
	for i in range(len(magic) - 2):
		if magic[i] == '4' and magic[i + 1] == '4' and (magic[i + 2] == '4'):
			ans = 'NO'
	print(ans)
else:
	print('NO')


d = list(map(int, input()))
s = d[::-1]
t = 'YES'
i = 0
n = len(s)
while True:
	try:
		if s[i] == 1:
			i += 1
		elif s[i] == 4 and i != n - 1 and (s[i + 1] == 1):
			i += 2
		elif s[i] == 4 and i != n - 2 and (s[i + 1] == 4) and (s[i + 2] == 1):
			i += 3
		else:
			t = 'NO'
	except:
		t = 'NO'
		break
	if t == 'NO' or i >= n:
		break
print(t)


kh = input()
ls = kh
f = True
while len(ls) > 0:
	if ls[0:3] == '144':
		ln = len(ls)
		ls = ls[3:ln + 1]
		ln = len(ls)
	elif ls[0:2] == '14':
		ln = len(ls)
		ls = ls[2:ln + 1]
		ln = len(ls)
	elif ls[0:1] == '1':
		ln = len(ls)
		ls = ls[1:ln + 1]
		ln = len(ls)
	else:
		break
if not ls:
	print('YES')
else:
	print('NO')


a = input()
i = 0
impflag = 0
while i < len(a):
	if a[i] == '4':
		if i + 3 <= len(a):
			if a[i + 1] == '4':
				if a[i + 2] == '4':
					impflag = 1
					break
				else:
					i = i + 1
	elif a[i] != '1':
		impflag = 1
		break
	i = i + 1
if a[0] != '1' or impflag == 1:
	print('NO')
else:
	print('YES')


p = input()
if p[0] != '1':
	print('NO')
else:
	s = [i for i in p.split('1') if i != '']
	for i in s:
		if i != '4' and i != '44':
			print('NO')
			break
	else:
		print('YES')


s = input()
ss = '144'
(i, j) = (0, 0)
n = len(s)
vale = True
while vale and i < n:
	if j == 3 or s[i] != ss[j]:
		j = 0
	if s[i] != ss[j]:
		vale = False
	j += 1
	i += 1
print('YES' if vale else 'NO')


import re
s = input()
l = list(map(lambda x: len(x), list(re.findall('(144|14|1)', s))))
print('YES' if len(s) == sum(l) else 'NO')


n = input()
print('NO' if len(n.replace('144', ' ').replace('14', ' ').replace('1', ' ').replace(' ', '')) else 'YES')


def answer(ns):
	if ns[0] != '1':
		return 'NO'
	num_fours = 0
	for i in range(1, len(ns)):
		if ns[i] != '1' and ns[i] != '4':
			return 'NO'
		elif ns[i] == '4':
			num_fours += 1
		elif ns[i] == '1':
			num_fours = 0
		if num_fours >= 3:
			return 'NO'
	return 'YES'

def main():
	ns = input()
	print(answer(ns))
main()


def main():
	a = str(input())
	a = a.replace('0', '9')
	a = a.replace('144', '0')
	a = a.replace('14', '0')
	a = a.replace('1', '0')
	if set(a) == {'0'}:
		print('YES')
	else:
		print('NO')
main()


n = list(input())
flag = True
res = True
i = 0
while i < len(n) and res:
	j = i
	if len(n[i:len(n)]) >= 3:
		if n[i:i + 3] == ['1', '4', '4']:
			j += 3
		elif n[i:i + 2] == ['1', '4'] and i == j:
			j += 2
		elif n[i:i + 1] == ['1'] and i == j:
			j += 1
		else:
			res = False
	elif len(n[i:len(n)]) <= 2:
		if n[i:len(n)] == ['1', '4']:
			j += 2
		elif n[i:i + 1] == ['1'] and i == j:
			j += 1
		else:
			res = False
	i = j
if res:
	print('YES')
else:
	print('NO')


s = input()
if s[0] != '1':
	print('NO')
elif '444' in s:
	print('NO')
else:
	k = 0
	for i in s:
		if i != '1' and i != '4':
			k = 1
			print('NO')
			break
	if k == 0:
		print('YES')


def gint():
	return int(input())

def gint_arr():
	return list(map(int, input().split()))

def gfloat():
	return float(input())

def gfloat_arr():
	return list(map(float, input().split()))

def pair_int():
	return map(int, input().split())
INF = 1 << 31
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
n = input()
if n.count('4') + n.count('1') != len(n):
	print('NO')
elif ~n.find('444') or n[0] == '4':
	print('NO')
else:
	print('YES')


import sys
input = sys.stdin.readline
I = lambda : list(map(str, input().split()))
(n,) = I()
f = 0
count = 0
for i in range(len(n)):
	if n[i] != '1' and n[i] != '4':
		f = f + 1
		break
	if n[i] == '4':
		if i == 0:
			f = f + 1
			break
		count = count + 1
	elif n[i] == '1':
		if count > 2:
			f = f + 1
			break
		count = 0
if count > 2:
	f = f + 1
if f == 0:
	print('YES')
else:
	print('NO')


import sys
n = input()
i = len(n) - 1
flag = 1
while i >= 0:
	if i >= 2 and (n[i] == '4' and n[i - 1] == '4' and (n[i - 2] == '1')):
		i = i - 3
	elif i >= 1 and (n[i] == '4' and n[i - 1] == '1'):
		i = i - 2
	elif n[i] == '1':
		i = i - 1
	else:
		flag = 0
		print('NO')
		break
if flag == 1:
	print('YES')


from collections import Counter

def main():
	n = input()
	if n[0] == '1':
		i = 0
		while i <= len(n) - 1:
			if i <= len(n) - 3 and n[i] == '4' and (n[i + 1] == '4') and (n[i + 2] == '4'):
				print('NO')
				return
			if n[i] != '4' and n[i] != '1':
				print('NO')
				return
			i += 1
		print('YES')
	else:
		print('NO')
main()


allowed = ['144', '14', '1']
data = input()
valid = True
while data and valid:
	valid = next((i for i in allowed if data.startswith(i)), None)
	if valid:
		data = data[len(valid):]
print('YES' if not data else 'NO')


n = list(input())
a = True
k = 0
if n[0] != '1':
	print('NO')
else:
	while k < len(n):
		if n[k] == '1':
			k += 1
		elif n[k] == '4' and n[k - 1] == '1':
			k += 1
		elif n[k] == '4' and n[k - 2] == '1' and (n[k - 1] == '4'):
			k += 1
		else:
			a = False
			print('NO')
			break
	if a:
		print('YES')


n = input()
r = ('1', '11', '14', '111', '114', '141', '144')

def check(s):
	if len(s) <= 3:
		return s in r
	return s[0] in r and check(s[1:]) or (s[0:2] in r and check(s[2:])) or (s[0:3] in r and check(s[3:]))
if check(n):
	print('YES')
else:
	print('NO')


inp = input()
off = inp.count('144')
of = inp.count('14') - off
o = inp.count('1') - (off + of)
len_should_be = 3 * off + 2 * of + o
if len(inp) == len_should_be:
	print('YES')
else:
	print('NO')


num = input()
num = num.replace('144', 'AAA').replace('14', 'AA').replace('1', 'A')
if num.count('A') == len(num):
	print('YES')
else:
	print('NO')


def magic_number(n):
	while n > 0:
		if n % 1000 == 144:
			n = n // 1000
		elif n % 100 == 14:
			n = n // 100
		elif n % 10 == 1:
			n = n // 10
		else:
			return 'NO'
	return 'YES'
n = int(input())
result = magic_number(n)
print(result)


s = input().strip()[::-1]
i = 0

def valid(x):
	return x < len(s)
while i < len(s):
	if s[i] == '1':
		i += 1
		continue
	if s[i] == '4':
		if valid(i + 1):
			if s[i + 1] == '1':
				i += 2
				continue
			if s[i + 1] == '4' and valid(i + 2):
				if s[i + 2] == '1':
					i += 3
					continue
			print('NO')
			break
		print('NO')
		break
	print('NO')
	break
else:
	print('YES')


k = input()
if k[0] != '1':
	print('NO')
elif set(list(k)) not in [{'1'}, {'4'}, {'1', '4'}]:
	print('NO')
elif '444' in k:
	print('NO')
else:
	print('YES')


n = input().strip()
if not set(n).issubset({'1', '4'}) or n[0] != '1':
	print('NO')
else:
	num_consecutives = 0
	for ch in n:
		if ch == '4':
			num_consecutives += 1
			if num_consecutives == 3:
				break
		else:
			num_consecutives = 0
	print('YES' if num_consecutives < 3 else 'NO')


s = input()
if '144' in s:
	s = s.replace('144', '.')
if '14' in s:
	s = s.replace('14', '/')
if '1' in s:
	s = s.replace('1', '^')
a = s.count('.')
b = s.count('/')
c = s.count('^')
if a + b + c == len(s):
	print('YES')
else:
	print('NO')


s = str(input())
truthO = 0
truthP = 0
truthQ = 0
for i in range(len(s)):
	if s[i:i + 1] == '1':
		truthO += 1
for i in range(len(s) - 1):
	if s[i:i + 2] == '14':
		truthP += 1
for i in range(len(s) - 2):
	if s[i:i + 3] == '144':
		truthQ += 1
if truthO / 2 + truthP + truthQ == len(s) or truthO + truthP + truthQ == len(s):
	print('YES')
else:
	print('NO')


import re
a = input()
if a == '1' or a == '14' or a == '144':
	print('YES')
else:
	match = re.findall('(144|14|1)', a)
	print('YES' if len(''.join(match)) == len(a) else 'NO')


s = input()
just_14 = all(map(lambda c: c in '14', s))
print(('NO', 'YES')[just_14 and s.find('444') == -1 and (s[0] != '4')])


string = input()
string = string.replace('144', '#').replace('14', '#').replace('1', '#')
if string.replace('#', ''):
	print('NO')
else:
	print('YES')


n = input()
n = n.replace('144', '*')
n = n.replace('14', '-')
n = n.replace('1', '+')
if len(set([i for i in n]) - {'*', '-', '+'}) != 0:
	print('NO')
else:
	print('YES')


s = input()
res = 1
while True and s != '':
	if s[0] == '1':
		try:
			d = s[1]
		except IndexError:
			break
		else:
			if s[1] == '1':
				s = s[1:]
			elif s[1] == '4':
				try:
					d = s[2]
				except IndexError:
					break
				else:
					if s[2] == '1':
						s = s[2:]
					elif s[2] == '4':
						s = s[3:]
					else:
						res = 0
						break
			else:
				res = 0
				break
	else:
		res = 0
		break
if res:
	print('YES')
else:
	print('NO')


x = input()
j = x.count('1')
k = x.count('4')
m = x.find('444')
if j + k == len(x) and m == -1 and (x[0] == '1'):
	print('YES')
else:
	print('NO')


S = input()
v = 0
v1 = 0
c = 0
for i in range(len(S)):
	if S[i] == '1':
		if v1 >= 1:
			v1 = 0
			v = 1
		else:
			v = v + 1
	elif v == 0 or v1 >= 2 or S[i] != '4':
		c = 1
		break
	else:
		v1 = v1 + 1
if c == 0:
	print('YES')
else:
	print('NO')


import re
try:
	s = input()
	v = True
	x = re.split('144|14', s)
	if len(set(s)) == 1 and s.__contains__('1'):
		print('YES')
	else:
		for i in range(len(x)):
			if re.search('[2-9|0]', x[i]) and (not x[i] == ''):
				print('NO')
				v = False
				break
		if v:
			print('YES')
except:
	pass


import re
s = input()
s = re.sub('(14{0,2})', '', s)
if s == '':
	print('YES')
else:
	print('NO')


n = input()
print('YES') if n.count('1') + n.count('4') == len(n) and n.count('444') == 0 and (n[0] != '4') else print('NO')


n = input()
result = True
state = 0
for i in n:
	if state == 0:
		if i != '1':
			result = False
			break
		state = 1
	elif state == 1:
		if i == '4':
			state = 2
		elif i == '1':
			pass
		else:
			result = False
			break
	elif state == 2:
		if i == '4':
			state = 0
		elif i == '1':
			state = 1
		else:
			result = False
			break
	else:
		result = False
		break
print('YES' if result else 'NO')


def main():
	s = input()
	if s.count('444') > 0:
		print('NO')
		return ()
	s = s.replace('144', '')
	s = s.replace('14', '')
	s = s.replace('1', '')
	if len(s) == 0:
		print('YES')
	else:
		print('NO')
main()


s = input()
f = False
for i in s:
	if i != '4' and i != '1':
		f = True
		break
if f or s.count('444') or s[0] == '4':
	print('NO')
else:
	print('YES')


s = input()
n = len(s)
d = 0
i = 0
while i < n:
	if s[i] == '1' or s[i] == '4':
		d = d + 1
	i = i + 1
if d != n:
	print('NO')
if d == n:
	if s[0] == '4':
		print('NO')
	elif '444' in s:
		print('NO')
	else:
		print('YES')


number = input()
length = len(number)
num = int(number)
magic = True
position = 0
while num != 0:
	a = num % 10
	num = num // 10
	if a == 1:
		position = 0
	elif a == 4 and position < 2:
		position = position + 1
	else:
		magic = False
if position != 0:
	magic = False
if magic == True:
	print('YES')
else:
	print('NO')


b = input()
x = b.count('1')
y = b.count('14')
z = b.count('144')
c = len(b)
w = x + y + z
if c == w:
	print('YES')
else:
	print('NO')


s = input()
n = len(s)
k = True
for item in s:
	if item in '02356789':
		print('NO')
		k = False
		break
if k:
	s = s.replace('144', '0')
	s = s.replace('14', '0')
	s = s.replace('1', '0')
	if s.count('0') == len(s):
		print('YES')
	else:
		print('NO')


import math

def main_function():
	input_str = input()
	intermediate_collector = ''
	i = 0
	is_144 = False
	is_14 = False
	is_1 = False
	while i < len(input_str):
		if len(input_str) - i >= 3:
			intermediate_collector = input_str[i] + input_str[i + 1] + input_str[i + 2]
			if intermediate_collector == '144':
				i += 3
			else:
				intermediate_collector = intermediate_collector[:-1]
				if intermediate_collector == '14':
					i += 2
				else:
					intermediate_collector = intermediate_collector[:-1]
					if intermediate_collector == '1':
						i += 1
					else:
						return 'NO'
		elif len(input_str) - i == 2:
			intermediate_collector = input_str[i] + input_str[i + 1]
			if intermediate_collector == '14':
				i += 2
			else:
				intermediate_collector = intermediate_collector[:-1]
				if intermediate_collector == '1':
					i += 1
				else:
					return 'NO'
		else:
			intermediate_collector = input_str[i]
			if intermediate_collector == '1':
				i += 1
			else:
				return 'NO'
	return 'YES'
print(main_function())


n = input()
flag = 1
i = 0
while i < len(n):
	if i < len(n) - 2 and n[i] + n[i + 1] + n[i + 2] == '144':
		i += 3
	elif i < len(n) - 1 and n[i] + n[i + 1] == '14':
		i += 2
	elif i < len(n) and n[i] == '1':
		i += 1
	else:
		flag = 0
		break
if flag:
	print('YES')
else:
	print('NO')


def main():
	n = str(input())
	if n[0] != '1':
		print('NO')
		return
	count = 0
	for i in range(1, len(n)):
		c = n[i]
		if c != '1' and c != '4':
			print('NO')
			return
		if c == '4':
			count = count + 1
			if count > 2:
				print('NO')
				return
		else:
			count = 0
	print('YES')
main()


import re
word = input().strip()
ans = re.sub('(144|14|1)*', '', word)
if ans == '':
	print('YES')
else:
	print('NO')


s = input()
k = 0
for x in s:
	if x == '1':
		k = 2
	elif x == '4' and k:
		k -= 1
	else:
		print('NO')
		break
else:
	print('YES')


l = ['1', '4']
x = input()
for i in x:
	if i not in l:
		print('NO')
		exit()
	elif '444' in x:
		print('NO')
		exit()
	elif x[0] != '1':
		print('NO')
		exit()
else:
	print('YES')


s = input()
for i in range(len(s)):
	if i == 0 and s[i] == '4':
		print('NO')
		exit()
	elif i > 1 and s[i] == '4' and (s[i - 1] == '4') and (s[i - 2] == '4'):
		print('NO')
		exit()
	elif s[i] != '4' and s[i] != '1':
		print('NO')
		exit()
print('YES')


s = input()
found = True
i = 0
while i < len(s):
	if i + 2 < len(s) and s[i] == '1' and (s[i + 1] == '4') and (s[i + 2] == '4'):
		i += 3
	elif i + 1 < len(s) and s[i] == '1' and (s[i + 1] == '4'):
		i += 2
	elif s[i] == '1':
		i += 1
	else:
		found = False
		break
print('YES' if found else 'NO')


s = input()
i = 0
magic = True
n = len(s)
while i < n:
	step = False
	if n - i >= 3 and (not step):
		if s[i:i + 3] == '144':
			i += 3
			step = True
	if n - i >= 2 and (not step):
		if s[i:i + 2] == '14':
			i += 2
			step = True
	if n - i >= 1 and (not step):
		if s[i:i + 1] == '1':
			i += 1
			step = True
		else:
			magic = False
			break
if magic:
	print('YES')
else:
	print('NO')


n = input()
ps = set(n.split('1'))
if n[0] == '1' and ps <= set(['', '4', '44']):
	print('YES')
else:
	print('NO')


s = input()
s += '1'
n = len(s)
if s.count('1') + s.count('4') == n:
	if s[0] != '1':
		print('NO')
	else:
		x = 0
		for i in range(1, n):
			if s[i] == '1':
				if i - x <= 3:
					x = i
				else:
					x = -1
					break
		if x == -1:
			print('NO')
		else:
			print('YES')
else:
	print('NO')


import re
S = input()
pattern = re.compile('(1|14|144)+')
if re.fullmatch(pattern, S) is not None:
	print('YES')
else:
	print('NO')


n = input()
bool = True
for i in range(len(n)):
	if i == 0:
		if n[i] != '1':
			print('NO')
			bool = False
			break
	if n[i] == '1' or n[i] == '4':
		if n[i] == '1' and i <= len(n) - 4 and ('1' not in n[i + 1:i + 4]):
			print('NO')
			bool = False
			break
	else:
		print('NO')
		bool = False
		break
if bool:
	print('YES')


n = input()
N = n.split('1')
if n.find('4') == 0:
	print('NO')
else:
	try:
		i = 0
		b = True
		while b == True:
			if N[i] == '' or N[i] == '4' or N[i] == '44':
				i = i + 1
			else:
				break
		if N[i] == '':
			print('YES')
		else:
			print('NO')
	except IndexError:
		print('YES')


x = str(input())
i = 0
while i <= len(x) - 1:
	if x[i] == '1':
		if x[i:i + 2] == '14':
			if x[i:i + 3] == '144':
				i += 3
			else:
				i += 2
		else:
			i += 1
	else:
		print('NO')
		break
else:
	print('YES')


a = input()
n = len(a)
i = 0
b = a[:] + '1'
c = []
while i <= n - 1:
	for j in range(i + 1, n + 1):
		if b[j] == '1':
			c.append(b[i:j])
			i = j
d = True
for each in c:
	if each == '1' or each == '14' or each == '144':
		pass
	else:
		d = False
		break
if d:
	print('YES')
else:
	print('NO')


s = input()
ok = True
i = 0
while i < len(s):
	if s[i] == '1':
		i += 1
		if i == len(s):
			break
		if s[i] == '4':
			i += 1
			if i == len(s):
				break
			if s[i] == '4':
				i += 1
	else:
		ok = False
		break
print('YES' if ok else 'NO')


liststr = list(input())
if (set(liststr) == {'1', '4'} or set(liststr) == {'1'}) and liststr[0] != '4':
	num4 = 0
	for i in liststr:
		if i == '1':
			num4 = 0
		elif i == '4':
			num4 += 1
		if num4 >= 3:
			print('NO')
			exit()
	print('YES')
else:
	print('NO')


n = input()
c = 0
o = 0
u = True
for i in range(len(n)):
	if c > 0:
		c -= 1
		continue
	if i <= len(n) - 3:
		if n[i] + n[i + 1] + n[i + 2] == '144':
			c = 2
			u = True
		elif n[i] + n[i + 1] == '14':
			c = 1
			u = True
		elif n[i] == '1':
			u = True
		else:
			u = False
			break
	elif i <= len(n) - 2:
		if n[i] + n[i + 1] == '14':
			c = 1
			u = True
		elif n[i] == '1':
			u = True
		else:
			u = False
			break
	elif n[i] == '1':
		u = True
	else:
		u = False
		break
if u:
	print('YES')
else:
	print('NO')


t = input()

def is_magic(s):
	if len(s) >= 3:
		if s[-3:] == '144':
			return is_magic(s[:-3])
	if len(s) >= 2:
		if s[-2:] == '14':
			return is_magic(s[:-2])
	if len(s) >= 1:
		if s[-1:] == '1':
			return is_magic(s[:-1])
	if len(s) == 0:
		return True
	return False
if is_magic(t):
	print('YES')
else:
	print('NO')


s = input()
s = s.replace('144', '*').replace('14', '*').replace('1', '*').replace('*', '')
if len(s) == 0:
	print('YES')
else:
	print('NO')


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
n = insr()
len = len(n)
flag = 0
for i in range(len):
	if n[0] != '1':
		flag = 1
		print('NO')
		break
	if n[i] != '1' and n[i] != '4':
		flag = 1
		print('NO')
		break
	if n[i] == '1':
		if i + 1 < len:
			if n[i + 1] != '4' and n[i + 1] != '1':
				flag = 1
				print('NO')
				break
		elif i + 2 < len:
			if n[i + 2] != '4' and n[i + 2] != '1':
				flag = 1
				print('NO')
				break
		if i + 3 < len:
			if n[i + 1] == '4' and n[i + 2] == '4' and (n[i + 3] != '1'):
				flag = 1
				print('NO')
				break
if i == len - 1 and flag == 0:
	print('YES')


from sys import stdin, stdout
input = stdin.readline
n = input()[:-1]
i = 0
while i < len(n):
	f = False
	if i + 3 <= len(n):
		if n[i:i + 3] == '144':
			i += 3
			f = True
			continue
	if i + 2 <= len(n):
		if n[i:i + 2] == '14':
			i += 2
			f = True
			continue
	if i + 1 <= len(n):
		if n[i] == '1':
			i += 1
			f = True
			continue
	if not f:
		stdout.write('NO')
		exit(0)
stdout.write('YES')


n = int(input())
(a, p) = ([], 0)
while n > 0:
	a.append(n % 10)
	n = n // 10
a.reverse()
while a != []:
	k = a.pop()
	if k in [1, 4]:
		if k == 1:
			continue
		if k == 4 and len(a) >= 1:
			t = a.pop()
			if t == 1:
				continue
			elif t == 4 and len(a) >= 1:
				q = a.pop()
				if q == 1:
					continue
				else:
					p = p + 1
					break
			else:
				p = p + 1
				break
		else:
			p = p + 1
			break
	else:
		p = p + 1
		break
if p == 0:
	print('YES')
else:
	print('NO')


def is_magic_number(s):
	if s[0] != '1':
		return False
	for x in s:
		if x != '1' and x != '4':
			return False
	if s.find('444') != -1:
		return False
	return True
s = input()
if is_magic_number(s):
	print('YES')
else:
	print('NO')


from sys import stdin

def solve(tc):
	s = stdin.readline().strip()
	for i in range(len(s)):
		if s[i] == '1':
			pass
		elif s[i] == '4':
			if i > 0 and s[i - 1] == '1':
				pass
			elif i > 1 and s[i - 1] == '4' and (s[i - 2] == '1'):
				pass
			else:
				print('NO')
				return
		else:
			print('NO')
			return
	print('YES')
LOCAL_TEST = not __debug__
if LOCAL_TEST:
	infile = __file__.split('.')[0] + '-test.in'
	stdin = open(infile, 'r')
tcs = int(stdin.readline().strip()) if LOCAL_TEST else 1
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


s = input()
s2 = ''
p = -1
s += '11'
for i in range(len(s) - 2):
	if (s[i] != '1' or s[i + 1] != '4' or s[i + 2] != '4') and i > p:
		s2 += s[i]
	elif p < i:
		p = i + 2
		s2 += '*'
p = -1
s = s2
s2 = ''
s += '11'
for i in range(len(s) - 1):
	if (s[i] != '1' or s[i + 1] != '4') and i > p:
		s2 += s[i]
	elif p < i:
		p = i + 1
		s2 += '*'
p = -1
s = s2
s2 = ''
for i in range(len(s)):
	if s[i] != '1':
		s2 += s[i]
s = s2
for i in range(len(s)):
	if s2[i] != '*':
		print('NO')
		return
print('YES')


m = input()
if '444' in m:
	print('NO')
else:
	x = m.replace('144', '')
	y = x.replace('14', '')
	z = y.replace('1', '')
	if len(z) == 0:
		print('YES')
	else:
		print('NO')


number = input()
magic = True
while len(number) != 0:
	if number[-3:] == '144':
		number = number[:-3]
	elif number[-2:] == '14':
		number = number[:-2]
	elif number[-1:] == '1':
		number = number[:-1]
	else:
		magic = False
		break
if magic == False:
	print('NO')
else:
	print('YES')


n = input()
a = ['144', '14', '1']
for i in range(3):
	if a[i] in n:
		n = n.replace(a[i], '.')
n = n.replace('.', '')
print('YES' if n == '' else 'NO')


s = input()
f = 0
if s[0] != '1':
	f = 1
for i in s:
	if i != '1' and i != '4':
		f = 1
if s.find('444') != -1:
	f = 1
if f == 0:
	print('YES')
else:
	print('NO')


s = input()
b = 1
for c in s:
	if c != '1' and c != '4':
		b = 0
if b == 0:
	print('NO')
elif s[0] == '4':
	print('NO')
elif s.find('444') == -1:
	print('YES')
else:
	print('NO')


n = input()
l = len(n)
if n[0] != '1':
	print('NO')
else:
	flag = 0
	for i in range(1, l):
		if n[i] == '1':
			continue
		elif n[i] == '4':
			if n[i - 1] == '1':
				continue
			elif i > 1 and n[i - 2] == '1':
				continue
			else:
				flag = 1
				break
		else:
			flag = 1
			break
	if flag == 0:
		print('YES')
	else:
		print('NO')


n = int(input())
n = str(n)
check = False
for x in n:
	if x == '1' or x == '4':
		pass
	else:
		check = True
		break
if not check and n[0] == '1' and ('444' not in n):
	print('YES')
else:
	print('NO')


class Code:

	def __init__(self):
		self.n = input()

	def process(self):
		self.n = self.n.replace('144', 'A')
		self.n = self.n.replace('14', 'A')
		self.n = self.n.replace('1', 'A')
		print('NO' if self.n.count('A') != len(self.n) else 'YES')
code = Code()
code.process()


p = int(input())
num = []
j = 0
while p > 0:
	r = int(p % 10)
	p = int(p / 10)
	num.append(r)
	j = j + 1
num.reverse()
flag = 0
for i in range(0, j):
	if num[i] == 1:
		continue
	elif int(num[i]) == 4 and (i > 0 and num[i - 1] == 1 or (i > 1 and num[i - 1] == 4 and (num[i - 2] == 1))):
		continue
	else:
		flag = 1
		break
if flag == 0:
	print('YES')
else:
	print('NO')


s = input()
c_i = 0
f = False
while c_i < len(s):
	if len(s) - c_i >= 3 and s[c_i:c_i + 3] == '144':
		c_i += 3
	elif len(s) - c_i >= 2 and s[c_i:c_i + 2] == '14':
		c_i += 2
	elif len(s) - c_i >= 1 and s[c_i:c_i + 1] == '1':
		c_i += 1
	else:
		f = True
		break
if f:
	print('NO')
else:
	print('YES')


import re
n = input()
res = re.search('^(1|14|144)+$', n)
if res:
	print('YES')
else:
	print('NO')


def check(n):
	if n[0] != '1':
		return 'NO'
	for i in n:
		if i != '1' and i != '4':
			return 'NO'
	if '444' in n:
		return 'NO'
	return 'YES'
n = input()
print(check(n))


n = input()
flag = True
for i in n:
	if i != '4' and i != '1':
		flag = False
		print('NO')
		break
if flag:
	if n[0] == '4':
		print('NO')
	elif '444' in n:
		print('NO')
	else:
		print('YES')


line = str(input())
if line.startswith('1'):
	line = line.split('1')
	flag = True
	line = list(set(line))
	for it in line:
		if it == '':
			continue
		if it != '4' and it != '44':
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


def index_(ns):
	i = 0
	while i < len(ns):
		if ns[i] == 1:
			i += 1
			if i == len(ns):
				return True
			if ns[i] == 4:
				i += 1
				if i == len(ns):
					return True
				if ns[i] == 4:
					i += 1
					if i == len(ns):
						return True
				elif ns[i] != 1:
					return False
			elif ns[i] != 1:
				return False
		else:
			return False
	return True
n = int(input())
ns = [int(d) for d in str(n)]
if index_(ns) == True:
	print('YES')
else:
	print('NO')


data = input()
i = 0
n = len(data)
while i < n:
	if data[i] == '4' or data[i] != '1':
		print('NO')
		exit(0)
	elif i + 2 < n and data[i + 1] == '4' and (data[i + 2] == '4'):
		i += 3
	elif i + 1 < n and data[i + 1] == '4':
		i += 2
	else:
		i += 1
print('YES')


inputstring = input()
if (inputstring.find('0') != -1) | (inputstring.find('2') != -1) | (inputstring.find('3') != -1) | (inputstring.find('5') != -1) | (inputstring.find('6') != -1) | (inputstring.find('7') != -1) | (inputstring.find('8') != -1) | (inputstring.find('9') != -1):
	print('NO')
elif inputstring[0] == '4':
	print('NO')
else:
	cnt4 = 0
	for i in inputstring[1:]:
		if i == '4':
			cnt4 = cnt4 + 1
		if i == '1':
			cnt4 = 0
		if cnt4 > 2:
			print('NO')
			break
	if cnt4 <= 2:
		print('YES')


num = input()
if '1444' in num:
	print('NO')
else:
	num = num.replace('144', '')
	num = num.replace('14', '')
	num = num.replace('1', '')
	if len(num) > 0:
		print('NO')
	else:
		print('YES')


import sys
str = input()
for i in range(0, len(str)):
	if str[i] == '1':
		continue
	elif str[i] == '4':
		if i > 0 and str[i - 1] == '1':
			continue
		elif i > 1 and str[i - 1] == '4' and (str[i - 2] == '1'):
			continue
		else:
			print('NO')
			return
	else:
		print('NO')
		return
print('YES')


n = list(input())
if n[0] == '4':
	print('NO')
	exit(0)
for i in range(10):
	if i != 4 and i != 1 and (str(i) in n):
		print('NO')
		exit(0)
n = ''.join(n)
if '444' in n:
	print('NO')
	exit(0)
print('YES')


n = [i.strip() for i in input().split('144') if i.strip() != '']
n = [i.strip() for i in ' '.join(n).split('14') if i.strip() != '']
n = [i.strip() for i in ' '.join(n).split('1') if i.strip() != '']
if n:
	print('NO')
else:
	print('YES')


s = input()
ind = 0
b = True
while ind < len(s):
	if s[ind] == '1':
		if ind + 2 < len(s) and s[ind + 1] == '4' and (s[ind + 2] == '4'):
			ind = ind + 2
		elif ind + 1 < len(s) and s[ind + 1] == '4':
			ind = ind + 1
	else:
		b = False
	ind = ind + 1
if b == True:
	print('YES')
else:
	print('NO')


str_ = input()
flag = True
if str_[0] != '1':
	print('NO')
else:
	for i in range(len(str_)):
		if str_[i] != '1' and str_[i] != '4':
			flag = False
			break
		if str_[i] == '1' and len(str_) > i + 3 and (str_[i + 3] == '4') and (str_[i + 1] == '4') and (str_[i + 2] != '1'):
			flag = False
			break
	print('YES' if flag else 'NO')


a = '144'
l = input()
l1 = len(l)
i = 0
flag = 0
while i < l1:
	if l[i] == '1':
		if i + 1 < l1:
			if l[i + 1] == '1':
				i += 1
			elif l[i + 1] == '4':
				if i + 2 < l1:
					if l[i + 2] == '4':
						i += 3
					elif l[i + 2] == '1':
						i += 2
					else:
						flag = 1
						break
				else:
					i += 2
			else:
				flag = 1
				break
		else:
			i += 1
	else:
		flag = 1
		break
if flag:
	print('NO')
else:
	print('YES')


f = lambda : map(int, input().split())
n = input()
if n[0] != '1' or '444' in n:
	exit(print('NO'))
l = [2, 3, 5, 6, 7, 8, 9, 0]
for i in n:
	if int(i) in l:
		exit(print('NO'))
print('YES')


import sys

def main():
	n = sys.stdin.readline().strip()
	if n[0] != '1':
		return False
	count = 0
	for number in n:
		if number == '1':
			count = 0
		elif number == '4':
			count += 1
			if count > 2:
				return False
		else:
			return False
	return True
if main():
	sys.stdout.write('YES')
else:
	sys.stdout.write('NO')


n = input().rstrip()
n = n.replace('144', ' ')
n = n.replace('14', ' ')
n = n.replace('1', ' ')
if len(n.strip()) == 0:
	print('YES')
else:
	print('NO')


n = input()
if '0' in n or '2' in n or '3' in n or ('5' in n) or ('6' in n) or ('7' in n) or ('8' in n) or ('9' in n):
	print('NO')
elif '444' in n or n[0] == '4':
	print('NO')
else:
	print('YES')


n = input()
l = list()
yes = True
for i in n:
	if i == '1':
		if len(l) > 0:
			l.clear()
		l.append(i)
	elif i == '4':
		if len(l) > 0:
			s = ''.join(l)
			if s == '14':
				l.clear()
			elif s == '1':
				l.append(i)
			else:
				yes = False
				break
		else:
			yes = False
			break
	else:
		yes = False
		break
print('YES' if yes else 'NO')


import sys

def check(number):
	n_4 = 0
	if number[0] != '1':
		return 'NO'
	for i in range(1, len(number)):
		if number[i] == '1':
			n_4 = 0
			continue
		elif number[i] == '4':
			n_4 += 1
			if n_4 > 2:
				return 'NO'
		else:
			return 'NO'
	return 'YES'
number = sys.stdin.readline().strip()
print(check(number))


a = input()
if '144' in a:
	a = a.replace('144', '   ')
if '14' in a:
	a = a.replace('14', '  ')
if '1' in a:
	a = a.replace('1', ' ')
if a == len(a) * ' ':
	print('YES')
else:
	print('NO')


def solve(num):
	return num[0] == '1' and all((x == '' or x == '4' or x == '44' for x in num.split('1')))
num = input()
is_magical = solve(num)
print('YES' if is_magical else 'NO')


s = input()
n = len(s)
if s[0] != '1':
	print('NO')
else:
	f = 0
	for i in range(1, n):
		if s[i] == '4':
			if s[i - 1] == '1':
				continue
			elif i > 1 and s[i - 2] == '1':
				continue
			else:
				f = 1
				break
		elif s[i] == '1':
			continue
		else:
			f = 1
			break
	if f == 0:
		print('YES')
	else:
		print('NO')


st = input()
works = True
for i in st:
	if i != '1' and i != '4':
		works = False
if st[0] != '1':
	works = False
for i in range(len(st) - 2):
	if st[i] == '4' and st[i + 1] == '4' and (st[i + 2] == '4'):
		works = False
		break
if works:
	print('YES')
else:
	print('NO')


import sys
a = input()

def solve():
	for i in a:
		if i != '1' and i != '4':
			print('NO')
			return
	if a[0] == '1':
		for i in range(1, len(a) - 2):
			if a[i] == a[i + 1] == a[i + 2] == '4':
				print('NO')
				return
		else:
			print('YES')
			return
	else:
		print('NO')
		return
solve()


l = list(input())
j = 0
e = 0
if l[j] == '1':
	j += 1
	while j < len(l):
		if l[j] == '1':
			j += 1
		elif l[j] == '4':
			if j > 1:
				if l[j - 1] == '4' and l[j - 2] == '4':
					e = 1
					break
			j += 1
		elif e == 1:
			break
		else:
			e = 1
			break
	if e == 1:
		print('NO')
	else:
		print('YES')
else:
	print('NO')


num = int(input())
list = [int(x) for x in str(num)]
if list[0] != 1:
	print('NO')
else:
	for i in range(0, len(list)):
		if list[i] != 1 and list[i] != 4:
			print('NO')
			break
	else:
		for j in range(0, len(list) - 2):
			if list[j] == 4 and list[j + 1] == 4 and (list[j + 2] == 4):
				print('NO')
				break
		else:
			print('YES')


s = input()
if s[0] != '1':
	print('NO')
else:
	l = 0
	for i in range(1, len(s)):
		if s[i] == '4' and l < 2:
			l += 1
		elif s[i] == '1':
			l = 0
		else:
			print('NO')
			break
	else:
		print('YES')


n = input()
l = [int(i) for i in n]
while 1 in l:
	l.remove(1)
while 4 in l:
	l.remove(4)
if '444' in n or len(l) > 0 or n[0] != '1':
	print('NO')
else:
	print('YES')


import sys
data = str(input())
bad = ['0', '2', '3', '5', '6', '7', '8', '9']
if any((i in data for i in bad)):
	print('NO')
	sys.exit()
elif data[0] != '1':
	print('NO')
	sys.exit()
elif '444' in data:
	print('NO')
	sys.exit()
else:
	print('YES')


n = input()
flag = True
for i in range(len(n)):
	if n[i] != '1' and n[i] != '4':
		flag = False
		break
if n[0] == '4':
	flag = False
b = n.find('444')
if b != -1:
	flag = False
if flag:
	print('YES')
else:
	print('NO')


from re import match
print(match('^(14?4?)*$', input()) and 'YES' or 'NO')


s = input()
if s[0] == '4' or set(s) not in [{'1'}, {'4'}, {'1', '4'}]:
	print('NO')
else:
	x = s.replace('1', ' ').split()
	if any((len(i) > 2 for i in x)):
		print('NO')
	else:
		print('YES')


a = list(input())
flag = True
i = 0
if len(a) <= 2:
	if len(a) == 1:
		if a[0] != '1':
			flag = False
	elif a[0] == '1' and (a[1] == '4' or a[1] == '1'):
		flag = True
	else:
		flag = False
else:
	while i < len(a):
		if a[i] == '1' and i < len(a):
			if i < len(a) - 1 and a[i + 1] == '4':
				if i < len(a) - 2 and a[i + 2] == '4':
					i = i + 3
				else:
					i = i + 2
			else:
				i = i + 1
		else:
			flag = False
			break
if flag == False:
	print('NO')
else:
	print('YES')


a = input()
ls = []
che = []
for b in a:
	ls.append(b)
	che.append(b)

def ch():
	if a[0] == '1':
		while 0 < len(ls):
			if ls[0] == '1':
				if len(ls) <= 3:
					print('YES')
					break
				else:
					del ls[0]
			elif ls[0] == '4':
				if ls[1] == '4':
					if ls[2] == '4':
						print('NO')
						break
					else:
						del ls[1]
						del ls[0]
				else:
					del ls[0]
			else:
				print('NO')
				break
	else:
		print('NO')
for k in range(len(che)):
	if '1' in che:
		del che[che.index('1')]
	if '4' in che:
		del che[che.index('4')]
if len(che) == 0:
	ch()
	if len(ls) == 0:
		print('YES')
else:
	print('NO')


n = input()
num = ['144', '14', '1']
for i in num:
	while i in n:
		n = n.replace(i, '*')
res = True
for i in n:
	if i != '*':
		res = False
		break
if res:
	print('YES')
else:
	print('NO')


s = str(input())
d = 0
flag = 0
e = 0
for i in range(0, len(s)):
	if s[i] == '1':
		e = e + 1
		d = 0
	elif s[i] == '4':
		if e > 0 and d < 2:
			d = d + 1
		elif e > 0 and d >= 2:
			flag = 1
			break
		elif e == 0:
			flag = 1
			break
	else:
		flag = 1
		break
if flag == 0:
	print('YES')
else:
	print('NO')


def solution(a):
	if a[0] != '1':
		return 'NO'
	for x in a:
		if x not in '14':
			return 'NO'
	i = 0
	while i < len(a) - 2:
		if a[i] == '4':
			if a[i + 1] == '4':
				if a[i + 2] == '4':
					return 'NO'
		i += 1
	return 'YES'

def answer():
	a = input()
	print(solution(a))
answer()


n = str(input())
ans = 'NO'
if all((x in '14' for x in n)):
	i = 0
	ans = 'YES'
	while i < len(n):
		step = min(i + 3, len(n))
		t = n[i:step]
		if t.startswith('144'):
			i += 3
		elif t.startswith('14'):
			i += 2
		elif t.startswith('1'):
			i += 1
		else:
			ans = 'NO'
			break
print(ans)


nn = input()
print('NO' if len(nn.replace('144', ' ').replace('14', ' ').replace('1', '').strip()) else 'YES')


s = input()
c = 0
arr = list(s)
boo = True
if s[0] != '1':
	print('NO')
else:
	for i in range(len(arr)):
		if s[i] == '4':
			c += 1
		elif s[i] == '1':
			c = 0
		elif s[i] != '1' and s[i] != '4':
			boo = False
			print('NO')
			break
		if c >= 3:
			print('NO')
			boo = False
			break
	if boo:
		print('YES')


from re import findall

def is_magic(n):
	if n[0] != '1':
		return False
	for c in n:
		if c != '1' and c != '4':
			return False
	if len(findall('4{3,}', n)):
		return False
	return True
print('YES' if is_magic(input()) else 'NO')


s = input()
i = 0
res = True
while True:
	if s.startswith('144'):
		s = s[3:]
	elif s.startswith('14'):
		s = s[2:]
	elif s.startswith('1'):
		s = s[1:]
	else:
		if len(s) != 0:
			res = False
		break
if res:
	print('YES')
else:
	print('NO')


n = str(input())
a = n.count('14') - n.count('144')
b = n.count('1') - a - n.count('144')
c = n.count('144')
if 2 * a + b + 3 * c == len(n):
	print('YES')
else:
	print('NO')


n = input()
n1 = n.replace('144', '')
n1 = n1.replace('14', '')
n1 = n1.replace('1', '')
if len(n1) > 0 or n.find('444') != -1:
	print('NO')
else:
	print('YES')


s = input()
n = len(s)
found = False
if s[0] != '1':
	print('NO')
elif '444' in s:
	print('NO')
else:
	arr = ['2', '3', '5', '6', '7', '8', '9', '0']
	for i in arr:
		if i in s:
			found = True
			break
	if found:
		print('NO')
	else:
		print('YES')


s = input('')
x = s.count('144')
y = s.count('14')
z = s.count('1')
if x + y + z == len(s):
	print('YES')
else:
	print('NO')


n = input()
while n:
	if n[:3] == '144':
		n = n[3:]
	elif n[:2] == '14':
		n = n[2:]
	elif n[:1] == '1':
		n = n[1:]
	else:
		break
if n:
	print('NO')
else:
	print('YES')


fl = True
cnt = int(0)
for a in input().strip()[::-1]:
	if a == '4':
		cnt += 1
	elif a == '1':
		cnt = int(0)
	else:
		fl = False
	if cnt > 2:
		fl = False
if cnt != 0:
	fl = False
print('YES' if fl else 'NO')


a = int(input())
a = str(a)
l1 = list(map(int, a))
flag = 0
flag1 = 0
flag2 = 0
for i in range(len(l1)):
	if l1[i] != 4 and l1[i] != 1:
		flag = 1
		break
if flag != 1:
	if l1[0] != 1:
		flag1 = 1
	else:
		for i in range(len(l1) - 2):
			if l1[i] == 4:
				if l1[i + 1] == 4 and l1[i + 2] == 4:
					flag2 = 1
if flag1 == 1 or flag2 == 1 or flag == 1:
	print('NO')
else:
	print('YES')


n = list(input())
flag = 0
for i in n:
	if flag == 0:
		if i == '1':
			flag = 1
			continue
		else:
			flag = -1
			break
	if flag == 1:
		if i == '1':
			flag = 1
			continue
		elif i == '4':
			flag = 2
			continue
		else:
			flag = -1
			break
	if flag == 2:
		if i == '1':
			flag = 1
			continue
		elif i == '4':
			flag = 3
			continue
		else:
			flag = -1
			break
	if flag == 3:
		if i == '1':
			flag = 1
			continue
		else:
			flag = -1
			break
if flag == -1:
	print('NO')
else:
	print('YES')


n = input()
x = n.count('1')
y = n.count('14')
z = n.count('144')
t1 = n.count('1')
t2 = n.count('4')
if t2 != y + z or '0' in n or '2' in n or ('3' in n) or ('5' in n) or ('6' in n) or ('7' in n) or ('8' in n) or ('9' in n):
	print('NO')
else:
	print('YES')


n = int(input())
li = list(str(n))
flag1 = 0
for i in li:
	i = int(i)
	flag2 = False
	if flag1 == 0:
		if i == 1:
			flag1 = 1
			flag2 = True
	elif flag1 == 1:
		if i == 1:
			flag1 = 1
			flag2 = True
		elif i == 4:
			flag1 = 2
			flag2 = True
	elif flag1 == 2:
		if i == 1:
			flag1 = 1
			flag2 = True
		elif i == 4:
			flag1 = 3
			flag2 = True
	elif flag1 == 3:
		if i == 1:
			flag1 = 1
			flag2 = True
	if flag2 == False:
		break
if flag2 == True:
	print('YES')
else:
	print('NO')


n = int(input())
while n != 0:
	last = n % 10
	if last != 1 and last != 4:
		break
	elif last == 1:
		n = n // 10
	elif last == 4:
		if n % 100 == 14:
			n = n // 100
		elif n % 1000 == 144:
			n = n // 1000
		else:
			break
if n == 0:
	print('YES')
else:
	print('NO')


n = input()
s = {'1', '14', '144'}
ans = 'YES'
for i in range(len(n)):
	j = max(0, i - 2)
	if n[i] in s or n[j:i + 1] in s or n[j + 1:i + 1] in s:
		continue
	ans = 'NO'
	break
print(ans)


a = list(input())
l = len(a)
i = 0
while i < l:
	if i + 2 < l and a[i] == '1' and (a[i + 1] == '4') and (a[i + 2] == '4'):
		i += 3
	elif i + 1 < l and a[i] == '1' and (a[i + 1] == '4'):
		i += 2
	elif i < l and a[i] == '1':
		i += 1
	else:
		print('NO')
		exit()
print('YES')


numbers = input()
if '2' in numbers or '3' in numbers or '6' in numbers or ('5' in numbers) or ('7' in numbers) or ('8' in numbers) or ('9' in numbers) or ('0' in numbers):
	numbers = False
	print('NO')
	quit()
if numbers[0] == '4':
	numbers = False
	print('NO')
	quit()
elif '444' in numbers:
	numbers = False
	print('NO')
	quit()
if numbers:
	print('YES')
else:
	print('NO')


def main():
	num = input()
	for i in range(len(num)):
		if num[i] != '1' and num[i] != '4':
			print('NO')
			return
	if num[0] != '1':
		print('NO')
		return
	if '444' in num:
		print('NO')
		return
	print('YES')
	return
main()


n = input()
a = set(n)
c = ['1', '14', '144']
f = True
if a | set('14') != set('14'):
	print('NO')
	f = False
s = n[0]
i = 0
while i < len(n) and f:
	if n[i] == '4':
		s += n[i]
	elif s not in c:
		f = False
		print('NO')
		break
	else:
		s = '1'
	i += 1
if f == True:
	if s not in c:
		print('NO')
	else:
		print('YES')


z = input()
a = 0
q = True
1141
if len(z) > 3:
	for i in range(len(z)):
		if a == len(z) - 3:
			break
		if a < len(z) - 2:
			if z[a] == '1' and z[a + 1] == '1':
				a += 1
			elif z[a] == '1' and z[a + 1] == '4' and (z[a + 2] == '4'):
				a += 3
			elif z[a] == '1' and z[a + 1] == '4' and (z[a + 2] == '1'):
				a += 2
			else:
				q = False
	if len(z) > 1:
		if len(z) - 1 == a:
			if z[a] != '1':
				q = False
		elif z[a] == '1' and z[a + 1] == '1':
			pass
		elif z[a] == '1' and z[a + 1] == '4':
			pass
		else:
			q = False
elif len(z) == 3:
	if z[a] == '1' and z[a + 1] == '1' and (z[a + 2] == '4' or z[a + 2] == '1'):
		pass
	elif z[a] == '1' and z[a + 1] == '4' and (z[a + 2] == '4' or z[a + 2] == '1'):
		pass
	else:
		q = False
elif len(z) == 2:
	if z[a] == '1' and (z[a + 1] == '1' or z[a + 1] == '4'):
		pass
	else:
		q = False
elif z[a] != '1':
	q = False
if q:
	print('YES')
else:
	print('NO')


a = input()
flag = True
if a[0] != '1' or '444' in a:
	flag = False
	print('NO')
else:
	for i in a:
		if not (i == str(1) or i == str(4)):
			print('NO')
			flag = False
			break
if flag:
	print('YES')


def solution(n):
	m = set(n)
	for i in m:
		if i not in ['1', '4']:
			return 'NO'
	if len(m) > 2 or n[0] != '1':
		return 'NO'
	elif '444' in n:
		return 'NO'
	else:
		return 'YES'
n = input()
print(solution(n))


n = input()
i = 0
j = 0
while j < len(n):
	if n[j:j + 3] == '144':
		j += 3
	elif n[j:j + 2] == '14':
		j += 2
	elif n[j:j + 1] == '1':
		j += 1
	else:
		i = 5
		break
print(['YES', 'NO'][i == 5])


def isMagicNumber(n):
	isOneFound = False
	noOfFoursFound = 0
	for i in n:
		if i == '1':
			isOneFound = True
			noOfFoursFound = 0
		elif i == '4' and isOneFound and (noOfFoursFound == 0):
			noOfFoursFound += 1
			isOneFound = False
		elif i == '4' and noOfFoursFound == 1:
			noOfFoursFound = 0
		else:
			return 'NO'
	return 'YES'
n = input()
print(isMagicNumber(n))


z = input()
result = 'YES'
garbage = ['0', '2', '3', '5', '6', '7', '8', '9']
for i in garbage:
	if i in z:
		result = 'NO'
		break
if result == 'YES':
	if z[0] != '1':
		result = 'NO'
	elif '444' in z:
		result = 'NO'
print(result)


S = input()
c = 0
if S[0] != '1':
	print('NO')
	c = 1
else:
	flag = 0
	for i in S:
		if i == '1':
			flag = 0
		elif i == '4':
			flag += 1
			if flag > 2:
				print('NO')
				c = 1
				break
		else:
			print('NO')
			c = 1
			break
	if c == 0:
		print('YES')


n = int(input())
flag = True
s = str(n)
l = len(s)
four = False
one = False
aux = 0
for i in range(l):
	if s[i] == '4':
		if not one:
			flag = False
		if four:
			aux += 1
			if aux > 2:
				flag = False
		else:
			aux = 1
			four = True
	elif s[i] == '1':
		one = True
		four = False
	else:
		flag = False
print('YES' if flag else 'NO')


var1 = input()
count = 0
count = count + var1.count('144')
var1 = var1.replace('144', '$')
count = count + var1.count('14')
var1 = var1.replace('14', '$')
count = count + var1.count('1')
var1 = var1.replace('1', '$')
if len(var1) == count:
	print('YES')
else:
	print('NO')


s = input()
k = len(s)
if s.count('4') + s.count('1') == k and s[0] == '1':
	c = 0
	for i in range(k - 2):
		if s[i:i + 3] == '444':
			c = -1
			break
	if c == 0:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


def Sol(s):
	i = 0
	while i < len(s) - 2:
		if s[i] == '1':
			if s[i + 1] == '4':
				if s[i + 2] == '4':
					s = s[3:]
				else:
					s = s[2:]
			else:
				s = s[1:]
		else:
			print('NO')
			return
	if len(s) == 0:
		print('YES')
		return
	elif len(s) == 1:
		if s == '1':
			print('YES')
			return
		else:
			print('NO')
			return
	elif s == '14' or s == '11':
		print('YES')
		return
	else:
		print('NO')
		return
n = input()
Sol(n)


a = input()
ans = 'YES'
if len(str(a)) < 3:
	for i in range(len(str(a))):
		if a[i] != '1' and a[i] != '4' or a[0] == '4':
			ans = 'NO'
else:
	for i in range(len(str(a)) - 2):
		if a[i] != '1' and a[i] != '4' or a[0] == '4':
			ans = 'NO'
		if a[i] == '4' and a[i + 1] == '4' and (a[i + 2] == '4'):
			ans = 'NO'
print(ans)


def gen(s):
	if len(s) >= n:
		magicNums.append(s)
		return
	magicNums.append(s)
	gen(s + '1')
	gen(s + '14')
	gen(s + '144')
magicNums = []
given = input()
n = len(given)
gen('')
if given in magicNums:
	print('YES')
else:
	print('NO')


s = input()
ans = True
a = s[0]
if a != '1':
	print('NO')
else:
	i = 1
	c = 0
	while i < len(s):
		if a == '1':
			if s[i] == '1':
				a = '1'
				c = 0
			elif s[i] == '4':
				a = '4'
				c += 1
				if c > 2:
					ans = False
					break
			else:
				ans = False
				break
		elif a == '4':
			if s[i] == '4':
				c += 1
				if c > 2:
					ans = False
					break
			elif s[i] == '1':
				c = 0
				a = '1'
			else:
				ans = False
				break
		else:
			ans = False
			break
		i += 1
	if ans:
		print('YES')
	else:
		print('NO')


n = list(map(int, input()))
li = [x for x in n if x != 1 and x != 4]
if len(li) > 0:
	print('NO')
elif len(n) == 1:
	if n[0] == 1:
		print('YES')
	else:
		print('NO')
else:
	li1 = []
	li14 = []
	li144 = []
	for i in range(len(n) - 2):
		if n[i] == 1:
			if n[i + 1] == 4:
				if n[i + 2] == 4:
					li144.append(3)
					i += 2
				else:
					li14.append(2)
					i += 1
			else:
				li1.append(1)
	for i in range(len(n) - 2, len(n)):
		try:
			if n[i] == 1:
				if n[i + 1] == 4:
					if n[i + 2] == 4:
						li144.append(3)
						break
					else:
						li14.append(2)
						i += 1
				else:
					li1.append(1)
		except IndexError:
			if i < len(n) - 1:
				if n[i] == 1:
					if n[i + 1] == 4:
						li14.append(2)
						break
			elif n[i] == 1:
				li1.append(1)
	print('YES') if sum(li1) + sum(li14) + sum(li144) == len(n) else print('NO')


s = input()
li = ['1', '4']
f = 0
for i in s:
	if i not in li:
		f = 1
if f:
	print('NO')
else:
	li = ['1', '144', '14']
	if s[0] == '4':
		f = 1
	for i in range(len(s)):
		if s[i] == '4':
			if i - 1 >= 0 and i - 2 < 0:
				if s[i - 1] != '1':
					f = 1
			elif i - 1 >= 0 and i - 2 >= 0:
				if s[i - 1] != '1' and s[i - 2] != '1':
					f = 1
	if f:
		print('NO')
	else:
		print('YES')


n = input()
if '144' in n:
	a = n.count('144')
	n = n.replace('144', ',', a)
if '14' in n:
	b = n.count('14')
	n = n.replace('14', ',', b)
if '1' in n:
	c = n.count('1')
	n = n.replace('1', ',', c)
if set(n) != {','}:
	print('NO')
else:
	print('YES')


s = input()
i = 0
flag = 1
while i < len(s):
	if s[i] == '1':
		if i < len(s) - 1:
			if s[i + 1] != '4':
				i += 1
			elif i < len(s) - 2:
				if s[i + 2] != '4':
					i += 2
				else:
					i += 3
			else:
				i += 2
		else:
			i += 1
	else:
		flag = 0
		break
if flag == 1:
	print('YES')
else:
	print('NO')


import re
print('YES' if not re.sub('(144|14|1)*', '', input().strip()) else 'NO')


lijstje = list(input())

def zoeken(getallen):
	if len(getallen) == 0:
		return 'YES'
	if len(getallen) >= 3:
		if getallen[0] == '1' and getallen[1] == '4' and (getallen[2] == '4'):
			del getallen[0]
			del getallen[0]
			del getallen[0]
			return zoeken(getallen)
		elif getallen[0] == '1' and getallen[1] == '4':
			del getallen[0]
			del getallen[0]
			return zoeken(getallen)
		elif getallen[0] == '1':
			del getallen[0]
			return zoeken(getallen)
		else:
			return 'NO'
	elif len(getallen) == 2:
		if getallen[0] == '1' and getallen[1] == '4':
			del getallen[0]
			del getallen[0]
			return zoeken(getallen)
		elif getallen[0] == '1':
			del getallen[0]
			return zoeken(getallen)
		else:
			return 'NO'
	elif len(getallen) == 1:
		if getallen[0] == '1':
			return 'YES'
		else:
			return 'NO'
print(zoeken(lijstje))


def solve(s):
	i = len(s) - 1
	while i >= 0:
		try:
			if s[i] == '1':
				i -= 1
			elif s[i - 1:i + 1] == '14':
				i -= 2
			elif s[i - 2:i + 1] == '144':
				i -= 3
			else:
				return 'NO'
		except:
			return 'NO'
	return 'YES'

def main():
	s = input()
	print(solve(s))
main()


n = list(input())
l = len(n)
i = 0
k = 0
while i < l:
	if i < l - 2 and n[i] + n[i + 1] + n[i + 2] == '144':
		i = i + 3
	elif i < l - 1 and n[i] + n[i + 1] == '14':
		i = i + 2
	elif i < l and n[i] == '1':
		i = i + 1
	else:
		print('NO')
		k = 1
		break
if k == 0:
	print('YES')


n = list(input())
t = len(n)
flag = 0
i = 0
while i < t:
	if i + 2 < t and n[i] == '1' and (n[i + 1] == '4') and (n[i + 2] == '4'):
		i += 3
	elif i + 1 < t and n[i] == '1' and (n[i + 1] == '4'):
		i += 2
	elif n[i] == '1':
		i += 1
	else:
		print('NO')
		flag = 1
		break
if flag == 0:
	print('YES')


n = input()
m = list(n)
if m[0] == '1':
	i = 1
	while i < len(m):
		if m[i] == '1':
			i += 1
			continue
		elif m[i] == '4':
			if i > 2:
				if m[i - 1] == '4' and m[i - 2] == '4':
					print('NO')
					break
				else:
					i += 1
					continue
			else:
				i += 1
				continue
		else:
			print('NO')
			break
	if i == len(m):
		print('YES')
else:
	print('NO')


import re
s = input()
print('YES') if re.match('(1|14|144)*$', s) else print('NO')


n = str(input())
f = len(n) - 1
ok = 1
while f >= 0:
	if n[f] == '1':
		f -= 1
	elif f > 0 and n[f] == '4' and (n[f - 1] == '1'):
		f -= 2
	elif f > 1 and n[f] == '4' and (n[f - 1] == '4') and (n[f - 2] == '1'):
		f -= 3
	else:
		ok = 0
		break
if ok:
	print('YES')
else:
	print('NO')


n = input()
if n.count('1') + n.count('4') != len(n):
	print('NO')
elif n[0] == '4':
	print('NO')
else:
	counter = 0
	maxc = 0
	for i in range(len(n)):
		if n[i] == '4':
			counter += 1
			if counter > maxc:
				maxc = counter
		else:
			counter = 0
	if maxc > 2:
		print('NO')
	else:
		print('YES')


s = input()
s = s.replace('144', ' ')
s = s.replace('14', ' ')
s = s.replace('1', ' ')
count = 0
for i in range(0, len(s)):
	if s[i] != ' ':
		count += 1
if count == 0:
	print('YES')
else:
	print('NO')


s = input()
ans = 'YES'
if s.count('1') + s.count('4') != len(s):
	ans = 'NO'
if '444' in s:
	ans = 'NO'
if s[0] != '1':
	ans = 'NO'
print(ans)


n = input()
cont = 0
if n[0] != '1':
	print('NO')
	exit(0)
for i in range(1, len(n)):
	if n[i] != '1' and n[i] != '4':
		print('NO')
		exit(0)
	elif n[i] == '4':
		cont += 1
		if cont == 3:
			print('NO')
			exit(0)
	else:
		cont = 0
print('YES')


s = input()
t = 0
i = 0
m = [' ' for i in range(len(s))]
while i < len(s) - 2:
	if s[i] == '1' and s[i + 1] == '4' and (s[i + 2] == '4'):
		m[i] = '*'
		m[i + 1] = '*'
		m[i + 2] = '*'
		t = t + 3
		i = i + 3
	else:
		i = i + 1
i = 0
while i < len(s) - 1:
	if m[i] != '*':
		if s[i] == '1' and s[i + 1] == '4':
			m[i] = '*'
			m[i + 1] = '*'
			i = i + 2
			t = t + 2
		else:
			i = i + 1
	else:
		i = i + 1
i = 0
f = 0
while i < len(s):
	if m[i] != '*' and s[i] != '1':
		print('NO')
		f = 1
		break
	i = i + 1
if f == 0:
	print('YES')


v = input()
i = 0
while i <= len(v) - 1:
	if v[i] == '1':
		if i + 1 <= len(v) - 1:
			if v[i + 1] == '4':
				if i + 2 <= len(v) - 1:
					if v[i + 2] == '4':
						i += 2
					else:
						i += 1
				else:
					print('YES')
					break
	else:
		print('NO')
		break
	i += 1
else:
	print('YES')


s = input()

def solve(s):
	for i in range(len(s)):
		if s[i] != '1' and s[i] != '4':
			return False
	if s[0] != '1':
		return False
	if '444' in s:
		return False
	return True
out = solve(s)
if out:
	print('YES')
else:
	print('NO')


a = input()
b = list(map(int, str(a)))
c = len(a)
d = 0
e = 0
for x in range(0, c):
	if b[x] == 1 or b[x] == 4:
		d += 1
if d != c:
	print('NO')
elif b[0] == 4:
	print('NO')
elif d == c and d <= 2 and (a != range(40, 49)) and (a != 4):
	print('YES')
else:
	for x in range(0, c - 2):
		if b[x] == b[x + 1] == b[x + 2] == 4:
			e += 1
	if e == 0:
		print('YES')
	else:
		print('NO')


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left

def L():
	return list(map(int, stdin.readline().split()))

def In():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())
P = 1000000007
n = input()
i = 0
flag = 1
while i <= len(n) - 1:
	if n[i:i + 3] == '144':
		i += 3
	elif n[i:i + 2] == '14':
		i += 2
	elif n[i:i + 1] == '1':
		i += 1
	else:
		flag = 0
		break
if flag:
	print('YES')
else:
	print('NO')


s = str(input())
i = 0
s += '00'
if s.count('1') + s.count('4') != len(s) - 2:
	print('NO')
else:
	while i < len(s) - 2:
		if s[i] == '1':
			if s[i + 1] != '4':
				i += 1
			elif s[i + 1] == '4':
				if s[i + 2] == '4':
					i += 3
				else:
					i += 2
			else:
				print('NO')
				break
		else:
			print('NO')
			break
	else:
		print('YES')


try:
	n = input()
	s = set(n)
	if (s == {'1', '4'} or s == {'1'} or s == {'4'}) and n[0] == '1':
		c = 0
		for i in range(1, len(n)):
			if n[i] == '4':
				c = c + 1
			else:
				c = 0
			if c == 3:
				print('NO')
				break
		else:
			print('YES')
	else:
		print('NO')
except:
	pass


n = input()
if n[0] != '1':
	print('NO')
	exit()
cnt4 = 0
for c in n:
	if c not in '14':
		print('NO')
		break
	elif c == '1':
		cnt4 = 0
	else:
		cnt4 += 1
		if cnt4 > 2:
			print('NO')
			break
else:
	print('YES')


def check(s):
	if len(s) == 0:
		return 1
	if len(s) == 1:
		if s != '1':
			return 0
		else:
			return 1
	elif s[0] == '1':
		return check(s[1:])
	elif s[0] == '4' and s[1] == '1':
		return check(s[2:])
	elif len(s) > 2:
		if s[0] == '4' and s[1] == '4' and (s[2] == '1'):
			return check(s[3:])
		else:
			return 0
n = input()
l = ['2', '3', '5', '6', '7', '8', '9', '0']
for i in n:
	if i in l:
		print('NO')
		exit(0)
l = list(n[::-1])
if check(n[::-1]) == 1:
	print('YES')
else:
	print('NO')


s = input()
fu = 0
for i in range(len(s)):
	if s[i] == '4' or s[i] == '1':
		continue
	else:
		fu = 1
		break
if s.count('444') or fu == 1 or s[0] == '4':
	print('NO')
else:
	print('YES')


s = str(input())
answer = True
i = 0
while i < len(s) and answer:
	if i + 2 < len(s) and s[i:i + 3] == '144':
		i += 3
	elif i + 1 < len(s) and s[i:i + 2] == '14':
		i += 2
	elif i < len(s) and s[i] == '1':
		i += 1
	else:
		answer = False
if answer:
	print('YES')
else:
	print('NO')


s = input()
a = s.replace('144', 'a')
a = a.replace('14', 'b')
a = a.replace('1', 'c')
for i in set(a):
	if i not in {'a', 'b', 'c'}:
		print('NO')
		break
else:
	print('YES')


s = input()
l = len(s)
cnt = 0
if s[0] == '1' and all((q == '' or q == '4' or q == '44' for q in s.split('1'))):
	cnt = 1
if cnt == 1:
	print('YES')
elif cnt == 0:
	print('NO')


a = input()
a = a.replace('144', ' ')
a = a.replace('14', ' ')
a = a.replace('1', ' ')
a = a.split()
if a == []:
	print('YES')
else:
	print('NO')


s = input()
if s.count('1') + s.count('4') != len(s) or s[0] != '1':
	print('NO')
else:
	for i in range(3, len(s)):
		if s[i] == '4' and s[i - 1] == '4' and (s[i - 2] == '4'):
			print('NO')
			break
	else:
		print('YES')


n = input()
a = 0
A = []
for i in n:
	A.append(i)
b = 0
c = 0
d = 0
for j in A:
	if j != '1' and j != '4':
		a = 1
		break
	elif j == '1':
		if b == 0:
			b = 1
		elif b == 1:
			if c == 1:
				c = 0
				d = 0
	elif j == '4':
		if b == 0 or d == 1:
			a = 1
			break
		elif b == 1:
			if c == 0:
				c = 1
			elif c == 1:
				d = 1
if a == 1:
	print('NO')
else:
	print('YES')


s = input()
print('YES' if set(s.replace('144', '!').replace('14', '!').replace('1', '!')) == {'!'} else 'NO')


inp = input('')
cnt = len(inp)
b = 1
t = 0
s = '/'
inp = inp + s
for i in range(len(inp)):
	i = t
	if t == cnt:
		break
	if inp[i] == '1' and inp[i + 1] == '4' and (inp[i + 2] == '4'):
		t = t + 3
	elif inp[i] == '1' and inp[i + 1] == '4':
		t = t + 2
	elif inp[i] == '1':
		t = t + 1
	else:
		b = 0
		break
if b == 0:
	print('NO')
else:
	print('YES')


w = input()
a = '1'
b = '14'
e = list(w)

def con(x):
	r = ''.join(map(str, x))
	return r
t = e[::-1]
s = 0
while s == 0 and len(e) != 0:
	if len(con(e)) < 3:
		if con(e) == a or con(e) == b or con(e) == '11':
			s = 1
			break
		else:
			s = 2
			break
	elif con(t[0:3]) == '441' or con(t[0:2]) == '41' or con(t[0:1]) == '1':
		del t[0]
		e = t[::-1]
	else:
		s = 2
		break
if s == 2:
	print('NO')
else:
	print('YES')


from re import sub
s = input()
s = sub('(144)', 'x', s)
s = sub('(14)', 'x', s)
s = sub('(1)', 'x', s)
if set(s) == set(['x']):
	print('YES')
else:
	print('NO')


n = input()
length = len(n)
tag = 0
count = 0
for i in range(0, length):
	if n[0] == '1' and (n[i] == '1' or n[i] == '4'):
		if n[i] == '4':
			count += 1
			if count >= 3:
				tag = 1
				break
			else:
				tag = 0
		else:
			count = 0
	else:
		tag = 1
		break
if tag == 1:
	print('NO')
else:
	print('YES')


n = input()
magic = set(['', '1', '14', '144'])
is_magic = True
suff = ''
for c in n:
	if c != '1':
		suff += c
	elif suff not in magic:
		is_magic = False
		break
	else:
		suff = '1'
if suff not in magic:
	is_magic = False
if is_magic:
	print('YES')
else:
	print('NO')


s = input()
if s[0] != '1':
	print('NO')
elif '444' in s:
	print('NO')
else:
	t = '02356789'
	i = 1
	for k in t:
		if k in s:
			i = 0
			break
	print(['NO', 'YES'][i])


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
s = [int(x) for x in list(input())]
for (i, v) in enumerate(s):
	if v != 1 and v != 4:
		print('NO')
		exit(0)
	if v == 4:
		if i == 0:
			print('NO')
			exit(0)
		elif s[i - 1] == 4:
			if i < 2:
				print('NO')
				exit(0)
			if s[i - 2] != 1:
				print('NO')
				exit(0)
print('YES')


n = input()
state = '1'
for l in n:
	if state == '1':
		if l != '1':
			print('NO')
			break
		state = '14'
	elif state == '14':
		if l == '1':
			state = '14'
		elif l == '4':
			state = '4'
		else:
			print('NO')
			break
	elif state == '4':
		if l == '1':
			state = '14'
		elif l == '4':
			state = '1'
		else:
			print('NO')
			break
else:
	print('YES')


s = input()
n = list(s)
if set(n) == {'1', '4'} or set(n) == {'4', '1'} or set(n) == {'1'}:
	if s.find('444') >= 0 or s[0] == '4':
		print('NO')
	else:
		print('YES')
else:
	print('NO')


def ok(L):
	M = [idx for (idx, e) in enumerate(L) if e == 1]
	for i in range(len(M) - 1):
		P = L[M[i]:M[i + 1]]
		if P.count(4) > 2:
			return 'NO'
	S = L[M[len(M) - 1]:len(L)]
	if S.count(4) > 2:
		return 'NO'
	return 'YES'
n = int(input(''))
L = [int(i) for i in str(n)]
if L.count(1) + L.count(4) != len(L) or 2 * L.count(1) < L.count(4) or L[0] != 1:
	print('NO')
else:
	print(ok(L))


def main():
	x = str(input())
	xix = int(x)
	xs = list(set(list(x)))
	if len(xs) == 1 and xs[0] == '1':
		print('YES')
	elif x[0] == '4':
		print('NO')
	elif len(xs) == 2:
		xs.sort()
		ncs = ''.join(xs)
		if ncs == '14':
			if len(x) >= 3 and x[0:3] == '441':
				print('NO')
			else:
				ind1 = x.find('444')
				if ind1 >= 0 or x == '414':
					print('NO')
				else:
					print('YES')
		else:
			print('NO')
	else:
		print('NO')
main()


s = input()
flag = True
if s[0] == '4':
	flag = False
s = s.split('1')
for i in s:
	if i != '' and i != '4' and (i != '44'):
		flag = False
		break
if flag == True:
	print('YES')
else:
	print('NO')


st = list(input())
a = -1
for i in range(len(st)):
	if a == -1:
		if st[i] == '1':
			a = 0
		else:
			a = 4
			break
	elif a == 0:
		if st[i] == '4':
			a = 1
		elif st[i] == '1':
			a = 0
		else:
			a = 4
			break
	elif a == 1:
		if st[i] == '4':
			a = 2
		elif st[i] == '1':
			a = 0
		else:
			a = 4
			break
	elif a == 2:
		if st[i] == '1':
			a = 0
		else:
			a = 4
			break
if a > 3:
	print('NO')
else:
	print('YES')


x = int(input())
s = str(x)
n = len(s)
i = 0
k = 'y'
while i < n:
	if i + 2 < n and i + 1 < n and (s[i] + s[i + 1] + s[i + 2] == '144'):
		i += 3
	elif i + 1 < n and s[i] + s[i + 1] == '14':
		i += 2
	elif s[i] == '1':
		i += 1
	else:
		k = 'n'
		break
if k == 'y':
	print('YES')
else:
	print('NO')


num = input()
judge = True
for i in list(num):
	if i != '1' and i != '4':
		judge = False
		break
if '444' in num or num[0] == '4' or num[0:1] == '44':
	judge = False
if judge:
	print('YES')
else:
	print('NO')


def magicNumber():
	s = input()
	i = 0
	size = len(s)
	while i < size:
		if s[i:i + 3] == '144':
			i = i + 3
		elif s[i:i + 2] == '14':
			i = i + 2
		elif s[i:i + 1] == '1':
			i = i + 1
		else:
			print('NO')
			return
	print('YES')
magicNumber()


n = input().strip()
ln = len(n)
s = set(n)

def is_magic(n, ln):
	state = 1
	if n[0] != '1':
		return False
	for i in range(ln):
		if n[i] == '1':
			state = 1
		elif n[i] == '4':
			state += 1
		else:
			return False
		if state > 3:
			return False
	return True
if is_magic(n, ln):
	print('YES')
else:
	print('NO')


def yesorno(n):
	count = len(n)
	length = count
	magicnumcreaters = {'1', '14', '144'}
	i = 0
	lst = ['0', '2', '3', '5', '6', '7', '8', '9']
	for char in n:
		if char in lst:
			print('NO')
			return
	while count != 0 and i < length - 2:
		if n[i] == '1' and n[i + 1] != '4':
			i += 1
			count -= 1
			continue
		elif n[i] == '1' and n[i + 1] == '4' and (n[i + 2] != '4'):
			i += 2
			count -= 2
			continue
		elif n[i] == '1' and n[i + 1] == '4' and (n[i + 2] == '4'):
			i += 3
			count -= 3
			continue
		else:
			i += 1
	if count == 2:
		if n[length - 2] == '1' and n[length - 1] != '4':
			count -= 1
		elif n[length - 2] == '1' and n[length - 1] == '4':
			count -= 2
	if count == 1:
		if n[length - 1] == '1':
			count -= 1
	if count == 0:
		print('YES')
	else:
		print('NO')
n = input()
yesorno(n)


a = input()
i = 0
flag = 0
while i < len(a):
	if a[i] == '1':
		if i + 1 < len(a) and a[i + 1] == '4':
			if i + 2 < len(a) and a[i + 2] == '4':
				i += 3
				continue
			elif i + 2 < len(a) and a[i + 2] == '1':
				i += 2
				continue
			elif i + 2 >= len(a):
				break
			else:
				flag = 1
				break
		elif i + 1 < len(a) and a[i + 1] == '1':
			i += 1
			continue
		elif i + 1 >= len(a):
			break
		else:
			flag = 1
			break
	else:
		flag = 1
		break
if flag == 1:
	print('NO')
else:
	print('YES')


s = input()
s1 = s.replace('144', '#')
s2 = s1.replace('14', '#')
s3 = s2.replace('1', '#')
s4 = s3.replace('#', '')
if len(s4) == 0:
	print('YES')
else:
	print('NO')


def magic_numbers(n):
	for i in range(len(n)):
		if len(n) >= 3 and n[0] == '1' and (n[1] == '4') and (n[2] == '4'):
			n = n[3:len(n)]
		elif len(n) >= 2 and n[0] == '1' and (n[1] == '4'):
			n = n[2:len(n)]
		elif len(n) >= 1 and n[0] == '1':
			n = n[1:len(n)]
		else:
			pass
	if n:
		print('NO')
	else:
		print('YES')
n = input()
magic_numbers(n)


n = input()
f = 1
if n[0] != '1':
	f = 0
if n.count('444') > 0:
	f = 0
for i in n:
	if i not in ['1', '4']:
		f = 0
		break
print('NO') if f == 0 else print('YES')


n = list(input())
k = 0
mas = []
if n[0] != '1':
	print('NO')
	exit()
for i in range(len(n)):
	if n[i] == '1' or n[i] == '4':
		if n[i] == '4':
			k += 1
			if k > 2:
				print('NO')
				exit()
		else:
			k = 0
	else:
		print('NO')
		exit()
print('YES')


def go():
	a = input()
	index = 0
	while index < len(a) - 3:
		if a[index:index + 3] == '144':
			index += 3
		elif a[index:index + 2] == '14':
			index += 2
		elif a[index:index + 1] == '1':
			index += 1
		else:
			return 'NO'
	if len(a) - index == 3:
		if a[index:len(a)] == '144':
			return 'YES'
		elif a[index:index + 1] == '1' and a[index + 1:index + 2] == '1' and (a[index + 2:index + 3] == '1'):
			return 'YES'
		elif a[index:index + 1] == '1' and a[index + 1:index + 3] == '14':
			return 'YES'
		elif a[index:index + 2] == '14' and a[index + 2:index + 3] == '1':
			return 'YES'
		return 'NO'
	if len(a) - index == 2:
		if a[index:len(a)] == '14':
			return 'YES'
		elif a[index:index + 1] == '1' and a[index + 1:index + 2] == '1':
			return 'YES'
		return 'NO'
	if len(a) - index == 1:
		if a[index:len(a)] == '1':
			return 'YES'
		return 'NO'
print(go())


a = input()
n = len(a)
count = 0
i = 0
while i < n:
	if i + 2 < n and a[i:i + 3] == '144':
		i = i + 3
		continue
	elif i + 1 < n and a[i:i + 2] == '14':
		i = i + 2
		continue
	elif a[i] == '1':
		i = i + 1
		continue
	else:
		print('NO')
		break
if i == n:
	print('YES')


n = 2
s = input()
if s != '':
	for i in s:
		if i != '1' and i != '4':
			print('NO')
			break
		elif i == '4':
			n += 1
			if n == 3:
				print('NO')
				break
		else:
			n = 0
	else:
		print('YES')
else:
	print('NO')


s = '#'.join(input().split('144'))
s = '#'.join(s.split('14'))
s = '#'.join(s.split('1'))
s = list(s)
flag = 0
for ch in s:
	if ch != '#':
		flag = 1
		break
if flag == 0:
	print('YES')
else:
	print('NO')


import re
line = input()
match = re.match('([1][4]{0,2})+', line)
if match and match.group(0) == line:
	print('YES')
else:
	print('NO')


def solve():
	num = input()
	numm = [int(x) for x in num]
	n = len(numm)
	for i in range(n):
		if numm[i] != 1 and numm[i] != 4:
			print('NO')
			return
	if numm[0] == 4:
		print('NO')
		return 0
	FLAG = 0
	for i in range(2, n):
		FLAG = 0
		if numm[i] == 1:
			FLAG = 1
		if numm[i] == 4:
			if numm[i - 1] == 1:
				FLAG = 1
			elif numm[i - 2] == 1:
				FLAG = 1
		if FLAG == 0:
			print('NO')
			return
	print('YES')
solve()


line = input()
B = [str(i) for i in line]
if B[0] != '1':
	print('NO')
else:
	A = [str(i) for i in line.split('1')]
	while '' in A:
		A.remove('')
	while '4' in A:
		A.remove('4')
	while '44' in A:
		A.remove('44')
	if len(A) == 0:
		print('YES')
	else:
		print('NO')


a = input()
x = 0
yes = 1
while x < len(a):
	if a[x] == '1':
		x += 1
		if x == len(a):
			break
		if a[x] == '4':
			x += 1
			if x == len(a):
				break
			if a[x] == '4':
				x += 1
				if x == len(a):
					break
	else:
		yes = 0
		x += 1
print(['NO', 'YES'][yes])


n = input()
if n.count('1') + n.count('4') != len(n):
	print('NO')
else:
	i = 0
	while i != len(n):
		if n[i:i + 3] == '144':
			i += 3
		elif n[i:i + 2] == '14':
			i += 2
		elif n[i:i + 1] == '1':
			i += 1
		else:
			print('NO')
			break
		if i == len(n):
			print('YES')


import sys
import math
n = sys.stdin.readline()
c = 0
i = 0
while i < len(n) - 1:
	if n[i] == '1':
		i += 1
		while n[i] == '4':
			c += 1
			i += 1
		if c > 2:
			print('NO')
			exit()
		else:
			c = 0
	else:
		print('NO')
		exit()
print('YES')


x = input()

def searching(s):
	if '144' in s:
		s = s.replace('144', 'a')
	if '14' in s:
		s = s.replace('14', 'a')
	if '1' in s:
		s = s.replace('1', 'a')
	if s.isalpha():
		return True
	else:
		return False
b = searching(str(x))
print('YES' if b else 'NO')


s = input()
index = 0
ans = True
length = len(s)
for i in range(length):
	if s[i] is not '1' and s[i] is not '4':
		ans = False
		break
if s[0] is not '1':
	ans = False
if s.find('444') >= 0:
	ans = False
if ans is True:
	print('YES')
else:
	print('NO')


x = int(input())
x = str(x)
str1 = ''
str3 = ''
list1 = list(x)
list2 = []
list3 = []
list1 = x.split('144')
for y in list1:
	list2 += y.split('14')
for wi in list2:
	list3 += wi.split('1')
for wi in range(list3.count('')):
	list3.remove('')
if not list3:
	print('YES')
else:
	print('NO')


n = input('')
if n[0] != '1':
	print('NO')
else:
	for i in range(1, len(n)):
		if n[i] == '2' or n[i] == '3' or n[i] == '5' or (n[i] == '6') or (n[i] == '7') or (n[i] == '8') or (n[i] == '9') or (n[i] == '0'):
			print('NO')
			break
		elif n[i] == '4':
			if i != len(n) - 1:
				if n[i - 1] == '4' and n[i + 1] == '4':
					print('NO')
					break
	else:
		print('YES')


def solve(num):
	str1 = list(str(num))
	if num == 1:
		return 'YES'
	elif num > 1 and num < 11:
		return 'NO'
	prevPrev = str1[0]
	prev = str1[1]
	if prevPrev != '1':
		return 'NO'
	if prev != '1' and prev != '4':
		return 'NO'
	length = len(str1)
	for i in range(2, length):
		current = str1[i]
		temp14 = prev + current
		temp144 = prevPrev + prev + current
		if current != '1' and temp14 != '14' and (temp144 != '144'):
			return 'NO'
		prevPrev = prev
		prev = current
	return 'YES'
num = int(input())
ans = solve(num)
print(ans)


n = input()
flag = 0
if n[0] != '1':
	flag = 1
for i in range(0, len(n)):
	if n[i] != '1' and n[i] != '4':
		flag = 1
		break
for i in range(1, len(n) - 1):
	if n[0] != '1':
		flag = 1
		break
	if n[i] == '4':
		if n[i - 1] == '4' and n[i + 1] == '4':
			flag = 1
if flag == 1:
	print('NO')
else:
	print('YES')


a = input()
a = a.replace('144', ' ')
a = a.replace('14', ' ')
a = a.replace('1', ' ')
a = a.strip()
if a != '':
	print('NO')
else:
	print('YES')


arr = input()
t = len(arr)
a = arr.count('1')
b = arr.count('14')
c = arr.count('144')
print('YES' if a + b + c == t else 'NO')


from sys import stdin

def main():
	it = iter(stdin.readline().strip())
	le = 2
	try:
		while True:
			c = next(it)
			if c == '1':
				le = 0
			elif c == '4':
				if le < 2:
					le += 1
				else:
					return 'NO'
			else:
				return 'NO'
	except StopIteration:
		return 'YES'
print(main())


a = input()
b = a.replace('144', ' ')
c = b.replace('14', ' ')
d = c.replace('1', ' ')
if len(d) == d.count(' '):
	print('YES')
else:
	print('NO')


n = [str(x) for x in input().split()][0]
if len(n) == 0:
	print('NO')
solutions = [n[0] == '1']
for index in range(1, len(n)):
	if n[index] == '1':
		solutions.append(solutions[-1])
	elif index - 1 >= 0 and n[index - 1:index + 1] == '14':
		if len(solutions) < 2:
			solutions.append(True)
		else:
			solutions.append(solutions[-2])
	elif index - 2 >= 0 and n[index - 2:index + 1] == '144':
		if len(solutions) < 3:
			solutions.append(True)
		else:
			solutions.append(solutions[-3])
	else:
		solutions.append(False)
if solutions[-1]:
	print('YES')
else:
	print('NO')


data = input()
i = 0
ans = False
while i < len(data):
	if i < len(data) - 2:
		if data[i:i + 3] == '144':
			i += 3
		elif data[i:i + 2] == '14':
			i += 2
		elif data[i] == '1':
			i += 1
		else:
			ans = True
			break
	elif i < len(data) - 1:
		if data[i:i + 2] == '14':
			i += 2
		elif data[i] == '1':
			i += 1
		else:
			ans = True
			break
	elif data[i] == '1':
		i += 1
	else:
		ans = True
		break
if ans == False:
	print('YES')
else:
	print('NO')


stri = input()
sum1 = stri.count('1') + stri.count('4')
if stri[0] == '1' and sum1 == len(stri) and ('444' not in stri):
	print('YES')
else:
	print('NO')


n = input()
a = list(n)
b = n.split('1')
flag = True
if a[0] != '1':
	flag = False
for i in b:
	if len(i) > 2:
		flag = False
		break
for i in a:
	if i == '1' or i == '4':
		pass
	else:
		flag = False
		break
if flag is False:
	print('NO')
else:
	print('YES')


s = input()
x = s.replace('144', 'c')
y = x.replace('14', 'b')
z = y.replace('1', 'a')
l = len(z)
c = z.count('a') + z.count('b') + z.count('c')
if c == l:
	print('YES')
else:
	print('NO')


x = input()
pos = 0
ok = True
while pos < len(x):
	if pos + 2 < len(x):
		if x[pos:pos + 3] == '144':
			pos += 3
			continue
	if pos + 1 < len(x):
		if x[pos:pos + 2] == '14':
			pos += 2
			continue
	if x[pos] == '1':
		pos += 1
	else:
		ok = False
		break
print('YES' if ok else 'NO')


n = int(input())
lst = list(str(n))
for i in range(len(lst) - 2):
	if lst[i] == '1' and lst[i + 1] == '4' and (lst[i + 2] == '4'):
		lst[i] = 0
		lst[i + 1] = 0
		lst[i + 2] = 0
for i in range(len(lst) - 1):
	if lst[i] == '1' and lst[i + 1] == '4':
		lst[i] = 0
		lst[i + 1] = 0
for i in range(len(lst)):
	if lst[i] == '1':
		lst[i] = 0
lst2 = [int(item) for item in lst]
if any(lst):
	print('NO')
else:
	print('YES')


s = input()
if len(s) == 1 and s == '1':
	print('YES')
elif len(s) == 2 and (s == '14' or s == '11'):
	print('YES')
elif len(s) >= 3 and ('1' in s or '4' in s):
	if '444' in s:
		print('NO')
	elif s.count('1') + s.count('4') == len(s) and s[0] == '1':
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = input()

def is_maginal(num: str) -> bool:
	if num[0] == '4':
		return False
	if num.find('444') != -1:
		return False
	for i in num:
		if i != '1' and i != '4':
			return False
	return True
if is_maginal(n):
	print('YES')
else:
	print('NO')


s = input()
p = s
s = s.replace('144', '#')
s = s.replace('14', '#')
s = s.replace('1', '#')
if s.count('#') == len(s):
	print('YES')
else:
	print('NO')


a = input()
if a[0] != '1':
	print('NO')
else:
	r = 0
	p = 0
	for i in a:
		if i != '1' and i != '4':
			r = 1
		elif i == '4':
			p += 1
			if p > 2:
				r = 1
		else:
			p = 0
		if r == 1:
			break
	if r == 1:
		print('NO')
	else:
		print('YES')


import sys
n = input()
for i in range(len(n)):
	if n[i] != '1' and n[i] != '4':
		print('NO')
		sys.exit()
while len(n) > 0:
	s = n[0:3]
	if s == '144':
		n = n[3:]
	elif s[0:2] == '14':
		n = n[2:]
	elif s[0] == '1':
		n = n[1:]
	else:
		print('NO')
		sys.exit()
print('YES')


n = input()
l = ['144', '14', '1']
y = len(n)
for i in range(y):
	for t in l:
		if n.startswith(t):
			n = n.replace(t, '', 1)
			break
if n:
	print('NO')
else:
	print('YES')


number = input()

def is_ones_fours(num):
	return num == '1' or num == '4'

def proper_fours(number):
	return '444' not in number and number[0] != '4'

def Magic_Number(number):
	return all(map(is_ones_fours, number)) and proper_fours(number)
if Magic_Number(number):
	print('YES')
else:
	print('NO')


num = input()
p = True
n = len(num)
i = 0
if n == 1:
	if num[i] != '1':
		p = False
else:
	while i < n:
		if i < n - 2:
			if num[i] == '1':
				if num[i + 1] == '4':
					if num[i + 2] == '1':
						i += 2
					elif num[i + 2] == '4':
						i += 3
					else:
						p = False
						break
				elif num[i + 1] == '1':
					i += 1
				else:
					p = False
					break
			else:
				p = False
				break
		elif i == n - 2:
			if num[i] == '1':
				if num[i + 1] == '4':
					i += 2
				elif num[i + 1] == '1':
					i += 1
				else:
					p = False
					break
			else:
				p = False
				break
		elif num[i] == '1':
			i += 1
		else:
			p = False
			break
if p is True:
	print('YES')
else:
	print('NO')


s = input()
if s[0] == '4':
	print('NO')
else:
	t = s.find('444')
	x = False
	for i in range(0, len(s)):
		if s[i] != '1' and s[i] != '4':
			x = True
			break
	if t != -1 or x is True:
		print('NO')
	else:
		print('YES')


r = str.replace
print('YES' if all((i == '-' for i in r(r(r(input(), '144', '-'), '14', '-'), '1', '-'))) else 'NO')


import re
n = input()
n = n.replace('144', '-')
n = n.replace('14', '-')
n = n.replace('1', '-')
n = n.replace('-', '')
if n == '':
	print('YES')
else:
	print('NO')


n = input()
while True:
	if '144' in n:
		g = n.find('144')
		n = n.replace('144', '')
		if g < len(n):
			if n[g] != '1':
				print('NO')
				break
	if '14' in n:
		n = n.replace('14', '')
	if '1' in n:
		n = n.replace('1', '')
	if len(n) == 0:
		print('YES')
		break
	if len(n) != 0:
		print('NO')
		break


s = input()
i = 0
n = len(s)
ok = True
while i < n:
	if i + 2 < n:
		if s[i:i + 3] == '144' or s[i:i + 2] == '14' or s[i] == '1':
			if s[i:i + 3] == '144':
				i += 3
			elif s[i:i + 2] == '14':
				i += 2
			else:
				i += 1
		else:
			ok = False
			break
	elif i + 1 < n:
		if s[i:i + 2] == '14' or s[i] == '1':
			if s[i:i + 2] == '14':
				i += 2
			else:
				i += 1
		else:
			ok = False
			break
	else:
		if s[i] != '1':
			ok = False
		i += 1
if ok == True:
	print('YES')
else:
	print('NO')


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	s = S()
	t = 9
	for c in s:
		if c == '4':
			t += 1
			if t > 2:
				return 'NO'
		elif c == '1':
			t = 0
		else:
			return 'NO'
	return 'YES'
print(main())


n = input()
a = 0
b = 0
c = 0
for i in range(len(n)):
	if n[i] == '1':
		a += 1
	elif n[i] == '4':
		b += 1
if '444' in n:
	c = 1
if a + b == len(n) and n[0] != '4' and (c == 0):
	print('YES')
else:
	print('NO')


s = input()
p = True
if '144' in s:
	s = s.replace('144', 'a')
if '14' in s:
	s = s.replace('14', 'a')
if '1' in s:
	s = s.replace('1', 'a')
for i in s:
	if i.isdigit():
		p = False
if p == True:
	print('YES')
else:
	print('NO')


print('YNEOS'[len(input().replace('144', ' ').replace('14', ' ').replace('1', ' ').replace(' ', '')) > 0::2])


def main():
	n = [ch for ch in input()]
	for d in n:
		if d not in ['1', '4']:
			print('NO')
			return
	f = 69
	for d in n:
		if d == '1':
			f = 0
		elif f < 2:
			f += 1
		else:
			print('NO')
			return
	print('YES')
main()


import math
import sys
import collections

def getdict(n):
	d = {}
	if type(n) is list:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)
s = input()
print('YES ') if s.count('1') + s.count('4') == len(s) and '444' not in s and (s[0] != '4') else print('NO')


n = input()
good = True
while n != '' and good:
	if n.endswith('144'):
		n = n[:-3]
	elif n.endswith('14'):
		n = n[:-2]
	elif n.endswith('1'):
		n = n[:-1]
	else:
		good = False
print('YES' if good else 'NO')


s = input()
i = 0
f = 0
n = len(s)
while i < n:
	if s[i] == '1':
		if i + 1 < n and s[i + 1] == '4':
			if i + 2 < n and s[i + 2] == '4':
				i += 3
			else:
				i += 2
		else:
			i += 1
	else:
		f = -1
		break
if f == -1:
	print('NO')
else:
	print('YES')


x = input()
z = 0
a = 0
for i in x:
	if i == '1':
		z = 1
	elif z == 1 and i == '4':
		z = 2
	elif z == 2 and i == '4':
		z = 3
	elif z == 3 and i == '4':
		a = 1
		break
	else:
		a = 1
		break
if a == 1:
	print('NO')
else:
	print('YES')


a = input()
x = [len(t) for t in a.split('1')]
if a.count('1') + a.count('4') != len(a) or a[0] == '4':
	print('NO')
elif x.count(0) + x.count(1) + x.count(2) != len(x):
	print('NO')
else:
	print('YES')


s = input().strip()
cm = '.' * len(s)
s = s.replace('144', '...')
s = s.replace('14', '..')
s = s.replace('1', '.')
print(['YES', 'NO'][s != cm])


a = int(input())
a = str(a)
s = 'YES'
for i in range(len(a)):
	if a[0] != '1':
		s = 'NO'
		break
	elif a[i] == '1':
		pass
	elif a[i] == '4':
		if a[i - 1] == '1':
			pass
		if a[i - 1] == '4':
			if a[i - 2] == '1':
				pass
			else:
				s = 'NO'
				break
	else:
		s = 'NO'
		break
print(s)


def check(s, dep):
	if len(s) == 0:
		return True
	flag = False
	if s[-1:] == '1':
		flag = flag or check(s[:-1], dep + 1)
	if s[-2:] == '14':
		flag = flag or check(s[:-2], dep + 1)
	if s[-3:] == '144':
		flag = flag or check(s[:-3], dep + 1)
	return flag
s = input()
if check(s, 0):
	print('YES')
else:
	print('NO')


def calc(n):
	n = str(n)
	for i in range(len(n)):
		if n[i] not in ['1', '4']:
			return 'NO'
		if n[i] == '1':
			continue
		if n[i] == '4':
			if i > 0 and n[i - 1] == '1' or (i > 1 and n[i - 1] == '4' and (n[i - 2] == '1')):
				continue
			else:
				return 'NO'
	return 'YES'
n = int(input())
print(calc(n))


def f(x):
	import re
	l = ['1', '4']
	for i in set(list(str(x))):
		if i not in l:
			return 'NO'
	x = str(x)
	for i in range(len(x) - 2):
		if (x[i] == x[i + 1]) & (x[i] != '1'):
			if x[i + 1] == x[i + 2]:
				return 'NO'
	x = ''.join([i for i in re.sub('144', '0', x) if i != '0'])
	x = ''.join([i for i in re.sub('14', '0', x) if i != '0'])
	x = ''.join([i for i in re.sub('1', '0', x) if i != '0'])
	if x == '':
		return 'YES'
	else:
		return 'NO'
x = int(input())
print(f(x))


string = input()
str1 = '1'
str2 = '14'
str3 = '144'
count1 = string.count(str1)
count2 = string.count(str2)
count3 = string.count(str3)
count1 = count1 - count2
count2 = count2 - count3
if count1 + 2 * count2 + 3 * count3 == len(string):
	print('YES')
else:
	print('NO')


n = input()
count = 0
for i in range(len(n)):
	if n[i] != '1' and n[i] != '4':
		count = 1
		break
if n[0] == '4':
	count = 1
t = n.count('444')
if t > 0:
	count = 1
if count == 0:
	print('YES')
else:
	print('NO')


import re
n = input()
mat = re.compile('(^1+$)|^([1]+(4{0,2}))+$')
res = mat.search(n)
if res:
	print('YES')
else:
	print('NO')


def fun(a, st):
	for i in st:
		if a in i:
			return 1
	return 0
st = input().strip().split(' ')
aa = ['144', '14', '1']
for a in aa:
	while fun(a, st):
		for i in st:
			if a in i:
				bb = i.split(a)
				del st[st.index(i)]
				for b in bb:
					if b:
						st.append(b)
ans = 1
for x in st:
	if x not in aa:
		ans = 0
print('YES') if ans else print('NO')


from itertools import product
l = ['1', '14', '144']
ans = list()
c = 0
for i in range(1, 10):
	k = product(l, repeat=i)
	for j in k:
		ans.append(j)
num = [''.join(i) for i in ans]
n = input()
if n in num:
	print('YES')
else:
	print('NO')


def main():
	n = input()
	state = -1
	for i in n:
		if state == -1:
			state = 0 if i == '1' else 3
		elif state == 0:
			state = 0 if i == '1' else 1 if i == '4' else 3
		elif state == 1:
			state = 0 if i == '1' else 2 if i == '4' else 3
		elif state == 2:
			state = 0 if i == '1' else 3
		elif state == 3:
			break
	if state in [0, 1, 2]:
		print('YES')
	else:
		print('NO')
main()


def magic(s):
	if '144' in s:
		s = s.replace('144', 'ramu')
	if '14' in s:
		s = s.replace('14', 'ramu')
	if '1' in s:
		s = s.replace('1', 'ramu')
	for i in s:
		if i.isdigit():
			return 'NO'
	return 'YES'
n = int(input())
print(magic(str(n)))


n = input().strip()
for i in '02356789':
	if i in n:
		print('NO')
		break
else:
	if '444' in n:
		print('NO')
	elif n[0] == '4':
		print('NO')
	else:
		print('YES')


n = input()

def magicNumbers(n):
	if n[0] != '1':
		return 'NO'
	for i in range(len(n)):
		if n[i] not in '14' or n[i:i + 3] == '444':
			return 'NO'
	else:
		return 'YES'
print(magicNumbers(n))


(c, s) = (0, input())
for i in range(len(s)):
	if s[i] != '1' and s[i] != '4':
		c = 1
	if s[i] == '4' and (not (i < len(s) - 1 and i > 0 and (s[i - 1] == '1' or s[i + 1] == '4')) and (not (i > 0 and s[i - 1] == '1')) and (not (i > 1 and s[i - 2:i] == '14'))):
		c = 1
print('NO') if c else print('YES')


n = int(input())
SO = str(n)
s = list(str(n))
C = 0
for i in range(len(s)):
	if s[i] != '1' and s[i] != '4':
		C = -1
if s[0] != '1':
	C = -1
if '444' in SO:
	C = -1
if C == 0:
	print('YES')
else:
	print('NO')


mp = {}
for s in ['1', '14', '144', '11']:
	mp[s] = True

def ok(s):
	if not s:
		return True
	if s in mp:
		return mp[s]
	if len(s) <= 2:
		return False
	if s[0:3] == '144':
		return ok(s[3:])
	if s[0:2] == '14':
		return ok(s[2:])
	if s[0] != '1':
		return False
	return ok(s[1:])
print(('NO', 'YES')[ok(input())])


import sys

def magic(num):
	while num > 0:
		if num % 1000 == 144:
			num //= 1000
		elif num % 100 == 14:
			num //= 100
		elif num % 10 == 1:
			num //= 10
		else:
			return False
	return True

def main():
	x = int(sys.stdin.readline())
	print('YES') if magic(x) else print('NO')
main()


_1 = 'Weird Algorithm'
l = []
_2 = 'Missing Number'
FORMULA_SUM_0_TO_N = 'n * (n+1) / 2'
_3 = 'Repetitions'
_4 = 'Increasing Array'
_5 = 'Permutations'
_6 = 'Number Spiral'
_7 = 'Two Knights'
_8 = 'Two Sets'
_9 = 'Bit Strings'
_10 = 'Trailing Zeros'
_11 = 'Coin Piles'
_12 = 'Palindrome Reorder'
s = list(str(input()))
flag = True
c = 0
v = [0] * len(s)
for i in range(len(s)):
	if s[i] == '1' or s[i] == '4':
		pass
	else:
		flag = False
if s[0] == '4':
	flag = False
if flag:
	for i in range(1, len(s)):
		if s[i] == '4':
			v[i] = v[i - 1] + 1
	if max(v) > 2:
		flag = False
if flag:
	print('YES')
else:
	print('NO')


s = input()
if s[0] != '1':
	print('NO')
elif '444' in s:
	print('NO')
elif set(map(str, (2, 3, 5, 6, 7, 8, 9, 0))) & set(list(s)):
	print('NO')
else:
	print('YES')


n = input()
n = n[::-1]
nums = {'1', '4'}
state = 0
for i in range(len(n)):
	if n[i] not in nums:
		print('NO')
		exit()
	if n[i] == '4' and state == 0:
		state = 1
	elif n[i] == '4' and state == 1:
		state = 2
	elif n[i] == '1' and state == 1:
		state = 0
	elif state == 2 and n[i] == '1':
		state = 0
	elif state == 2 and n[i] != '1':
		print('NO')
		exit()
if state == 0:
	print('YES')
else:
	print('NO')


import sys
import math
input = sys.stdin.readline

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
n = input().strip()
s = ''
while '144' in n:
	if n.count('144') >= 2:
		n = n.replace('144', '', 1)
	else:
		(n, s) = n.split('144')
if '14' in n or '14' in s:
	n = n.replace('14', '')
	s = s.replace('14', '')
if '1' in n or '1' in s:
	n = n.replace('1', '')
	s = s.replace('1', '')
if n == '' and s == '':
	print('YES')
else:
	print('NO')


s = input()
streak4 = 0
bad = False
if s[0] != '1':
	bad = True
for c in s:
	if c == '1':
		streak4 = 0
	elif c == '4':
		if streak4 == 2:
			bad = True
			break
		else:
			streak4 += 1
	else:
		bad = True
		break
if bad:
	print('NO')
else:
	print('YES')


s = input()

def solve(l):
	if l == -1:
		return 'YES'
	if s[l] == '1':
		return solve(l - 1)
	if s[l] != '1' and s[l] != '4':
		return 'NO'
	if l - 1 < 0:
		return 'NO'
	if s[l - 1] == '1':
		return solve(l - 2)
	if l - 2 < 0:
		return 'NO'
	if s[l - 2] == '1':
		return solve(l - 3)
	return 'NO'
print(solve(len(s) - 1))


inpt = str(input())
while inpt != '':
	if inpt[:3] == '144':
		inpt = inpt[3:]
	elif inpt[:2] == '14':
		inpt = inpt[2:]
	elif inpt[0] == '1':
		inpt = inpt[1:]
	else:
		print('NO')
		break
if inpt == '':
	print('YES')


s = input()
n = len(s)
i = 0
stat = False
while True:
	if i == n:
		stat = True
		break
	if i + 3 <= n and s[i:i + 3] == '144':
		i += 3
		continue
	elif i + 2 <= n and s[i:i + 2] == '14':
		i += 2
		continue
	elif i + 1 <= n and s[i:i + 1] == '1':
		i += 1
		continue
	else:
		stat = False
		break
print(['NO', 'YES'][stat])


n = input()
i = 0
res = True
while i < len(n) - 2:
	if n[i] == '1':
		if n[i + 1] == '4':
			if n[i + 2] == '4':
				i += 3
			else:
				i += 2
		else:
			i += 1
	else:
		res = False
		break
if not res:
	print('NO')
elif i < len(n):
	if i < len(n) - 1:
		if n[i] == '1':
			if n[i + 1] == '4' or n[i + 1] == '1':
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
	elif n[i] == '1':
		print('YES')
	else:
		print('NO')
elif res:
	print('YES')
else:
	print('NO')


from sys import stdin
s = stdin.readline().rstrip()
cur_len = 0
m = 0
for (i, char) in enumerate(s):
	if char == '4':
		cur_len += 1
		m = max(m, cur_len)
		if i == 0:
			print('NO')
			exit()
	elif char == '1':
		cur_len = 0
	else:
		print('NO')
		exit()
if m >= 3:
	print('NO')
else:
	print('YES')


num = input()

def isMagic(n):
	if n == '':
		return True
	elif n[-1] == '1':
		return isMagic(n[:-1])
	elif n[-2:] == '14':
		return isMagic(n[:-2])
	elif n[-3:] == '144':
		return isMagic(n[:-3])
	else:
		return False
if isMagic(num):
	print('YES')
else:
	print('NO')


number = input()
if '444' in number:
	print('NO')
elif number[0] == '1':
	for i in number:
		if i != '1' and i != '4':
			print('NO')
			break
	else:
		print('YES')
else:
	print('NO')


import re
x = input()
print('YES' if re.match('(14?4?)*$', x) else 'NO')


n = input()
d = {'1': True, '14': True, '144': True}
s = ''
for i in n[::-1]:
	s = i + s
	if d.get(s, False):
		s = ''
if s == '':
	print('YES')
else:
	print('NO')


__copyright__ = ''
__author__ = 'Son-Huy TRAN'
__email__ = 'sonhuytran@gmail.com'
__doc__ = ''
__version__ = '1.0'

def is_magic_number(number: str) -> bool:
	if number[0] != '1' or '444' in number:
		return False
	for char in number:
		if char != '1' and char != '4':
			return False
	return True

def main() -> int:
	number = input()
	print('YES' if is_magic_number(number) else 'NO')
	return 0
exit(main())


num = input()
if num[0] != '1':
	print('NO')
else:
	for x in range(len(num) - 2):
		if num[x] == num[x + 1] == num[x + 2] == '4' or (num[x] != '4' and num[x] != '1'):
			print('NO')
			break
	else:
		for x in num:
			if x != '4' and x != '1':
				print('NO')
				break
		else:
			print('YES')


n = input()
nums = '02356789'
NO = 0
for i in range(8):
	if n[0] != '1':
		print('NO')
		NO += 1
		break
	if nums[i] in n:
		print('NO')
		NO += 1
		break
if NO == 0:
	fours = 0
	no = 0
	for i in range(len(n)):
		if n[i] == '4':
			fours += 1
		else:
			fours = 0
		if fours == 3:
			print('NO')
			no += 1
			break
	if no == 0:
		print('YES')


magic = input().strip()
bad = '23567890'
n = len(magic)
i = 0
if magic[0] != '1':
	print('NO')
elif '444' in magic:
	print('NO')
else:
	for char in bad:
		if char in magic:
			print('NO')
			break
	else:
		print('YES')


word = input().strip()
while word.count('X') != len(word):
	if '144' in word:
		word = word.replace('144', 'X')
	elif '14' in word:
		word = word.replace('14', 'X')
	elif '1' in word:
		word = word.replace('1', 'X')
	else:
		print('NO')
		break
if word.count('X') == len(word):
	print('YES')


import sys, threading, os.path
import collections, heapq, math, bisect
import string
from platform import python_version
import itertools
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)

def main():
	if os.path.exists('input.txt'):
		input = open('input.txt', 'r')
	else:
		input = sys.stdin
	n = str(input.readline().rstrip('\n'))
	j = 0
	sol = 'YES'
	for i in range(len(n)):
		if j >= len(n):
			break
		if j + 2 < len(n) and n[j] + n[j + 1] + n[j + 2] == '144':
			j += 3
		elif j + 1 < len(n) and n[j] + n[j + 1] == '14':
			j += 2
		elif n[j] == '1':
			j += 1
		else:
			sol = 'NO'
			break
	output = sol
	if os.path.exists('output.txt'):
		open('output.txt', 'w').writelines(str(output))
	else:
		sys.stdout.write(str(output))
main()


import sys
import math

def main():
	s = sys.stdin.readline().strip()
	s = s.replace('144', '*')
	s = s.replace('14', '*')
	s = s.replace('1', '*')
	print('NYOE S'[s == '*' * len(s)::2])
main()


def magic(n):
	s = str(n)
	if len(s) == 0:
		return True
	elif len(s) >= 3 and s[:3] == '144':
		return magic(s[3:])
	elif len(s) >= 2 and s[:2] == '14':
		return magic(s[2:])
	elif len(s) >= 1 and s[:1] == '1':
		return magic(s[1:])
	else:
		return False
n = int(input())
if magic(n):
	ans = 'YES'
else:
	ans = 'NO'
print(ans)


i = [j for j in input()]
t = 0
found = 0
while t < len(i):
	if i[t] == '1':
		if t + 1 < len(i) and i[t + 1] == '4':
			if t + 2 < len(i) and i[t + 2] == '4':
				t += 3
			else:
				t += 2
		else:
			t += 1
	else:
		found = 1
		print('NO')
		break
if found == 0:
	print('YES')


s = input()
ind = 0
var = 0
while ind < len(s):
	if len(s) - ind >= 3:
		if s[ind] + s[ind + 1] + s[ind + 2] == '144':
			ind += 3
			continue
	if len(s) - ind >= 2:
		if s[ind] + s[ind + 1] == '14':
			ind += 2
			continue
	if len(s) - ind >= 1:
		if s[ind] == '1':
			ind += 1
			continue
	var = 1
	break
if var == 0:
	print('YES')
else:
	print('NO')


n = input()
a = n.count('1')
b = n.count('4')
if len(n) == a + b:
	if '444' in n or n[0] == '4':
		print('NO')
	else:
		print('YES')
else:
	print('NO')


magNum = input()
idx = 0
while idx < len(magNum):
	if magNum[idx] == '4':
		print('NO')
		break
	elif magNum[idx] == '1':
		if idx + 1 < len(magNum):
			if magNum[idx + 1] == '1':
				idx += 1
			elif magNum[idx + 1] == '4':
				if idx + 2 < len(magNum):
					if magNum[idx + 2] == '1':
						pass
					elif magNum[idx + 2] == '4':
						idx += 1
				idx += 2
			else:
				idx += 1
		else:
			idx += 1
	else:
		print('NO')
		break
else:
	print('YES')


n = str(input())
flag = 1
sum = 0
for i in range(0, len(n), 1):
	if sum > 0 and sum < 3 and (n[i] == '4'):
		sum += 1
	elif n[i] == '1':
		sum = 1
	else:
		flag = 0
if flag:
	print('YES')
else:
	print('NO')


n = input()
printed = False
if n[0] != '1':
	print('NO')
	printed = True
if '444' in n and (not printed):
	print('NO')
	printed = True
if not printed:
	for i in n:
		if i == '1' or i == '4':
			continue
		print('NO')
		printed = True
		break
if not printed:
	print('YES')


a = input()
n = a.split('1')
b = ['4', '44']
k = 0
if a[0] != '1':
	print('NO')
else:
	for i in n:
		if i != '':
			if i not in b:
				k += 1
				print('NO')
				break
	if k == 0:
		print('YES')


def mn(s):
	c4 = -1
	for d in s:
		if d == '4':
			c4 += 1
			if c4 in (0, 3):
				return 'NO'
		elif d == '1':
			c4 = 0
		else:
			return 'NO'
	return 'YES'
print(mn(input()))


st = input()
flag = True
i = 0
l = len(st)
while i < l:
	if i < l - 2 and st[i] == '1' and (st[i + 1] == '4') and (st[i + 2] == '4'):
		i += 3
	elif i < l - 1 and st[i] == '1' and (st[i + 1] == '4'):
		i += 2
	elif st[i] == '1':
		i += 1
	else:
		flag = False
		break
if flag == True:
	print('YES')
else:
	print('NO')


s = input()
if all((i == '1' or i == '4' for i in s)):
	if '144' in s:
		s = s.replace('144', '0')
	if '14' in s:
		s = s.replace('14', '0')
	if '1' in s:
		s = s.replace('1', '0')
	if all((j == '0' for j in s)):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


import re
a = input()
b = a.replace('144', '*')
c = b.replace('14', '*')
d = c.replace('1', '*')
if re.sub('\\**', '*', d) == '*':
	print('YES')
else:
	print('NO')


n = input()
i = len(n) - 1
c = True
if n[0] == '4':
	c = False
else:
	while i >= 0:
		if n[i] == '4':
			if n[i - 1] == '4':
				if n[i - 2] == '1':
					i -= 3
				else:
					c = False
					break
			elif n[i - 1] == '1':
				i -= 2
			else:
				c = False
				break
		elif n[i] == '1':
			i -= 1
		else:
			c = False
			break
if c:
	print('YES')
else:
	print('NO')


n = input()
fours = 0
for i in range(len(n)):
	if n[i] != '4' and n[i] != '1':
		print('NO')
		break
	elif n[0] == '4':
		print('NO')
		break
	elif n[i] == '1':
		fours = 0
	else:
		fours += 1
	if fours > 2:
		print('NO')
		break
	if i == len(n) - 1:
		print('YES')


n = input()
k = 0
if n[0] != '4':
	for i in n:
		if i != '1' and i != '4':
			print('NO')
			exit()
		if i == '4':
			k += 1
			if k >= 3:
				print('NO')
				exit()
		else:
			k = 0
	print('YES')
	exit()
else:
	print('NO')
	exit()


import sys
import math
import collections
from collections import deque
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))
T = 1
for _ in range(T):
	s = str(stdin.readline().strip('\n'))
	x = s.count('1')
	y = s.count('14')
	z = s.count('144')
	y = y - z
	x = x - z - y
	if x * 1 + y * 2 + z * 3 == len(s):
		print('YES')
	else:
		print('NO')


s = input()
s1 = s.replace('144', '***')
s2 = s1.replace('14', '**')
s3 = s2.replace('1', '*')
for i in s3:
	if i != '*':
		print('NO')
		break
else:
	print('YES')


el = input().replace('144', ' ').replace('14', ' ').replace('1', ' ')
ch = 0
for i in range(len(el)):
	if el[i] != ' ':
		print('NO')
		ch = 1
		break
if ch == 0:
	print('YES')


a = str(input())
n = len(a)
i = 0
while i < n:
	if n - i >= 3 and a[i] is '1' and (a[i + 1] is '4') and (a[i + 2] is '4'):
		i = i + 3
	elif n - i >= 2 and a[i] is '1' and (a[i + 1] is '4'):
		i = i + 2
	elif a[i] is '1':
		i = i + 1
	else:
		print('NO')
		exit()
print('YES')


n = input()
i = k = o = 0
if n.count('2') == 0 and n.count('3') == 0 and (n.count('5') == 0) and (n.count('6') == 0) and (n.count('7') == 0) and (n.count('8') == 0) and (n.count('9') == 0) and (n.count('0') == 0) and (n[0] != '4'):
	while i < len(n) and o == 0:
		if n[i] == '4':
			k += 1
		else:
			k = 0
		if k > 2:
			print('NO')
			o += 1
		i += 1
	if o == 0:
		print('YES')
else:
	print('NO')


input = input()
flag = 1
for i in input:
	if i not in '14':
		print('NO')
		flag = 0
		break
if flag != 0:
	if len(input) < 3:
		if input == '1' or input == '14' or input == '11':
			print('YES')
		else:
			print('NO')
	else:
		k = 2
		m = 0
		n = 1
		while m < len(input):
			if k < len(input) and n < len(input) and (input[k] == '4') and (input[n] == '4') and (input[m] == '1'):
				m = k + 1
				n = k + 2
				k = n + 1
			elif n < len(input) and input[n] == '4' and (input[m] == '1'):
				m = n + 1
				n = n + 2
				k = n + 1
			elif input[m] == '1':
				m = m + 1
				n = n + 1
				k = n + 1
			else:
				flag = 0
				break
		if flag == 0:
			print('NO')
		else:
			print('YES')


n = input()
f = 0
one = 0
ans = 'YES'
for i in n:
	if i == '1':
		f = 0
		one += 1
	elif i == '4':
		if f < 2 and one:
			f += 1
		else:
			ans = 'NO'
			break
	else:
		ans = 'NO'
		break
print(ans)


I = input()
count = 0
four = 0
for i in I:
	if i != '1':
		if i != '4':
			print('NO')
			break
		elif four == 0:
			print('NO')
			break
		else:
			count += 1
			four -= 1
	else:
		count += 1
		four = 2
if count == len(I):
	print('YES')


s = input()
dp = []

def recur(s):
	if len(s) == 10:
		dp.append(s)
	elif len(s) > 10:
		return
	else:
		dp.append(s)
		recur(s + '1')
		recur(s + '14')
		recur(s + '144')
recur('')
if s in dp:
	print('YES')
else:
	print('NO')


n = input()
if n.find('444') != -1:
	print('NO')
	exit()
if n[0] == '4':
	print('NO')
	exit()
for i in range(len(n)):
	if n[i] != '1' and n[i] != '4':
		print('NO')
		exit()
print('YES')


n = list(map(int, input()))
flag = True
if len(n) == 1:
	if n[0] != 1:
		flag = False
elif n[0] != 1:
	flag = False
elif n[1] in [2, 3, 5, 6, 7, 8, 9, 0]:
	flag = False
elif len(n) > 2:
	for i in range(2, len(n)):
		if n[i] == 4 and n[i - 1] == 4 and (n[i - 2] == 4):
			flag = False
			break
		elif n[i] in [2, 3, 5, 6, 7, 8, 9, 0]:
			flag = False
			break
if flag:
	print('YES')
else:
	print('NO')


import sys
array = list(str(input()))
size = len(array)
flag = 0
if array[0] != '1':
	print('NO')
	sys.exit()
if size == 1:
	if array[0] == '1':
		print('YES')
		sys.exit()
	else:
		print('NO')
		sys.exit()
for i in range(1, size):
	if array[i] == '1':
		flag = 1
		continue
	elif array[i] == '4':
		if array[i - 1] == '1':
			flag = 1
			continue
		elif array[i - 1] == '4' and array[i - 2] == '1':
			flag = 1
			continue
		else:
			print('NO')
			sys.exit()
	else:
		print('NO')
		sys.exit()
if flag == 1:
	print('YES')


x = input()
if x[0] != '1':
	print('NO')
else:
	c = 0
	k = 9
	for i in range(1, len(x)):
		if x[i] == '4':
			c += 1
			if c > 2:
				k = 1
				break
		if x[i] == '1':
			c = 0
		if x[i] != '1' and x[i] != '4':
			k = 1
			break
	if k != 1:
		print('YES')
	else:
		print('NO')


n = str(input())
counter = 0
bool = 0
for i in n:
	if i != '1' and i != '4':
		print('NO')
		exit()
	if i == '4':
		counter += 1
		if counter > 2:
			print('NO')
			exit()
	else:
		counter = 0
	if bool == 0:
		if i != '1':
			print('NO')
			exit()
		bool = 1
print('YES')


def magic(n):
	while n > 0:
		if n % 1000 == 144:
			n //= 100
		elif n % 100 == 14:
			n //= 100
		elif n % 10 == 1:
			n //= 10
		else:
			return False
	return True
print('YES' if magic(int(input())) else 'NO')


import sys
n = input()
i = 0
ans = True
if len(n) == 1 and n == '1':
	print('YES')
	sys.exit()
elif n[0] != '1':
	print('NO')
	sys.exit()
while i < len(n) - 1:
	if n[i] == '1':
		if n[i + 1] == '1' or n[i + 1] == '4':
			i += 1
			continue
		else:
			ans = False
			break
	elif n[i] == '4':
		if n[i - 1] == '1' and n[i + 1] == '4' or n[i + 1] == '1':
			i += 1
			continue
		else:
			ans = False
			break
if ans == True:
	print('YES')
else:
	print('NO')


n = input()
num4 = 0
res = True
for (idx, val) in enumerate(n):
	if val == '4':
		if num4 < 2 and idx > 0:
			num4 += 1
		else:
			res = False
			break
	elif val == '1':
		num4 = 0
	else:
		res = False
		break
print('YES') if res else print('NO')


s = input()
pool = {'1', '4'}
for char in s:
	if char not in pool:
		print('NO')
		exit()
if s[0] == '4' or '444' in s:
	print('NO')
else:
	print('YES')


x = input()
if x[0] != '1':
	print('NO')
elif '444' in x:
	print('NO')
else:
	flag = 1
	for i in range(1, len(x)):
		if x[i] != '1' and x[i] != '4':
			print('NO')
			flag = 0
			break
	if flag == 1:
		print('YES')


s = str(input())
while s != '':
	if s[-3:] == '144':
		s = s[:-3]
	elif s[-2:] == '14':
		s = s[:-2]
	elif s[-1] == '1':
		s = s[:-1]
	else:
		print('NO')
		break
else:
	print('YES')


magic = ['1', '14', '144']
s = input()
length = len(s)
i = 0
ans = 'YES'
while i < length:
	yes = False
	for (j, num) in enumerate(magic[::-1]):
		if s[i:i + 3 - j] == num:
			i += 3 - j
			yes = True
			break
	if not yes:
		ans = 'NO'
		break
print(ans)


import re
a = input()
ex = re.compile('^(1|14|144)+$')
print('YES' if re.search(ex, a) else 'NO')


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def minput():
	return map(int, input().split())

def listinput():
	return list(map(int, input().split()))
s = input()
s = s.replace('144', ' ')
s = s.replace('14', ' ')
s = s.replace('1', ' ')
s = s.replace(' ', '')
if len(s) == 0:
	print('YES')
else:
	print('NO')


n = input()
f = True
if n[0] == '4':
	f = False
a = n.count('1')
b = n.count('4')
if a + b < len(n):
	f = False
if n.count('444') > 0:
	f = False
if f:
	print('YES')
else:
	print('NO')


def main(N):
	N = str(N)
	if N[0] != '1':
		print('NO')
		return
	cnt4 = 0
	flag = True
	for i in range(1, len(N)):
		if N[i] == '4':
			cnt4 += 1
		else:
			cnt4 = 0
		if cnt4 == 3:
			flag = False
			break
		elif N[i] != '1' and N[i] != '4':
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')
	return

def text():
	with open('input.txt', 'r') as f:
		t = int(f.readline().rstrip())
		while t:
			N = int(f.readline().rstrip())
			main(N)
			t -= 1

def normal():
	N = int(input())
	main(N)
normal()


def magic_number():
	number = input()
	dic = {1, 14, 144}
	if number[0] != '1':
		print('NO')
		return
	i = 0
	while i < len(number):
		if number[i] == '1':
			if i + 1 != len(number):
				if number[i + 1] == '1':
					i += 1
					continue
				elif number[i + 1] == '4':
					if i + 2 != len(number):
						if number[i + 2] != '4':
							i += 2
							continue
						elif number[i + 2] == '4':
							i += 3
							continue
						else:
							print('NO')
							break
					else:
						break
				else:
					print('NO')
					return
			else:
				break
		else:
			print('NO')
			return
	print('YES')
	return
magic_number()


number = input()
i = 0
done = 0
while i < len(number):
	if number[i] == '1':
		if i == len(number) - 1:
			done = 1
			print('YES')
			break
		if i == len(number) - 2:
			if number[i + 1] != '1' and number[i + 1] != '4':
				print('NO')
				break
		if number[i + 1] == '1':
			i += 1
			continue
		elif number[i + 1] == '4':
			if i + 1 == len(number) - 1:
				print('YES')
				done = 1
				break
			if number[i + 2] != '4':
				i += 2
				continue
			if number[i + 2] == '4':
				i += 3
				continue
		i += 1
	else:
		print('NO')
		break
if i >= len(number) and done == 0:
	print('YES')


n = input()
if n.replace('144', 'zzz').replace('14', 'zz').replace('1', 'z').count('z') == len(n):
	print('YES')
else:
	print('NO')


s = input()
one = 0
four = 0
res = 'YES'
for i in s:
	if i != '1' and i != '4':
		res = 'NO'
		break
	if one == 0 and i == '4':
		res = 'NO'
		break
	if i == '1':
		one = 1
		four = 0
	elif i == '4' and four == 2:
		res = 'NO'
		break
	elif i == '4':
		four += 1
print(res)


num = input()
tam = len(num)
cont = 0
cond = True
if num[0] != '1':
	cond = False
else:
	for i in range(1, tam):
		if num[i] == '4':
			cont += 1
			if cont == 3:
				cond = False
				break
		elif num[i] == '1':
			cont = 0
		else:
			cond = False
			break
if cond:
	print('YES')
else:
	print('NO')


import re
number = input()
pattern = re.compile('(1|14|144)*$')
if re.match(pattern, number):
	print('YES')
else:
	print('NO')


s = input()
a = ['144', '14', '1']
for i in a:
	s = ' '.join(s.split(i))
if any((str(i) in s for i in range(0, 10))):
	print('NO')
else:
	print('YES')


s = input()
one = s.count('1')
four = s.count('4')
if one + four == len(s):
	if one == 0:
		print('NO')
	elif four == 0:
		print('YES')
	else:
		c = 0
		i = 0
		while i < len(s):
			if s[i:i + 3] == '144':
				i = i + 3
			elif s[i:i + 2] == '14':
				i = i + 2
			elif s[i] == '1':
				i = i + 1
			else:
				c = 1
				break
		if c == 1:
			print('NO')
		else:
			print('YES')
else:
	print('NO')


num = input()
if num[0] == '4':
	print('NO')
	exit(0)
for i in range(len(num)):
	if num[i] == '4' and num[i - 1] == '1':
		continue
	elif num[i] == '4' and num[i - 1] == '1' and (num[i + 1] == '4'):
		continue
	elif num[i] == '4' and num[i - 1] == '4' and (num[i - 2] == '1'):
		continue
	elif num[i] == '1':
		continue
	else:
		print('NO')
		exit(0)
print('YES')


n = input('')
count = 0
valid = True
i = 0
while i < len(n) and valid:
	if n[i] == '1' or n[i] == '4':
		if n[i] == '4' and i == 0:
			valid = False
			break
		if n[i] == '1':
			count = 0
		else:
			count = count + 1
		if count > 2:
			valid = False
	else:
		valid = False
	i = i + 1
if valid == True:
	print('YES')
else:
	print('NO')


n = input()
while n[:1] == '1':
	for i in ('144', '14', '1'):
		if n[:len(i)] == i:
			n = n[len(i):]
			break
print(['NO', 'YES'][n == ''])


s = input()
i = 0
flag = True
while i < len(s):
	if s[i] == '1':
		i += 1
	elif s[i] == '4':
		if i > 0 and s[i - 1] == '1' or (i > 1 and s[i - 2:i] == '14'):
			i += 1
		else:
			flag = False
			break
	else:
		flag = False
		break
if not flag:
	print('NO')
else:
	print('YES')


n = input()
if n[0] != '1':
	print('NO')
	exit()
t = 0
for i in range(len(n) - 1):
	if n[i] == '1' and n[i + 1] == '1' or (n[i] == '1' and n[i + 1] == '4'):
		t = 0
		pass
	elif n[i] == '4':
		t = t + 1
		if t == 1 and n[i + 1] == '4' or n[i + 1] == '1':
			pass
		else:
			print('NO')
			exit()
	else:
		print('NO')
		exit()
print('YES')


from itertools import groupby
flag = 0
victim = list(input())
for i in victim:
	if i != '1' and i != '4':
		print('NO')
		flag = 1
		break
if flag == 0:
	if victim[0] != '1':
		print('NO')
		flag = 1
victim = victim[1:]
groups = groupby(victim)
if flag == 0:
	for (key, value) in groups:
		if key == '4' and len(list(value)) > 2:
			print('NO')
			flag = 1
			break
if flag == 0:
	print('YES')


n = input()
x = len(n)
n += '1'
i = 0
flag = 0
while i < x:
	if n[i] == '1':
		if n[i + 1] == '4':
			i += 1
			if n[i + 1] == '4':
				i += 1
		i += 1
	else:
		flag = 1
		break
if flag == 0:
	print('YES')
	exit()
print('NO')


X = input()
S = '2356789'
for i in S:
	if i in X:
		print('NO')
		exit()
i = 0
while i < len(X):
	if X[i] != '1':
		print('NO')
		exit()
	if i <= len(X) - 3 and X[i + 1] == '4' and (X[i + 2] == '4'):
		i += 3
		continue
	if i <= len(X) - 2 and X[i + 1] == '4':
		i += 2
		continue
	i += 1
print('YES')


r = input()
print(['NO', 'YES'][r.count('1') + r.count('144') + r.count('14') == len(r)])


s = input()
for i in s:
	if i != '1' and i != '4':
		print('NO')
		exit()
if s.count('444') == 0 and s[0] == '1':
	print('YES')
else:
	print('NO')


n = input()
flag3 = 0
counter = 0
while True:
	if counter >= len(n):
		print('YES')
		break
	if counter < len(n) - 2:
		if [n[counter], n[counter + 1], n[counter + 2]] == ['1', '4', '4']:
			counter += 3
		elif [n[counter], n[counter + 1]] == ['1', '4']:
			counter += 2
		elif [n[counter]] == ['1']:
			counter += 1
		else:
			print('NO')
			break
	elif counter < len(n) - 1:
		if [n[counter], n[counter + 1]] == ['1', '4']:
			counter += 2
		elif [n[counter]] == ['1']:
			counter += 1
		else:
			print('NO')
			break
	elif [n[counter]] == ['1']:
		counter += 1
	else:
		print('NO')
		break


t = input()
n = list(t)
n.insert(0, '0')
n.append('0')
k = 0
q = 0
for i in range(1, len(n) - 1):
	if n[i] == '4' or n[i] == '1':
		if n[i] == '4' and n[i - 1] == '0':
			q = 1
			break
		if n[i] == '4':
			j = i
			while n[j] == '4':
				k += 1
				j += 1
			if k > 2:
				q = 1
				break
			else:
				k = 0
	else:
		q = 1
		break
if q == 0:
	print('YES')
else:
	print('NO')


def f(a):
	if not a:
		return True
	if a[:3] == '144':
		return f(a[3:])
	if a[:2] == '14':
		return f(a[2:])
	if a[0] == '1':
		return f(a[1:])
	return False
print('YES' if f(input()) else 'NO')


n = str(input().strip())
pi1 = False
pi4 = False
javob = True
for i in n:
	if i == '1':
		pi1 = True
		pi4 = False
	elif i == '4':
		if pi1 == True:
			pi1 = False
			pi4 = True
		elif pi4 == True:
			pi4 = False
		else:
			javob = False
			break
	else:
		javob = False
		break
print('YES' if javob == True else 'NO')


print(['NO', 'YES'][len(input().replace('144', ' ').replace('14', ' ').replace('1', ' ').replace(' ', '')) == 0])


n = input()
if n[0] == '1' and set(n).issubset({'1', '4'}) and (n.find('444') == -1):
	print('YES')
else:
	print('NO')


n = int(input())
N = str(n)
x = list(N)
x.append('0')
x.append('0')
magic = True
i = 0
while i < len(x) - 2:
	if x[i] + x[i + 1] + x[i + 2] == '144':
		i += 3
	elif x[i] + x[i + 1] == '14':
		i += 2
	elif x[i] == '1':
		i += 1
	else:
		magic = False
		break
if magic:
	print('YES')
else:
	print('NO')


a = list(input())
for i in range(0, len(a) - 2):
	if a[i] == '1' and a[i + 1] == '4' and (a[i + 2] == '4'):
		a[i] = '+'
		a[i + 1] = '+'
		a[i + 2] = '+'
for i in range(0, len(a) - 1):
	if a[i] == '1' and a[i + 1] == '4':
		a[i] = '+'
		a[i + 1] = '+'
for i in range(0, len(a)):
	if a[i] == '1':
		a[i] = '+'
flag = 1
for i in range(0, len(a)):
	if a[i] != '+':
		print('NO')
		flag = 0
		break
if flag == 1:
	print('YES')


n = input()
a = 0
z = 0
for i in range(len(n)):
	if n[0] == '1':
		if n[i] == '4':
			z = z + 1
			a = a + 1
		elif n[i] == '1' and z < 3:
			z = 0
			a = a + 1
		else:
			print('NO')
			break
	else:
		print('NO')
		break
if a == len(n) and z < 3:
	print('YES')
elif a == len(n) and z > 2:
	print('NO')


s = input()
flag = True
a = ['2', '3', '5', '6', '7', '8', '9', '0']
if s[0] != '1':
	flag = False
if '444' in s:
	flag = False
if any((x in s for x in a)):
	flag = False
if flag == True:
	print('YES')
else:
	print('NO')


n = int(input())
s = str(n)
x = '114144'
(f1, f2, f3) = (True, True, True)
i = 0
while True:
	if s[i] == '1':
		if i + 1 < len(s):
			if s[i + 1] == '4':
				if i + 2 < len(s):
					if s[i + 2] == '4':
						i = i + 3
					else:
						i = i + 2
				else:
					i = i + 2
			else:
				i = i + 1
		else:
			i = i + 1
	else:
		print('NO')
		break
	if i >= len(s):
		print('YES')
		break


accepted_vals = ['', '1', '14', '144']
number = input()
i = -1
while i < len(number):
	cur_str = ''
	while i < len(number) - 1 and cur_str + number[i + 1] in accepted_vals:
		cur_str += number[i + 1]
		i += 1
	if cur_str == '':
		if i < len(number) - 1:
			print('NO')
		else:
			print('YES')
		break


n = str(input())
ac = ['1', '14', '144']
l = 0
prev = ''
while l < len(n):
	if prev != '' and prev not in ac:
		break
	if prev + n[l] in ac:
		prev += n[l]
	else:
		prev = n[l]
	l += 1
if l == len(n) and prev in ac:
	print('YES')
else:
	print('NO')


st = input()
i = 0
n = len(st)
for _ in range(n):
	if st[i] == '1':
		if i + 1 < n and st[i + 1] == '4':
			if i + 2 < n and st[i + 2] == '4':
				i += 3
			else:
				i += 2
		else:
			i += 1
	else:
		print('NO')
		exit(0)
	if i >= n:
		break
print('YES')


n = int(input())

def fun(n):
	s = str(n)
	for i in s:
		if i != '1' and i != '4':
			return False
	if '444' in s:
		return False
	if s[0] == '4':
		return False
	return True
if fun(n):
	print('YES')
else:
	print('NO')


n = str(input())

def is14(s):
	ans = True
	for i in s:
		if i != '1' and i != '4':
			ans = False
	return ans
if n.startswith('1') and n.find('444') == -1 and (is14(n) == True):
	print('YES')
else:
	print('NO')


a = input()
n = len(a)
i = 0
f = 0
while i < n:
	if a[0] != '1':
		f = 1
		break
	elif a[i] == '1':
		i += 1
	elif a[i] == '4':
		if a[i - 1] == '1':
			i += 1
		elif a[i - 1] == '4' and a[i - 2] == '1':
			i += 1
		else:
			f = 1
			break
	else:
		f = 1
		break
if f == 1:
	print('NO')
else:
	print('YES')


s = input().strip()
n = len(s)
i = 0
while i < n:
	if i < n - 2 and s[i:i + 3] == '144':
		i += 3
	elif i < n - 1 and s[i:i + 2] == '14':
		i += 2
	elif s[i] == '1':
		i += 1
	else:
		print('NO')
		exit()
print('YES')


n = input()
k = '23567890'
flag = ''
i = 0
while i < len(n):
	if n[i] in k or n[0] == '4':
		flag = 'NO'
		break
	if n[i] == '1':
		if i + 1 < len(n) and n[i + 1] == '4':
			if i + 2 < len(n) and n[i + 2] == '4':
				if i + 3 < len(n) and n[i + 3] == '4':
					flag = 'NO'
					break
				i += 3
				flag = 'YES'
				continue
			else:
				i += 2
				flag = 'YES'
				continue
		i += 1
		flag = 'YES'
print(flag)


n = input()
c = n.count('1444')
b = set(n)
if n.count('1') > 0 and b.issubset({'1', '4'}) and (n[0] != '4'):
	if c == 0:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


s = input()
flag = False
if s.count('1') + s.count('4') != len(s):
	print('NO')
else:
	if s[0] == '4':
		flag = False
	elif s.count('444') >= 1:
		flag = False
	else:
		flag = True
	if flag:
		print('YES')
	else:
		print('NO')


s = input()
s = list(s)
i = len(s) - 1
f = 0
while i >= 0:
	if len(s) >= 3 and s[i] == '4' and (s[i - 1] == '4') and (s[i - 2] == '1'):
		s.pop(i)
		s.pop(i - 1)
		s.pop(i - 2)
		i = i - 3
	elif len(s) >= 2 and s[i] == '4' and (s[i - 1] == '1'):
		s.pop(i)
		s.pop(i - 1)
		i = i - 2
	elif s[i] == '1':
		s.pop(i)
		i = i - 1
	else:
		f = 1
		break
if f == 1:
	print('NO')
elif f == 0 and len(s) == 0:
	print('YES')


s = input()
i = 0
while i < len(s):
	if s[i:i + 3] == '144' and len(s[i:i + 3]) == 3:
		i = i + 3
		continue
	if s[i:i + 2] == '14' and len(s[i:i + 2]) == 2:
		i = i + 2
		continue
	if s[i:i + 1] == '1' and len(s[i:i + 1]) == 1:
		i = i + 1
		continue
	print('NO')
	exit(0)
print('YES')


def main():
	s = str(input())
	ss = set(s)
	if s == '1':
		print('YES')
		return
	if s == '14':
		print('YES')
		return
	if s == '144':
		print('YES')
		return
	if s.find('444') != -1:
		print('NO')
		return
	f1 = s.find('1') != -1 or s.find('14') != -1 or s.find('14') != -1
	f2 = ss == {'1', '4'} or ss == {'1'}
	f3 = s.count('1') > 1
	f4 = s[0] == '1'
	if f1 and f2 and f3 and f4:
		print('YES')
	else:
		print('NO')
main()


n = input()
prev = ''
possible = True
for i in range(len(n)):
	if n[i] == '1':
		prev = '1'
		continue
	if n[i] == '4' and prev == '1':
		prev = '4'
		continue
	if n[i] == '4' and prev == '4':
		prev = '44'
		continue
	else:
		possible = False
if possible:
	print('YES')
else:
	print('NO')


number = input()
temp = ''
flag = 0
for i in range(len(number)):
	if number[i] == '1':
		temp = '1'
	elif number[i] == '4':
		if len(temp) > 0:
			temp += '4'
			if temp == '14' or temp == '144':
				continue
			else:
				flag = 1
				break
		else:
			flag = 1
			break
	else:
		flag = 1
		break
if flag == 1:
	print('NO')
else:
	print('YES')


n = str(input())
l = ['1', '4']
if any((i not in l for i in n)):
	print('NO')
elif n[0] != '1':
	print('NO')
elif n.find('444') != -1:
	print('NO')
else:
	print('YES')


s = input()
print('YES' if s[0] == '1' and all((q == '' or q == '4' or q == '44' for q in s.split('1'))) else 'NO')


a = input().split()[0]
b = set(a)
if len(b) > 2:
	print('NO')
elif b != {'1'} and b != {'4'} and (b != {'1', '4'}):
	print('NO')
elif '444' in a:
	print('NO')
elif a[0] == '4':
	print('NO')
else:
	print('YES')


def Main():
	s = input()
	lft = 0
	while lft < len(s):
		f = False
		if lft + 3 <= len(s):
			if s[lft:lft + 3] == '144':
				lft += 3
				f = True
				continue
		if lft + 2 <= len(s):
			if s[lft:lft + 2] == '14':
				lft += 2
				f = True
				continue
		if lft + 1 <= len(s):
			if s[lft] == '1':
				lft += 1
				f = True
				continue
		if not f:
			print('NO')
			return 0
	print('YES')
Main()


s = input()
res = True
for i in s:
	if i not in ['1', '4']:
		res = False
if s[0] != '1':
	res = False
if s.count('444'):
	res = False
if res:
	print('YES')
else:
	print('NO')


a = input()
c = 0
for i in range(len(a)):
	if a[c:c + 3] == '144':
		c += 3
	elif a[c:c + 2] == '14':
		c += 2
	elif a[c] == '1':
		c += 1
	else:
		print('NO')
		break
	if c == len(a):
		print('YES')
		break


def oddNum(n):
	list = [2, 3, 5, 6, 7, 8, 9, 0]
	num = n
	r = True
	while num > 9:
		l = num % 10
		num = num // 10
		if l in list:
			r = False
			break
	if num != 1:
		r = False
	return r

def consequitive4(num):
	c = 0
	d = 0
	while num:
		l = num % 10
		if l == 4:
			c = c + 1
		else:
			c = 0
		num = num // 10
		if d < c:
			d = c
	if d < 3:
		return True
	else:
		return False
number = int(input())
r = False
if oddNum(number):
	r = consequitive4(number)
if r:
	print('YES')
else:
	print('NO')


state = 0
states = {0: {'1': 1}, 1: {'1': 1, '4': 2}, 2: {'1': 1, '4': 0}}
for c in input():
	state = states[state].get(c, -1)
	if state == -1:
		print('NO')
		break
else:
	print('YES')


n = input()
x = 0
for i in range(len(n)):
	if n[i] == '1':
		if x == 0:
			x = 1
		elif x == 2:
			x = 1
	elif n[i] == '4':
		if x == 0:
			x = 3
		elif x == 1:
			x = 2
		elif x == 2:
			x = 0
	else:
		x = 3
	if x == 3:
		break
if x == 3:
	print('NO')
else:
	print('YES')


s = input()
l = s.split('1')
flag = True
for i in range(1, len(l)):
	if l[i] == '':
		continue
	elif (l[i] == '4' or l[i] == '44') and (l[i - 1] == '' or l[i - 1] == '4' or l[i - 1] == '44'):
		continue
	else:
		flag = False
		break
if flag and l[0] == '':
	print('YES')
else:
	print('NO')


i1 = ''
i2 = ''
s = 'YES'
for i in input():
	if i1 == '' or i2 == '':
		if i1 == '' and i != '1':
			s = 'NO'
			break
		elif i1 == '' and i == '1':
			i1 = i
		elif i2 == '' and (i == '1' or i == '4'):
			i2 = i
		else:
			s = 'NO'
			break
	elif i == '1' or (i == '4' and (i2 == '1' or (i2 == '4' and i1 == '1'))):
		i1 = i2
		i2 = i
	else:
		s = 'NO'
		break
print(s)


string = str(input())
list1 = ['0', '2', '3', '5', '6', '7', '8', '9', '0']
count = 0
for i in list1:
	if i in string:
		count = count + 1
	else:
		continue
if count == 0:
	if string[0] == str(1):
		if '444' not in string:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
else:
	print('NO')


import sys
import re
from collections import deque
from copy import copy
p = re.compile('^(1|14|144)+$')
S = sys.stdin.readline()
if p.match(S):
	print('YES')
else:
	print('NO')


s = input()
l = list(s)
count = 1
length = []
d = 0
cd = 0
if len(s) > 1:
	for i in range(1, len(s)):
		if s[i - 1] == s[i]:
			count += 1
		else:
			length.append((s[i - 1], count))
			count = 1
	length.append((s[i], count))
else:
	i = 0
	length.append((s[i], count))
if l[0] == '4':
	print('NO')
elif '0' in s or '2' in s or '3' in s or ('5' in s) or ('6' in s) or ('7' in s) or ('8' in s) or ('9' in s):
	print('NO')
else:
	for i in range(len(length)):
		if length[i][0] == '4':
			if length[i][1] > 2:
				cd += 1
	if cd != 0:
		print('NO')
	else:
		print('YES')


inp_1 = input()
inp_1 = list(inp_1)
j = 0
b = True
n = len(inp_1)
while True:
	if j > n - 1:
		break
	if inp_1[j] == '1':
		if j + 1 > n - 1:
			break
		if inp_1[j + 1] == '4':
			if j + 2 > n - 1:
				break
			if inp_1[j + 2] == '4':
				j = j + 3
			else:
				if j + 2 > n - 1:
					break
				if inp_1[j + 2] == '1':
					j = j + 2
				else:
					print('NO')
					b = False
					break
		else:
			if j + 1 > n - 1:
				break
			if inp_1[j + 1] == '1':
				j = j + 1
			else:
				print('NO')
				b = False
				break
	else:
		print('NO')
		b = False
		break
if b:
	print('YES')


n = input()
m = n
c = 0
while '144' in n or '14' in n or '1' in n:
	if '144' in n:
		c += 3
		n = n.replace('144', '0', 1)
	elif '14' in n:
		c += 2
		n = n.replace('14', '0', 1)
	elif '1' in n:
		c += 1
		n = n.replace('1', '0', 1)
if c == len(m):
	print('YES')
else:
	print('NO')


s = input()
flag = 0
for i in range(len(s)):
	if s[0] != '1':
		flag = 1
		print('NO')
		break
	elif s[i] != '1' and s[i] != '4':
		print('NO')
		flag = 2
		break
	elif s[i:i + 3] == '444':
		print('NO')
		flag = 3
		break
else:
	print('YES')


import re
S = input()
print('YES' if len(re.match('(144|14|1)*', S).group(0)) == len(S) else 'NO')


n = list(input())
n = list(map(int, n))
if any((n[i] > 4 or (n[i] < 4 and n[i] < 1) for i in range(len(n)))):
	print('NO')
else:
	i = 0
	while len(n) > 0:
		if len(n) == 1:
			if n[0] == 1:
				print('YES')
				break
			else:
				print('NO')
				break
		elif len(n) == 2:
			if n[0] == 1 and n[1] == 1 or (n[0] == 1 and n[1] == 4):
				print('YES')
				break
			else:
				print('NO')
				break
		elif len(n) == 3:
			if n[0] == 1 and n[1] == 1 and (n[2] == 1) or (n[0] == 1 and n[1] == 4 and (n[2] == 4)) or (n[0] == 1 and n[1] == 1 and (n[2] == 4)) or (n[0] == 1 and n[1] == 4 and (n[2] == 1)):
				print('YES')
				break
			else:
				print('NO')
				break
		elif n[0] == 1 and n[1] == 4 and (n[2] == 4):
			n = n[3:]
		elif n[0] == 1 and n[1] == 4 and (n[2] == 1):
			n = n[2:]
		elif n[0] == 1 and n[1] == 1:
			n = n[1:]
		else:
			print('NO')
			break


a = input()
magicNumber = True
index = 0
for i in a:
	if i == '4' or i == '1':
		if i == '4':
			if index - 1 >= 0 and index - 2 >= 0:
				if a[index - 1] == '1':
					index += 1
					continue
				elif a[index - 1] == '4' and a[index - 2] == '1':
					index += 1
					continue
				else:
					magicNumber = False
					break
			elif index - 1 >= 0:
				if a[index - 1] == '1':
					index += 1
					continue
			else:
				magicNumber = False
				break
	else:
		magicNumber = False
		break
	index += 1
if magicNumber:
	print('YES')
else:
	print('NO')


import math
numbers = input()
numbers = numbers.replace('144', ' ')
numbers = numbers.replace('14', ' ')
numbers = numbers.replace('1', ' ')
numbers = numbers.replace(' ', '')
if len(numbers) == 0:
	print('YES')
else:
	print('NO')


n = input().split('1')
for x in range(len(n)):
	if n[x] != '4' and n[x] != '' and (n[x] != '44'):
		print('NO')
		break
	if n[x] == '4' or n[x] == '44':
		if x == 0:
			print('NO')
			break
else:
	print('YES')


import sys
b = 0
ans = 1
for line in sys.stdin:
	n = list(line)
	for x in range(0, len(n) - 1):
		if b == 0:
			if n[x] == '1':
				b = 1
			else:
				ans = 0
				print('NO')
				break
		elif b == 1:
			if n[x] == '1':
				b = 1
			elif n[x] == '4':
				b = 2
			else:
				ans = 0
				print('NO')
				break
		elif b == 2:
			if n[x] == '1':
				b = 1
			elif n[x] == '4':
				b = 0
			else:
				ans = 0
				print('NO')
				break
		if x == len(n) - 2 and ans == 1:
			print('YES')
	ans = 1
	b = 0


s = str(input())
s1 = ['1', '4']
flag = True
for i in range(len(s)):
	if s[i] not in s1:
		flag = False
		break
s2 = ['11', '14', '41', '44']
for i in range(len(s) - 1):
	if s[i:i + 2] not in s2:
		flag = False
		break
s3 = ['111', '114', '141', '411', '144', '441', '414']
for i in range(len(s) - 2):
	if s[i:i + 3] not in s3:
		flag = False
		break
if s[0] != '1':
	flag = False
if flag == True:
	print('YES')
else:
	print('NO')


n = int(input())
n = str(n)

def magical(n):
	for i in range(len(n)):
		if n[i] != '1' and n[i] != '4':
			return False
	if n[0] == '4':
		return False
	if n.count('444') > 0:
		return False
	return True
if magical(n) == True:
	print('YES')
else:
	print('NO')


n = input()
if n.count('1') == len(n) or n.count('14') == len(n) or n.count('144') == len(n) or (n.count('1') + n.count('14') + n.count('144') >= len(n)):
	print('YES')
else:
	print('NO')


(r, c) = (0, 2)
for x in input()[::-1]:
	c = [2, c - 1][x == '4']
	r = [1, r][c >= 0 and x in '14']
r = [r, 1][c != 2]
print('YNEOS'[r::2])


a = input()
c = a.count('2') + a.count('3') + a.count('5') + a.count('6') + a.count('7') + a.count('8') + a.count('9') + a.count('0') + a.count('444')
if a[0] != '1':
	print('NO')
elif c == 0:
	print('YES')
else:
	print('NO')


n = input()
flag = 0
for x in range(len(n)):
	if n[x] == '1' or n[x] == '4':
		if n[x] == '4':
			if x == 0:
				print('NO')
				flag = 1
				break
			elif x == 1:
				if n[x - 1] == '1':
					pass
				else:
					print('NO')
					flag = 1
					break
			elif n[x - 1] == '1':
				pass
			elif n[x - 2] == '1':
				pass
			else:
				print('NO')
				flag = 1
				break
	else:
		print('NO')
		flag = 1
		break
if flag == 0:
	print('YES')


n = input()
b = list(set(n))
if len(b) == 2:
	if '1' in b and '4' in b:
		if n[0] == '4':
			print('NO')
		elif n.count('444') != 0:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')
elif len(b) == 1:
	if '1' in b:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


import re
n = input()
s = '1'
mind = True
if int(n[0]) == 1:
	for x in n:
		if bool(x == '1') == False:
			s = s + '' + x
		elif s == '1' or s == '14' or s == '144':
			s = '1'
			continue
		else:
			mind = False
else:
	mind = False
if (s == '1' or s == '14' or s == '144') == False:
	mind = False
if mind:
	print('YES')
else:
	print('NO')


num = input()
num = num.replace('144', '*')
num = num.replace('14', '*')
num = num.replace('1', '*')
num = num.replace('*', '')
if len(num) >= 1:
	print('NO')
else:
	print('YES')


import sys
a = input()
w = 0
count = 0
if len(a) == 1:
	if a[0] == '1':
		print('YES')
		sys.exit
	else:
		print('NO')
		sys.exit
for i in range(1, len(a)):
	if a[0] != '1':
		print('NO')
		break
	if a[i] != '1' and a[i] != '4':
		print('NO')
		break
	if a[i - 1] + a[i] == '14':
		count += 1
	elif a[i - 1] + a[i] == '44':
		count += 1
	elif a[i - 1] + a[i] == '41':
		count = 0
	if count > 2:
		print('NO')
		break
	w = i
if w == len(a) - 1 and len(a) > 1:
	print('YES')


i = 0
x = input()
x = list(map(int, x))
k = True
while i < len(x):
	if i < len(x) - 2:
		if x[i + 2] == 4 and x[i + 1] == 4 and (x[i] == 1):
			i += 3
			continue
	if i < len(x) - 1:
		if x[i + 1] == 4 and x[i] == 1:
			i += 2
			continue
	if x[i] == 1:
		i += 1
		continue
	k = False
	break
if k:
	print('YES')
else:
	print('NO')


def isItThoughaMmagicNumber(number):
	yesAndNos = []
	for a in number:
		if number[0] is not '4':
			if a is '1' or a is '4':
				yesAndNos.append('YES')
			else:
				yesAndNos.append('NO')
		else:
			return 'NO'
	yesAndNos = yesAndNos.count('YES')
	if '1444' in number:
		return 'NO'
	if yesAndNos == len(number):
		return 'YES'
	else:
		return 'NO'
number = input()
print(isItThoughaMmagicNumber(number))


S = input()
N = len(S)
i = 0
while i < N:
	if i + 2 < N and S[i:i + 3] == '144':
		i += 3
	elif i + 1 < N and S[i:i + 2] == '14':
		i += 2
	elif i < N and S[i] == '1':
		i += 1
	else:
		print('NO')
		exit()
print('YES')


n = list(map(int, input()))
ans = 'YES'
i = 0
while i < len(n) - 1:
	if n[i] == 1:
		i += 1
		if n[i] == 4:
			i += 1
			if i < len(n) and n[i] == 4:
				i += 1
	else:
		ans = 'NO'
		break
if i == len(n) - 1 and n[i] != 1:
	ans = 'NO'
print(ans)


a = input().strip()
b = len(a)
i = 0
j = 0
while i < b:
	if a[i] != '1':
		j = 1
		break
	elif i + 2 < b and a[i:i + 3] == '144':
		i = i + 3
	elif i + 1 < b and a[i:i + 2] == '14':
		i = i + 2
	else:
		i = i + 1
if j == 1:
	print('NO')
else:
	print('YES')


def magic_number(s):
	if s.count('1') == s.count('4') == 0:
		return 'NO'
	if s[0] == '4':
		return 'NO'
	i = 0
	while i < len(s):
		if s[i] == '1':
			if i + 1 < len(s) and s[i + 1] == '4':
				if i + 2 < len(s) and s[i + 2] == '4':
					i += 2
				else:
					i += 1
		else:
			return 'NO'
		i += 1
	return 'YES'
print(magic_number(input()))


def helper(s):
	for a in s:
		if a != '1' and a != '4':
			return False
	if s.find('444') != -1:
		return False
	if s[0] != '1':
		return False
	return True
s = str(input())
if helper(s):
	print('YES')
else:
	print('NO')


s = input()
flag = 0
flag1 = 0
cons = 0
for i in range(0, len(s)):
	if s[i] != '1' and s[i] != '4':
		flag = 1
		break
	elif flag1 == 0:
		if s[i] == '4':
			if i == 0:
				flag = 1
				break
			if s[i - 1] != '1':
				flag = 0
				break
			else:
				flag1 = 1
				cons = 1
	elif s[i] == '4':
		cons += 1
	else:
		cons = 0
		flag1 = 0
	if cons > 2:
		flag = 1
		break
if flag == 0:
	print('YES')
else:
	print('NO')


n = input()
count = 0
flag = 0
ones = 0
for i in range(len(n)):
	if n[i] == '4':
		if ones == 0:
			flag = 1
			break
		if count >= 2:
			flag = 1
			break
		else:
			count += 1
	elif n[i] == '1':
		count = 0
		ones += 1
	else:
		flag = 1
		break
if flag:
	print('NO')
else:
	print('YES')


n = input()
i = 0
flag = 1
while i < len(n):
	if n[i:i + 3] == '144':
		i += 3
	elif n[i:i + 2] == '14':
		i += 2
	elif n[i] == '1':
		i += 1
	else:
		flag = 0
		break
print('NYOE S'[flag == 1::2])


a = input()
b = a.split('1')
faltu = b.count('')
for i in range(faltu):
	b.remove('')
p = b.count('4')
q = b.count('44')
yo = a.count('1')
ro = a.count('4')
if yo + ro == len(a) and p + q == len(b) and (a[0] == '1'):
	print('YES')
else:
	print('NO')


s = input()
if s[0] != '1':
	print('NO')
else:
	x = 0
	for i in range(len(s)):
		if s[i] == '1':
			continue
		elif s[i] == '4':
			if s[i - 1] == '1' or (s[i - 2] == '1' and s[i - 1] == '4'):
				continue
			else:
				x = 1
				break
		else:
			x = 1
			break
	if x == 1:
		print('NO')
	else:
		print('YES')


n = input()
magic = True
if n[0] == '4':
	magic = False
else:
	for char in n:
		if char != '1' and char != '4':
			magic = False
			break
		else:
			if char == '4':
				fours += 1
			else:
				fours = 0
			if fours > 2:
				magic = False
				break
if magic:
	print('YES')
else:
	print('NO')


s = str(input())
ff = 0
if len(s) == 1:
	if s == '1':
		print('YES')
	else:
		print('NO')
	ff = 1
if len(s) == 2:
	if s == '11' or s == '14':
		print('YES')
	else:
		print('NO')
	ff = 1
if len(s) == 3:
	if s == '111' or s == '144' or s == '114' or (s == '141'):
		print('YES')
	else:
		print('NO')
	ff = 1
if ff == 0:
	f = 0
	for i in range(len(s)):
		if s[i] == '1':
			continue
		elif s[i] == '4' and i != 0:
			if s[i - 1] == '1':
				continue
			elif s[i - 1] == '4' and s[i - 2] == '1':
				continue
			else:
				f = 1
				break
		else:
			f = 1
			break
	if f == 1:
		print('NO')
	else:
		print('YES')


a = list(map(int, str(input())))
c = 0
if a[0] != 1:
	print('NO')
else:
	while len(a) != 0:
		if len(a) > 2 and (a[-1] == 4 and a[-2] == 4 and (a[-3] == 1)):
			del a[-1]
			del a[-1]
			del a[-1]
		elif len(a) > 1 and (a[-1] == 4 and a[-2] == 1):
			del a[-1]
			del a[-1]
		elif a[-1] == 1:
			del a[-1]
		else:
			c = 1
			break
	if c:
		print('NO')
	else:
		print('YES')


n = int(input())
s = str(n)
flag = 1
for i in s:
	if i in '02356789':
		flag = 0
		break
if '44' in s and '144' not in s:
	flag = 0
if '4' in s and '14' not in s:
	flag = 0
if '444' in s:
	flag = 0
if s[0] != '1':
	flag = 0
if flag == 1:
	print('YES')
else:
	print('NO')


a = str(input())
l = len(a)
i = 0
while i < l:
	if a[i] == '1':
		if i < l - 2:
			if a[i + 1] == '4' and a[i + 2] == '4':
				i += 3
				continue
		if i < l - 1:
			if a[i + 1] == '4':
				i += 2
				continue
	else:
		print('NO')
		exit(0)
	i += 1
print('YES')


n = input()
arr = n.split('1')
flag = True
if n[0] == '4':
	flag = False
else:
	for num in arr:
		if num == '' or num == '4' or num == '44':
			continue
		else:
			flag = False
			break
if flag:
	print('YES')
else:
	print('NO')


s = input().replace('144', 'a').replace('14', 'a').replace('1', 'a')
print(['YES', 'NO'][s.count('a') != len(s)])


num = str(input())

def magic():
	for i in range(len(num)):
		if num[i] != '1' and num[i] != '4':
			print('NO')
			return
	if num[0] != '1':
		print('NO')
		return
	elif '444' in num:
		print('NO')
		return
	else:
		print('YES')
		return
magic()


a = input()
lna = len(a)
magic = True
if a[0] != '1':
	magic = False
if lna > 1 and (a[1] == '4' and a[0] != '1' or (a[1] != '1' and a[1] != '4')):
	magic = False
for i in range(2, lna):
	if a[i] == '1':
		continue
	elif a[i] == '4' and a[i - 1] == '1':
		continue
	elif a[i] == '4' and a[i - 1] == '4' and (a[i - 2] == '1'):
		continue
	else:
		magic = False
		break
if magic:
	print('YES')
else:
	print('NO')


import re
n = input()
p = re.compile('^(1|14|144)+$')
if p.match(n):
	print('YES')
else:
	print('NO')


from sys import stdin, stdout
from bisect import bisect_left, bisect_right
n = input()
l = len(n)
if n[0] != '1':
	print('NO')
else:
	flag = 0
	for i in range(1, l):
		if n[i] == '1':
			continue
		elif n[i] == '4':
			if n[i - 1] == '1':
				continue
			elif i > 1 and n[i - 2] == '1':
				continue
			else:
				flag = 1
				break
		else:
			flag = 1
			break
	if flag == 0:
		print('YES')
	else:
		print('NO')


n = int(input())
c1 = 0
c14 = 0
c144 = 0
n = list(str(n))
for i in range(len(n)):
	if n[i] == '1':
		c1 += 1
		if ''.join(n[i:i + 2]) == '14':
			c14 += 1
		if ''.join(n[i:i + 3]) == '144':
			c144 += 1
			c14 -= 1
c1 = c1 - (c14 + c144)
l = c1 * 1 + c14 * 2 + c144 * 3
if l == len(n):
	print('YES')
else:
	print('NO')


def remove_all(sub, s):
	return s.replace(sub, '#', -1)
n = input()
n = remove_all('144', n)
n = remove_all('14', n)
n = remove_all('1', n)
f = 1
for c in n:
	if c != '#':
		f = 0
		break
if f:
	print('YES')
else:
	print('NO')


number = input()
numlist = list(number)
flag = 1
pointer = 0
numlen = len(numlist)
while pointer < numlen:
	if numlist[pointer] == '1':
		if pointer + 1 < numlen:
			if numlist[pointer + 1] == '4':
				if pointer + 2 < numlen:
					if numlist[pointer + 2] == '4':
						pointer += 3
					elif numlist[pointer + 2] == '1':
						pointer += 2
					else:
						flag = 0
						break
				else:
					break
			elif numlist[pointer + 1] == '1':
				pointer += 1
			else:
				flag = 0
				break
		else:
			break
	else:
		flag = 0
		break
if flag:
	print('YES')
else:
	print('NO')


string = input()
length_original = len(string)
string = string.replace('144', 'xxx').replace('14', 'xx').replace('1', 'x')
if string.count('x') == length_original:
	print('YES')
else:
	print('NO')


p = input()
c = 0
cnt = 0
if p[0] == '4':
	c = 1
for i in p:
	if i != '4' and i != '1':
		c = 1
		break
	else:
		if i == '1':
			cnt = 0
		else:
			cnt += 1
		if cnt > 2:
			c = 1
if c == 1:
	print('NO')
else:
	print('YES')


n = input()
i = 0
while i < len(n):
	if i <= len(n) - 3:
		if n[i + 2] == '4' and n[i + 1] == '4' and (n[i] == '1'):
			i += 3
			continue
	if i <= len(n) - 2:
		if n[i + 1] == '4' and n[i] == '1':
			i += 2
			continue
	if n[i] == '1':
		i += 1
	else:
		print('NO')
		exit()
print('YES')


s = input()
if '444' not in s and s[0] == '1':
	z = 0
	for x in s:
		if x == '1' or x == '4':
			continue
		else:
			z = 1
			break
	if z == 1:
		print('NO')
	else:
		print('YES')
else:
	print('NO')


s = input()
a = list(set(s))
f = 0
if s[0] != '1':
	print('NO')
else:
	for x in a:
		if x != '1' and x != '4':
			f = 1
			break
	if f == 1:
		print('NO')
	else:
		g = 0
		k = s.split('1')
		for y in k:
			if len(y) > 2:
				g = 1
				break
		if g == 1:
			print('NO')
		else:
			print('YES')


a = list(input())
ln = len(a)
ind = -1
if a[0] != '1':
	print('NO')
	exit()
for i in range(ln):
	if a[i] == '1':
		ind = i
		for j in range(i + 1, ln):
			if a[j] == '1':
				x = ''.join(a[i:j])
				if x == '1' or x == '14' or x == '144':
					break
				else:
					print('NO')
					exit()
x = ''.join(a[ind:])
if x == '1' or x == '14' or x == '144':
	print('YES')
	exit()
print('NO')


n = input()
flag = 0
for i in n:
	if i != '1' and i != '4':
		flag = 1
if n[0] == '4':
	flag = 1
if n.find('444') != -1:
	flag = 1
if flag == 0:
	print('YES')
else:
	print('NO')


def magical_string(s: str):
	for i in s:
		if i != '1' and i != '4':
			return 'NO'
	if s.find('444') != -1 or s[0] != '1':
		return 'NO'
	return 'YES'
s = input()
print(magical_string(s))


v = True
A = input()
if A[0] == '4':
	v = False
cur4 = 0
for a in A:
	if a != '4' and a != '1':
		v = False
		break
	elif a == '1':
		cur4 = 0
	else:
		cur4 += 1
	if cur4 > 2:
		v = False
		break
if v:
	print('YES')
else:
	print('NO')


a = int(input())
b = a
d = []
x = 0
while b != 0:
	b = b % 10
	a = a // 10
	d.append(b)
	b = a
d.reverse()
if d[0] == 4:
	x += 5
for i in range(len(d)):
	if d[i] != 1 and d[i] != 4:
		x += 5
for i in range(0, len(d) - 2):
	if d[i] == 4 and d[i + 1] == 4 and (d[i + 2] == 4):
		x += 5
if x == 0:
	print('YES')
else:
	print('NO')


def main():
	l = list(input())
	n = len(l)
	i = 0
	while i < n:
		if i + 2 < n and l[i] == '1' and (l[i + 1] == '4') and (l[i + 2] == '4'):
			i += 3
		elif i + 1 < n and l[i] == '1' and (l[i + 1] == '4'):
			i += 2
		elif l[i] == '1':
			i += 1
		else:
			return False
	return True
print('YES') if main() else print('NO')


s = input()
v = []
for i in s:
	v.append(int(i))
n = len(v)
v.append(0)
v.append(0)
v.append(0)
ok = True
i = 0
while i < n:
	if v[i] == 1 and v[i + 1] == 4 and (v[i + 2] == 4):
		i += 2
	elif v[i] == 1 and v[i + 1] == 4:
		i += 1
	elif v[i] == 1:
		i
	else:
		ok = False
	i += 1
if ok:
	print('YES')
else:
	print('NO')


s = int(input())
t = 0
while s > 0:
	if s % 1000 == 144:
		s = s // 1000
	elif s % 100 == 14:
		s = s // 100
	elif s % 10 == 1:
		s = s // 10
	else:
		t = 1
		break
if t == 0:
	print('YES')
else:
	print('NO')


inp = input()
r = True
if inp[0] != '1':
	r = False
else:
	nf = 0
	for i in inp:
		if i not in ['1', '4']:
			r = False
			break
		if i == '4':
			nf += 1
		else:
			nf = 0
		if nf > 2:
			r = False
			break
if r == True:
	print('YES')
else:
	print('NO')


mn = input()

def magic(n):
	for char in n:
		if char not in ('4', '1'):
			return False
	if n[0] != '1' or '444' in n:
		return False
	return True
if magic(mn):
	print('YES')
else:
	print('NO')


l = str(input())
r = l.count('1')
s = l.count('4')
if (r + s == len(l) and l[0] != '4') and '444' not in l:
	print('YES')
else:
	print('NO')


s = input()
if set(s) == {'1'}:
	print('YES')
elif set(s) == {'1', '4'}:
	i = 0
	n = len(s)
	valid = True
	while i < n:
		flag = False
		if i + 3 <= n and s[i:i + 3] == '144':
			i += 3
			flag = True
		elif i + 2 <= n and s[i:i + 2] == '14':
			i += 2
			flag = True
		elif i + 1 <= n and s[i] == '1':
			i += 1
			flag = True
		if not flag:
			valid = False
			break
	if valid:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


text = input()
i = 0
flag = True
while i < len(text) and flag == True:
	check = text[i:i + 3]
	if check == '144':
		i += 3
	elif check[0:2] == '14':
		i += 2
	elif check[0:1] == '1':
		i += 1
	else:
		flag = False
		break
if flag == True:
	print('YES')
else:
	print('NO')


t = input()
c = t.count('144')
b = t.count('14') - c
a = t.count('1') - b - c
print(['NO', 'YES'][a + 2 * b + 3 * c == len(t)])


s = input()

def m(s: str):
	d = True
	for i in s:
		if i != '1' and i != '4':
			d = False
	if s[0] == '4':
		d = False
	if s.find('444') >= 0:
		d = False
	return d
if m(s):
	print('YES')
else:
	print('NO')


q = input()
w = len(q)
t = 0
r = 0
for i in range(w):
	if q[i] == '1':
		r = 1
		t = 1
	elif q[i] == '4' and r == 1 and (t < 3):
		t += 1
		pass
	else:
		print('NO')
		exit()
print('YES')


x = y = input()
y = y.replace('1', '').replace('4', '')
p = 0
a = []
if x[0] == '4' or len(y) != 0:
	print('NO')
else:
	for i in x[::-1]:
		if i != '4':
			a.append(p)
			p = 0
		else:
			p += 1
	print('NO' if max(a) > 2 else 'YES')


num = input()
set_num = set(num)
out = 'YES'
magic_keys = ['1', '4', '14', '41']
keys = ''.join(set_num)
if keys not in magic_keys:
	out = 'NO'
elif num[0] != '1':
	out = 'NO'
elif '444' in num:
	out = 'NO'
print(out)


def magic(n):
	for i in range(len(n)):
		if n[i] == '4':
			if i < 1 or (n[i - 1] != '1' and n[i - 2] != '1'):
				return 'NO'
		elif n[i] != '4' and n[i] != '1':
			return 'NO'
	return 'YES'
n = input()
print(magic(n))


s = str(input())
valid = ['1', '14', '144']
i = 0
l = len(s)
while i < l:
	if s[i] is '1':
		if i + 1 < l and s[i + 1] == '1':
			i += 1
		elif (i + 1 < l and i + 2 < l) and s[i + 1] == s[i + 2]:
			i += 3
		elif i + 1 < l and s[i + 1] == '4':
			i += 2
		else:
			break
	else:
		break
if i == l or (i == l - 1 and s[-1] == '1'):
	print('YES')
else:
	print('NO')


song = input().strip()
song = song.replace('144', '.')
song = song.replace('14', '.')
song = song.replace('1', '.')
song = song.replace('.', '')
if '' != song:
	print('NO')
else:
	print('YES')


s = input()
ans = False
i = 0
if s[i] == '1':
	ans = True
	i += 1
	try:
		while i < len(s):
			if s[i] == '1':
				i += 1
				continue
			elif s[i] == '4' and s[i - 1] == '1':
				i += 1
				continue
			elif s[i] == '4' and s[i - 2] == '1':
				i += 1
				continue
			else:
				ans = False
				break
	except IndexError:
		ans = False
print('YES' if ans else 'NO')


n = input()
s = {'111', '114', '141', '441', '414', '144', '411', '144', '11', '14', '41', '44', '4', '1'}
if len(n) == 2:
	print('YES' if n in {'11', '14'} else 'NO')
elif len(n) == 1:
	print('YES' if n == '1' else 'NO')
elif n[:3] not in {'111', '114', '141', '144'}:
	print('NO')
else:
	for i in range(len(n)):
		if n[i:i + 3] not in s:
			print('NO')
			break
	else:
		print('YES')


x = input()
i = 0
while i < len(x) - 2:
	if x[i] == '1' and x[i + 1] == '4' and (x[i + 2] == '4'):
		x = x[:i] + '.' + x[i + 3:]
	else:
		i = i + 1
i = 0
while i < len(x) - 1:
	if x[i] == '1' and x[i + 1] == '4':
		x = x[:i] + '.' + x[i + 2:]
	else:
		i = i + 1
i = 0
while i < len(x):
	if x[i] == '1' or x[i] == '.':
		x = x[:i] + x[i + 1:]
	else:
		i = i + 1
if len(x) > 0:
	print('NO')
else:
	print('YES')


def solve(n):
	str_n = str(n)
	i = 0
	l = len(str_n)
	while i < l:
		if str_n[i] == '1':
			if i + 1 < l and str_n[i + 1] == '4':
				if i + 2 < l and str_n[i + 2] == '4':
					i += 3
				else:
					i += 2
			else:
				i += 1
		else:
			return 'NO'
	return 'YES'
n = int(input())
print(solve(n))


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
I = sys.stdin.readline

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def valid(row, col, rows, cols, rcross, lcross):
	return rows[row] == 0 and cols[col] == 0 and (rcross[col + row] == 0) and (lcross[col - row] == 0)

def div(n):
	tmp = []
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			cnt = 0
			while n % i == 0:
				n = n // i
				cnt += 1
			tmp.append((i, cnt))
	if n > 1:
		tmp.append((n, 1))
	return tmp

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		flag = True
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				flag = False
				break
		return flag

def s(b):
	ans = []
	while b > 0:
		tmp = b % 10
		ans.append(tmp)
		b = b // 10
	return ans

def main():
	s = I().strip()
	last1 = -math.inf
	cnt4 = 0
	flag = 0
	for i in range(len(s)):
		if s[i] == '1':
			last1 = i
		elif s[i] == '4':
			if 2 < i - last1:
				flag = 1
				break
		else:
			flag = 1
			break
	if flag:
		print('NO')
	else:
		print('YES')
main()


number_string = input()
number_string = number_string.replace('144', 'X')
number_string = number_string.replace('14', 'X')
number_string = number_string.replace('1', 'X')
helper_set = {x for x in number_string}
if len(helper_set) == 1 and helper_set.pop() == 'X':
	print('YES')
else:
	print('NO')


import sys
s = input()
l = len(s)
i = 0
while i < l:
	if s[i:i + 3] == '144':
		i = i + 3
	elif s[i:i + 2] == '14':
		i = i + 2
	elif s[i] == '1':
		i = i + 1
	else:
		print('NO')
		sys.exit(0)
print('YES')
sys.exit(0)


number = input()
flag = True
count = 0
if number[0] != '1':
	flag = False
if flag:
	for i in range(len(number)):
		if number[i] == '1':
			i += 1
			if i == len(number):
				break
			if number[i] != '4' and number[i] != '1':
				flag = False
				break
			if number[i] == '1':
				continue
			elif number[i] == '4':
				count = 0
				while i < len(number) and number[i] == '4':
					i += 1
					count += 1
					if count > 2:
						flag = False
						break
		elif number[i] != '4':
			flag = False
			break
if flag:
	print('YES')
else:
	print('NO')


s = input()
x = '02356789'
l = list(set(s))
if len(l) > 2:
	print('NO')
elif len(l) == 1 and l[0] in x:
	print('NO')
elif s[0] == '4':
	print('NO')
else:
	i = 0
	flag = 0
	s1 = ''
	n = len(s)
	while i < n:
		if s[i] != '1':
			flag = 1
			break
		elif s[i] == '1':
			if i + 1 < n and s[i + 1] == '4':
				if i + 2 < n and s[i + 2] == '4':
					s1 += s[i] + s[i + 1] + s[i + 2]
					i += 3
				else:
					s1 += s[i] + s[i + 1]
					i += 2
			else:
				s1 += s[i]
				i += 1
		else:
			flag = 1
			break
	if flag == 0:
		print('YES')
	else:
		print('NO')


from sys import stdin
inFile = stdin
tokens = []
tokens_next = 0

def next_str():
	global tokens, tokens_next
	while tokens_next >= len(tokens):
		tokens = inFile.readline().split()
		tokens_next = 0
	tokens_next += 1
	return tokens[tokens_next - 1]

def nextInt():
	return int(next_str())
s = next_str()
import re
if re.fullmatch('(1|14|144)*', s, re.IGNORECASE):
	print('YES')
else:
	print('NO')


q = input()
if q[0] == '1':
	for i in set(q):
		if i != '1' and i != '4':
			print('NO')
			exit()
	if '444' in q:
		print('NO')
	else:
		print('YES')
else:
	print('NO')


n = int(input())
s = str(n)
l = len(str(n))
f = 1
while n != 0:
	if l >= 3 and s[l - 1] == '4' and (s[l - 2] == '4') and (s[l - 3] == '1'):
		n //= 1000
		l = len(str(n))
	elif l >= 2 and s[l - 1] == '4' and (s[l - 2] == '1'):
		n //= 100
		l = len(str(n))
	elif s[l - 1] == '1':
		n //= 10
		l = len(str(n))
	else:
		f = 0
		break
if n == 0:
	print('YES')
elif f == 0:
	print('NO')


n = input()
ans = 'YES'
while len(n) != 0:
	if n[:3] == '144':
		n = n[3:]
	elif n[:2] == '14':
		n = n[2:]
	elif n[:1] == '1':
		n = n[1:]
	else:
		ans = 'NO'
		break
print(ans)


from functools import reduce
from operator import *
from math import *
import sys
sys.setrecursionlimit(10 ** 7)
x = int(input())
while x:
	if x % 10 != 1 and x % 100 != 14 and (x % 1000 != 144):
		print('NO')
		sys.exit(0)
	x //= 10
print('YES')


k = input()
m = list(k)
t = 0
for i in range(len(m)):
	if int(m[i]) in [1, 4]:
		continue
	else:
		t = 1
		break
for i in range(len(m) - 2):
	if m[i] == '4' and m[i + 1] == '4' and (m[i + 2] == '4'):
		t = 1
		break
		t = 1
		break
	else:
		continue
if m[0] == '4':
	t = 1
if t == 1:
	print('NO')
else:
	print('YES')


from sys import stdin, stdout

def trace(f):

	def traced(*args, **kw):
		print('calling {} with args {}, {}'.format(f.__name__, args, kw))
		return f(*args, **kw)
	return traced

@trace
def f(x):
	print(x)

def read():
	return stdin.readline()[:-1]

def readarr(sep=None, maxsplit=-1):
	return read().split(sep, maxsplit)

def readint():
	return int(read())

def readintarr(sep=None, maxsplit=-1):
	return [int(a) for a in readarr(sep, maxsplit)]

def write(*args, **kwargs):
	sep = kwargs.get('sep', ' ')
	end = kwargs.get('end', '\n')
	stdout.write(sep.join((str(a) for a in args)) + end)

def writearr(arr, sep=' ', end='\n'):
	stdout.write(sep.join((str(a) for a in arr)) + end)
from itertools import *
while True:
	sx = read()
	if not sx:
		break
	write('YES' if all(map(lambda x: x == '-', sx.replace('144', '-').replace('14', '-').replace('1', '-'))) else 'NO')


import math
t = input()
flag = True
i = 0
while i < len(t):
	if t[i:i + 3] == '144':
		i += 3
	elif t[i:i + 2] == '14':
		i += 2
	elif t[i] == '1':
		i = i + 1
	else:
		flag = False
		break
if flag == True:
	print('YES')
else:
	print('NO')


def magic(num):
	i = 0
	leng = len(num)
	while i < leng:
		if num[i] == '1':
			if i + 1 < leng and num[i + 1] == '4':
				if i + 2 < leng and num[i + 2] == '4':
					num = num[3:]
					leng -= 3
				else:
					num = num[2:]
					leng -= 2
			else:
				num = num[1:]
				leng -= 1
		else:
			print('NO')
			return
	print('YES')
number = input()
magic(number)


num = input()
i = 0
f = 0
while True:
	if num[i] != '1' and num[i] != '4':
		f = 1
		break
	elif num[i] == '4':
		if i - 1 >= 0:
			if num[i - 1] == '1':
				i += 1
			elif i - 2 >= 0 and num[i - 2] == '1':
				i += 1
			else:
				f = 1
				break
		else:
			f = 1
			break
	else:
		i += 1
	if i >= len(num):
		break
if f == 1:
	print('NO')
else:
	print('YES')


st = input()
c144 = st.count('144')
c14 = st.count('14') - c144
c1 = st.count('1') - c14 - c144
print('NYOE S'[len(st) == 3 * c144 + 2 * c14 + c1::2])


string = input()
string = string.replace('144', ' ')
string = string.replace('14', ' ')
string = string.replace('1', ' ')
string.replace(' ', '')
flag = 0
for i in string:
	if i != ' ':
		print('NO')
		flag = 1
		break
if flag == 0:
	print('YES')


s = input()
a = [['144', 'a'], ['14', 'b'], ['1', 'c']]
for i in a:
	if i[0] in s:
		s = s.replace(i[0], i[1])

def fn(s):
	for i in s:
		if i not in 'abc':
			return 'NO'
	return 'YES'
print(fn(s))


a = input()
result = 1
if a[0] != '1':
	print('NO')
	result = 0
else:
	for i in range(len(a)):
		if a[i] != '1' and a[i] != '4':
			print('NO')
			result = 0
			break
	if result == 1:
		length = len(a)
		for i in range(length - 2):
			if a[i] == '4' and a[i + 1] == '4' and (a[i + 2] == '4'):
				print('NO')
				result = 0
				break
if result == 1:
	print('YES')


a = input()
if a[0] != '1':
	print('NO')
elif '444' in a:
	print('NO')
elif a.count('4') + a.count('1') != len(a):
	print('NO')
else:
	print('YES')


stra = input()
last = stra[0]
if last != '1':
	print('NO')
else:
	bv = True
	for c in stra[1:]:
		if last == '1' and (c == '4' or c == '1'):
			last = c
		elif last == '4' and c == '4':
			last = '44'
		elif last == '4' and c == '1':
			last = '1'
		elif last == '44' and c == '1':
			last = '1'
		else:
			bv = False
			break
	if bv:
		print('YES')
	else:
		print('NO')


N = int(input())
arr = str(N)
if arr.count('1') + arr.count('4') == len(arr):
	if '444' in arr:
		print('NO')
	elif arr[0] == '4':
		print('NO')
	else:
		print('YES')
else:
	print('NO')


n = input()
one = 0
four = 0
one_four = 0
for i in n:
	if i == '1':
		one = 1
		if four == 1:
			four = 0
	elif i == '4':
		if one == 0:
			print('NO')
			exit()
		if four == 1:
			four = 0
			one = 0
		else:
			four = 1
	else:
		print('NO')
		exit()
print('YES')


import sys
input = lambda : sys.stdin.readline().strip()
s = input()
if s[0] == '4':
	print('NO')
elif s.find('444') >= 0:
	print('NO')
else:
	for i in s:
		if i != '4' and i != '1':
			print('NO')
			break
	else:
		print('YES')


n = int(input())
s = str(n)
a = list(s)
w = set(a)
c = 0
if len(w) == 2 or len(w) == 1:
	for x in range(0, len(a)):
		if a[0] == '4':
			print('NO')
			c = 1
			break
		if a[x] == '1':
			pass
		elif len(a) > 1 and (a[x - 1] + a[x] == '14' or a[x - 2] + a[x - 1] + a[x] == '144'):
			pass
		else:
			print('NO')
			c = 1
			break
else:
	c = 1
	print('NO')
if c == 0:
	print('YES')


s = input()
i = 0
while i + 2 < len(s):
	if s[i] == '1' and s[i + 1] == '4' and (s[i + 2] == '4'):
		i += 3
		continue
	elif s[i] == '1' and s[i + 1] == '4':
		i += 2
		continue
	elif s[i] == '1':
		i += 1
		continue
	else:
		print('NO')
		exit(0)
if i + 1 < len(s) and (s[i] != '1' or (s[i + 1] != '1' and s[i + 1] != '4')):
	print('NO')
	exit(0)
if i < len(s) and s[i] != '1':
	print('NO')
	exit(0)
print('YES')


n = input()
count = 0
if n[0] != '1':
	print('NO')
	quit()
for i in n:
	if i != '1' and i != '4':
		print('NO')
		quit()
	if i == '4':
		count += 1
	if i == '1':
		count = 0
	if count > 2:
		print('NO')
		quit()
print('YES')


str = input()
str2 = str
oneff = str.count('144')
str = str.replace('144', 'X')
onef = str.count('14')
str = str.replace('14', 'Y')
one = str.count('1')
leg = oneff * 3 + onef * 2 + one
if leg == len(str2):
	print('YES')
else:
	print('NO')


def magic(number):
	if number[0] != '1' or '444' in number:
		return False
	for char in number:
		if char != '1' and char != '4':
			return False
	else:
		return True
sa = input()
if magic(sa):
	print('YES')
else:
	print('NO')


def is_magic_number(s):
	n = len(s)
	i = 0
	while i < n:
		if s[i] == '1':
			if i + 1 < n:
				if s[i + 1] == '1':
					i += 1
					continue
				elif s[i + 1] == '4':
					i += 1
					if i + 1 < n:
						if s[i + 1] == '1':
							i += 1
							continue
						elif s[i + 1] == '4':
							i += 2
						else:
							return False
					else:
						break
				else:
					return False
			else:
				break
		else:
			return False
	return True
s = input()
if is_magic_number(s):
	print('YES')
else:
	print('NO')


s = input()
if '1' in s and s[0] != '4':
	for e in s.split('1'):
		if e not in ['', '4', '44']:
			print('NO')
			break
	else:
		print('YES')
else:
	print('NO')


n = [int(X) for X in list(input())]
an = 1
if n[0] == 4:
	an = 0
for i in n:
	if i != 1 and i != 4:
		an = 0
		break
if an:
	for i in range(len(n) - 2):
		if n[i] == 4 and n[i + 1] == 4 and (n[i + 2] == 4):
			an = 0
if an:
	print('YES')
else:
	print('NO')


n = input()
flag = 0
for i in range(len(n)):
	if n[i] != '1' and n[i] != '4':
		flag += 1
	if n[0] == '4':
		flag += 1
	if '444' in n:
		flag += 1
if flag > 0:
	print('NO')
elif flag == 0:
	print('YES')


line1 = list(map(int, list(input())))
num_str = line1[:]
n = len(num_str)
matchers = [[1, 4, 4], [1, 4], [1]]
for match in matchers:
	i = 0
	match_len = len(match)
	while i < n - len(match) + 1:
		if num_str[i:i + match_len] == match:
			num_str[i:i + match_len] = [-1] * match_len
			i += match_len
		else:
			i += 1
if sum(num_str) == -1 * n:
	print('YES')
else:
	print('NO')


s = input()
l = len(s)
flag = True
t = l - 1
while t >= 0:
	if s[t] == '1':
		t -= 1
	elif t > 0 and s[t] == '4' and (s[t - 1] == '1'):
		t -= 2
	elif t > 1 and s[t] == '4' and (s[t - 1] == '4') and (s[t - 2] == '1'):
		t -= 3
	else:
		flag = False
		break
if flag:
	print('YES')
else:
	print('NO')


l = input()
ok = True
while True:
	p = l.find('11')
	if p == -1:
		break
	else:
		l = l[:p] + l[p + 1:]
while True:
	p = l.find('44')
	if p == -1:
		break
	if p != 0 and l[p - 1] == '1':
		if p + 2 < len(l):
			if l[p + 2] == '1':
				l = l[:p - 1] + l[p + 2:]
			else:
				ok = False
				break
		else:
			l = l[:p - 1] + l[p + 2:]
	else:
		ok = False
		break
if not ok:
	print('NO')
	exit()
while True:
	p = l.find('4')
	if p == -1:
		break
	if p != 0 and l[p - 1] == '1':
		l = l[:p - 1] + l[p + 1:]
	else:
		ok = False
		break
if not ok:
	print('NO')
	exit()
for i in l:
	if i != '1':
		print('NO')
		exit()
print('YES')


s = input().strip()
if s.count('1') + s.count('14') + s.count('144') == len(s):
	print('YES')
else:
	print('NO')


n = input()
if n[0] == '1':
	num = len(n)
	error = 0
	strike_4 = 0
	max_strike_4 = 0
	last_num4 = 0
	for i in range(num):
		if n[i] != '1' and n[i] != '4':
			error = 1
		if n[i] == '4':
			last_num4 = 1
			strike_4 += 1
		if n[i] != '4' and last_num4 == 1:
			max_strike_4 = max(max_strike_4, strike_4)
			strike_4 = 0
			last_num4 = 0
	max_strike_4 = max(max_strike_4, strike_4)
	if max_strike_4 > 2:
		error = 1
	if error == 1:
		print('NO')
	else:
		print('YES')
else:
	print('NO')


s = input()
if s[0] != '1':
	print('NO')
elif s[-1] != '4' and s[-1] != '1':
	print('NO')
else:
	p = s[0]
	k = 0
	f = 1
	for i in range(1, len(s)):
		if s[i] == '4':
			k += 1
			if k > 2:
				f = 0
				print('NO')
				break
		elif s[i] != '1' and s[i] != '4':
			print('NO')
			f = 0
			break
		else:
			k = 0
	if f:
		print('YES')


s = input()
n = len(s)
if '444' in s or s[0] == '4':
	print('NO')
else:
	for i in range(n):
		ele = s[i]
		if ele != '1' and ele != '4':
			print('NO')
			break
		if i == n - 1:
			print('YES')


nuum = input()
res = True
j = 0
k = 0
while j < len(nuum):
	try:
		if nuum[j] == '1' and nuum[j + 1] == '4' and (nuum[j + 2] == '4'):
			j += 3
		elif nuum[j] == '1' and nuum[j + 1] == '4':
			j += 2
		elif nuum[j] == '1':
			j += 1
		else:
			res = False
			break
	except IndexError:
		break
if res == True:
	print('YES')
else:
	print('NO')


s = input()
flag = 0
for i in s:
	if not (i == '1' or i == '4'):
		flag = 1
		break
if flag == 1:
	print('NO')
elif s[0] == '4':
	print('NO')
else:
	test = list(s.split('444'))
	if len(test) > 1:
		print('NO')
	else:
		print('YES')


a = input()
print(['YES', 'NO']['444' in a or a[0] == '4' or set(a) - {'1', '4'} != set()])


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().rstrip().split())
inl = lambda : list(map(int, input().split()))
out = lambda x, s='\n': print(s.join(map(str, x)))
n = ins().replace('144', ' ').replace('14', ' ').replace('1', ' ').replace(' ', '')
print('YES' if len(n) == 0 else 'NO')


n = int(input())
x = str(n)
i = 0
flag = 0
while i < len(x):
	if x[i:i + 3] == '144':
		flag = 1
		i += 3
	elif x[i:i + 2] == '14':
		flag = 1
		i += 2
	elif x[i] == '1':
		flag = 1
		i += 1
	else:
		flag = 0
		print('NO')
		break
else:
	print('YES')


import sys
a = [int(x) for x in input()]
if a[0] != 1:
	print('NO')
	sys.exit()
i = 1
onepr = True
flag = False
fourcount = 0
while i < len(a):
	if a[i] == 1:
		onepr = True
		fourcount = 0
		i = i + 1
		continue
	elif a[i] == 4 and (onepr or fourcount <= 1):
		onepr = False
		fourcount += 1
	else:
		flag = True
		break
	i += 1
if flag:
	print('NO')
else:
	print('YES')


n = input()
c = 0
if not n[0] == '1':
	print('NO')
elif not n.count('1') + n.count('4') == len(n):
	print('NO')
else:
	for i in range(len(n)):
		if n[i] == '4':
			if not (n[i - 1] == '1' or (n[i - 1] == '4' and n[i - 2] == '1')):
				print('NO')
				c = 1
				break
	if not c:
		print('YES')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def prime_factors(x):
	s = set()
	n = x
	i = 2
	while i * i <= n:
		if n % i == 0:
			while n % i == 0:
				n //= i
			s.add(i)
		i += 1
	if n > 1:
		s.add(n)
	return s
from collections import Counter
import heapq
from collections import Counter
from bisect import bisect_right
import heapq

def dfs(x):
	if 0 < x <= n:
		s.add(x)
		x *= 10
		dfs(x + i)
		dfs(x + j)
n = str(input())
f = 0
i = 0
while i < len(n):
	if n[i] == '4':
		if f == 0:
			print('NO')
			exit()
		else:
			if i + 1 < len(n) and n[i + 1] == '4':
				i += 1
			i += 1
			f = 0
	elif n[i] == '1':
		i += 1
		f = 1
	else:
		print('NO')
		exit()
print('YES')


import sys
i = sys.stdin.readline()
if '2' in i or '0' in i or '3' in i or ('5' in i) or ('6' in i) or ('7' in i) or ('8' in i) or ('9' in i) or ('444' in i):
	print('NO')
elif i[0] == '4':
	print('NO')
else:
	print('YES')


n = str(input())
(x, y, z) = (0, 0, 0)
x += n.count('144')
y += n.count('14')
z += n.count('1')
print('YES' if len(n) == 3 * x + 2 * (y - x) + z - y else 'NO')


n = input()
n = list(n)
mn = [1, 4]
n = list(map(int, n))
if n[0] != 1:
	print('NO')
else:
	for i in range(1, len(n)):
		if i == len(n) - 1:
			if n[i] not in mn:
				print('NO')
				break
			elif n[i] == 4:
				if n[i - 1] == 1:
					pass
				elif n[i - 1] == 4:
					if n[i - 2] == 1:
						pass
					else:
						print('NO')
						break
		elif n[i] not in mn:
			print('NO')
			break
		else:
			if n[i] == 1:
				continue
			if n[i] == 4:
				if n[i - 1] == 1 and n[i + 1] == 1 or (n[i - 1] == 1 and n[i + 1] == 4) or (n[i - 1] == 4 and n[i + 1] == 1):
					continue
				else:
					print('NO')
				break
	else:
		print('YES')


a = input()
p = 0
if len(a) == 1:
	if a == '1':
		p = 1
		print('YES')
	else:
		print('NO')
		p = 1
if p != 1:
	if a[0] == '4':
		print('NO')
	else:
		for i in range(10):
			if i != 4 and i != 1:
				if str(i) in a:
					print('NO')
					p = 1
					break
		s = 0
		if p == 0:
			for i in range(len(a)):
				if a[i] == '1':
					s = 0
				else:
					s = s + 1
					if s == 3:
						p = 1
						print('NO')
						break
			if p == 0:
				print('YES')


s = input()
if any((i in s for i in '02356789')):
	exit(print('NO'))
if s.startswith('4'):
	exit(print('NO'))
if '444' in s:
	exit(print('NO'))
print('YES')


n = input()
valid = ['1', '14', '144']
i = 0
while i < len(n):
	flag = False
	for j in range(1, 4):
		if i + j == len(n) + 1:
			break
		if n[i:j + i] in valid:
			if j == 3:
				j += 1
			flag = True
		else:
			break
	if not flag:
		print('NO')
		break
	i += j - 1
if flag:
	print('YES')


number = input()
while number:
	if number.startswith('144'):
		number = number[3:]
	elif number.startswith('14'):
		number = number[2:]
	elif number.startswith('1'):
		number = number[1:]
	else:
		break
if not number:
	print('YES')
else:
	print('NO')


import re
s = input()
if re.match('(14?4?)*$', s):
	print('YES')
else:
	print('NO')


l = list((int(i) for i in input()))
while len(l) != 0:
	if l[:1] == [1] or l[:2] == [1, 4] or l[:3] == [1, 4, 4]:
		if l[:3] == [1, 4, 4]:
			l.pop(0)
			l.pop(0)
			l.pop(0)
		elif l[:2] == [1, 4]:
			l.pop(0)
			l.pop(0)
		else:
			l.pop(0)
	else:
		print('NO')
		exit()
print('YES')


def main():
	s = str(input())
	if s == '1':
		print('YES')
		return
	if s == '14':
		print('YES')
		return
	if s == '144':
		print('YES')
		return
	if s.find('444') != -1:
		print('NO')
		return
	f2 = s.count('4') + s.count('1') == len(s)
	f3 = s.count('1') > 1
	f4 = s[0] == '1'
	if f2 and f3 and f4:
		print('YES')
	else:
		print('NO')
main()


n = input()
if n.count('1') + n.count('4') != len(n):
	print('NO')
elif n[0] == '4':
	print('NO')
else:
	p = n.split('1')
	p.sort()
	if len(p[-1]) >= 3:
		print('NO')
	else:
		print('YES')


import sys
from os import path
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
n = int(input())
temp = 1
while n > 0:
	if n % 1000 == 144:
		n = n // 1000
	elif n % 100 == 14:
		n = n // 100
	elif n % 10 == 1:
		n = n // 10
	else:
		print('NO')
		temp = 0
		break
if temp == 1:
	print('YES')


n = input()
a = ['1', '4']
if n[0] != '1':
	print('NO')
else:
	count = 0
	flag = True
	for i in n:
		if i not in a or count == 3:
			flag = False
			break
		if i is not '4':
			count = 0
		if i is '4':
			count += 1
	if flag and count < 3:
		print('YES')
	else:
		print('NO')


import time
import random
from math import *
from collections import defaultdict
from itertools import *
import re

def solve(n):
	return bool(re.fullmatch('(1|14|144)*', n))
print('YES' if solve(input()) else 'NO')


n = str(int(input()))
check = {'1', '14', '144'}
i = 0
while i < len(n):
	for j in [3, 2, 1]:
		if n[i:i + j] in check:
			i += j
			break
	else:
		print('NO')
		exit()
print('YES')