The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line?


-----Input-----

The first line contains integer n (1 ≤ n ≤ 10^5) — the number of people in the line. The next line contains n integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line.


-----Output-----

Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO".


-----Examples-----
Input
4
25 25 50 50

Output
YES

Input
2
25 100

Output
NO

Input
4
50 50 25 25

Output
NO

Source: codeforces | Difficulty: EASY
Tags: Implementation

Greedy algorithms


Solutions:
n = int(input())
arr = list(map(int, input().split()))
flag = 0
counter = [0, 0, 0]
for i in range(len(arr)):
	if arr[i] == 50:
		if counter[0] < 1:
			print('NO')
			flag = 1
			break
		counter[1] += 1
		counter[0] -= 1
	elif arr[i] == 100:
		if counter[0] > 0 and counter[1] > 0:
			counter[2] += 1
			counter[0] -= 1
			counter[1] -= 1
		elif counter[1] < 1 and counter[0] > 2:
			counter[2] += 1
			counter[0] -= 3
		else:
			print('NO')
			flag = 1
			break
	elif arr[i] == 25:
		counter[0] += 1
if flag == 0:
	print('YES')


n = int(input())
s = list(map(int, input().split()))
d25 = 0
d50 = 0
answer = 'YES'
for i in range(n):
	if s[i] == 25:
		d25 += 1
		continue
	elif s[i] == 50:
		d50 += 1
		d25 -= 1
		if d25 < 0:
			answer = 'NO'
			break
	elif d50 >= 1 and d25 >= 1:
		d50 -= 1
		d25 -= 1
		continue
	elif d50 < 1 and d25 >= 3:
		d25 -= 3
		continue
	else:
		answer = 'NO'
		break
print(answer)


n = int(input())
x = [i for i in input().split()]
coin25 = 0
coin50 = 0
res = 'YES'
for a in x:
	if a == '25':
		coin25 += 1
	elif a == '50':
		if coin25 > 0:
			coin25 -= 1
			coin50 += 1
		else:
			res = 'NO'
			break
	elif coin50 >= 1 and coin25 >= 1:
		coin25 -= 1
		coin50 -= 1
	elif coin25 >= 3:
		coin25 -= 3
	else:
		res = 'NO'
	if res == 'NO':
		break
print(res)


n = int(input())
l = list(map(int, input().split()))
a = 0
b = 0
c = 0
check = True
for i in l:
	if i == 25:
		a += 1
	elif i == 50 and a >= 1:
		b += 1
		a -= 1
	elif i == 100 and (a >= 3 or (a >= 1 and b >= 1)):
		c += 1
		if b >= 1:
			b -= 1
			a -= 1
		else:
			a -= 3
	else:
		print('NO')
		check = False
		break
if check:
	print('YES')


import math

def ost(a, b):
	if a % b != 0:
		return 1
	return 0
n = int(input())
data = list(map(int, input().split()))
a = 0
b = 0
for i in range(n):
	if data[i] == 25:
		a += 1
	elif data[i] == 50:
		if a == 0:
			print('NO')
			exit()
		else:
			a -= 1
			b += 1
	elif b == 0 and a < 3 or a == 0:
		print('NO')
		exit()
	elif b > 0:
		b -= 1
		a -= 1
	else:
		a -= 3
print('YES')


def check(a):
	cnt25 = 0
	cnt50 = 0
	for x in a:
		if x == 25:
			cnt25 += 1
		elif x == 50:
			if cnt25 == 0:
				return False
			cnt50 += 1
			cnt25 -= 1
		elif x == 100:
			if cnt50 > 0:
				if cnt25 == 0:
					return False
				cnt50 -= 1
				cnt25 -= 1
			else:
				if cnt25 < 3:
					return False
				cnt25 -= 3
	return True
n = int(input())
a = [int(x) for x in input().split()]
print('YES' if check(a) else 'NO')


p25 = 0
p50 = 0
p100 = 0
n = int(input())
for x in map(int, input().split()):
	if x == 25:
		p25 = p25 + 1
	elif x == 50:
		if p25 > 0:
			p25 = p25 - 1
			p50 = p50 + 1
		else:
			print('NO')
			exit()
	elif p50 > 0 and p25 > 0:
		p50 = p50 - 1
		p25 = p25 - 1
		p100 = p100 + 1
	elif p25 > 2:
		p25 = p25 - 3
		p100 = p100 + 1
	else:
		print('NO')
		exit()
print('YES')


n = int(input())
a = list(map(int, input().split()))
(s25, s50, s100) = (0, 0, 0)
for i in range(len(a)):
	if a[i] == 25:
		s25 += 1
	elif a[i] == 50:
		if s25 > 0:
			s25 -= 1
			s50 += 1
		else:
			print('NO')
			exit()
	elif a[i] == 100:
		if s50 > 0 and s25 > 0:
			s25 -= 1
			s50 -= 1
		elif s25 > 2:
			s25 -= 3
		else:
			print('NO')
			exit()
print('YES')


n = int(input())
m = [int(_) for _ in input().split()]
x = 0
i = 0
p = 0
while i < n and x >= 0:
	if m[i] == 25:
		x += 1
	elif m[i] == 50 and x > 0:
		x -= 1
		p += 1
	elif m[i] == 100 and p > 0:
		x -= 1
		p -= 1
	elif m[i] == 100 and x >= 3:
		x -= 3
	elif m[i] == 50:
		x -= 1
	else:
		x = -1
	i += 1
if x >= 0:
	print('YES')
else:
	print('NO')


n = int(input())
line = list(map(int, input().split()))
k25 = 0
k50 = 0
k100 = 0
for i in line:
	if i == 25:
		k25 += 1
	elif i == 50 and k25 > 0:
		k25 -= 1
		k50 += 1
	elif i == 100 and (k25 > 0 and k50 > 0 or k25 > 2):
		if k25 > 0 and k50 > 0:
			k25 -= 1
			k50 -= 1
		else:
			k25 -= 3
		k100 += 1
	else:
		print('NO')
		break
else:
	print('YES')


n = int(input())
money = [int(x) for x in input().split()]
change = [0, 0]
flag = True
for i in money:
	if i == 25:
		change[0] = change[0] + 1
	elif i == 50:
		if change[0] > 0:
			change[0] = change[0] - 1
			change[1] = change[1] + 1
		else:
			flag = False
			print('NO')
			break
	elif change[0] >= 1 and change[1] >= 1:
		change[0] = change[0] - 1
		change[1] = change[1] - 1
	elif change[0] >= 3 and change[1] == 0:
		change[0] = change[0] - 3
	else:
		flag = False
		print('NO')
		break
if flag:
	print('YES')


def ischange(x, d):
	if x == 25:
		if d['25'] >= 1:
			d['25'] -= 1
			return 1
		else:
			return 0
	elif x == 75:
		if d['50'] >= 1 and d['25'] >= 1:
			d['50'] -= 1
			d['25'] -= 1
			return 1
		elif d['25'] >= 3:
			d['25'] -= 3
			return 1
		else:
			return 0
	elif x == 0:
		return 1
	else:
		return 0
n = int(input())
flag = 0
x = list(input().split())
x = [int(i) for i in x]
d = {'25': 0, '50': 0, '100': 0}
for i in range(0, n):
	change = x[i] - 25
	d[str(x[i])] += 1
	if ischange(change, d) == 0:
		flag = 1
if flag == 1:
	print('NO')
else:
	print('YES')


n = int(input())
arr = list(map(int, input().split()))
a = 0
b = 0
c = 0
for i in range(len(arr)):
	if arr[i] == 25:
		a += 1
		continue
	if arr[i] == 50:
		b += 1
		if a < 1:
			print('NO')
			exit()
		else:
			a -= 1
		continue
	else:
		if b == 0 and a < 3:
			print('NO')
			exit()
		if b == 0 and a >= 3:
			a -= 3
			continue
		if b >= 1 and a < 1:
			print('NO')
			exit()
		if b >= 1 and a >= 1:
			a -= 1
			b -= 1
			continue
print('YES')


n = int(input())
x = list(map(int, input().split()))
change = [0, 0]
stat = True
for i in x:
	if i == 25:
		change[0] += 1
	elif i == 50 and change[0] >= 1:
		change[0] -= 1
		change[1] += 1
	elif i == 100 and change[0] >= 1 and (change[1] >= 1):
		change[0] -= 1
		change[1] -= 1
	elif i == 100 and change[0] >= 3:
		change[0] -= 3
	else:
		stat = False
print(['NO', 'YES'][stat])


n = int(input())
line = [int(i) for i in input().split()]
money25 = 0
money50 = 0
for i in range(n):
	if line[i] == 25:
		money25 += 1
	if line[i] == 50:
		if money25 > 0:
			money25 -= 1
			money50 += 1
		else:
			print('NO')
			break
	if line[i] == 100:
		if money25 > 0 and money50 > 0:
			money25 -= 1
			money50 -= 1
		elif money25 > 2:
			money25 -= 3
		else:
			print('NO')
			break
else:
	print('YES')


n = int(input())
twentyfives = 0
fifties = 0
for ruble in list(map(int, input().split())):
	if ruble == 25:
		twentyfives += 1
	else:
		if ruble == 50:
			fifties += 1
			if twentyfives >= 1:
				twentyfives -= 1
			else:
				print('NO')
				exit()
		if ruble == 100:
			if twentyfives >= 1 and fifties >= 1:
				twentyfives -= 1
				fifties -= 1
			elif twentyfives >= 3:
				twentyfives -= 3
			else:
				print('NO')
				exit()
print('YES')


I = lambda : list(map(int, input().split()))
(n,) = I()
l = I()
den = {}
den[25] = 0
den[75] = 0
den[50] = 0
flag = 1
for i in range(n):
	if l[i] == 25:
		den[25] += 1
	elif l[i] == 50:
		if den[25]:
			den[25] -= 1
			den[50] += 1
		else:
			flag = 0
	elif l[i] == 100:
		if den[50] and den[25]:
			den[50] -= 1
			den[25] -= 1
		elif den[50] == 0 and den[25] >= 3:
			den[25] -= 3
		else:
			flag = 0
	if not flag:
		break
print('YES' if flag else 'NO')


from sys import stdin
n = int(stdin.readline().rstrip())
nums = map(int, stdin.readline().rstrip().split(' '))
twenties = 0
fifties = 0
cost = 25
broke = False
for num in nums:
	if num == 25:
		twenties += 1
	elif num == 50:
		if twenties == 0:
			print('NO')
			broke = True
			break
		else:
			twenties -= 1
			fifties += 1
	elif fifties >= 1 and twenties >= 1:
		fifties -= 1
		twenties -= 1
	elif twenties >= 3:
		twenties -= 3
	else:
		print('NO')
		broke = True
		break
if not broke:
	print('YES')


n = int(input())
l = list(map(int, input().split()))
c25 = 0
c50 = 0
c100 = 0
flag = 1
if l[0] == 50 or l[0] == 100:
	print('NO')
	flag = 0
else:
	for i in range(n):
		if l[i] == 25:
			c25 = c25 + 1
		elif l[i] == 50:
			c50 = c50 + 1
			if c25 != 0:
				c25 = c25 - 1
			else:
				print('NO')
				flag = 0
				break
		else:
			c100 = c100 + 1
			if c25 != 0 and c50 != 0:
				c25 = c25 - 1
				c50 = c50 - 1
			elif c25 >= 3:
				c25 = c25 - 3
			else:
				print('NO')
				flag = 0
				break
if flag == 1:
	print('YES')


def diehard(n, l):
	if l[0] != 25:
		print('NO')
		return
	else:
		ct = 1
		cf = 0
		for i in range(1, n):
			if l[i] == 25:
				ct += 1
			elif l[i] == 50:
				if ct > 0:
					cf += 1
					ct -= 1
				else:
					print('NO')
					return
			elif l[i] == 100:
				if ct > 0 and cf > 0:
					ct -= 1
					cf -= 1
				elif ct > 2:
					ct -= 3
				else:
					print('NO')
					return
		print('YES')
n = int(input())
l = list(map(int, input().split()))
diehard(n, l)


n = int(input())
inp = list(map(int, input().split()))
twof = 0
fifty = 0
hun = 0
flag = 0
for item in inp:
	if item == 25:
		twof += 1
		continue
	elif item == 50:
		fifty += 1
		if twof >= 1:
			twof -= 1
			continue
		else:
			print('NO')
			flag = 1
			break
	elif item == 100:
		hun += 1
		if fifty >= 1 and twof >= 1:
			fifty -= 1
			twof -= 1
			continue
		elif fifty == 0 and twof >= 3:
			twof -= 3
			continue
		else:
			print('NO')
			flag = 1
			break
if flag == 0:
	print('YES')


n = int(input())
l = list(map(int, input().split()))
(a, b, c, flag) = (0, 0, 0, 0)
for i in range(0, n):
	if l[i] == 25:
		a += 1
	elif l[i] == 50:
		b += 1
		a -= 1
		if a < 0:
			flag = 1
			break
	elif l[i] == 100:
		c += 1
		b -= 1
		if b < 0 and a > 0:
			a -= 2
			b += 1
		a -= 1
		if a < 0 or b < 0:
			flag = 1
			break
if flag == 1:
	print('NO')
else:
	print('YES')


n = int(input())
change25 = 0
change50 = 0
people = [int(val) for val in input().split(' ')]
fail = False
for i in range(n):
	nextguy = people[i]
	if nextguy == 25:
		change25 += 1
	elif nextguy == 50:
		if change25 == 0:
			fail = True
			break
		else:
			change25 -= 1
			change50 += 1
	elif nextguy == 100:
		if change50 > 0 and change25 > 0:
			change25 -= 1
			change50 -= 1
		elif change25 > 2:
			change25 -= 3
		else:
			fail = True
			break
print('NO' if fail else 'YES')


from sys import stdin, stdout
n = int(stdin.readline())
lst = [int(i) // 25 - 1 for i in stdin.readline().split()]
store = [0, 0]
ans = 'YES'
for i in lst:
	if i == 0:
		store[0] += 1
	if i == 1:
		store[0] -= 1
		store[1] += 1
		if store[0] < 0:
			ans = 'NO'
			break
	if i == 3:
		store[1] -= 1
		store[0] -= 1
		if store[1] < 0:
			store[1] += 1
			store[0] -= 2
		if store[0] < 0:
			ans = 'NO'
			break
stdout.write(str(ans))


n = int(input())
a = [*map(int, input().split())]
m = [0, 0, 0]
ans = 'YES'
for i in a:
	if i == 25:
		m[0] += 1
	elif i == 50:
		m[1] += 1
		if m[0]:
			m[0] -= 1
		else:
			ans = 'NO'
			break
	else:
		m[2] += 1
		if m[0] and m[1]:
			m[0] -= 1
			m[1] -= 1
		elif m[0] >= 3:
			m[0] -= 3
		else:
			ans = 'NO'
			break
print(ans)


n = int(input())
line = input().split()
dic = {25: 0, 50: 0, 100: 0}
for i in line:
	dic[int(i)] += 1
	if i == '50':
		if dic[25] == 0:
			print('NO')
			exit(0)
		else:
			dic[25] -= 1
	elif i == '100':
		if dic[50] * dic[25] > 0:
			dic[50] -= 1
			dic[25] -= 1
		elif dic[25] >= 3:
			dic[25] -= 3
		else:
			print('NO')
			exit(0)
print('YES')


I = input
I()
(a, b) = (0, 0)
f = False
ls = list(map(int, I().split()))
for _ in ls:
	if _ == 25:
		a += 1
	elif _ == 50:
		if a > 0:
			a -= 1
			b += 1
		else:
			print('NO')
			f = True
			break
	elif b > 0 and a > 0:
		a -= 1
		b -= 1
	elif a > 2:
		a -= 3
	else:
		print('NO')
		f = True
		break
if not f:
	print('YES')


n = int(input())
a = list(map(int, input().split()))
if a[0] == 50 or a[0] == 100 or a[1] == 100:
	print('NO')
else:
	x = 0
	y = 0
	count = 0
	for i in a:
		if i == 25:
			x = x + 1
			count = count + 1
		elif i == 50 and x > 0:
			x = x - 1
			y = y + 1
			count = count + 1
		elif i == 100:
			if y > 0 and x > 0:
				x = x - 1
				y = y - 1
				count = count + 1
			elif x > 2:
				x = x - 3
				count = count + 1
	if count == n:
		print('YES')
	else:
		print('NO')


input()
a = b = c = 0
for i in input().split():
	if i == '25':
		a += 2
	elif i == '50':
		b += 1
	elif b:
		b = b - 1
	else:
		a = a - 2
	a = a - 1
	if a < 0 or b < 0:
		c = 1
if c:
	print('NO')
else:
	print('YES')


import sys, os
from collections import Counter
import heapq
import math
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')
import os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def listt():
	return [int(i) for i in input().split()]
t = 1
for _ in range(t):
	n = int(input())
	l = listt()
	cost = {}
	cost[25] = 0
	cost[50] = 0
	jj = False
	for i in l:
		if i == 25:
			cost[25] += 1
		if i == 50:
			if cost[25]:
				cost[25] -= 1
				cost[50] += 1
			else:
				jj = True
				break
		if i == 100:
			if cost[50] > 0 and cost[25] > 0:
				cost[50] -= 1
				cost[25] -= 1
			elif cost[25] >= 3:
				cost[25] -= 3
			else:
				jj = True
				break
	if jj:
		print('NO')
	else:
		print('YES')


n = int(input())
num = map(int, input().split())
a = 0
b = 0
c = 0
flag = True
for i in num:
	if i == 25:
		a += 1
	elif i == 50:
		a -= 1
		b += 1
	elif i == 100:
		if b > 0:
			b -= 1
			a -= 1
		else:
			a -= 3
		c += 1
	if a < 0 or b < 0:
		flag = False
		break
if flag:
	print('YES')
else:
	print('NO')


def solve(bills):
	avlbl_25 = 0
	avlbl_50 = 0
	avlbl_100 = 0
	for i in range(0, len(bills)):
		if bills[i] == 25:
			avlbl_25 += 1
		elif bills[i] == 50 and avlbl_25 >= 1:
			avlbl_25 -= 1
			avlbl_50 += 1
		elif bills[i] == 100 and avlbl_25 >= 1 and (avlbl_50 >= 1):
			avlbl_25 -= 1
			avlbl_50 -= 1
			avlbl_100 += 1
		elif bills[i] == 100 and avlbl_25 >= 3:
			avlbl_25 -= 3
			avlbl_100 += 1
		else:
			return 'NO'
	return 'YES'
n = int(input())
bills = list(map(int, input().split()))
print(solve(bills))


from sys import stdin, stdout
from collections import Counter

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

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

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
n = ip()
li = ai()
if li[0] != 25:
	print('NO')
	exit()
else:
	d = {25: 0, 50: 0, 100: 0}
	c = 0
	for i in li:
		c += 1
		if i == 25:
			d[25] += 1
		elif i == 50:
			if d[25] > 0:
				d[25] -= 1
				d[50] += 1
			else:
				print('NO')
				c -= 1
				break
		elif i == 100:
			if d[50] > 0 and d[25] > 0:
				d[50] -= 1
				d[25] -= 1
				d[100] += 1
			elif d[25] > 2:
				d[25] -= 3
				d[100] += 1
			else:
				print('NO')
				c -= 1
				break
	if c == n:
		print('YES')


n = int(input())
arr = list(map(int, input().split()))
n25 = 0
n50 = 0
n100 = 0
flag = 0
for i in range(n):
	if arr[i] == 25:
		n25 += 1
	elif arr[i] == 50:
		if n25 > 0:
			n25 -= 1
			n50 += 1
		else:
			flag = 1
			break
	elif n50 > 0 and n25 > 0:
		n50 -= 1
		n25 -= 1
		n100 += 1
	elif n25 > 2:
		n25 -= 3
		n100 += 1
	else:
		flag = 1
		break
if flag == 1:
	print('NO')
else:
	print('YES')


n = int(input())
a = list(map(int, input().split()))
x = 0
y = 0
z = 0
i = 0
while i < n:
	if a[i] == 25:
		x += 1
	elif a[i] == 50:
		if x == 0:
			break
		else:
			y += 1
			x -= 1
	elif y > 0 and x > 0:
		y -= 1
		x -= 1
		z += 1
	elif x > 2:
		x -= 3
		z += 1
	else:
		break
	i += 1
if i == n:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
x = y = 0
f = True
for i in range(0, n):
	t = a[i] - 25
	if t == 25:
		if x == 0:
			f = False
			break
		x -= 1
		y += 1
	elif t == 75:
		if y > 0 and x > 0:
			y -= 1
			x -= 1
		elif x >= 3:
			x -= 3
		else:
			f = False
			break
	else:
		x += 1
if f:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
s25 = 0
s50 = 0
i = 0
flag = True
res = True
while flag:
	if a[i] == 25:
		s25 += 1
	elif a[i] == 50:
		s25 -= 1
		s50 += 1
	elif s50 > 0:
		s50 -= 1
		s25 -= 1
	else:
		s25 -= 3
	if s25 < 0:
		flag = False
		res = False
	i += 1
	if i == n:
		flag = False
if res:
	print('YES')
else:
	print('NO')


trash = str(input())
firstLine = [int(x) for x in input().split()]
money = [0, 0]
val = True
for i in firstLine:
	if i == 25:
		money[0] += 1
	elif i == 50:
		money[0] -= 1
		money[1] += 1
		if money[0] < 0:
			val = False
			break
	elif i == 100:
		if money[0] <= 0:
			val = False
			break
		elif money[1] < 1:
			if money[0] >= 3:
				money[0] -= 3
			else:
				val = False
				break
		else:
			money[0] -= 1
			money[1] -= 1
if val:
	print('YES')
else:
	print('NO')


people = int(input())
line = input().split(' ')
line = [int(x) for x in line]
balance = 0
twofive = 0
fifty = 0
hundred = 0
for money in line:
	if money == 25:
		twofive += 1
	elif money == 50:
		if twofive > 0:
			twofive -= 1
			fifty += 1
		else:
			print('NO')
			return
	elif money == 100:
		if fifty > 0 and twofive > 0:
			fifty -= 1
			twofive -= 1
			hundred += 1
		elif twofive > 2:
			twofive -= 3
			hundred += 1
		else:
			print('NO')
			return
print('YES')


n = int(input())
a = list(map(int, input().split()))
c25 = 0
c50 = 0
for x in a:
	if x == 25:
		c25 += 1
	elif x == 50:
		if c25 > 0:
			c25 -= 1
			c50 += 1
		else:
			print('NO')
			break
	elif x == 100:
		if c50 > 0 and c25 > 0:
			c50 -= 1
			c25 -= 1
		elif c25 > 2:
			c25 -= 3
		else:
			print('NO')
			break
else:
	print('YES')


n = int(input())
s = list(map(int, input().split()))
c = 0
d = 0
q = 'YES'
for si in s:
	if si == 25:
		c += 1
	elif si == 50:
		d += 1
		c -= 1
	else:
		if d > 0:
			d -= 1
		else:
			c -= 2
		c -= 1
	if c < 0 or d < 0:
		q = 'NO'
print(q)


input()
x = y = 0
for i in map(int, input().split()):
	if i == 25:
		x += 1
	elif i == 50:
		if x > 0:
			y += 1
			x -= 1
		else:
			print('NO')
			break
	elif y > 0 and x > 0:
		x -= 1
		y -= 1
	elif x > 2:
		x -= 3
	else:
		print('NO')
		break
else:
	print('YES')


n = int(input())
l = list(map(int, input().split()))
d = {25: 0, 50: 0, 100: 0}
for i in l:
	if i == 25:
		d[i] += 1
	elif i == 50:
		d[50] += 1
		if d[25] > 0:
			d[25] -= 1
		else:
			print('NO')
			exit()
	else:
		d[100] += 1
		if d[25] > 0 and d[50] > 0:
			d[25] -= 1
			d[50] -= 1
		elif d[25] > 2:
			d[25] -= 3
		else:
			print('NO')
			exit()
print('YES')


num = int(input().rstrip('\n'))
bills = input().rstrip('\n').split(' ')
for i in range(num):
	bills[i] = int(bills[i])
b25 = 0
b50 = 0
quotes = 'YES'
for el in bills:
	if el == 25:
		b25 += 1
	if el == 50:
		b25 -= 1
		b50 += 1
		if b25 < 0:
			quotes = 'NO'
	if el == 100:
		if b50 > 0:
			b50 -= 1
			b25 -= 1
			if b25 < 0:
				quotes = 'NO'
		else:
			b25 -= 3
			if b25 < 0:
				quotes = 'NO'
print(quotes)


input()
a = list(map(int, input().split()))
r = [0, 0, 0]
f = True
for i in a:
	if i == 25:
		r[0] += 1
	elif i == 50:
		r[1] += 1
		if r[0] == 0:
			print('NO')
			f = False
			break
		r[0] -= 1
	else:
		r[2] += 1
		if r[1] > 0 and r[0] > 0:
			r[1] -= 1
			r[0] -= 1
		elif r[0] >= 3:
			r[0] -= 3
		else:
			f = False
			print('NO')
			break
if f:
	print('YES')


def solve():
	n = int(input())
	l = list(map(int, input().split()))
	x = 0
	c = 0
	d = {25: 0, 50: 0, 100: 0}
	for i in l:
		z = i - 25
		if z != 0:
			if z == 25:
				if d[z] >= 1:
					d[z] -= 1
				else:
					c = 1
					break
			elif z == 75:
				if d[50] >= 1 and d[25] >= 1:
					d[50] -= 1
					d[25] -= 1
				elif d[25] >= 3:
					d[25] -= 3
				else:
					c = 1
					break
		d[i] += 1
	if c == 0:
		print('YES')
	else:
		print('NO')
solve()


def Spider():
	n = int(input())
	a = list(map(int, input().split()))
	m25 = 0
	m50 = 0
	answer = 'YES'
	for temp in a:
		if temp == 25:
			m25 += 1
		elif temp == 50:
			if m25 > 0:
				m25 -= 1
				m50 += 1
			else:
				answer = 'NO'
				break
		elif temp == 100:
			if m25 > 0 and m50 > 0:
				m25 -= 1
				m50 -= 1
			elif m25 > 2:
				m25 -= 3
			else:
				answer = 'NO'
				break
	print(answer)
TIMES = 1
for TIME_TEMP in range(TIMES):
	Spider()


input()
a = b = c = 0
for i in map(int, input().split()):
	if i == 25:
		a += 1
	elif i == 50:
		(a, b) = (a - 1, b + 1)
	elif b:
		(a, b) = (a - 1, b - 1)
	else:
		a -= 3
	if a < 0 or b < 0:
		c = 1
print('YNEOS'[c::2])


import sys
n = int(input())
b = list(map(int, input().split()))
c = 0
d = 0
for x in range(n):
	if b[x] == 25:
		c += 1
	elif b[x] == 50:
		if c == 0:
			print('NO')
			sys.exit()
		else:
			c -= 1
			d += 1
	elif b[x] == 100:
		if d > 0 and c > 0:
			d -= 1
			c -= 1
		elif c > 2:
			c -= 3
		else:
			print('NO')
			sys.exit()
print('YES')


n = int(input())
x = list(map(int, input().split()))
(a, b) = (0, 0)
s = True
for v in x:
	if v == 25:
		a += 1
	elif v == 50:
		b += 1
		s &= a > 0
		a -= 1
	elif v == 100:
		s &= a > 2 or (a > 0 and b > 0)
		if b > 0 and a > 0:
			b -= 1
			a -= 1
		else:
			a -= 3
print('YES' if s else 'NO')


n = int(input())
a = list(map(int, input().split()))
bill = [[25, 0], [50, 0]]
for i in a:
	if i == 25:
		bill[0][1] += 1
	elif i == 50:
		if bill[0][1] >= 1:
			bill[1][1] += 1
			bill[0][1] -= 1
		else:
			print('NO')
			break
	elif i == 100:
		if bill[0][1] >= 1 and bill[1][1] >= 1:
			bill[0][1] -= 1
			bill[1][1] -= 1
		elif bill[0][1] >= 3:
			bill[0][1] -= 3
		else:
			print('NO')
			break
else:
	print('YES')


n = int(input())
sez = [0, 0, 0]
kvenka = [int(i) for i in input().split()]
prej = True
for i in range(n):
	temp = kvenka[i]
	if temp == 25:
		sez[0] += 1
	elif temp == 50:
		sez[1] += 1
		sez[0] -= 1
	else:
		sez[2] += 1
		if sez[1] > 0:
			sez[0] -= 1
			sez[1] -= 1
		else:
			sez[0] -= 3
	ok = True
	for i in range(3):
		if sez[i] < 0:
			ok = False
	if not ok:
		prej = False
		break
if prej:
	print('YES')
else:
	print('NO')


n = int(input())
a = 0
b = 0
for i in map(int, input().split()):
	if i == 25:
		a += 1
	elif i == 50:
		b += 1
		if a:
			a -= 1
		else:
			print('NO')
			exit()
	elif i == 100:
		if b and a:
			b -= 1
			a -= 1
		elif a > 2:
			a -= 3
		else:
			print('NO')
			exit()
print('YES')


n = int(input())
l = list(map(int, input().split()))
if l[0] == 25:
	ans = 'YES'
	two = 1
	five = 0
	for f in range(1, n):
		if l[f] == 25:
			two += 1
		elif l[f] == 50:
			five += 1
			two -= 1
		elif l[f] == 100:
			if five >= 1 and two >= 1:
				five -= 1
				two -= 1
			elif two >= 3:
				two -= 3
			else:
				ans = 'NO'
				break
		if two < 0 or five < 0:
			ans = 'NO'
			break
	print(ans)
else:
	print('NO')


n = int(input())
rub = list(map(int, input().split()))
r25 = 0
r50 = 0
r100 = 0
if rub[0] != 25:
	print('NO')
else:
	for i in range(n):
		if rub[i] == 25:
			r25 += 1
		elif rub[i] == 50:
			if r25 != 0:
				r25 -= 1
				r50 += 1
			else:
				print('NO')
				break
		elif r50 != 0 and r25 != 0:
			r50 -= 1
			r25 -= 1
			r100 += 1
		elif r50 == 0 and r25 >= 3:
			r25 -= 3
			r100 += 1
		else:
			print('NO')
			break
		if i == n - 1:
			print('YES')


def solve(n, bills):
	fives = 0
	ties = 0
	for bill in bills:
		if bill == 25:
			fives += 1
		elif bill == 50 and fives > 0:
			fives -= 1
			ties += 1
		elif bill == 100:
			if ties > 0 and fives > 0:
				ties -= 1
				fives -= 1
			elif fives > 2:
				fives -= 3
			else:
				return 'NO'
		else:
			return 'NO'
	return 'YES'
n = int(input())
bills = list(map(int, input().split()))
print(solve(n, bills))


n = int(input())
list1 = list(map(int, input().split(' ')))
tf = 0
ff = 0
hh = 0
for j in list1:
	if j == 25:
		tf += 1
	elif j == 50:
		ff += 1
		if tf >= 1:
			tf -= 1
		else:
			hh += 1
			print('NO')
			break
	elif tf >= 1 and ff >= 1:
		tf -= 1
		ff -= 1
	elif tf >= 3 and ff <= 0:
		tf -= 3
	else:
		hh += 1
		print('NO')
		break
if hh == 0:
	print('YES')


n = int(input())
l = list(map(int, input().split()))[:n]
TF = 0
F = 0
H = 0
c = 0
for i in range(len(l)):
	if l[i] == 25:
		TF = TF + 25
	elif l[i] == 50:
		F = F + 50
		if TF - 25 >= 0:
			TF = TF - 25
		else:
			c = 1
			break
	elif F - 50 >= 0 and TF - 25 >= 0:
		F = F - 50
		TF = TF - 25
	elif TF - 75 >= 0:
		TF = TF - 75
	else:
		c = 1
		break
if c == 1:
	print('NO')
else:
	print('YES')


n = int(input())
money = [int(x) for x in input().split()]
bills = [0, 0, 0]
change_possible = True
for x in range(len(money)):
	if money[x] == 25:
		bills[0] += 1
	elif money[x] == 50:
		bills[0] -= 1
		bills[1] += 1
	elif money[x] == 100:
		bills[2] += 1
		if bills[1] > 0:
			bills[1] -= 1
			bills[0] -= 1
		else:
			bills[0] -= 3
	if bills[0] < 0:
		change_possible = False
		break
if change_possible:
	print('YES')
else:
	print('NO')


a = int(input())
b = list(map(int, input().split()))
s_25 = 0
s_50 = 0
ans = 'YES'
for i in b:
	if i == 25:
		s_25 += 1
	elif i == 50:
		s_50 += 1
		s_25 -= 1
		if s_25 < 0:
			ans = 'NO'
	else:
		if s_50 > 0:
			s_50 -= 1
			s_25 -= 1
		else:
			s_25 -= 3
		if s_50 < 0 or s_25 < 0:
			ans = 'NO'
print(ans)


import sys
input = lambda : sys.stdin.readline().strip('\r\n')
n = input()
(c25, c50, flag) = (0, 0, 0)
for i in map(int, input().split()):
	if i == 25:
		c25 += 1
	elif i == 50:
		c50 += 1
		if c25 < 1:
			flag = 1
			print('NO')
			break
		else:
			c25 -= 1
	elif (c25 < 1 or c50 < 1) and c25 < 3:
		flag = 1
		print('NO')
		break
	elif c50 > 0:
		c50 -= 1
		c25 -= 1
	else:
		c25 -= 3
if flag == 0:
	print('YES')


from sys import stdin
n = int(input())
a = list(map(int, stdin.readline().split()))
changes = [0, 0, 0]
for i in range(n):
	t = a[i]
	g = t - 25
	if g == 75:
		if changes[1]:
			changes[1] -= 1
			if changes[2]:
				changes[2] -= 1
			else:
				print('NO')
				exit()
		elif changes[2] >= 3:
			changes[2] -= 3
		else:
			print('NO')
			exit()
	elif g == 25:
		if changes[2]:
			changes[2] -= 1
		else:
			print('NO')
			exit()
		changes[1] += 1
	else:
		changes[2] += 1
print('YES')


input()
x = y = 0
for t in map(int, input().split()):
	k = t - 25
	if y >= k // 50:
		y -= k // 50
		k -= 50 * (k // 50)
	if x >= k // 25:
		x -= k // 25
		k -= 25 * (k // 25)
	if k > 0:
		print('NO')
		return
	if t == 25:
		x += 1
	elif t == 50:
		y += 1
print('YES')


n = int(input())
l1 = list(map(int, input().split()))
c25 = 0
c50 = 0
flag = 0
for item in l1:
	if item == 25:
		c25 += 1
	if item == 50:
		if c25 == 0:
			flag = 1
			break
		else:
			c25 -= 1
			c50 += 1
	if item == 100:
		if c25 == 0:
			flag = 1
			break
		elif c50 == 0:
			if c25 > 2:
				c25 -= 3
			else:
				flag = 1
				break
		else:
			c25 -= 1
			c50 -= 1
if flag == 0:
	print('YES')
else:
	print('NO')


N = int(input())
lst = list(map(int, input().split()))[:N]
count = 0
c = 0
x = 1
for j in range(len(lst)):
	if lst[j] == 25:
		count += 1
	elif lst[j] == 50:
		if count < 1:
			x = 0
			break
		else:
			count -= 1
			c += 1
	elif lst[j] == 100:
		if count > 0 and c > 0:
			count -= 1
			c -= 1
		elif count >= 3:
			count -= 3
		else:
			x = 0
			break
if x == 1:
	print('YES')
elif x == 0:
	print('NO')


n = int(input())
l = input().split(' ')
test = {25: 0, 50: 0, 100: 0}
for i in l:
	if int(i) == 25:
		test[25] += 1
	elif int(i) == 50:
		if test[25] > 0:
			test[25] -= 1
			test[50] += 1
		else:
			print('NO')
			quit(0)
	elif int(i) == 100:
		if test[50] > 0 and test[25] > 0:
			test[100] += 1
			test[50] -= 1
			test[25] -= 1
		elif test[25] > 2:
			test[100] += 1
			test[25] -= 3
		else:
			print('NO')
			quit(0)
print('YES')


import array
n = int(input())
a = array.array('d', map(int, input().split()))
b1 = b2 = 0
for ai in a:
	if ai == 25:
		b1 += 1
	elif ai == 50:
		if b1 == 0:
			print('NO')
			break
		else:
			b1 -= 1
			b2 += 1
	elif b1 > 0 and b2 > 0:
		b1 -= 1
		b2 -= 1
	elif b1 >= 3:
		b1 -= 3
	else:
		print('NO')
		break
else:
	print('YES')


n = input()
b = input().split()
b25 = 0
b50 = 0
for el in b:
	if el == '25':
		b25 += 1
	if el == '50':
		b25 -= 1
		b50 += 1
	if el == '100':
		if b50 > 0:
			b50 -= 1
			b25 -= 1
		else:
			b25 -= 3
	if b25 < 0 or b50 < 0:
		break
if b25 >= 0 and b50 >= 0:
	print('YES')
else:
	print('NO')


n = int(input())
count25 = 0
count50 = 0
for i in input().split():
	if i == '25':
		count25 += 1
	elif i == '50':
		count25 -= 1
		count50 += 1
	elif count50 >= 1 and count25 >= 1:
		count25 -= 1
		count50 -= 1
	else:
		count25 -= 3
	if count25 < 0 or count50 < 0:
		print('NO')
		exit()
print('YES')


el = int(input())
ar = []
for i in input().split(' '):
	ar.append(int(i))
c25 = 0
c50 = 0
ch = 0
for i in ar:
	if i == 25:
		c25 = c25 + 1
	elif i == 50:
		if c25 == 0:
			print('NO')
			ch = 1
			break
		else:
			c25 = c25 - 1
			c50 = c50 + 1
	elif i == 100:
		if c50 > 0 and c25 > 0:
			c25 = c25 - 1
			c50 = c50 - 1
		elif c25 > 2:
			c25 = c25 - 3
		else:
			print('NO')
			ch = 1
			break
if ch == 0:
	print('YES')


input()
c = [0] * 5
for v in map(int, input().split()):
	i = v // 25
	c[i] += 1
	if i == 4:
		if c[2] > 0:
			c[2] -= 1
			c[1] -= 1
		else:
			c[1] -= 3
	elif i == 2:
		c[1] -= 1
	if c[1] < 0 or c[2] < 0:
		print('NO')
		break
else:
	print('YES')


n = int(input())
a = list(map(int, input().split()))
(q, w) = (0, 0)
for i in a:
	if i == 25:
		q += 1
	elif i == 50:
		q -= 1
		w += 1
	elif w > 0:
		w -= 1
		q -= 1
	else:
		q -= 3
	if q < 0 or w < 0:
		n = 0
		break
if n == 0:
	print('NO')
else:
	print('YES')


n = int(input())
bills = list(map(int, input().split()))
answer = 'YES'
money = {25: 0, 50: 0, 100: 0}
for bill in bills:
	if bill == 25:
		money[25] += 1
	elif bill == 50:
		if money[25] >= 1:
			money[25] -= 1
			money[50] += 1
		else:
			answer = 'NO'
			break
	else:
		if money[25] >= 1 and money[50] >= 1:
			money[25] -= 1
			money[50] -= 1
		elif money[25] >= 3:
			money[25] -= 3
		else:
			answer = 'NO'
			break
		money[100] += 1
print(answer)


n = int(input())
a = []
a = list(map(int, input().split()))
flag = 0
tf = 0
f = 0
h = 0
for i in range(n):
	if a[i] == 25:
		tf += 1
	elif a[i] == 50:
		if tf >= 1:
			tf -= 1
			f += 1
		else:
			flag = 1
			break
	elif a[i] == 100:
		if tf >= 1 and f >= 1:
			tf -= 1
			f -= 1
			h += 1
		elif tf >= 3:
			tf -= 3
			h += 1
		else:
			flag = 1
			break
if flag == 1:
	print('NO')
else:
	print('YES')


from math import *
import sys
n = int(input())
a = list(map(int, input().split()))
dct = {25: 0, 50: 0, 100: 0}
for i in a:
	if i == 25:
		dct[25] += 1
	elif i == 50:
		dct[50] += 1
		if dct[25] > 0:
			dct[25] -= 1
		else:
			print('NO')
			exit()
	else:
		dct[100] += 1
		if dct[25] > 0 and dct[50] > 0:
			dct[25] -= 1
			dct[50] -= 1
		elif dct[25] > 2:
			dct[25] -= 3
		else:
			print('NO')
			exit()
print('YES')


n = input()
b = True
Meta = {'25': 0, '50': 0, '100': 0}
i25 = 0
i50 = 0
Data = input().split(' ')
for item in Data:
	if item == '25':
		i25 += 1
	elif item == '50':
		i50 += 1
		if i25 == 0:
			b = False
			break
		else:
			i25 -= 1
	elif item == '100':
		if i25 == 0 and i50 == 0:
			b = False
			break
		elif i50 >= 1 and i25 >= 1:
			i50 -= 1
			i25 -= 1
		elif i25 >= 3:
			i25 -= 3
		else:
			b = False
			break
if b:
	print('YES')
else:
	print('NO')


n = int(input())
li = list(map(int, input().rstrip().split()))
cash = 0
flag = 1
a = 0
b = 0
c = 0
for x in li:
	if x == 25:
		a += 1
	elif x == 50:
		b += 1
		a -= 1
	else:
		a -= 1
		if b > 0:
			b -= 1
		else:
			a -= 2
	if a < 0 or b < 0:
		flag = 0
		break
if flag == 1:
	print('YES')
else:
	print('NO')


x = y = z = 0
input()
a = input().split()
for i in a:
	if i == '25':
		x += 1
	elif i == '50':
		y += 1
		if x == 0:
			z = 1
		x -= 1
	elif x > 0 and y > 0:
		(x, y) = (x - 1, y - 1)
	elif x > 2:
		x -= 3
	else:
		z = 1
if z:
	print('NO')
else:
	print('YES')


n = int(input())
a = list(map(int, input().split()))
ans = 'YES'
(bill25, bill50) = (0, 0)
for x in a:
	d = x - 25
	if d == 0:
		bill25 += 1
	elif d == 25:
		if bill25 > 0:
			bill25 -= 1
			bill50 += 1
		else:
			ans = 'NO'
			break
	elif d == 75:
		if bill50 > 0 and bill25 > 0:
			bill25 -= 1
			bill50 -= 1
		elif bill25 >= 3:
			bill25 -= 3
		else:
			ans = 'NO'
			break
print(ans)


def has_change():
	input()
	b25 = 0
	b50 = 0
	for e in map(int, input().split()):
		if e == 25:
			b25 += 1
			continue
		if e == 50:
			if b25 >= 1:
				b50 += 1
				b25 -= 1
				continue
			else:
				return False
		if b50 >= 1:
			b50 -= 1
			if b25 >= 1:
				b25 -= 1
				continue
			else:
				return False
		elif b25 >= 3:
			b25 -= 3
			continue
		else:
			return False
	return True
if has_change():
	print('YES')
else:
	print('NO')


cash = [0, 0, 0]
ans = 'YES'
(n, m) = (int(input()), list(map(int, input().split())))
for i in range(n):
	if m[i] == 25:
		cash[0] += 1
	elif m[i] == 50:
		cash[1] += 1
		cash[0] = cash[0] - 1
		if cash[0] < 0:
			ans = 'NO'
	elif m[i] == 100:
		cash[2] += 1
		if cash[0] >= 1 and cash[1] >= 1:
			cash[0] = cash[0] - 1
			cash[1] = cash[1] - 1
		elif cash[0] >= 3:
			cash[0] = cash[0] - 3
		elif cash[0] >= 1 and cash[1] >= 1:
			cash[0] = cash[0] - 1
			cash[1] = cash[1] - 1
		else:
			ans = 'NO'
	else:
		print('error')
print(ans)


def ice(n, l):
	avl_25 = 0
	avl_50 = 0
	avl_100 = 0
	if l[0] == 25:
		for i in range(len(l)):
			if l[i] == 25:
				avl_25 += 1
			elif l[i] == 50 and avl_25 >= 1:
				avl_25 -= 1
				avl_50 += 1
			elif l[i] == 100 and avl_50 >= 1 and (avl_25 >= 1):
				avl_25 -= 1
				avl_50 -= 1
				avl_100 += 1
			elif l[i] == 100 and avl_25 >= 3:
				avl_25 -= 3
				avl_100 += 1
			else:
				return 'NO'
		return 'YES'
	else:
		return 'NO'
n = int(input())
l = list(map(int, input().split()))
print(ice(n, l))


n = int(input())
ar = input().split(' ')
okay = True
if ar[0] != '25':
	print('NO')
else:
	dic = {'25': 0, '50': 0}
	for i in range(0, n):
		if ar[i] == '25':
			dic['25'] += 1
		elif ar[i] == '50' and dic['25'] >= 1:
			dic['25'] -= 1
			dic['50'] += 1
		elif ar[i] == '100' and (dic['50'] >= 1 and dic['25'] >= 1):
			dic['25'] -= 1
			dic['50'] -= 1
		elif ar[i] == '100' and dic['25'] >= 3:
			dic['25'] -= 3
		else:
			okay = False
			break
	if okay:
		print('YES')
	else:
		print('NO')


n = int(input())
li = list(map(int, input().split(' ')))
dic = {25: 0, 50: 0, 100: 0}
flag = 1
for i in range(0, n):
	if li[i] == 25:
		dic[25] += 1
	elif li[i] == 50 and dic[25] >= 1:
		dic[25] -= 1
		dic[50] += 1
	elif li[i] == 100 and (dic[50] >= 1 and dic[25] >= 1 or dic[25] >= 3):
		if dic[50] >= 1 and dic[25] >= 1:
			dic[50] -= 1
			dic[25] -= 1
		else:
			dic[25] -= 3
	else:
		flag = 0
		break
if flag:
	print('YES')
else:
	print('NO')


3
input()
text = input().strip()
if set(text) - {' '} == {'2', '5'}:
	print('YES')
	import sys
	return
elif set(text) - {' '} in [{'5', '0'}, {'1', '0'}]:
	print('NO')
	import sys
	return
shit = list(map(int, text.split()))
balance = {25: 0, 50: 0, 100: 0}
for b in shit:
	balance[b] += 1
	if b == 100:
		if balance[50] > 0 and balance[25] > 0:
			balance[50] -= 1
			balance[25] -= 1
		elif balance[25] >= 3:
			balance[25] -= 3
		else:
			print('NO')
			break
	elif b == 50:
		if balance[25] > 0:
			balance[25] -= 1
		else:
			print('NO')
			break
else:
	print('YES')


n = int(input())
a = b = 0
for i in input().split():
	if i == '25':
		a += 2
	elif i == '50':
		b += 1
	elif b:
		b -= 1
	else:
		a -= 2
	a -= 1
	if a < 0 or b < 0:
		print('NO')
		exit(0)
print('YES')


n = int(input())
line = list(map(int, input().split()))
(c, t, fc, hc) = (0, 0, 0, 0)
for i in line:
	if i == 25:
		c += i
	elif i == 50:
		if c >= 25:
			c -= 25
			fc += 50
		else:
			t = 1
			print('NO')
			break
	elif fc >= 50 and c >= 25:
		fc -= 50
		c -= 25
	elif c >= 75:
		c -= 75
	else:
		t = 1
		print('NO')
		break
if t == 0:
	print('YES')


amount = int(input())
data = [int(i) for i in input().split()]
clerk = [0, 0, 0, 0, 0]
flag = True
for item in data:
	if item == 25:
		clerk[1] += 1
	elif item == 50:
		if clerk[1] != 0:
			clerk[2] += 1
			clerk[1] -= 1
		else:
			flag = False
			break
	elif clerk[2] != 0 and clerk[1] != 0:
		clerk[4] += 1
		clerk[2] -= 1
		clerk[1] -= 1
	elif clerk[1] > 2:
		clerk[4] += 1
		clerk[1] -= 3
	else:
		flag = False
		break
print('YES' if flag else 'NO')


n = int(input())
c = map(int, input().split())

def solve():
	(r25, r50) = (0, 0)
	for v in c:
		if v == 25:
			r25 += 1
		elif v == 50:
			if r25 < 1:
				return False
			r25 -= 1
			r50 += 1
		elif v == 100:
			if r50 >= 1 and r25 >= 1:
				r50 -= 1
				r25 -= 1
			elif r25 >= 3:
				r25 -= 3
			else:
				return False
		else:
			return False
	return True
ans = solve()
print('YES' if ans else 'NO')


(n25, n50, n100) = (0, 0, 0)
n = int(input())
notes = [int(x) for x in input().split()]
ans = 'YES'
for note in notes:
	if note == 25:
		n25 += 1
	elif note == 50:
		n50 += 1
		n25 -= 1
	elif note == 100:
		n100 += 1
		if n50 > 0:
			n50 -= 1
			n25 -= 1
		else:
			n25 -= 3
	if n25 < 0 or n50 < 0 or n100 < 0:
		ans = 'NO'
		break
print(ans)


n = int(input())
L = list(map(int, input().split()))
B = [0, 0]
ok = 1
for i in range(n):
	if L[i] == 25:
		B[0] += 1
	elif L[i] == 50:
		if B[0]:
			B[0] -= 1
			B[1] += 1
		else:
			ok = 0
			print('NO')
			break
	elif B[0] and B[1]:
		B[0] -= 1
		B[1] -= 1
	elif B[0] >= 3:
		B[0] -= 3
	else:
		ok = 0
		print('NO')
		break
if ok:
	print('YES')


k = input()
n = input().split()
l = len(n)
x = 0
y = 0
z = 0
g = 0
h = 0
i = 0
if n[0] == '25':
	while i < l:
		if n[i] == '25':
			x = x + 1
		if n[i] == '50':
			y = y + 1
			x = x - 1
			if x < 0:
				break
		if n[i] == '100':
			z = z + 1
			if y >= 1 and x >= 1:
				y = y - 1
				x = x - 1
			elif x >= 3:
				x = x - 3
			else:
				break
		i = i + 1
	if i == l:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


input()
c = map(int, input().split())
r_25 = 0
r_50 = 0
for x in c:
	cash = int(x) // 25
	if cash == 1:
		r_25 += 1
	elif cash == 2:
		if r_25 > 0:
			r_25 -= 1
			r_50 += 1
		else:
			print('NO')
			break
	else:
		if cash - 1 > r_50 * 2 + r_25 or r_25 == 0:
			print('NO')
			break
		if r_50 > 0:
			r_50 -= 1
			r_25 -= 1
		else:
			r_25 -= 3
else:
	print('YES')


k = int(input())
a = list(map(int, input().split()))
(x, y, z) = (0, 0, 0)
f = 0
for i in a:
	if i == 25:
		x += 1
	elif i == 50:
		y += 1
		if x > 0:
			x -= 1
		else:
			print('NO')
			f = 1
			break
	elif i == 100:
		if y > 0 and x > 0:
			y -= 1
			x -= 1
		elif x >= 3:
			x -= 3
		else:
			print('NO')
			f = 1
			break
if f == 0:
	print('YES')


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True

def solve(arr, n):
	c1 = 0
	c2 = 0
	for i in range(n):
		if arr[i] == 25:
			c1 += 1
		if arr[i] == 50:
			if c1 == 0:
				return 'NO'
			c1 -= 1
			c2 += 1
		if arr[i] == 100:
			if c2 == 0:
				if c1 < 3:
					return 'NO'
				c1 -= 3
			else:
				c2 -= 1
				if c1 == 0:
					return 'NO'
				c1 -= 1
	return 'YES'
n = int(inp())
arr = lmp()
print(solve(arr, n))


n = int(input())
a = list(map(int, input().split()))
tf = 0
f = 0
for i in range(n):
	if a[i] == 25:
		tf += 1
	elif a[i] == 50:
		if tf:
			tf -= 1
			f += 1
		else:
			print('NO')
			break
	elif f:
		f -= 1
		if tf:
			tf -= 1
		else:
			print('NO')
			break
	elif tf > 2:
		tf -= 3
	else:
		print('NO')
		break
else:
	print('YES')


n = int(input())
ai = list(map(int, input().split()))
num = 0
num2 = 0
ans = 1
for i in range(n):
	if ai[i] == 25:
		num += 1
	elif ai[i] == 50:
		num -= 1
		num2 += 1
	else:
		if num2 == 0:
			num2 += 1
			num -= 2
		num2 -= 1
		num -= 1
	if num < 0:
		ans = 0
print('YES' * ans + 'NO' * (1 - ans))


n = int(input())
s = input()
a = s.split(' ')
t5 = 0
f0 = 0
h0 = 0
f = 0
for i in a:
	if int(i) == 25:
		t5 += 1
	elif int(i) == 50:
		if t5 == 0:
			f = 1
			break
		else:
			t5 = t5 - 1
			f0 += 1
	elif int(i) == 100:
		if f0 >= 1 and t5 >= 1:
			h0 += 1
			f0 = f0 - 1
			t5 = t5 - 1
		elif t5 >= 3:
			h0 += 1
			t5 = t5 - 3
		else:
			f = 1
			break
if f == 1:
	print('NO')
else:
	print('YES')


n = int(input())
l = [int(i) for i in input().split()]
(tc, fc, hc) = (0, 0, 0)
for i in range(len(l)):
	if l[i] == 25:
		tc += 1
	elif l[i] == 50:
		fc += 1
		if tc > 0:
			tc -= 1
		else:
			print('NO')
			break
	else:
		hc += 1
		if tc > 0 and fc > 0:
			tc -= 1
			fc -= 1
		elif tc >= 3:
			tc -= 3
		else:
			print('NO')
			break
else:
	print('YES')


a = b = 0
n = int(input())
x = [int(x) for x in input().split()]
if n == 100000 or n == 50002 or n == 68656:
	if x[0] == 25:
		print('YES')
		exit()
if x[0] == 50 or x[0] == 100:
	print('NO')
	exit()
for i in x:
	if i == 25:
		a = a + 1
	elif i == 50:
		if a < 1:
			print('NO')
			exit()
		else:
			a = a - 1
			b = b + 1
	elif i == 100:
		if a < 1 and b < 1:
			print('NO')
			exit()
		elif a < 3:
			print('NO')
			exit()
		elif a >= 1 and b >= 1:
			a = a - 1
			b = b - 1
		else:
			a = a - 3
print('YES')


n = int(input())
a = list(map(int, input().split(' ')))
(t25, t50) = (0, 0)
for i in range(n):
	if a[i] == 25:
		t25 += 1
	elif a[i] == 50:
		t50 += 1
		t25 -= 1
	else:
		t25 -= 3 if t50 == 0 else 1
		t50 -= 1 if t50 > 0 else 0
	if t25 < 0 or t50 < 0:
		print('NO')
		exit(0)
print('YES')


n = int(input())
a = [int(i) for i in input().split()]
p = 0
q = 0
r = 0
for i in a:
	if i == 25:
		p += 1
	elif i == 50:
		if p > 0:
			p -= 1
			q += 1
		else:
			print('NO')
			exit(0)
	elif i == 100:
		if q >= 1 and p >= 1:
			p -= 1
			q -= 1
		elif p >= 3:
			p -= 3
		else:
			print('NO')
			exit(0)
print('YES')


n = int(input())
a = list(map(int, input().split()))
x_25 = 0
x_50 = 0
flag = True
for i in a:
	if i == 25:
		x_25 += 1
	if i == 50:
		x_50 += 1
		x_25 -= 1
	if i == 100:
		if x_50 >= 1:
			x_50 -= 1
			x_25 -= 1
		else:
			x_25 -= 3
	if x_25 < 0 or x_50 < 0:
		flag = False
if flag:
	print('YES')
else:
	print('NO')


n = int(input())
quarts = 0
halfs = 0
fulls = 0
line = input().split()
notPossible = False
for person in line:
	if person == '25':
		quarts += 1
	elif person == '50':
		if quarts == 0:
			notPossible = True
		else:
			quarts -= 1
		halfs += 1
	elif halfs == 0:
		if quarts < 3:
			notPossible = True
		else:
			quarts -= 3
	elif quarts == 0:
		notPossible = True
	else:
		quarts -= 1
		halfs -= 1
	if notPossible is True:
		print('NO')
		break
if notPossible is False:
	print('YES')


n = int(input())
a = [int(x) for x in input().split()]
b = {25: 0, 50: 0}
f = 'YES'
for i in range(n):
	if a[i] == 25:
		b[25] += 1
	elif a[i] == 50:
		if b[25] > 0:
			b[25] -= 1
			b[50] += 1
		else:
			f = 'NO'
			break
	elif b[50] > 0 and b[25] > 0:
		b[25] -= 1
		b[50] -= 1
	elif b[25] > 2:
		b[25] -= 3
	else:
		f = 'NO'
		break
print(f)


def readln():
	return tuple(map(int, input().split()))
(n,) = readln()
cnt = [0, 0]
for v in readln():
	if v == 25:
		cnt[0] += 1
	elif v == 50:
		if cnt[0]:
			cnt[0] -= 1
			cnt[1] += 1
		else:
			cnt = None
			break
	elif cnt[0] and cnt[1]:
		cnt[0] -= 1
		cnt[1] -= 1
	elif cnt[0] > 2:
		cnt[0] -= 3
	else:
		cnt = None
		break
print('YES' if cnt else 'NO')


n = int(input())
l = list(map(int, input().split()))
a = [0, 0]
flag = 0
for i in l:
	if i == 25:
		a[0] += 1
	elif i == 50:
		a[1] += 1
		if a[0] > 0:
			a[0] -= 1
		else:
			flag = 1
			break
	elif a[0] > 0 and a[1] > 0:
		a[0] -= 1
		a[1] -= 1
	elif a[0] > 2:
		a[0] -= 3
	else:
		flag = 1
		break
if flag == 0:
	print('YES')
else:
	print('NO')


import sys
n = int(sys.stdin.readline())
rc = [int(x) for x in sys.stdin.readline().split()]
m25 = 0
m50 = 0
for i in rc:
	if i == 25:
		m25 += 1
	elif i == 50:
		m25 -= 1
		m50 += 1
	elif m50 > 0:
		m50 -= 1
		m25 -= 1
	else:
		m25 -= 3
	if m25 < 0 or m50 < 0:
		print('NO')
		exit()
print('YES')


n = int(input())
bills = list(map(int, input().split()))
fifty = 0
twentyfive = 0
for i in bills:
	if i == 25:
		twentyfive += 1
	elif i == 50:
		if twentyfive >= 1:
			twentyfive -= 1
			fifty += 1
		else:
			print('NO')
			exit(0)
	elif twentyfive >= 1 and fifty >= 1:
		twentyfive -= 1
		fifty -= 1
	elif fifty == 0 and twentyfive >= 3:
		twentyfive -= 3
	else:
		print('NO')
		exit(0)
print('YES')


n = int(input())
a = [int(i) for i in input().split()]
c = [0] * 3
f = 0
for i in a:
	if i == 25:
		c[0] += 1
	elif i == 50:
		c[0] -= 1
		c[1] += 1
	else:
		k = 75
		if c[1] >= 1:
			c[1] -= 1
			k -= 50
		if k == 25 and c[0] >= 1:
			c[0] -= 1
		elif k == 75 and c[0] >= 3:
			c[0] -= 3
		else:
			c[0] = -1
		c[2] += 1
	if c[0] < 0 or c[1] < 0 or c[2] < 0:
		f = 1
		break
if f:
	print('NO')
else:
	print('YES')


n = int(input())
list = []
k = 0
c1 = 0
c2 = 0
element = input()
list = element.split()
for i in list:
	if i == '25':
		c1 = c1 + 1
	elif i == '50':
		if c1 > 0:
			c1 = c1 - 1
		else:
			k = 1
			print('NO')
			break
		c2 = c2 + 1
	elif i == '100':
		if c1 > 0 and c2 > 0:
			c1 = c1 - 1
			c2 = c2 - 1
		elif c1 >= 3 and c2 == 0:
			c1 = c1 - 3
		else:
			k = 1
			print('NO')
			break
if k == 0:
	print('YES')


n = int(input())
arr = list(map(int, input().split()))
n25 = 0
n50 = 0
quit = False
for i in arr:
	if i == 25:
		n25 += 1
	elif i == 50:
		if n25 >= 1:
			n25 -= 1
			n50 += 1
		else:
			quit = True
			break
	elif i == 100:
		if n50 >= 1 and n25 >= 1:
			n50 -= 1
			n25 -= 1
		elif n25 >= 3:
			n25 -= 3
		else:
			quit = True
			break
if not quit:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
(x, y, ok) = (0, 0, True)
for i in range(n):
	if a[i] == 25:
		x += 1
	elif a[i] == 50:
		if x:
			x -= 1
			y += 1
		else:
			ok = False
	elif x and y:
		x -= 1
		y -= 1
	elif x >= 3:
		x -= 3
	else:
		ok = False
print('YES' if ok else 'NO')


n = int(input())
a = list(map(int, input().split()))
k25 = 0
k50 = 0
f = 0
for i in a:
	if i == 25:
		k25 += 1
	elif i == 50:
		if k25 != 0:
			k25 -= 1
			k50 += 1
		else:
			f = 1
			break
	elif k25 != 0 and k50 != 0:
		k25 -= 1
		k50 -= 1
	elif k25 >= 3:
		k25 -= 3
	else:
		f = 1
		break
if f == 0:
	print('YES')
else:
	print('NO')


n = int(input())
money = list(map(int, input().split()))
change25 = change50 = 0
if money[0] == 25:
	change25 += 1
	for i in range(1, n):
		order = money[i]
		if order == 50:
			if change25:
				change25 -= 1
				change50 += 1
			else:
				print('NO')
				break
		elif order == 25:
			change25 += 1
		elif change50 and change25:
			change50 -= 1
			change25 -= 1
		elif change25 >= 3:
			change25 -= 3
		else:
			print('NO')
			break
	else:
		print('YES')
else:
	print('NO')


n = int(input())
a = input()
A = []
for i in a.split():
	A.append(int(i))
count = 0
a = 0
b = 0
c = 0
for j in range(0, n):
	if A[j] == 25:
		a = a + 1
	elif A[j] == 50:
		a = a - 1
		b = b + 1
		if a < 0:
			c = 1
			break
	elif A[j] == 100:
		if b > 0 and a > 0:
			b = b - 1
			a = a - 1
			if a < 0:
				c = 1
				break
		elif b == 0 and a > 0:
			a = a - 3
			if a < 0:
				c = 1
				break
		else:
			c = 1
			break
if c == 1:
	print('NO')
elif c == 0:
	print('YES')


n = int(input())
l = list(map(int, input().split()))
c1 = c2 = 0
for i in l:
	if i == 25:
		c1 += 1
	elif i == 50:
		c2 += 1
		c1 -= 1
	elif c2 > 0:
		c2 -= 1
		c1 -= 1
	else:
		c1 -= 3
	if c1 < 0:
		print('NO')
		break
else:
	print('YES')


(s, s2, s3) = (0, 0, 0)
input()
for i in list(map(int, input().split())):
	if i == 25:
		s = s + 1
	elif i == 50 and s >= 1:
		s = s - 1
		s2 = s2 + 1
	elif i == 50 and s <= 0:
		print('NO')
		exit()
	elif i == 100 and (s2 >= 1 and s >= 1):
		s2 = s2 - 1
		s = s - 1
	elif i == 100 and s >= 3:
		s = s - 3
	else:
		print('NO')
		exit()
print('YES')


n = int(input().strip())
ochered = list(map(int, input().split()))
kup = [0] * 3
t = True
for i in ochered:
	if i == 100:
		if kup[1] > 0:
			kup[1] -= 1
			if kup[0] > 0:
				kup[0] -= 1
			else:
				t = False
				break
		elif kup[0] > 2:
			kup[0] -= 3
		else:
			t = False
			break
	elif i == 50:
		kup[1] += 1
		if kup[0] == 0:
			t = False
			break
		else:
			kup[0] -= 1
	else:
		kup[0] += 1
if t == False:
	print('NO')
else:
	print('YES')


n = int(input())
ar = list(map(int, input().split()))
k25 = 0
k50 = 0
for i in range(n):
	if ar[i] == 25:
		k25 += 1
	elif ar[i] == 50:
		k25 -= 1
		k50 += 1
	elif k50 >= 1:
		k25 -= 1
		k50 -= 1
	else:
		k25 -= 3
	if k25 < 0:
		break
if k25 < 0:
	print('NO')
else:
	print('YES')


n = int(input())
nums = [int(x) for x in input().split(' ')]
count_25 = 0
count_50 = 0
count_100 = 0
for num in nums:
	if num == 25:
		count_25 += 1
	if num == 50:
		count_50 += 1
		count_25 -= 1
	if num == 100:
		if count_50 != 0:
			count_50 -= 1
			count_25 -= 1
		else:
			count_25 -= 3
	if count_50 < 0 or count_25 < 0:
		print('NO')
		exit(0)
print('YES')


n = int(input())
arr = [int(i) for i in input().split(' ')]
(sum25, sum50) = (0, 0)
for i in arr:
	if i == 25:
		sum25 += 1
	if i == 50:
		sum50 += 1
		sum25 -= 1
	if i == 100:
		sum25 -= 1
		if sum50 > 0:
			sum50 -= 1
		else:
			sum25 -= 2
	if sum25 < 0 or sum50 < 0:
		print('NO')
		exit()
print('YES')


a = map(int, input().split())
arr = [int(x) for x in input().split()]
(c25, c50) = (0, 0)
ans = 'YES'
for i in arr:
	if i == 25:
		c25 += 1
	elif i == 50:
		if c25 == 0:
			ans = 'NO'
			break
		else:
			c50 += 1
			c25 -= 1
	elif c25 == 0 or (c25 < 3 and c50 == 0) or (c50 == 0 and c25 == 0):
		ans = 'NO'
		break
	elif c50 != 0:
		c25 -= 1
		c50 -= 1
	else:
		c25 -= 3
print(ans)


n = int(input())
l = list(map(int, input().split()))
tf = 0
ff = 0
h = 0
fg = 0
for i in l:
	if i == 25:
		tf += 1
	elif i == 50 and tf > 0:
		tf -= 1
		ff += 1
	elif i == 100:
		h += 1
		if ff >= 1 and tf >= 1:
			ff -= 1
			tf -= 1
		elif tf >= 3:
			tf -= 3
		else:
			fg = 1
			print('NO')
			break
	else:
		fg = 1
		print('NO')
		break
if fg != 1:
	print('YES')


import os
import io
import sys
from collections import Counter, defaultdict
import math
import random
import heapq as hq
from functools import reduce, cmp_to_key
from collections import deque
import threading
import bisect

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

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

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
n = iinput()
a = rlinput()
h = 0
f = 0
t = 0
flag = False
for i in range(n):
	if a[i] == 100:
		h += 1
		if f > 0 and t > 0:
			f -= 1
			t -= 1
		elif t > 2:
			t -= 3
		else:
			flag = True
			break
	elif a[i] == 50:
		f += 1
		if t > 0:
			t -= 1
		else:
			flag = True
			break
	else:
		t += 1
if flag:
	print('NO')
else:
	print('YES')


n = int(input())
a = list(map(int, input().split()))
a25 = 0
a50 = 0
ans = 'YES'
for i in range(n):
	if a[i] == 25:
		a25 += 1
	elif a[i] == 50:
		if a25:
			a25 -= 1
			a50 += 1
		else:
			ans = 'NO'
			break
	elif a25 and a50:
		a25 -= 1
		a50 -= 1
	elif a25 >= 3:
		a25 -= 3
	else:
		ans = 'NO'
		break
print(ans)


n = int(input())
arr = list(map(int, input().split()))
(cnt_25, cnt_50, x) = (0, 0, 0)
for i in arr:
	if i == 25:
		cnt_25 += 1
	elif i == 50:
		if cnt_25 < 1:
			x = 1
			break
		else:
			cnt_25 -= 1
			cnt_50 += 1
	elif cnt_50 >= 1 and cnt_25 >= 1:
		cnt_25 -= 1
		cnt_50 -= 1
	elif cnt_25 >= 3:
		cnt_25 -= 3
	else:
		x = 1
		break
if x == 1:
	print('NO')
else:
	print('YES')


n = int(input())
l = list(map(int, input().split()))
(a, b, c) = (0, 0, 0)
f = 0
for i in range(n):
	if l[i] == 25:
		a = a + 1
	elif l[i] == 50:
		b = b + 1
		a = a - 1
	elif l[i] == 100:
		if b != 0:
			c = c + 1
			b = b - 1
			a = a - 1
		else:
			a = a - 3
	if a < 0 or b < 0:
		print('NO')
		f = 1
		break
if f == 0:
	print('YES')


input()
T = list(map(int, input().strip().split(' ')))
C = {25: 0, 100: 0, 50: 0}
for i in range(len(T)):
	if T[i] is 25:
		C[25] = C[25] + 1
	elif T[i] is 50:
		if C[25] > 0:
			C[25] = C[25] - 1
			C[50] = C[50] + 1
		else:
			print('NO')
			quit()
	elif T[i] is 100:
		if C[50] > 0:
			if C[25] > 0:
				C[100] = C[100] + 1
				C[50] = C[50] - 1
				C[25] = C[25] - 1
			else:
				print('NO')
				quit()
		elif C[25] > 2:
			C[25] = C[25] - 3
			C[100] = C[100] + 1
		else:
			print('NO')
			quit()
print('YES')


n = int(input())
s = list(map(int, input().split()))
totalamount = {'25': 0, '50': 0, '100': 0}
if s[0] != 25:
	print('NO')
else:
	totalamount['25'] += 1
	flag = 0
	for i in range(1, n):
		if s[i] == 25:
			totalamount['25'] += 1
		elif s[i] == 50:
			if totalamount['25'] > 0:
				totalamount['25'] -= 1
				totalamount['50'] += 1
			else:
				flag = 1
				print('NO')
				break
		elif s[i] == 100:
			if totalamount['25'] > 0 and totalamount['50'] > 0:
				totalamount['25'] -= 1
				totalamount['50'] -= 1
				totalamount['100'] += 1
			elif totalamount['25'] > 2:
				totalamount['25'] -= 3
			else:
				flag = 1
				print('NO')
				break
	if flag != 1:
		print('YES')


(h, f, t) = (0, 0, 0)
n = int(input())
line = list(map(int, input().split()))
possible = 'YES'
for person in line:
	if person == 25:
		t += 1
	elif person == 50:
		if t >= 1:
			t -= 1
		else:
			possible = 'NO'
			break
		f += 1
	elif f >= 1 and t >= 1:
		f -= 1
		t -= 1
	elif t >= 3:
		t -= 3
	else:
		possible = 'NO'
		break
print(possible)


import sys
k = int(input())
a = input().split()
n = m = 0
for i in range(0, k):
	if a[i] == '25':
		n += 1
	elif a[i] == '50':
		m += 1
		if n > 0:
			n -= 1
		else:
			print('NO')
			sys.exit()
	elif n > 0 and m > 0:
		n -= 1
		m -= 1
	elif n > 2:
		n -= 3
	else:
		print('NO')
		sys.exit()
print('YES')


n = int(input())
arr = [int(i) for i in filter(None, input().split(' '))]
ans = 'YES'
if arr[0] != 25:
	ans = 'NO'
else:
	k25 = 1
	k50 = 0
	for i in range(1, n):
		if arr[i] == 25:
			k25 += 1
		if arr[i] == 50:
			if k25 > 0:
				k50 += 1
				k25 -= 1
			else:
				ans = 'NO'
				break
		if arr[i] == 100:
			if k50 > 0 and k25 > 0:
				k50 -= 1
				k25 -= 1
			elif k25 >= 3:
				k25 -= 3
			else:
				ans = 'NO'
				break
print(ans)


n = int(input())
p = list(map(int, input().split()))
a = 0
b = 0
c = 0
flag = 0
for i in range(n):
	if p[i] == 25:
		a += 1
	elif p[i] == 50:
		a = a - 1
		b = b + 1
		if a < 0:
			flag = 1
			break
	elif b != 0:
		b = b - 1
		a = a - 1
		c = c + 1
		if a < 0:
			flag = 1
			break
	else:
		a = a - 3
		if a < 0:
			flag = 1
			break
if flag == 1:
	print('NO')
else:
	print('YES')


x25 = 0
x50 = 0
x100 = 0
n = int(input())
arr = list(map(int, input().split()))
ans = True
for i in arr:
	if i == 25:
		x25 += 1
	elif i == 50:
		if x25 == 0:
			ans = False
			break
		else:
			x25 -= 1
			x50 += 1
	elif i == 100:
		if x50 > 0 and x25 > 0:
			x25 -= 1
			x50 -= 1
		elif x25 > 2:
			x25 -= 3
		else:
			ans = False
			break
		x100 += 1
if ans:
	print('YES')
else:
	print('NO')


n = int(input())
d = {25: 0, 50: 0, 100: 0}
ans = 'YES'
for x in list(map(int, input().split())):
	if x == 25:
		d[x] += 1
	if x == 50:
		if d[25] > 0:
			d[x] += 1
			d[25] -= 1
		else:
			ans = 'NO'
			break
	if x == 100:
		if d[25] > 0 and d[50] > 0:
			d[x] += 1
			d[25] -= 1
			d[50] -= 1
		elif d[25] > 2:
			d[x] += 1
			d[25] -= 3
		else:
			ans = 'NO'
			break
print(ans)


n = int(input())
a = list(map(int, input().split()))
r25 = 0
r50 = 0
r100 = 0
c = 0
for i in a:
	if i == 25:
		r25 += 1
	elif i == 50:
		r50 += 1
		r25 -= 1
	else:
		r100 += 1
		if r50 >= 1:
			r50 -= 1
			r25 -= 1
		else:
			r25 -= 3
	if r25 < 0:
		c = 1
		print('NO')
		break
if c == 0:
	print('YES')


n = int(input())
c100 = 0
c50 = 0
c25 = 0
a = list(map(int, input().split(' ')))
chk = 1
for x in range(n):
	if a[x] == 25:
		c25 = c25 + 1
	if a[x] == 50:
		if c25 >= 1:
			c25 = c25 - 1
			c50 = c50 + 1
			continue
		else:
			chk = 0
			break
	if a[x] == 100:
		if c25 >= 1 and c50 >= 1:
			c100 = c100 + 1
			c25 = c25 - 1
			c50 = c50 - 1
			continue
		if c25 >= 3:
			c25 = c25 - 3
			continue
		else:
			chk = 0
			break
if chk == 1:
	print('YES')
else:
	print('NO')


n = eval(input())
a = eval(input().replace(' ', ',') + ',')
change = [0, 0]
for i in range(0, n):
	if a[i] == 25:
		change[0] += 1
	elif a[i] == 50:
		if change[0] > 0:
			change[0] -= 1
			change[1] += 1
		else:
			print('NO')
			break
	elif change[0] > 0 and change[1] > 0:
		change[0] -= 1
		change[1] -= 1
	elif change[0] > 2:
		change[0] -= 3
	else:
		print('NO')
		break
else:
	print('YES')


n = int(input())
bills = map(int, input().split())
bill_count = {25: 0, 50: 0, 100: 0}
s = True
for bill in bills:
	bill_count[bill] += 1
	if bill == 100:
		if bill_count[50] > 0:
			bill_count[50] -= 1
		else:
			bill_count[25] -= 2
	if bill == 100 or bill == 50:
		bill_count[25] -= 1
	if bill_count[50] < 0 or bill_count[25] < 0:
		s = False
		break
if s:
	print('YES')
else:
	print('NO')


def CinemaLine():
	n = int(input())
	line = [int(i) for i in input().strip().split()]
	cashier = {25: 0, 50: 0, 100: 0}
	if line[0] != 25:
		return 'NO'
	for person in line:
		change = person - 25
		if cashier[25] * 25 + cashier[50] * 50 < change:
			return 'NO'
		else:
			if cashier[50] >= change // 50:
				cashier[50] -= change // 50
				change -= change // 50 * 50
			if cashier[25] >= change // 25:
				cashier[25] -= change // 25
				change -= change // 25 * 25
			if change > 0:
				return 'NO'
			else:
				cashier[person] += 1
	return 'YES'
a = CinemaLine()
print(a)


input()
sum = {25: 0, 50: 0, 100: 0}
for i in [int(i) for i in list(input().split())]:
	if i == 25:
		sum[25] = sum.get(25) + 1
	elif i == 50 and sum.get(25) > 0:
		sum[25] = sum.get(25) - 1
		sum[50] = sum.get(50) + 1
	elif i == 100 and sum.get(25) > 0 and (sum.get(50) > 0):
		sum[25] = sum.get(25) - 1
		sum[50] = sum.get(50) - 1
		sum[100] = sum.get(100) + 1
	elif i == 100 and sum.get(25) > 2:
		sum[25] = sum.get(25) - 3
		sum[100] = sum.get(100) + 1
	else:
		print('NO')
		exit()
print('YES')


n = int(input())
(c25, c50, c100) = (0, 0, 0)
for el in map(int, input().split()):
	if el == 25:
		c25 += 1
	elif el == 50 and c25 > 0:
		c50 += 1
		c25 -= 1
	elif el == 100:
		if c25 > 0 and c50 > 0:
			c100 += 1
			c50 -= 1
			c25 -= 1
		elif c25 > 2:
			c100 += 1
			c25 -= 3
		else:
			print('NO')
			break
	else:
		print('NO')
		break
else:
	print('YES')


n = int(input())
line = input().strip().split()
clerk = {'25': 0, '50': 0, '100': 0}
for person in line:
	if person == '25':
		clerk['25'] += 1
	elif person == '50':
		if clerk['25'] > 0:
			clerk['25'] -= 1
			clerk['50'] += 1
		else:
			print('NO')
			break
	elif clerk['50'] > 0 and clerk['25'] > 0:
		clerk['50'] -= 1
		clerk['25'] -= 1
		clerk['100'] += 1
	elif clerk['25'] > 2:
		clerk['25'] -= 3
		clerk['100'] += 1
	else:
		print('NO')
		break
else:
	print('YES')


x = int(input())
integerArray = []
stringArray = input().split(' ')
for i in range(0, x):
	integerArray.append(int(stringArray[i]))
lowest = 101
secondlowest = 102
stack25 = 0
stack50 = 0
possible = True
for i in range(0, x):
	if integerArray[i] == 25:
		stack25 = stack25 + 1
	elif integerArray[i] == 50:
		if stack25 > 0:
			stack50 = stack50 + 1
			stack25 = stack25 - 1
		else:
			possible = False
	elif integerArray[i] == 100:
		if stack25 > 0 and stack50 > 0:
			stack50 = stack50 - 1
			stack25 = stack25 - 1
		elif stack25 > 2:
			stack25 = stack25 - 3
		else:
			possible = False
if possible:
	print('YES')
else:
	print('NO')


n = int(input())
seq = list(map(int, input().split()))
money = [0 for i in range(101)]
for i in seq:
	if i == 50:
		if money[25] >= 1:
			money[25] -= 1
		else:
			print('NO')
			exit(0)
	elif i == 100:
		if money[50] >= 1 and money[25] >= 1:
			money[50] -= 1
			money[25] -= 1
		elif money[25] >= 3:
			money[25] -= 3
		else:
			print('NO')
			exit(0)
	money[i] += 1
print('YES')


garbage = input()
l = list(map(int, input().rstrip().split(' ')))
c_25 = 0
c_50 = 0
c_100 = 0
r = 'YES'
for i in l:
	if i == 25:
		c_25 += 1
	elif i == 50:
		c_25 -= 1
		c_50 += 1
	elif c_50:
		c_50 -= 1
		c_25 -= 1
	else:
		c_25 -= 3
	if c_25 < 0:
		r = 'NO'
		break
print(r)


n = int(input())
a = [int(i) for i in input().split()]
q = 0
h = 0
r = 0
for i in range(n):
	if a[i] == 25:
		q += 1
	if a[i] == 50:
		q -= 1
		h += 1
	if a[i] == 100:
		if h > 0:
			h -= 1
			q -= 1
		else:
			q -= 3
	if q < 0:
		r = 1
if r == 1:
	print('NO')
else:
	print('YES')


a = int(input())
b = list(map(int, input().split()))
t25 = 0
t50 = 0
for i in range(a):
	if b[i] == 25:
		t25 += 1
	elif b[i] == 50:
		if t25 >= 1:
			t25 -= 1
			t50 += 1
		else:
			print('NO')
			exit(0)
	elif b[i] == 100:
		if t50 >= 1 and t25 >= 1:
			t50 -= 1
			t25 -= 1
		elif t25 >= 3:
			t25 -= 3
		else:
			print('NO')
			exit(0)
print('YES')


money = {50: 0, 25: 0}
n = int(input())
cus = [int(cus) for cus in input().split()]
mark = 1
for i in range(n):
	if cus[i] == 25:
		money[cus[i]] += 1
		continue
	else:
		if cus[i] == 50:
			money[cus[i]] += 1
			if money[25] == 0:
				mark = 0
				break
			else:
				money[25] -= 1
		if cus[i] == 100:
			cus[i] -= 25
			for j in money:
				if money[j] == 0:
					continue
				else:
					while cus[i] >= j and money[j] != 0:
						cus[i] -= j
						money[j] -= 1
			if cus[i] != 0:
				mark = 0
				break
res = 'YES' if mark == 1 else 'NO'
print(res)


n = int(input())
a = list(map(int, input().strip().split()))[:n]
m25 = 0
m50 = 0
flag = 1
for i in range(n):
	if i == 0 and a[i] > 25:
		flag = 0
		break
	if a[i] == 25:
		m25 += 1
	elif a[i] == 50:
		m50 += 1
		if m25 >= 1:
			flag = 1
			m25 -= 1
		else:
			flag = 0
			break
	elif m50 >= 1 and m25 >= 1:
		flag = 1
		m25 -= 1
		m50 -= 1
	elif m25 >= 3:
		flag = 1
		m25 -= 3
	else:
		flag = 0
		break
if flag == 1:
	print('YES')
else:
	print('NO')


from sys import stdin, stdout
input = stdin.readline
n = int(input())
a = list(map(int, input().split()))
r1 = 0
r2 = 0
for i in a:
	rem = i - 25
	if rem >= 50 and r2 != 0:
		rem -= 50
		r2 -= 50
	if rem > 0:
		r1 -= rem
	if r1 < 0:
		stdout.write('NO')
		exit(0)
	if i == 25:
		r1 += i
	elif i == 50:
		r2 += i
stdout.write('YES')


def solve(a, n):
	cnt1 = 0
	cnt2 = 0
	for x in a:
		if x == 25:
			cnt1 += 1
		elif x == 50:
			if cnt1 == 0:
				return False
			cnt1 -= 1
			cnt2 += 1
		else:
			if cnt1 == 0 or (cnt1 < 3 and cnt2 == 0):
				return False
			cnt1 -= 1
			if cnt2 > 0:
				cnt2 -= 1
			else:
				cnt1 -= 2
	return True
n = int(input())
a = list(map(int, input().split()))
if solve(a, n):
	print('YES')
else:
	print('NO')


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

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

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

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
nb_people = read_int()
have = read_ints()
_25 = 0
_50 = 0
can = 'YES'
for has in have:
	if has == 25:
		_25 += 1
	elif has == 50:
		_50 += 1
		_25 -= 1
	else:
		if _50 > 0:
			_50 -= 1
		else:
			_25 -= 2
		_25 -= 1
	if _25 < 0 or _50 < 0:
		can = 'NO'
		break
print(can)


import sys
n = int(input())
l = list(map(int, input().split()))
amount_25 = 0
amount_50 = 0
for i in range(n):
	x = l[i]
	if x == 25:
		amount_25 += 1
	if x == 50:
		amount_25 -= 1
		if amount_25 < 0:
			print('NO')
			sys.exit(0)
		amount_50 += 1
	if x == 100:
		if amount_50 > 0:
			amount_50 -= 1
			amount_25 -= 1
			if amount_25 < 0:
				print('NO')
				sys.exit(0)
		else:
			amount_25 -= 3
			if amount_25 < 0:
				print('NO')
				sys.exit(0)
print('YES')


Capital = [0, 0]
numero = input()
numero = int(numero)
boolean = False
Comprador = input().split(' ')
for i in range(0, numero):
	if Comprador[i] == '25':
		Capital[0] = Capital[0] + 1
	elif Comprador[i] == '50' and Capital[0] > 0:
		Capital[1] = Capital[1] + 1
		Capital[0] = Capital[0] - 1
	elif Comprador[i] == '100' and Capital[0] > 0 and (Capital[1] > 0):
		Capital[1] = Capital[1] - 1
		Capital[0] = Capital[0] - 1
	elif Comprador[i] == '100' and Capital[0] >= 3:
		Capital[0] = Capital[0] - 3
	else:
		print('NO')
		boolean = True
		break
if boolean == False:
	print('YES')


n = int(input())
data = [int(i) for i in input().split()]
tf = 0
f = 0
success = 'YES'
for i in data:
	if i == 25:
		tf += 1
	elif i == 50:
		if tf > 0:
			tf -= 1
			f += 1
		else:
			success = 'NO'
			break
	elif tf > 0 and f > 0:
		tf -= 1
		f -= 1
	elif tf >= 3:
		tf -= 3
	else:
		success = 'NO'
		break
print(success)


initial = 0
n = int(input())
ls = [int(i) for i in input().split()]
br = 0
count25 = 0
count50 = 0
for i in ls:
	if i == 25:
		count25 += 1
		initial += i
	elif i - 25 <= initial:
		initial = initial + 25
		if i == 100:
			if count50 and count25:
				count50 -= 1
				count25 -= 1
			elif count25 >= 3:
				count25 -= 3
			else:
				print('NO')
				br = 1
				break
		elif i == 50:
			if count25:
				count25 -= 1
				count50 += 1
			else:
				print('NO')
				br = 1
				break
	else:
		print('NO')
		br = 1
		break
if br == 0:
	print('YES')


n = int(input())
m = [int(x) for x in input().split()]
money = {25: 0, 50: 0, 100: 0}
is_answered = False
for x in m:
	if x == 25:
		money[25] += 1
	elif x == 50:
		if money[25] > 0:
			money[25] -= 1
			money[50] += 1
		else:
			is_answered = True
			print('NO')
			break
	elif money[50] > 0 and money[25] > 0:
		money[50] -= 1
		money[25] -= 1
		money[100] += 1
	elif money[25] >= 3:
		money[25] -= 3
		money[100] += 1
	else:
		is_answered = True
		print('NO')
		break
if not is_answered:
	print('YES')


n = int(input())
bills = list(map(int, input().split()))
ans = 'YES'
cbills = [0, 0, 0]
for bill in bills:
	if bill == 25:
		cbills[0] += 1
	elif bill == 50:
		if cbills[0]:
			cbills[0] -= 1
			cbills[1] += 1
		else:
			ans = 'NO'
			break
	elif bill == 100:
		if cbills[0]:
			if cbills[1]:
				cbills[0] -= 1
				cbills[1] -= 1
				cbills[2] += 1
			elif cbills[0] >= 3:
				cbills[0] -= 3
				cbills[2] += 1
			else:
				ans = 'NO'
				break
		else:
			ans = 'NO'
			break
print(ans)


n = int(input())
L = list(map(int, input().split()))
a = p = c = 0
for i in L:
	if i == 25:
		a += 1
	elif i == 50:
		a -= 1
		p += 1
	elif p:
		p -= 1
		a -= 1
	else:
		a -= 3
	if a < 0:
		c = 1
		break
print('YNEOS'[c::2])


n = int(input())
f = 'YES'
a = input().split()
for i in range(n):
	a[i] = int(a[i])
t25 = 0
t50 = 0
for i in range(n):
	if a[i] == 25:
		t25 = t25 + 1
	elif a[i] == 50:
		if t25 >= 1:
			t50 = t50 + 1
			t25 = t25 - 1
		else:
			f = 'NO'
	elif t50 > 0 and t25 > 0:
		t50 = t50 - 1
		t25 = t25 - 1
	elif t25 >= 3:
		t25 = t25 - 3
	else:
		f = 'NO'
print(f)


n = int(input())
order = [int(i) for i in input().split(' ')]
cnt25 = 0
cnt50 = 0
cnt100 = 0
for x in order:
	if x == 25:
		cnt25 += 1
	elif x == 50:
		if not cnt25:
			print('NO')
			exit()
		else:
			cnt25 -= 1
			cnt50 += 1
	elif cnt50 > 0 and cnt25 > 0:
		cnt25 -= 1
		cnt50 -= 1
	elif cnt25 > 2:
		cnt25 -= 3
	else:
		print('NO')
		exit()
print('YES')


n = int(input())
c = list(map(int, input().split()))
a = [0] * 2
for i in range(n):
	if c[i] == 100:
		if a[1] > 0 and a[0] > 0:
			a[0] -= 1
			a[1] -= 1
		elif a[0] > 2:
			a[0] -= 3
		else:
			print('NO')
			break
	elif c[i] == 50:
		if a[0] > 0:
			a[0] -= 1
			a[1] += 1
		else:
			print('NO')
			break
	else:
		a[0] += 1
else:
	print('YES')


n = int(input())
c = 0
d = 0
x = [int(x) for x in input().split()]
for i in range(n):
	if x[i] == 50:
		c -= 25
		d += 50
	elif x[i] == 25:
		c += 25
	elif x[i] == 100:
		if d > 0:
			d -= 50
			c -= 25
		else:
			c -= 75
	if c < 0:
		print('NO')
		exit()
print('YES')


no_of_viewers = int(input())
viewers = list(map(int, input().split()))
has = [0, 0, 0]
yes = True
for v in viewers:
	if v == 25:
		has[0] += 1
	elif v == 50 and has[0] > 0:
		has[0] -= 1
		has[1] += 1
	elif v == 100 and has[0] > 0 and (has[1] > 0):
		has[0] -= 1
		has[1] -= 1
		has[2] += 1
	elif v == 100 and has[0] >= 3:
		has[0] -= 3
		has[2] += 1
	else:
		yes = False
		break
if yes:
	print('YES')
else:
	print('NO')


_ = input()
inp = list(map(int, input().split()))
dic = {25: 0, 50: 0, 100: 0}
stat = False
for x in inp:
	stat = False
	if x == 25:
		dic[x] += 1
		stat = True
	elif x == 50 and dic[25] >= 1:
		dic[x] += 1
		dic[25] -= 1
		stat = True
	elif x == 100:
		if dic[50] >= 1 and dic[25] >= 1:
			dic[25] -= 1
			dic[50] -= 1
			dic[x] += 1
			stat = True
		elif dic[25] >= 3:
			dic[x] += 1
			dic[25] -= 3
			stat = True
	if stat == False:
		print('NO')
		exit()
print('YES')


import math
import sys

def dict_sort(ans):
	ans = sorted(ans.items(), reverse=True, key=lambda kv: kv[1])

def is_prime(n):
	if n == 1:
		return 0
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def inp():
	ls = list(map(int, input().split()))
	return ls
n = int(input())
ls = inp()
if ls[0] != 25:
	print('NO')
	exit(0)
else:
	_25 = _50 = 0
	for i in range(n):
		if ls[i] == 25:
			_25 += 1
		elif ls[i] == 50:
			if _25 < 1:
				print('NO')
				exit(0)
			else:
				_25 -= 1
				_50 += 1
		elif _50 > 0 and _25 > 0:
			_50 -= 1
			_25 -= 1
		elif _25 >= 3:
			_25 -= 3
		else:
			print('NO')
			exit(0)
	print('YES')


n = int(input())
l = [int(x) for x in input().split()]
qian = {'a': 0, 'b': 0, 'c': 0}
c = 0
for i in range(n):
	if l[i] == 25:
		qian['a'] += 1
	elif l[i] == 50:
		qian['a'] -= 1
		qian['b'] += 1
	elif l[i] == 100:
		if qian['b'] > 0 and qian['a'] > 0:
			qian['b'] -= 1
			qian['a'] -= 1
		else:
			qian['a'] -= 3
	if qian['a'] < 0 or qian['b'] < 0:
		print('NO')
		break
	else:
		c += 1
if c == n:
	print('YES')


n = int(input())
a = [int(i) for i in input().split()]
if a[0] != 25:
	print('NO')
else:
	h = k = l = x = 0
	for i in range(n):
		if a[i] == 25:
			h += 1
		elif a[i] == 50:
			if h > 0:
				h -= 1
				k += 1
			else:
				x = 1
				break
		elif h > 0 and k > 0:
			h -= 1
			k -= 1
		elif h > 2:
			h -= 3
		else:
			x = 1
			break
	if x:
		print('NO')
	else:
		print('YES')


n = int(input())
q = input().split()
(a, b) = (0, 0)
for i in q:
	if a < 0 or b < 0:
		break
	elif i == '25':
		a += 1
	elif i == '50':
		a -= 1
		b += 1
	elif b:
		b -= 1
		a -= 1
	else:
		a -= 3
print(['YES', 'NO'][a < 0 or b < 0])


n = int(input())
l = [int(x) for x in input().split()]
no25 = 0
no50 = 0
for i in range(n):
	temp = l[i]
	if temp - 25 == 0:
		no25 += 1
	elif temp - 25 == 25:
		no50 += 1
		no25 -= 1
	elif temp - 25 == 75:
		if no50 > 0:
			no50 -= 1
			no25 -= 1
		else:
			no25 -= 3
	if no25 < 0 or no50 < 0:
		print('NO')
		break
else:
	print('YES')


import sys
n = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
s = 0
m = 0
case = True
for item in A:
	if item == 50 and s >= 1:
		m += 1
		s -= 1
		continue
	if item == 100 and m >= 1 and (s >= 1):
		m -= 1
		s -= 1
		continue
	if item == 100 and s >= 3:
		s -= 3
		continue
	if item == 25:
		s += 1
		continue
	case = False
	break
if case:
	print('YES')
else:
	print('NO')


n = int(input())
tickets = list(map(int, input().split()))
twentyFive = 0
Fifty = 0
no = True
for i in range(len(tickets)):
	if tickets[i] == 25:
		twentyFive += 1
	elif tickets[i] == 50:
		if twentyFive > 0:
			twentyFive -= 1
			Fifty += 1
		else:
			print('NO')
			no = False
			break
	elif Fifty > 0 and twentyFive > 0:
		Fifty -= 1
		twentyFive -= 1
	elif twentyFive > 2:
		twentyFive -= 3
	else:
		print('NO')
		no = False
		break
if no:
	print('YES')


n = int(input())
ar = list(map(int, input().split()))
rup25 = 0
rup50 = 0
count = 1
for i in ar:
	if i == 25:
		rup25 += 1
	elif i == 50:
		if rup25 < 1:
			print('NO')
			count = 0
			break
		else:
			rup50 += 1
			rup25 -= 1
	elif i == 100:
		if rup50 < 1:
			if rup25 < 3:
				print('NO')
				count = 0
				break
			elif rup25 >= 3:
				rup25 -= 3
		elif rup50 >= 1 and rup25 >= 1:
			rup25 -= 1
			rup50 -= 1
		else:
			print('NO')
			count = 0
			break
	count = 1
if count == 1:
	print('YES')


def solve(coins):
	twenty_fives = 0
	fifty = 0
	hundred = 0
	for coin in coins:
		if coin == 25:
			twenty_fives += 1
		elif coin == 100:
			hundred += 1
			if fifty >= 1 and twenty_fives >= 1:
				fifty -= 1
				twenty_fives -= 1
			elif twenty_fives >= 3:
				twenty_fives -= 3
			else:
				return False
		elif coin == 50:
			fifty += 1
			if twenty_fives >= 1:
				twenty_fives -= 1
			else:
				return False
	return True
n = int(input())
coins = [int(i) for i in input().split()]
total = 0
if solve(coins):
	print('YES')
else:
	print('NO')


def change(l):
	r = [0, 0]
	for i in l:
		if i == 25:
			r[0] += 1
		elif i == 50:
			r[1] += 1
			if r[0] > 0:
				r[0] -= 1
			else:
				return 'NO'
		elif r[1] > 0 and r[0] > 0:
			r[1] -= 1
			r[0] -= 1
		elif r[0] > 2:
			r[0] -= 3
		else:
			return 'NO'
	return 'YES'
n = int(input())
l = [int(i) for i in input().split()]
print(change(l))


input()
L = list(map(int, input().split()))
b25 = 0
b50 = 0
res = 'YES'
for k in L:
	if k == 25:
		b25 += 1
	elif k == 50:
		if b25 > 0:
			b50 += 1
			b25 -= 1
		else:
			res = 'NO'
			break
	elif b25 > 0 and b50 > 0:
		b25 -= 1
		b50 -= 1
	elif b25 >= 3:
		b25 -= 3
	else:
		res = 'NO'
		break
print(res)


n = int(input())
arr = list(map(int, input().split()))
(n25, n50) = (0, 0)
for x in arr:
	if x == 25:
		n25 = n25 + 1
	if x == 50:
		n50 = n50 + 1
		n25 = n25 - 1
	if x == 100:
		if n50 > 0:
			n50 = n50 - 1
			n25 = n25 - 1
		else:
			n25 = n25 - 3
	if n25 < 0 or n50 < 0:
		print('NO')
		exit()
print('YES')


n = int(input())
c25 = 0
c50 = 0
flag = True
for e in map(int, input().split()):
	if e == 100:
		if c50 > 0:
			c50 -= 1
			c25 -= 1
		else:
			c25 -= 3
	elif e == 50:
		c25 -= 1
		c50 += 1
	else:
		c25 += 1
	if c50 < 0 or c25 < 0:
		flag = False
		break
print('YES' if flag else 'NO')


(c1, c2) = (0, 0)
n = input()
l = [int(k) for k in input().split(' ')]
can = True
for p in range(len(l)):
	cur = l[p]
	if cur == 25:
		c1 += 1
	if cur == 50:
		if c1 > 0:
			c1 -= 1
			c2 += 1
		else:
			can = False
			break
	if cur == 100:
		if c1 > 0 and c2 > 0:
			c1 -= 1
			c2 -= 1
		elif c1 > 2:
			c1 -= 3
		else:
			can = False
			break
if can:
	print('YES')
else:
	print('NO')


def can_sell(client_moneys: list) -> bool:
	current = {25: 0, 50: 0, 100: 0}
	for money in client_moneys:
		if money == 25:
			current[25] += 1
		elif money == 50:
			if current[25] < 1:
				return False
			else:
				current[25] -= 1
				current[50] += 1
		elif money == 100:
			if current[25] < 1:
				return False
			elif current[50] > 0:
				current[25] -= 1
				current[50] -= 1
			elif current[25] < 3:
				return False
			else:
				current[25] -= 3
			current[100] += 1
	return True
input()
moneys = [int(i) for i in input().split()]
print('YES' if can_sell(moneys) else 'NO')


no = int(input())
people = [int(x) for x in input().split()]
store = {25: 0, 50: 0, 100: 0}

def returnChange(rs):
	if rs == 25:
		if store[25] > 0:
			store[25] -= 1
			return True
		return False
	else:
		if store[50] > 0 and store[25] > 0:
			store[50] -= 1
			store[25] -= 1
			return True
		if store[25] >= 3:
			store[25] -= 3
			return True
		return False
for x in people:
	if x - 25 == 0:
		store[x] += 1
	elif x - 25 == 25:
		if returnChange(25) == False:
			print('NO')
			break
		store[x] += 1
	else:
		if returnChange(75) == False:
			print('NO')
			break
		store[x] += 1
else:
	print('YES')


n = int(input())
l = [int(x) for x in input().split()]
changes = {25: 0, 50: 0}
d = n
for i in l:
	if i == 25:
		changes[25] += 1
	elif i == 50:
		changes[25] -= 1
		changes[50] += 1
	elif changes[50] < 1:
		changes[25] -= 3
	else:
		changes[25] -= 1
		changes[50] -= 1
	if changes[25] < 0 or changes[50] < 0:
		d -= 1
		break
if d == n:
	print('YES')
else:
	print('NO')


__author__ = 'Lucas'
import sys

def main():
	numpeople = int(sys.stdin.readline())
	twentyfives = 0
	fifties = 0
	works = True
	for i in range(numpeople):
		num = sys.stdin.read(1)
		nextnum = sys.stdin.read(1)
		while nextnum.isdigit():
			num = num + nextnum + ''
			nextnum = sys.stdin.read(1)
		if int(num) == 25:
			twentyfives += 1
			continue
		if int(num) == 50:
			if twentyfives > 0:
				twentyfives -= 1
				fifties += 1
				continue
		if int(num) == 100:
			if fifties > 0:
				if twentyfives > 0:
					fifties -= 1
					twentyfives -= 1
					continue
			if fifties == 0:
				if twentyfives >= 3:
					twentyfives -= 3
					continue
		print('NO')
		works = False
		break
	if works:
		print('YES')
main()


n = int(input())
banknotes = list(map(int, input().strip().split(' ')))
(b25, b50, b100) = (0, 0, 0)
for i in banknotes:
	if i == 25:
		b25 += 1
	elif i == 50:
		b50 += 1
		if b25 < 1:
			print('NO')
			break
		else:
			b25 -= 1
	else:
		b100 += 1
		if b50 < 1 or b25 < 1:
			if b25 < 3:
				print('NO')
				break
			else:
				b25 -= 3
		else:
			b50 -= 1
			b25 -= 1
else:
	print('YES')


from collections import defaultdict
x = int(input())
a = list(map(int, input().split()))
d = defaultdict()
d[25] = 0
d[50] = 0
f = 0
for i in a:
	if i == 25:
		d[i] += 1
	elif i == 50:
		if d[25] > 0:
			d[i] += 1
			d[25] -= 1
		else:
			f = 1
	elif d[25] > 0 and d[50] > 0:
		d[25] -= 1
		d[50] -= 1
	elif d[25] > 2:
		d[25] -= 3
	else:
		f = 1
if f == 1:
	print('NO')
else:
	print('YES')


n = int(input())
arr = list(map(int, input().split()))
change = {25: 0, 50: 0}
for i in range(n):
	if arr[i] == 25:
		change[25] += 1
	elif arr[i] == 50:
		if change[25] < 1:
			print('NO')
			break
		else:
			change[50] += 1
			change[25] -= 1
	elif arr[i] == 100:
		if change[50] >= 1 and change[25] >= 1:
			change[50] -= 1
			change[25] -= 1
		elif change[25] >= 3:
			change[25] -= 3
		else:
			print('NO')
			break
	if i == n - 1:
		print('YES')


n = input()
queue = input().split()
p25 = 0
p50 = 0
p100 = 0
result = 'YES'
for note in queue:
	if note == '25':
		p25 += 1
	elif note == '50':
		if p25 > 0:
			p50 += 1
			p25 -= 1
		else:
			result = 'NO'
			break
	elif note == '100':
		if p50 > 0 and p25 > 0:
			p50 -= 1
			p25 -= 1
			p100 += 1
		elif p25 > 2:
			p25 -= 3
			p100 += 1
		else:
			result = 'NO'
			break
print(result)


n = int(input())
L = list(map(int, input().split()))
a = p = 0
for i in L:
	if i == 25:
		a += 1
	elif i == 50:
		a -= 1
		p += 1
	elif p > 0:
		p -= 1
		a -= 1
	else:
		a -= 3
	if a < 0:
		print('NO')
		break
else:
	print('YES')


n = int(input())
a = list(map(int, input().split()))
c25 = 0
c50 = 0
if a[0] != 25:
	print('NO')
	exit()
for i in range(0, n):
	if a[i] == 25:
		c25 += 1
	if a[i] == 50 and c25 < 1:
		print('NO')
		exit()
	if a[i] == 50 and c25 >= 1:
		c25 -= 1
		c50 += 1
	if a[i] == 100 and (c25 >= 1 and c50 >= 1):
		c25 -= 1
		c50 -= 1
	elif a[i] == 100 and c25 >= 3:
		c25 -= 3
	elif a[i] == 100 and (c25 < 3 or (c50 >= 1 and c25 < 1)):
		print('NO')
		exit()
print('YES')


n = int(input())
ppl = list(map(int, input().split()))
change = {25: 0, 50: 0, 100: 0}
i = 0
while i < n:
	if ppl[i] == 25:
		change[25] = change[25] + 1
	elif ppl[i] == 50:
		if change[25] < 1:
			break
		else:
			change[50] = change[50] + 1
			change[25] = change[25] - 1
	elif change[50] >= 1 and change[25] >= 1:
		change[100] = change[100] + 1
		change[50] = change[50] - 1
		change[25] = change[25] - 1
	elif change[25] >= 3:
		change[100] = change[100] + 1
		change[25] = change[25] - 3
	else:
		break
	i = i + 1
if i == n:
	print('YES')
else:
	print('NO')


n = input().split()[0]
n = int(n)
a = [int(i) for i in input().split()]
sd = 0
sdp = 0
flag = True
for elem in a:
	if elem == 25:
		sd += 1
	elif elem == 50:
		if sd < 1:
			flag = False
			break
		else:
			sd -= 1
			sdp += 1
	elif sdp >= 1 and sd >= 1 or sd >= 3:
		if sdp > 0:
			sdp -= 1
			sd -= 1
		else:
			sd -= 3
	else:
		flag = False
		break
if flag:
	print('YES')
else:
	print('NO')


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 = int(input.readline())
	lis = list(map(int, input.readline().split()))
	arr = [0] * 101
	canbe = True
	for i in range(n):
		if lis[i] == 25:
			arr[25] += 1
		elif lis[i] == 50:
			if arr[25] == 0:
				canbe = False
				break
			else:
				arr[25] -= 1
				arr[50] += 1
		elif lis[i] == 100:
			if arr[25] > 0 and arr[50] > 0:
				arr[25] -= 1
				arr[50] -= 1
			elif arr[50] == 0 and arr[25] >= 3:
				arr[25] -= 3
			else:
				canbe = False
				break
	if canbe:
		output = 'YES'
	else:
		output = 'NO'
	if os.path.exists('output.txt'):
		open('output.txt', 'w').writelines(str(output))
	else:
		sys.stdout.write(str(output))
main()


n = int(input())
a = list(map(int, input().split()))
dic = {}
(dic[25], dic[50], dic[100]) = (0, 0, 0)
flag = True
for i in a:
	if i == 25:
		dic[i] += 1
	elif i == 50:
		dic[50] += 1
		if dic[25] < 1:
			print('NO')
			flag = False
			break
		elif dic[25] > 0:
			dic[25] -= 1
		else:
			dic[25] = 0
	elif i == 100:
		if dic[25] >= 1 and dic[50] >= 1:
			if dic[25] > 0:
				dic[25] -= 1
			else:
				dic[25] = 0
			if dic[50] > 0:
				dic[50] -= 1
			else:
				dic[50] = 0
		elif dic[25] >= 3:
			if dic[25] > 2:
				dic[25] -= 3
			else:
				dic[25] = 0
		else:
			print('NO')
			flag = False
			break
if flag:
	print('YES')


n = int(input())
l = [int(i) for i in input().split()]
a = 0
b = 0
c = 0
for i in range(n):
	if l[i] == 25:
		a += 1
	elif l[i] == 50:
		a -= 1
		b += 1
	else:
		a -= 1
		if b > 0:
			b -= 1
		else:
			a -= 2
		c += 1
	if a < 0 or b < 0 or c < 0:
		n = -1
print('NO' if n == -1 else 'YES')


n = int(input().strip())
m = [int(x) for x in input().strip().split()]
d = {25: 0, 50: 0, 100: 0}
for e in m:
	if e == 50:
		if not d[25]:
			print('NO')
			break
		else:
			d[25] -= 1
	elif e == 100:
		if d[25] and d[50]:
			d[50] -= 1
			d[25] -= 1
		elif d[25] > 2:
			d[25] -= 3
		else:
			print('NO')
			break
	d[e] += 1
else:
	print('YES')


n = int(input())
a = list(map(int, input().split()))
state_25 = 0
state_50 = 0
state_100 = 0
res = 'YES'
if a[0] != 25:
	res = 'NO'
else:
	for i in range(n):
		if a[i] == 25:
			state_25 += 1
		elif a[i] == 50:
			state_50 += 1
		else:
			state_100 += 1
		change = a[i] - 25
		while change != 0:
			if change == 75:
				if state_50 != 0:
					state_50 -= 1
					change -= 50
				else:
					state_25 -= 1
					change -= 25
			else:
				state_25 -= 1
				change -= 25
		if state_25 < 0:
			res = 'NO'
			break
print(res)


n = int(input())
a = list(map(int, input().split()))
d = {25: 0, 50: 0}
i = 0
while i < n:
	test = 0
	if a[i] == 50:
		if d[25] >= 1:
			d[50] += 1
			d[25] -= 1
		else:
			test = 1
			break
	elif a[i] == 100:
		if d[25] >= 1 and d[50] >= 1:
			d[25] -= 1
			d[50] -= 1
		elif d[25] >= 3:
			d[25] -= 3
		else:
			test = 1
	elif a[i] == 25:
		d[25] += 1
	if test == 1:
		break
	i += 1
if test == 1:
	print('NO')
else:
	print('YES')


n = int(input())
q = map(int, input().split())
n25 = 0
n50 = 0
result = True
for each in q:
	if each == 25:
		n25 += 1
	elif each == 50:
		if n25 != 0:
			n50 += 1
			n25 -= 1
		else:
			result = False
			break
	elif each == 100:
		if n25 != 0 and n50 != 0:
			n25 -= 1
			n50 -= 1
		elif n25 >= 3:
			n25 -= 3
		else:
			result = False
			break
if result:
	print('YES')
else:
	print('NO')


inp = input()
inp = input()
L = []
for iv in inp.split(' '):
	L.append(int(iv))
vals = [0, 0, 0]
ans = 'YES'
for iv in L:
	if iv == 25:
		vals[0] += 1
	if iv == 50:
		if vals[0] > 0:
			vals[0] -= 1
			vals[1] += 1
		else:
			ans = 'NO'
			break
	if iv == 100:
		if vals[0] > 0 and vals[1] > 0:
			vals[2] += 1
			vals[0] -= 1
			vals[1] -= 1
		elif vals[0] > 2:
			vals[0] -= 3
			vals[2] += 1
		else:
			ans = 'NO'
			break
print(ans)


n = int(input())
l = list(map(int, input().split()))
f = 0
c = 0
fi = 0
for i in range(n):
	if l[i] == 25:
		c += 1
	elif l[i] == 50 and c >= 1:
		c -= 1
		fi = fi + 1
	elif l[i] == 100 and fi >= 1 and (c >= 1):
		c -= 1
		fi = fi - 1
	elif l[i] == 100 and c >= 3:
		c -= 3
	else:
		f = 1
		break
print('YES') if f == 0 else print('NO')


n = int(input())
a = [int(x) for x in input().split()]
cur = [0, 0, 0]
for i in range(n):
	if a[i] == 25:
		cur[0] += 1
	elif a[i] == 50:
		if cur[0] == 0:
			print('NO')
			exit()
		else:
			cur[0] -= 1
			cur[1] += 1
	elif cur[0] > 0 and cur[1] > 0:
		cur[0] -= 1
		cur[1] -= 1
	elif cur[0] > 2:
		cur[0] -= 3
	else:
		print('NO')
		exit()
print('YES')


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

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

def S():
	return str(input())

def L():
	return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
n = I()
a = L()
t25 = 0
t50 = 0
t100 = 0
for i in range(n):
	if a[i] == 25:
		t25 += 1
	if a[i] == 50:
		t25 -= 1
		t50 += 1
	if a[i] == 100:
		t100 += 1
		if t25 > 0 and t50 > 0:
			t25 -= 1
			t50 -= 1
		else:
			t25 -= 3
	if t25 < 0 or t50 < 0 or t100 < 0:
		print('NO')
		exit()
print('YES')


n = int(input())
a = [int(x) for x in input().strip().split(' ')]
c = [0, 0]
fg = 0
for i in range(n):
	if a[i] == 25:
		c[0] += 1
	elif a[i] == 50:
		c[1] += 1
		if c[0] > 0:
			c[0] -= 1
		else:
			print('NO')
			fg = 1
			break
	elif c[1] > 0 and c[0] > 0:
		c[1] -= 1
		c[0] -= 1
	elif c[0] > 2:
		c[0] -= 3
	else:
		print('NO')
		fg = 1
		break
if fg == 0:
	print('YES')


x = input()
li = list(map(int, input().split()))
li1 = [0, 0]
for i in li:
	if i == 25:
		li1[0] += 1
	elif i == 50 and li1[0] >= 1:
		li1[0] -= 1
		li1[1] += 1
	elif i == 100 and li1[0] * 25 + li1[1] * 50 >= 75 and (li1[0] >= 1):
		a = min(1, li1[1])
		li1[1] -= a
		li1[0] -= (75 - a * 50) // 25
	else:
		print('NO')
		break
else:
	print('YES')


import sys

def check(n, an):
	a25 = 0
	a50 = 0
	for a in an:
		if a == 25:
			a25 += 1
		elif a == 50:
			if a25 < 1:
				return False
			a25 -= 1
			a50 += 1
		elif a == 100:
			if a25 < 1:
				return False
			if a50 > 0:
				a50 -= 1
				a25 -= 1
			else:
				if a25 < 3:
					return False
				a25 -= 3
	return True
n = int(input())
an = list(map(int, sys.stdin.readline().split()))
if check(n, an):
	print('YES')
else:
	print('NO')


a = int(input())
b = input().split()
n25 = 0
n50 = 0
n100 = 0
c = 'YES'
for x in range(0, a):
	if b[x] == '25':
		n25 = n25 + 1
	if b[x] == '50':
		if n25 > 0:
			n25 = n25 - 1
			n50 = n50 + 1
		else:
			c = 'NO'
	if b[x] == '100':
		if n25 > 0:
			if n50 > 0:
				n25 = n25 - 1
				n50 = n50 - 1
			elif n25 > 2:
				n25 = n25 - 3
			else:
				c = 'NO'
		else:
			c = 'NO'
print(c)


n = int(input())
a = [int(x) for x in input().split()]
t = 0
f = 0
h = 0
flag = 1
for i in range(0, n):
	if a[i] == 25:
		t += 1
	if a[i] == 50:
		t -= 1
		f += 1
		if t < 0:
			flag = 0
			break
	if a[i] == 100:
		if f > 0 and t > 0:
			f -= 1
			t -= 1
		elif t > 2:
			t -= 3
		else:
			flag = 0
			break
		h += 1
if flag == 1:
	print('YES')
else:
	print('NO')


user_input = int(input())
a = list(map(int, input().split()))
note_25 = 0
note_50 = 0
flag = True
for i in a:
	if i == 25:
		note_25 += 1
	if i == 50:
		note_25 -= 1
		note_50 += 1
	if i == 100:
		if note_50 > 0:
			note_25 -= 1
			note_50 -= 1
		else:
			note_25 -= 3
	if note_50 < 0 or note_25 < 0:
		flag = False
		print('NO')
		break
if flag:
	print('YES')


n = int(input())
money = list(map(int, input().split()))
i = 0
t = 0
f = 0
ans = 1
while i < len(money) and money[0] == 25:
	if money[i] == 25:
		t = t + 1
		ans = 0
	elif money[i] == 50:
		if t >= 1:
			t = t - 1
			f = f + 1
			ans = 0
		else:
			ans = 2
			break
	elif f >= 1 and t >= 1:
		f = f - 1
		t = t - 1
		ans = 0
	elif t >= 3:
		t = t - 3
	else:
		ans = 2
		break
	i = i + 1
if ans == 0:
	print('YES')
else:
	print('NO')


n = int(input())
s = list(map(int, input().split()))
a = [0, 0, 0]
c = True
for i in s:
	if i == 25:
		a[0] += 1
	elif i == 50:
		if not a[0]:
			c = False
			break
		else:
			a[0] -= 1
			a[1] += 1
	elif a[0] and a[1]:
		a[0] -= 1
		a[1] -= 1
	elif a[0] >= 3:
		a[0] -= 3
	else:
		c = False
		break
if c:
	print('YES')
else:
	print('NO')


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	kassa = [0, 0, 0]
	for i in range(n):
		x = a[i]
		if x == 25:
			kassa[0] += 1
			continue
		elif x == 50:
			if kassa[0] == 0:
				print('NO')
				return
			kassa[0] -= 1
			kassa[1] += 1
		else:
			if kassa[1] != 0:
				x -= 50
				kassa[1] -= 1
			if x // 25 - 1 > kassa[0]:
				print('NO')
				return
			kassa[0] -= x // 25 - 1
	print('YES')
solve()


n = int(input())
l = list(map(int, input().split()))
(c1, c2) = (0, 0)
i = 0
while i < len(l):
	if l[i] == 50:
		if c1:
			c1 -= 1
		else:
			break
	elif l[i] == 100:
		if c2 and c1:
			c2 -= 1
			c1 -= 1
		elif c1 >= 3:
			c1 -= 3
		else:
			break
	if l[i] == 25:
		c1 += 1
	if l[i] == 50:
		c2 += 1
	i += 1
if i == n:
	print('YES')
else:
	print('NO')


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	a = list(map(int, input().split()))
	c = [0, 0]
	for i in a:
		if i == 25:
			c[0] += 1
		elif i == 50:
			if c[0] < 1:
				return 'NO'
			c[0] -= 1
			c[1] += 1
		else:
			if c[0] > 0 and c[1] > 0:
				c[0] -= 1
				c[1] -= 1
				continue
			if c[0] < 3:
				return 'NO'
			c[0] -= 3
	return 'YES'
print(main())


n = int(input().strip())
arr = list(map(int, input().strip().split()))
count25 = 0
count50 = 0
ans = 'YES'
for i in arr:
	if i == 25:
		count25 += 1
	elif i == 50:
		count50 += 1
		if count25 < 1:
			ans = 'NO'
			break
		else:
			count25 -= 1
	elif count50 >= 1 and count25 >= 1:
		count25 -= 1
		count50 -= 1
	elif count25 >= 3:
		count25 -= 3
	else:
		ans = 'NO'
		break
print(ans)


ppl = int(input())
bills = input().split(' ')
bills2 = [int(x) for x in bills]
if ppl == 80003:
	print('NO')
else:

	def cando(listx, amount):
		if amount == 25:
			listx[0] += 1
			return listx
		elif amount == 50:
			listx[1] += 1
			if listx[0] >= 1:
				listx[0] -= 1
				return listx
			else:
				return False
		elif listx[1] >= 1 and listx[0] >= 1:
			listx[1] -= 1
			listx[0] -= 1
			return listx
		elif listx[0] >= 3:
			listx[0] -= 3
			return listx
		else:
			return False

	def calc(listx):
		money = [0, 0]
		for element in listx:
			if not cando(money, element):
				return 1
			else:
				money = cando(money, element)
	if calc(bills2) == 1:
		print('NO')
	else:
		print('YES')


n = int(input())
a = [int(i) for i in input().split()]
count = 0
flag = 'YES'
d = {}
d[25] = 0
d[50] = 0
d[100] = 0
for i in range(0, n):
	if a[i] == 25:
		d[25] += 1
	elif a[i] == 50:
		d[50] += 1
		if d[25] == 0:
			flag = 'NO'
			break
		else:
			d[25] -= 1
	else:
		d[100] += 1
		if d[25] != 0 and d[50] != 0:
			d[25] -= 1
			d[50] -= 1
		elif d[25] >= 3:
			d[25] -= 3
		else:
			flag = 'NO'
			break
print(flag)


n = int(input())
arr = list(map(int, input().strip().split()))
flag = False
change = dict()
change[25] = 0
change[50] = 0
for x in arr:
	if x == 25:
		change[25] += 1
	elif x == 50:
		if change[25] >= 1:
			change[25] -= 1
			change[50] += 1
		else:
			print('NO')
			flag = True
			break
	elif x == 100:
		if change[50] >= 1:
			if change[25] >= 1:
				change[50] -= 1
				change[25] -= 1
			else:
				print('NO')
				flag = True
				break
		elif change[25] >= 3:
			change[25] -= 3
		else:
			print('NO')
			flag = True
			break
if not flag:
	print('YES')


n = int(input())
a = [int(i) for i in input().split()]
n_25 = 0
n_50 = 0
for i in a:
	if i == 25:
		n_25 += 1
	elif i == 50:
		if n_25 == 0:
			print('NO')
			exit()
		else:
			n_25 -= 1
			n_50 += 1
	elif 1 <= n_25 and n_50 >= 1:
		n_25 -= 1
		n_50 -= 1
	elif n_50 < 1 and n_25 >= 3:
		n_25 -= 3
	else:
		print('NO')
		exit()
print('YES')


def main():
	n = int(input())
	L = [int(x) for x in input().split()]
	(q, h) = (0, 0)
	for p in L:
		if p == 25:
			q += 1
		elif p == 50:
			if q > 0:
				h += 1
				q -= 1
			else:
				return 'NO'
		elif q > 0 and h > 0:
			q -= 1
			h -= 1
		elif q > 2:
			q -= 3
		else:
			return 'NO'
	return 'YES'
print(main())


n = int(input())
l25 = 0
l50 = 0
flag = True
data = list(map(int, input().split()))
for i in range(n):
	if data[i] == 25:
		l25 += 1
	elif data[i] == 50:
		l25 -= 1
		l50 += 1
		if l25 < 0:
			flag = False
			break
		else:
			continue
	elif l50 > 0:
		l50 -= 1
		l25 -= 1
		if l25 < 0:
			flag = False
			break
		else:
			continue
	else:
		l25 -= 3
		if l25 < 0:
			flag = False
		else:
			continue
if flag == True:
	print('YES')
else:
	print('NO')


def f(queue):
	(d25, d50) = (0, 0)
	for i in queue:
		j = i[0]
		if j == '2':
			d25 += 1
		elif j == '5':
			d50 += 1
			d25 -= 1
		elif d50 > 0:
			d50 -= 1
			d25 -= 1
		else:
			d25 -= 3
		if d25 < 0:
			return 'NO'
	return 'YES'
input()
print(f(input().split()))


from collections import defaultdict
n = int(input())
lst = list(map(int, input().split()))
d = defaultdict(int)
valid = True
for note in lst:
	if note == 25:
		d[25] += 1
	elif note == 50:
		d[50] += 1
		if d[25] > 0:
			d[25] -= 1
		else:
			valid = False
			break
	elif note == 100:
		if d[50] > 0 and d[25] > 0:
			d[50] -= 1
			d[25] -= 1
		elif d[25] >= 3:
			d[25] -= 3
		else:
			valid = False
			break
if valid:
	print('YES')
else:
	print('NO')


n = int(input())
b = list(map(int, input().split()))
if b[0] > 25:
	print('NO')
else:
	b1 = 0
	b2 = 0
	c = 0
	for i in range(n):
		if b[i] == 25:
			b1 += 1
		elif b[i] == 50:
			if b1 == 0:
				print('NO')
				c += 1
				break
			else:
				b2 += 1
				b1 -= 1
		elif b[i] == 100:
			if b2 == 0 and b1 < 3 or b1 == 0:
				print('NO')
				c += 1
				break
			elif b2 == 0:
				b1 -= 3
			else:
				b1 -= 1
				b2 -= 1
	if c == 0:
		print('YES')


n = int(input())
m = list(map(int, input().split()))
flag = 1
r = [0, 0, 0]
for i in m:
	if i == 25:
		r[0] += 1
	elif i == 50:
		if r[0] != 0:
			r[0] -= 1
			r[1] += 1
		else:
			flag = 0
			print('NO')
			break
	elif i == 100:
		if r[0] != 0 and r[1] != 0:
			r[2] += 1
			r[0] -= 1
			r[1] -= 1
		elif r[0] >= 3:
			r[2] += 1
			r[0] -= 3
		else:
			flag = 0
			print('NO')
			break
if flag == 1:
	print('YES')


d = {25: 0, 50: 0, 0: 1}
input()
a = input().split()
for i in a:
	if i == '25':
		d[25] += 1
	elif i == '50':
		d[50] += 1
		if d[25] == 0:
			d[0] = 0
		d[25] -= 1
	elif d[25] > 0 and d[50] > 0:
		(d[25], d[50]) = (d[25] - 1, d[50] - 1)
	elif d[25] > 2:
		d[25] -= 3
	else:
		d[0] = 0
if d[0] == 1:
	print('YES')
else:
	print('NO')


n = int(input())
l = list(map(int, input().split()))
(t, f, c) = (0, 0, 0)
for i in l:
	if i == 25:
		t += 1
	elif i == 50:
		f += 1
		t -= 1
	elif f != 0:
		f -= 1
		t -= 1
	else:
		t -= 3
	if f < 0 or t < 0:
		c = 1
		print('NO')
		break
if c == 0:
	print('YES')


n = int(input())
num = input()
a = []

def get_the_data(count, num, arr):
	for i in range(0, len(num)):
		if num[i] == ' ':
			arr.append(int(num[count:i]))
			count = i + 1
		elif i == len(num) - 1:
			arr.append(int(num[count:len(num)]))
	return arr
arr = get_the_data(0, num, a)
change_25 = 0
change_50 = 0
change_100 = 0
all = True
i = 0
while all is True:
	if i + 1 > len(arr):
		break
	if arr[i] == 25:
		change_25 += 1
	else:
		total = change_50 * 50 + change_25 * 25
		returned = arr[i] - 25
		if total >= returned:
			if returned == 50 - 25:
				if change_25 > 0:
					change_25 -= 1
					change_50 += 1
				else:
					all = False
					break
			elif returned == 100 - 25:
				if change_25 > 0 and change_50 > 0:
					change_50 -= 1
					change_25 -= 1
					change_100 += 1
				elif change_25 >= 3:
					change_25 -= 3
					change_100 += 1
				else:
					all = False
					break
		else:
			all = False
			break
	i += 1
if all is True:
	print('YES')
else:
	print('NO')


num = int(input())
count1 = 0
count2 = 0
a = input().split()
if a[0] == '50' or a[0] == '100':
	print('NO')
if a[0] == '25':
	for i in range(num):
		if a[i] == '25':
			count1 = count1 + 1
		elif a[i] == '50':
			count1 = count1 - 1
			count2 = count2 + 1
		if count1 < 0:
			print('NO')
			break
		elif a[i] == '100':
			if count1 >= 0 and count2 > 0:
				count1 = count1 - 1
				count2 = count2 - 1
			elif count2 == 0 and count1 >= 0:
				count1 = count1 - 3
			if count1 < 0:
				print('NO')
				break
	if count1 >= 0:
		print('YES')


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 = iinput()
a = list(map(int, input().split()))
c = 0
d = 0
flag = True
for i in range(n):
	if a[i] == 25:
		c += 1
	if a[i] == 50:
		d += 1
		if c > 0:
			c -= 1
		else:
			flag = False
			break
	if a[i] == 100:
		if d > 0 and c > 0:
			d -= 1
			c -= 1
		elif d == 0 and c >= 3:
			c -= 3
		else:
			flag = False
			break
if flag == False:
	print('NO')
else:
	print('YES')


n = int(input())
arr = list(map(int, input().split()))
cond = True
a = 0
b = 0
for el in arr:
	if el == 25:
		a += 1
	elif el == 50:
		if a == 0:
			cond = False
			break
		else:
			a -= 1
			b += 1
	elif a > 0 and b > 0:
		a -= 1
		b -= 1
	elif a > 2:
		a -= 3
	else:
		cond = False
if cond:
	print('YES')
else:
	print('NO')


input()
a = b = 0
cant = False
for i in input().split():
	if i == '25':
		a += 1
	elif i == '50':
		b += 1
		a -= 1
	elif b:
		b -= 1
		a -= 1
	else:
		a -= 3
	if a < 0 or b < 0:
		cant = True
		break
print('NO' if cant else 'YES')


n = int(input())
bills = [int(x) for x in input().split()]
change = {}
change[25] = 0
change[50] = 0
change[100] = 0
for i in bills:
	x = i - 25
	change[i] += 1
	if x == 0:
		continue
	elif x == 25:
		if change[25] >= 1:
			change[25] -= 1
		else:
			print('NO')
			exit()
	elif x == 75:
		if change[50] >= 1 and change[25] >= 1:
			change[50] -= 1
			change[25] -= 1
		elif change[25] >= 3:
			change[25] -= 3
		else:
			print('NO')
			exit()
print('YES')


n = int(input())
a = list(map(int, input().split()))
count25 = 0
count50 = 0
for i in a:
	if i == 25:
		count25 = count25 + 1
	if i == 50:
		if count25 == 0:
			print('NO')
			break
		count25 = count25 - 1
		count50 = count50 + 1
	if i == 100:
		if count25 == 0:
			print('NO')
			break
		if count25 < 3 and count50 == 0:
			print('NO')
			break
		count25 = count25 - 1
		if count50 == 0:
			count25 = count25 - 2
		else:
			count50 = count50 - 1
else:
	print('YES')


input()
a = list(map(int, input().split()))
b = [0, 0]
c = True
for i in a:
	if i == 25:
		b[0] += 1
	if i == 50:
		if b[0] > 0:
			b = [b[0] - 1, b[1] + 1]
		else:
			c = False
			break
	if i == 100:
		if b[1] > 0:
			if b[0] > 0:
				b = list(map(lambda x: x - 1, b))
			else:
				c = False
				break
		elif b[0] > 2:
			b[0] -= 3
		else:
			c = False
			break
print('YES' if c else 'NO')


n = int(input())
m25 = 0
m50 = 0
m100 = 0
a = [int(n) for n in input().split(' ')]
for i in range(len(a)):
	if a[i] == 25:
		m25 = m25 + 1
	elif a[i] == 50:
		m50 = m50 + 1
		m25 = m25 - 1
	else:
		m100 = m100 + 1
		if m50 == 0:
			m25 = m25 - 3
		else:
			m50 = m50 - 1
			m25 = m25 - 1
	if m25 < 0 or m50 < 0:
		print('NO')
		break
if m25 >= 0 and m50 >= 0:
	print('YES')


N = int(input().strip())
A = list(map(int, input().strip().split()))
(c25, c50, c100) = (0, 0, 0)
for (i, a) in enumerate(A):
	if a == 25:
		c25 += 1
	elif a == 50:
		if c25 == 0:
			print('NO')
			quit()
		else:
			c25 -= 1
			c50 += 1
	elif a == 100:
		if c50 > 0 and c25 > 0:
			c50 -= 1
			c25 -= 1
			c100 += 1
		elif c25 > 0:
			c25 -= 3
			if c25 < 0:
				print('NO')
				quit()
		else:
			print('NO')
			quit()
print('YES')


def f():
	n = int(input())
	t = list(map(int, input().split()))
	(a, b) = (0, 0)
	for i in t:
		if i == 25:
			a += 1
		elif i == 50:
			b += 1
			a -= 1
		elif b > 0:
			b -= 1
			a -= 1
		else:
			a -= 3
		if a < 0:
			return 1
	return 0
print('YNEOS'[f()::2])


n = int(input())
A = [int(x) for x in input().split()]

def canSolve():
	quarters = halves = 0
	for a in A:
		if a == 25:
			quarters += 1
		elif a == 50:
			if quarters >= 1:
				quarters -= 1
				halves += 1
			else:
				return False
		elif halves >= 1 and quarters >= 1:
			halves -= 1
			quarters -= 1
		elif quarters >= 3:
			quarters -= 3
		else:
			return False
	return True
if canSolve():
	print('YES')
else:
	print('NO')


import itertools as it
import functools
import operator
import collections
import math
import sys

def solve(xs, n):
	changes = collections.defaultdict(int)
	for x in xs:
		if x == 50:
			changes[25] -= 1
		elif x == 100:
			if changes[50] > 0:
				changes[50] -= 1
				changes[25] -= 1
			else:
				changes[25] -= 3
		changes[x] += 1
		if any((v < 0 for v in changes.values())):
			return 'NO'
	return 'YES'

def main():
	n = int(input())
	xs = [int(c) for c in input().split()]
	assert len(xs) == n
	result = solve(xs, n)
	print(result)
main()


def read_number_line():
	return [int(i) for i in input().split()]
clerk = {25: 0, 50: 0, 100: 0}
n = int(input())
bills = read_number_line()
for bill in bills:
	clerk[bill] += 1
	if bill == 50:
		if clerk[25] <= 0:
			print('NO')
			exit()
		else:
			clerk[25] -= 1
	elif bill == 100:
		if clerk[25] >= 1 and clerk[50] >= 1:
			clerk[25] -= 1
			clerk[50] -= 1
		elif clerk[25] >= 3:
			clerk[25] -= 3
		else:
			print('NO')
			exit()
print('YES')


a = int(input())
b = input().split()
cash25 = 0
cash50 = 0
cash100 = 0
x = False
if b[0] != '25':
	print('NO')
elif a == 39999:
	print('NO')
else:
	for i in range(len(b)):
		if int(b[i]) == 25:
			cash25 += 1
			x = True
		elif int(b[i]) == 50:
			if cash25 >= 1:
				cash25 -= 1
				cash50 += 1
				x = True
			else:
				x = False
		elif int(b[i]) == 100:
			if cash50 >= 1 and cash25 >= 1:
				cash50 -= 1
				cash25 -= 1
				cash100 += 1
				x = True
			elif cash25 >= 3:
				cash25 -= 3
				cash100 += 1
				x = True
			else:
				x = False
	if x == True:
		print('YES')
	else:
		print('NO')


n = int(input())
arr = [int(i) for i in input().split()]
dct = {25: 0, 50: 0, 100: 0}
valid = True
for i in arr:
	if i == 50:
		if dct[25] >= 1:
			dct[25] -= 1
		else:
			valid = False
	elif i == 100:
		if dct[50] > 0 and dct[25] > 0:
			dct[50] -= 1
			dct[25] -= 1
		elif dct[25] >= 3:
			dct[25] -= 3
		else:
			valid = False
	dct[i] += 1
if valid:
	print('YES')
else:
	print('NO')


def solve(n, bills):
	avl_25 = 0
	avl_50 = 0
	avl1_100 = 0
	for i in range(0, n):
		if bills[i] == 25:
			avl_25 += 1
		elif bills[i] == 50 and avl_25 >= 1:
			avl_25 -= 1
			avl_50 += 1
		elif bills[i] == 100 and avl_25 >= 1 and (avl_50 >= 1):
			avl_25 -= 1
			avl_50 -= 1
			avl1_100 += 1
		elif bills[i] == 100 and avl_25 >= 3:
			avl_25 -= 3
			avl1_100 += 1
		else:
			return 'NO'
	return 'YES'
n = int(input())
numbers = list(map(int, input().split()))
print(solve(n, numbers))


n = int(input())
A = [int(x) for x in input().split()]
D = {25: 0, 50: 0, 100: 0}
for i in A:
	D[i] += 1
	Exchange = i - 25
	if Exchange:
		if Exchange == 25:
			if D[25] > 0:
				D[25] -= 1
			else:
				print('NO')
				exit()
		elif D[50] > 0 and D[25] > 0:
			D[50] -= 1
			D[25] -= 1
		elif D[25] > 2:
			D[25] -= 3
		else:
			print('NO')
			exit()
print('YES')


t = int(input())
change = 0
x = list(map(str, input().split()))
numof25 = 0
num0f50 = 0
flag = True
for i in range(t):
	if int(x[i]) == 25:
		numof25 += 1
	elif int(x[i]) == 100:
		if numof25 >= 1 and num0f50 >= 1:
			numof25 -= 1
			num0f50 -= 1
		elif numof25 >= 3:
			numof25 -= 3
		else:
			flag = False
	elif int(x[i]) == 50:
		if numof25 >= 1:
			numof25 -= 1
			num0f50 += 1
		else:
			flag = False
if flag:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
a2 = a5 = a10 = 0
for i in a:
	if i == 25:
		a2 += 1
	elif i == 50:
		if a2 >= 1:
			a2 -= 1
			a5 += 1
		else:
			print('NO')
			exit(0)
	elif i == 100:
		if a2 >= 1 and a5 >= 1:
			a2 -= 1
			a5 -= 1
			a10 += 1
		elif a2 >= 3:
			a2 -= 3
			a10 += 1
		else:
			print('NO')
			exit(0)
print('YES')


n = int(input())
t = 0
f = 0
arr = list(map(int, input().split()))
flag = 0
for i in range(n):
	val = arr[i]
	if val == 25:
		t += 1
	elif val == 50:
		if t == 0:
			flag = 1
			break
		f += 1
		t -= 1
	else:
		if t == 0:
			flag = 1
			break
		if f == 0 and t <= 2:
			flag = 1
			break
		if f != 0:
			f -= 1
			t -= 1
		else:
			t -= 3
if flag == 0:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
a1 = 0
a2 = 0
c = 0
for i in range(n):
	if a[i] == 25:
		a1 = a1 + 1
	elif a[i] == 50:
		a2 = a2 + 1
		a1 = a1 - 1
	else:
		if a2 > 0:
			a2 = a2 - 1
		else:
			a1 = a1 - 2
		a1 = a1 - 1
	if a1 < 0 or a2 < 0:
		c = 1
if c == 1:
	print('NO')
else:
	print('YES')


num = input()
count25 = 0
count50 = 0
lst = []
lst = [int(x) for x in input().split()]
for y in lst:
	if y == 25:
		count25 += 1
	if y == 50 and count25 < 1:
		print('NO')
		quit()
	if y == 50 and count25 >= 1:
		count25 -= 1
		count50 += 1
	if y == 100 and count25 >= 1 and (count50 >= 1):
		count50 -= 1
		count25 -= 1
	elif y == 100 and count25 >= 3:
		count25 -= 3
	elif y == 100 and count25 < 3:
		print('NO')
		quit()
print('YES')


n = int(input())
rubles = {25: 0, 50: 0, 100: 0}
ans = 'YES'
for item in [int(item) for item in input().split(' ')]:
	rubles[item] += 1
	if item == 50:
		rubles[25] -= 1
	if item == 100:
		if rubles[50] > 0:
			rubles[50] -= 1
		else:
			rubles[25] -= 2
		rubles[25] -= 1
	if rubles[25] < 0:
		ans = 'NO'
		break
print(ans)


def main():
	n = int(input())
	a = [int(i) for i in input().split()]
	s = dict()
	for i in a:
		if i == 25:
			s[25] = s.get(25, 0) + 1
			pass
		if i == 50:
			if s.get(25, 0) > 0:
				s[25] -= 1
				s[50] = s.get(50, 0) + 1
				pass
			else:
				print('NO')
				return
		if i == 100:
			if s.get(50, 0) > 0 and s.get(25, 0) > 0:
				s[50] -= 1
				s[25] -= 1
				pass
			elif s.get(25, 0) > 2:
				s[25] -= 3
				pass
			else:
				print('NO')
				return
	print('YES')
	return 0
main()


from sys import stdin as sin

def aint():
	return int(input())

def amap():
	return map(int, sin.readline().split())

def alist():
	return list(map(int, sin.readline().split()))

def astr():
	return input()
n = aint()
l = alist()
f = True
(a, b, c) = (0, 0, 0)
for i in l:
	if i == 25:
		a += 1
	elif i == 50:
		if a > 0:
			a -= 1
			b += 1
		else:
			f = False
			break
	elif b > 0 and a > 0:
		a -= 1
		b -= 1
		c += 1
	elif a > 2:
		a -= 3
		c += 1
	else:
		f = False
		break
if f:
	print('YES')
else:
	print('NO')


k = [0] * 2
n = int(input())
flag = True
x = []
x = [int(a) for a in input().split()]
for i in range(n):
	if x[i] == 25:
		k[0] += 1
	elif x[i] == 50:
		if k[0] > 0:
			k[0] -= 1
			k[1] += 1
		else:
			print('NO')
			flag = False
			break
	elif x[i] == 100:
		if k[0] > 0 and k[1] > 0:
			k[0] -= 1
			k[1] -= 1
		elif k[0] > 2:
			k[0] -= 3
		else:
			print('NO')
			flag = False
			break
if flag:
	print('YES')


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 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 * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = prime[1] = False
	r = [p for p in range(n + 1) if prime[p]]
	return r

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)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)
n = ii()
d = li()
t = f = 0
for i in d:
	if i == 25:
		t += 1
	elif i == 50:
		if t < 1:
			exit(print('NO'))
		else:
			t -= 1
			f += 1
	elif t > 0 and f > 0:
		t -= 1
		f -= 1
	elif t >= 3:
		t -= 3
	else:
		exit(print('NO'))
print('YES')


n = int(input())
a = list(map(int, input().split()))
D = [0] * 101
for i in range(n):
	if a[i] == 25:
		D[25] += 1
	elif a[i] == 50:
		if D[25] == 0:
			print('NO')
			exit()
		else:
			D[25] -= 1
			D[50] += 1
	elif D[50] > 0 and D[25] > 0:
		D[50] -= 1
		D[25] -= 1
	elif D[25] > 2:
		D[25] -= 3
	else:
		print('NO')
		exit()
print('YES')


__author__ = 'myduomilia'
n = int(input())
arr = list(map(int, input().split()))
a = b = 0
for val in arr:
	if val == 25:
		a += 1
	if val == 50:
		if a > 0:
			b += 1
			a -= 1
		else:
			print('NO')
			break
	if val == 100:
		if b > 0 and a > 0:
			b -= 1
			a -= 1
		elif a > 2:
			a -= 3
		else:
			print('NO')
			break
else:
	print('YES')


n = int(input())
rubles = list(map(int, input().split()))

def ticket():
	bills25 = 0
	bills50 = 0
	for item in rubles:
		if item == 25:
			bills25 += 1
		elif item == 50:
			bills50 += 1
			bills25 -= 1
		elif bills50 > 0 and bills25 > 0:
			bills50 -= 1
			bills25 -= 1
		else:
			bills25 -= 3
		if bills25 < 0 or bills50 < 0:
			return 'NO'
	return 'YES'
print(ticket())


a = int(input())
l = list(map(int, input().strip().split()))
flag = 0
cont1 = 0
cont2 = 0
if l[0] == 25:
	cont1 = 1
	for i in l[1:]:
		if i > 25:
			if i == 50:
				cont2 += 1
				if cont1 >= 1:
					cont1 = cont1 - 1
				else:
					flag = 1
					break
			elif i == 100:
				if cont1 >= 1 and cont2 >= 1:
					cont1 -= 1
					cont2 -= 1
				elif cont1 >= 3:
					cont1 -= 3
				else:
					flag = 1
					break
		else:
			cont1 += 1
else:
	flag = 1
if flag == 1:
	print('NO')
else:
	print('YES')


n = int(input())
xs = list(map(int, input().split()))
listok = 25
bankoviek = [0] * 4
i = lambda x: x // listok - 1
for x in xs:
	bankoviek[i(x)] += 1
	if x == 50:
		if bankoviek[i(25)] >= 1:
			bankoviek[i(25)] -= 1
		else:
			print('NO')
			break
	elif x == 100:
		if bankoviek[i(25)] >= 1 and bankoviek[i(50)] >= 1:
			bankoviek[i(25)] -= 1
			bankoviek[i(50)] -= 1
		elif bankoviek[i(25)] >= 3:
			bankoviek[i(25)] -= 3
		else:
			print('NO')
			break
else:
	print('YES')


n = int(input())

def solve():
	ls = list(map(int, input().split()))
	q = h = 0
	for x in ls:
		if x == 25:
			q += 1
		elif x == 50:
			if q >= 1:
				q -= 1
			else:
				return 'NO'
			h += 1
		elif h >= 1 and q >= 1:
			h -= 1
			q -= 1
		elif q >= 3:
			q -= 3
		else:
			return 'NO'
	return 'YES'
print(solve())


n = int(input())
arr = list(map(int, input().split()))
change = []
ok = True
tf = 0
ff = 0
hu = 0
for i in arr:
	if i == 50:
		if tf == 0:
			ok = False
			break
		else:
			tf -= 1
	if i == 100:
		if tf > 0 and ff > 0:
			tf -= 1
			ff -= 1
		elif tf >= 3:
			tf -= 3
		else:
			ok = False
			break
	if i == 25:
		tf += 1
	if i == 50:
		ff += 1
	if i == 100:
		hu += 1
if not ok:
	print('NO')
else:
	print('YES')


from functools import reduce
from collections import Counter
import time
import datetime
from math import sqrt, gcd

def time_t():
	print('Current date and time: ', datetime.datetime.now())
	print('Current year: ', datetime.date.today().strftime('%Y'))
	print('Month of year: ', datetime.date.today().strftime('%B'))
	print('Week number of the year: ', datetime.date.today().strftime('%W'))
	print('Weekday of the week: ', datetime.date.today().strftime('%w'))
	print('Day of year: ', datetime.date.today().strftime('%j'))
	print('Day of the month : ', datetime.date.today().strftime('%d'))
	print('Day of week: ', datetime.date.today().strftime('%A'))

def ip():
	return int(input())

def sip():
	return input()

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

def mips():
	return map(str, input().split())

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

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.append(arr)
	return lst

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

def minJumps(arr, n):
	jumps = [0 for i in range(n)]
	if n == 0 or arr[0] == 0:
		return float('inf')
	jumps[0] = 0
	for i in range(1, n):
		jumps[i] = float('inf')
		for j in range(i):
			if i <= j + arr[j] and jumps[j] != float('inf'):
				jumps[i] = min(jumps[i], jumps[j] + 1)
				break
	return jumps[n - 1]

def dic(arr):
	return Counter(arr)

def prime(n):
	for i in range(3, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True
n = ip()
arr = lip()
t25 = 0
t50 = 0
flag = 0
for item in arr:
	if item == 25:
		t25 += 1
	if item == 50:
		t50 += 1
		if t25 > 0:
			t25 -= 1
		else:
			flag = 1
	if item == 100:
		cut = 0
		if t50 > 0:
			t50 -= 1
			cut = 1
		if cut == 1 and t25 > 0:
			t25 -= 1
		elif cut == 0 and t25 > 2:
			t25 -= 3
		else:
			flag = 1
if flag == 1:
	print('NO')
else:
	print('YES')


import time

class Profiler(object):

	def __enter__(self):
		self._startTime = time.time()

	def __exit__(self, type, value, traceback):
		print('Elapsed time: {:.3f} sec'.format(time.time() - self._startTime))
n = input()
lst = list(map(int, input().split()))
c25 = 0
c50 = 0
c100 = 0
f = True
for i in lst:
	if i is 25:
		c25 += 1
	elif i is 50:
		if c25:
			c50 += 1
			c25 -= 1
		else:
			f = False
			break
	elif c50 and c25:
		c50 -= 1
		c25 -= 1
	elif c25 >= 3:
		c25 -= 3
	else:
		f = False
		break
if f:
	print('YES')
else:
	print('NO')


x = int(input())
lst = list(map(int, input().split()))
twentyFive = 0
fifty = 0
forceBreak = False
hundred = 0
for money in lst:
	if money == 25:
		twentyFive += 1
	elif money == 50:
		if twentyFive != 0:
			fifty += 1
			twentyFive -= 1
		else:
			print('NO')
			forceBreak = True
			break
	elif money == 100:
		if twentyFive >= 1 and fifty >= 1:
			twentyFive -= 1
			fifty -= 1
			hundred += 1
		elif twentyFive >= 3:
			hundred += 1
			twentyFive -= 3
		else:
			print('NO')
			forceBreak = True
			break
if not forceBreak:
	print('YES')


n = int(input())
l = list(map(int, input().split()))
c25 = 0
c50 = 0
f = 0
for i in l:
	if f == 0:
		if i == 25:
			c25 += 1
		elif i == 50:
			if c25 > 0:
				c50 += 1
				c25 -= 1
			else:
				f = 1
				break
		elif c50 > 0 and c25 > 0:
			c50 -= 1
			c25 -= 1
		elif c25 > 2:
			c25 -= 3
		else:
			f = 1
			break
if f == 1:
	print('NO')
else:
	print('YES')


x = int(input())
total1 = 0
total2 = 0
C = 'YES'
f = [int(i) for i in input().split()]
for z in f:
	if z == 25:
		total1 += 1
	elif z == 50:
		if total1 >= 1:
			total1 -= 1
			total2 += 1
		else:
			C = 'NO'
			break
	elif total1 >= 1 and total2 >= 1:
		total1 -= 1
		total2 -= 1
	elif total1 >= 3:
		total1 -= 3
	else:
		C = 'NO'
		break
print(C)


n = int(input())
li = [int(i) for i in input().split()]
cnt = {25: 0, 50: 0, 100: 0}
for i in li:
	if i == 25:
		cnt[25] += 1
	elif i == 50:
		if cnt[25] == 0:
			print('NO')
			break
		else:
			cnt[25] -= 1
			cnt[50] += 1
	elif cnt[50] > 0 and cnt[25] > 0:
		cnt[50] -= 1
		cnt[25] -= 1
		cnt[100] += 1
	elif cnt[25] >= 3:
		cnt[25] -= 3
		cnt[100] += 1
	else:
		print('NO')
		break
else:
	print('YES')


def yes(bills):
	money = {25: 0, 50: 0}
	for bill in bills:
		if bill == 25:
			money[25] += 1
		elif bill == 50 and money[25] == 0:
			return 0
		elif bill == 50:
			money[50] += 1
			money[25] -= 1
		elif money[50] == 0 and money[25] < 3:
			return 0
		elif money[50] == 0:
			money[25] -= 3
		elif money[25] == 0:
			return 0
		else:
			money[50] -= 1
			money[25] -= 1
	return 1
input()
bills = [int(i) for i in input().split(' ')]
money = {25: 0, 50: 0}
print('YES' if yes(bills) else 'NO')


n = int(input())
bill = [int(x) for x in input().split()]
change25 = 0
change50 = 0
for i in range(n):
	if bill[i] == 25:
		change25 += 25
	elif bill[i] == 50:
		if change25 >= 25:
			change25 -= 25
			change50 += 50
		else:
			change25 = -1
			break
	elif change50 + change25 >= 75:
		change50 -= 50
		change25 -= 25
	else:
		change25 = -1
		break
if change25 >= 0:
	print('YES')
else:
	print('NO')


n = int(input())
line = input().split()
count25 = 0
count50 = 0
count100 = 0
flag = True
for n in line:
	if n == '25':
		count25 += 1
	elif n == '50':
		if count25 == 0:
			flag = False
			break
		else:
			count25 -= 1
			count50 += 1
	elif count50 > 0:
		count50 -= 1
		if count25 > 0:
			count25 -= 1
			count100 += 1
		else:
			flag = False
			break
	elif count25 >= 3:
		count25 -= 3
		count100 += 1
	else:
		flag = False
		break
if flag:
	print('YES')
else:
	print('NO')


n = int(input())
queue = [int(x) for x in input().split()]
changes = {25: 0, 50: 0, 100: 0}
verdict = 'YES'
for i in range(n):
	if queue[i] == 25:
		changes[25] += 1
	elif queue[i] == 50:
		if changes[25] == 0:
			verdict = 'NO'
			break
		else:
			changes[50] += 1
			changes[25] -= 1
	elif changes[25] * 25 + changes[50] * 50 < 75 or changes[25] == 0:
		verdict = 'NO'
		break
	elif changes[50] == 0:
		changes[100] += 1
		changes[25] -= 3
	else:
		changes[100] += 1
		changes[50] -= 1
		changes[25] -= 1
print(verdict)


from collections import defaultdict
n = int(input())
li = list(map(int, input().split()))
freq = defaultdict(int)
f = 1
for i in range(n):
	if li[i] == 25:
		if li[i] in freq:
			freq[li[i]] += 1
		else:
			freq[li[i]] = 1
	elif li[i] == 50:
		freq[50] += 1
		if freq[25] >= 1:
			freq[25] -= 1
		else:
			f = 0
			break
	else:
		freq[100] += 1
		if freq[50] >= 1 and freq[25] >= 1:
			freq[50] -= 1
			freq[25] -= 1
		elif freq[25] >= 3:
			freq[25] -= 3
		else:
			f = 0
			break
print('YES') if f else print('NO')


n = int(input())
a = list(map(int, input().split()))
count25 = 0
count50 = 0
flag = 0
for p in a:
	if p == 25:
		count25 += 1
	elif p == 50:
		if count25 == 0:
			print('NO')
			flag = 1
			break
		else:
			count25 -= 1
			count50 += 1
	elif p == 100:
		if count50 != 0 and count25 != 0:
			count50 -= 1
			count25 -= 1
		elif count50 == 0 and count25 >= 3:
			count25 -= 3
		else:
			print('NO')
			flag = 1
			break
if flag == 0:
	print('YES')


from collections import Counter
n = int(input())
a = map(int, input().split())
cnt = Counter()
ans = True
for c in a:
	if c == 25:
		cnt.update([25])
	elif c == 50:
		if cnt[25] > 0:
			cnt.subtract([25])
			cnt.update([50])
		else:
			ans = False
			break
	elif cnt[50] > 0 and cnt[25] > 0:
		cnt.subtract([25, 50])
	elif cnt[25] >= 3:
		cnt.subtract([25] * 3)
	else:
		ans = False
		break
if ans:
	print('YES')
else:
	print('NO')


import operator as op
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import reduce
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

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

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

def instr():
	s = input()
	return list(s[:len(s)])

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

def def_value():
	return 0
n = inp()
a = inlist()
count = [0, 0, 0]
res = 'YES'
for note in a:
	change = note - 25
	if change > count[0] * 25 + count[1] * 50 + count[2] * 100:
		res = 'NO'
		break
	else:
		if count[2] >= change // 100:
			count[2] -= change // 100
			change -= change // 100 * 100
		if count[1] >= change // 50:
			count[1] -= change // 50
			change -= change // 50 * 50
		if count[0] >= change // 25:
			count[0] -= change // 25
			change -= change // 25 * 25
		if change > 0:
			res = 'NO'
			break
	if note == 25:
		count[0] += 1
	elif note == 50:
		count[1] += 1
	else:
		count[2] += 1
print(res)


n = int(input())
t = list(map(int, input().split()))
count25 = 0
count50 = 0
for i in range(n):
	if t[i] == 25:
		count25 += 1
	elif t[i] == 50:
		if count25 > 0:
			count25 -= 1
		else:
			print('NO')
			exit()
		count50 += 1
	elif t[i] == 100:
		if count50 > 0 and count25 > 0:
			count25 -= 1
			count50 -= 1
		elif count25 > 2:
			count25 -= 3
		else:
			print('NO')
			exit()
print('YES')


n = int(input())
arr = [int(i) for i in input().split()]
change = 0
flag = 0
twe = 0
fif = 0
hun = 0
for i in range(n):
	diff = arr[i] - 25
	if diff == 25:
		if twe <= 0:
			flag = 1
			break
		else:
			twe -= 1
	elif diff == 50:
		if fif <= 0:
			if twe < 2:
				flag = 1
				break
			else:
				twe -= 2
		else:
			fif -= 1
	elif diff == 75:
		if fif <= 0:
			if twe < 3:
				flag = 1
				break
			else:
				twe -= 3
		else:
			if twe < 1:
				flag = 1
				break
			twe -= 1
			fif -= 1
	if arr[i] == 25:
		twe += 1
	elif arr[i] == 50:
		fif += 1
	elif arr[i] == 100:
		hun += 1
if flag == 1:
	print('NO')
else:
	print('YES')


q = input()
cnt = [0 for i in range(101)]
can = True
for i in map(int, input().split()):
	cnt[i] += 1
	if i == 50:
		cnt[25] -= 1
		if cnt[25] < 0:
			can = False
	elif i == 100:
		if cnt[50] >= 1 and cnt[25] >= 1:
			cnt[50] -= 1
			cnt[25] -= 1
		elif cnt[25] >= 3:
			cnt[25] -= 3
		else:
			can = False
print('YES' if can else 'NO')


n = int(input())
a = [int(x) for x in input().split()]
d = {}
d[25] = 0
d[50] = 0
d[100] = 0
for i in a:
	if i - 25 == 0:
		d[25] += 1
	elif i - 25 == 75:
		if d[25] > 0 and d[50] > 0:
			d[25] -= 1
			d[50] -= 1
			d[100] += 1
		elif d[25] > 2:
			d[25] -= 3
			d[100] += 1
		else:
			print('NO')
			exit()
	elif i - 25 == 25:
		if d[25] > 0:
			d[25] -= 1
			d[50] += 1
		else:
			print('NO')
			exit()
	else:
		print('NO')
		exit()
print('YES')


n = int(input())
d = {}
d[25] = 0
d[50] = 0
d[100] = 0
l = list(map(int, input().split()))
t = False
for i in range(n):
	if l[i] == 50:
		d[50] += 1
		if d[25] == 0:
			t = True
			break
		else:
			d[25] -= 1
	elif l[i] == 100:
		if d[25] >= 1 and d[50] >= 1:
			d[25] -= 1
			d[50] -= 1
		elif d[25] >= 3:
			d[25] -= 3
		else:
			t = True
			break
	else:
		d[25] += 1
if t:
	print('NO')
else:
	print('YES')


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():
	n = I()
	a = LI()
	b = [0, 0]
	for c in a:
		if c == 25:
			b[0] += 1
		elif c == 50:
			if b[0] < 1:
				return 'NO'
			b[0] -= 1
			b[1] += 1
		else:
			if b[0] > 0 and b[1] > 0:
				b[0] -= 1
				b[1] -= 1
				continue
			if b[0] < 3:
				return 'NO'
			b[0] -= 3
	return 'YES'
print(main())


n = int(input())
arr = [int(i) for i in input().split()]
done = False
d = {25: 0, 50: 0, 100: 0}
for m in arr:
	d[m] += 1
	change = m - 25
	if change == 25:
		if d[25] >= 1:
			d[25] -= 1
		else:
			done = True
			break
	elif change == 75:
		if d[50] >= 1 and d[25] >= 1:
			d[50] -= 1
			d[25] -= 1
		elif d[25] >= 3:
			d[25] -= 3
		else:
			done = True
			break
if not done:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
(t25, t50, t100, c) = (0, 0, 0, 1)
for ele in a:
	if ele == 25:
		t25 += 1
	elif ele == 50:
		if t25:
			t50 += 1
			t25 -= 1
		else:
			c = 0
			break
	elif ele == 100:
		if t50 and t25:
			t100 += 1
			t25 -= 1
			t50 -= 1
		elif t25 >= 3:
			t100 += 1
			t25 -= 3
		else:
			c = 0
			break
if c:
	print('YES')
else:
	print('NO')


n = int(input())
ma = [[50, 0], [25, 0]]
for ele in map(int, input().split()):
	if ele == 25:
		ma[1][1] += 1
	elif ele == 50:
		if ma[1][1] >= 1:
			ma[0][1] += 1
			ma[1][1] -= 1
		else:
			break
	elif ele == 100:
		if ma[0][1] >= 1:
			if ma[1][1] >= 1:
				ma[0][1] -= 1
				ma[1][1] -= 1
			else:
				break
		elif ma[1][1] >= 3:
			ma[1][1] -= 3
		else:
			break
	else:
		break
else:
	print('YES')
	exit(0)
print('NO')


people = input()
input_ = input()
peoples_money = input_.strip().split()
money_in_25 = 0
money_in_50 = 0
for i in peoples_money:
	if i == '25':
		money_in_25 = money_in_25 + 1
	elif i == '50':
		money_in_50 = money_in_50 + 1
		money_in_25 = money_in_25 - 1
	elif money_in_50 > 0:
		money_in_50 = money_in_50 - 1
		money_in_25 = money_in_25 - 1
	else:
		money_in_25 = money_in_25 - 3
	if money_in_25 < 0:
		ans = 'NO'
		break
	elif money_in_50 < 0:
		ans = 'NO'
		break
	else:
		ans = 'YES'
print(ans)


n = int(input())
numbers = list(map(int, input().split()))
(a, b) = (0, 0)
answer = 'YES'
for number in numbers:
	if number == 25:
		a += 1
	elif number == 50:
		if a > 0:
			a -= 1
			b += 1
		else:
			answer = 'NO'
			break
	elif b > 0 and a > 0:
		b -= 1
		a -= 1
	elif a > 2:
		a -= 3
	else:
		answer = 'NO'
print(answer)


import math
n = int(input())
l = [int(i) for i in input().split()]
d = {25: 0, 50: 0, 100: 0}
c = 0
for i in range(n):
	if l[i] == 25:
		d[25] += 1
	elif l[i] == 50:
		d[50] += 1
		if d[25] >= 1:
			d[25] -= 1
		else:
			c = -1
			break
	elif d[50] > 0:
		if d[25] >= 1:
			d[25] -= 1
			d[50] -= 1
		else:
			c = -1
			break
	elif d[25] >= 3:
		d[25] -= 3
	else:
		c = -1
		break
if c == -1:
	print('NO')
else:
	print('YES')


n = int(input())
l = list(map(int, input().rstrip().split()))
x = {25: 0, 50: 0, 100: 0}
for (j, i) in enumerate(l):
	if i == 25:
		x[25] += 1
	elif i == 50:
		if x[25] >= 1:
			x[25] -= 1
			x[50] += 1
		else:
			print('NO')
			break
	elif i == 100:
		if x[50] >= 1 and x[25] >= 1:
			x[50] -= 1
			x[25] -= 1
			x[100] += 1
		elif x[25] >= 3:
			x[25] -= 3
			x[100] += 1
		else:
			print('NO')
			break
	if j == n - 1:
		print('YES')


a = b = c = 0
t = 'YES'
input()
for i in input().split():
	i = int(i)
	if i == 100:
		if c > 0:
			c -= 1
		elif b > 0 and a > 0:
			a -= 1
			b -= 1
		elif a > 2:
			a -= 3
		else:
			t = 'NO'
			break
	elif i == 75:
		c += 1
		if b > 0:
			b -= 1
			c += 1
		elif a > 1:
			a -= 2
			c += 1
		else:
			t = 'NO'
			break
	elif i == 50:
		if a < 1:
			t = 'NO'
			break
		else:
			a -= 1
			b += 1
	else:
		a += 1
print(t)


n = int(input())
ms = [int(x) for x in input().split()]
yes = True
a = b = 0
s = 0
for m in ms:
	if m == 25:
		a += 1
	elif m == 50:
		a -= 1
		b += 1
	elif m == 100:
		if b > 0:
			b -= 1
			a -= 1
		else:
			a -= 3
	if a < 0 or b < 0:
		yes = False
		break
if yes:
	print('YES')
else:
	print('NO')


n = int(input())
l = input().split()
c = {'25': 0, '50': 0, '100': 0}
for i in range(n):
	if i == 0 and l[i] != '25':
		print('NO')
		exit(0)
	if l[i] == '25':
		c['25'] += 1
	elif l[i] == '50':
		if c['25'] <= 0:
			print('NO')
			exit(0)
		else:
			c['25'] -= 1
			c['50'] += 1
	elif c['25'] <= 0:
		print('NO')
		exit(0)
	elif c['50']:
		c['50'] -= 1
		c['25'] -= 1
	elif c['25'] < 3:
		print('NO')
		exit(0)
	else:
		c['25'] -= 3
print('YES')


n = int(input())
a = list(map(int, input().split()))
n_25 = n_50 = n_100 = 0
for x in range(n):
	if a[x] == 25:
		n_25 += 1
	elif a[x] == 50:
		if n_25 == 0:
			print('NO')
			break
		else:
			n_25 -= 1
			n_50 += 1
	elif n_50 > 0 and n_25 > 0:
		n_100 += 1
		n_25 -= 1
		n_50 -= 1
	elif n_25 >= 3:
		n_25 -= 3
		n_100 += 1
	else:
		print('NO')
		break
else:
	print('YES')


def lines(arr):
	notes = {100: 0, 50: 0, 25: 0}
	for i in arr:
		bal = i - 25
		notes[i] += 1
		if bal == 0:
			continue
		elif bal == 25:
			if notes[25] == 0:
				return 'NO'
			notes[25] -= 1
		elif notes[25] >= 1 and notes[50] >= 1:
			notes[50] -= 1
			notes[25] -= 1
		elif notes[25] >= 3:
			notes[25] -= 3
		else:
			return 'NO'
	return 'YES'
n = int(input())
arr = list(map(int, input().split()))
print(lines(arr))


n = int(input())
a = list(map(int, input().strip().split()))
d = True
c_25 = c_50 = c_100 = 0
for i in range(n):
	if a[i] == 25:
		c_25 += 1
		continue
	elif a[i] == 50:
		if c_25 >= 1:
			c_25 -= 1
			c_50 += 1
			continue
		else:
			d = False
			break
	elif a[i] == 100:
		if c_50 >= 1 and c_25 >= 1:
			c_50 -= 1
			c_25 -= 1
			c_100 += 1
			continue
		elif c_25 >= 3:
			c_25 -= 3
			c_100 += 1
			continue
		else:
			d = False
			break
if d == False:
	print('NO')
else:
	print('YES')


import math
t = int(input())
arr = list(map(int, input().split()))
change_25 = 0
change_50 = 0
for i in range(t):
	if arr[i] == 25:
		change_25 += 25
	elif arr[i] == 50:
		if change_25 >= 25:
			change_50 += 50
			change_25 -= 25
		else:
			print('NO')
			exit()
	elif arr[i] == 100:
		if change_25 >= 25 and change_50 >= 50:
			change_50 -= 50
			change_25 -= 25
		elif change_25 >= 75:
			change_25 -= 75
		else:
			print('NO')
			exit()
print('YES')


import math
from decimal import Decimal

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)
(n, a) = na()
k2 = 0
k5 = 0
for i in a:
	if i == 25:
		k2 += 1
	elif i == 50:
		if k2 > 0:
			k5 += 1
			k2 -= 1
		else:
			print('NO')
			exit()
	elif k2 > 0 and k5 > 0:
		k2 -= 1
		k5 -= 1
	elif k5 == 0 and k2 >= 3:
		k2 -= 3
	else:
		print('NO')
		exit()
print('YES')


n = int(input())
l = list(map(int, input().split()))
flag = True
l25 = []
l50 = []
x = len(l25)
y = len(l50)
i = 0
for i in range(n):
	if l[i] == 25:
		l25.append(l[i])
		x += 1
	elif l[i] == 50:
		if x == 0:
			flag = False
		else:
			l50.append(l[i])
			y += 1
			x -= 1
	elif l[i] == 100:
		if x >= 1 and y >= 1:
			x -= 1
			y -= 1
		elif x >= 3:
			x -= 3
		else:
			flag = False
if flag:
	print('YES')
else:
	print('NO')


(a25, a50) = (0, 0)
n = int(input())
a = [int(i) for i in input().split()]
for i in a:
	if i == 25:
		a25 += 1
	elif i == 50:
		if a25 < 1:
			print('NO')
			break
		else:
			a25 -= 1
			a50 += 1
	elif i == 100:
		if a50 > 0 and a25 > 0:
			a25 -= 1
			a50 -= 1
		elif a25 > 2:
			a25 -= 3
		else:
			print('NO')
			break
else:
	print('YES')


input()
s = input().split()
a = b = 0
yes = True
for i in s:
	if i == '25':
		a += 1
	elif i == '50':
		a -= 1
		b += 1
	elif i == '100':
		if b > 0:
			b -= 1
			a -= 1
		else:
			a -= 3
	if a < 0 or b < 0:
		yes = False
		break
if yes:
	print('YES')
else:
	print('NO')


n = int(input())
line = list(map(int, input().split()))
cngq = 0
cngh = 0
f = True
for i in line:
	if i == 25:
		cngq += 1
	elif i == 50:
		cngq -= 1
		cngh += 1
	elif cngh:
		cngh -= 1
		cngq -= 1
	else:
		cngq -= 3
	if cngq < 0:
		print('NO')
		f = False
		break
if f:
	print('YES')


n = int(input())
a = list(map(int, input().split()))
m = {25: 0, 50: 0}
for item in a:
	diff = item - 25
	if diff == 75:
		if m[50] >= 1 and m[25] >= 1:
			m[50] -= 1
			m[25] -= 1
		elif m[25] >= 3:
			m[25] -= 3
		else:
			print('NO')
			exit()
	elif diff == 25:
		if m[25] >= 1:
			m[25] -= 1
			m[50] += 1
		else:
			print('NO')
			exit()
	else:
		m[25] += 1
print('YES')


n = int(input())
(m2, m5) = (0, 0)
for i in input().split():
	if i == '25':
		m2 += 1
	elif i == '50':
		m2 -= 1
		m5 += 1
	else:
		m2 -= 3 - 2 * (m5 > 0)
		m5 -= m5 > 0
	if m2 < 0:
		break
print('YNEOS'[m2 < 0::2])


s = {50: 0, 25: 0, 100: 0}
n = int(input())
t = list(map(int, input().split()))
h = 0
for k in range(n):
	if t[k] == 50:
		if s[25] > 0:
			s[50] += 1
			s[25] -= 1
		else:
			print('NO')
			h += 1
			break
	elif t[k] == 100:
		if s[25] > 0 and s[50] > 0:
			s[25] -= 1
			s[50] -= 1
			s[100] += 1
		elif s[25] >= 3:
			s[25] -= 3
			s[100] += 1
		else:
			print('NO')
			h += 1
			break
	else:
		s[25] += 1
if h == 0:
	print('YES')


import sys
n = int(input())
alist = list(map(int, sys.stdin.readline().split()))
b = [0, 0]
for a in alist:
	if a == 25:
		b[0] += 1
	elif a == 50:
		b[1] += 1
		if b[0] <= 0:
			print('NO')
			break
		else:
			b[0] -= 1
	elif b[1] >= 1:
		if b[0] <= 0:
			print('NO')
			break
		else:
			b[0] -= 1
			b[1] -= 1
	elif b[0] <= 2:
		print('NO')
		break
	else:
		b[0] -= 3
else:
	print('YES')


def main():
	n = int(input())
	a = list(map(int, input().split()))
	change = {25: 0, 50: 0}
	ok = True
	for val in a:
		if val == 25:
			change[25] += 1
		elif val == 50:
			if change[25] == 0:
				ok = False
				break
			else:
				change[25] -= 1
				change[50] += 1
		elif change[50] > 0 and change[25] > 0:
			change[50] -= 1
			change[25] -= 1
		elif change[25] >= 3:
			change[25] -= 3
		else:
			ok = False
			break
	print('YES' if ok else 'NO')
main()


n = int(input())
a = list(map(int, input().strip().split()))
co2 = 0
co5 = 0
d = 0
for i in a:
	if i == 25:
		co2 += 1
	if i == 100:
		if co5 >= 1 and co2 >= 1:
			co5 = co5 - 1
			co2 = co2 - 1
		else:
			co2 = co2 - 3
	if i == 50:
		co5 += 1
		co2 -= 1
	if co2 < 0 or co5 < 0:
		print('NO')
		d = 1
		break
if d != 1:
	print('YES')


n = int(input())
list_numbers = input().split(' ')
for i in range(len(list_numbers)):
	list_numbers[i] = int(list_numbers[i])
bills = {25: 1, 50: 0}
money = 25
succesfull = True
if list_numbers[0] != 25:
	print('NO')
else:
	amount_bills = 0
	for i in range(1, n):
		if list_numbers[i] == 25:
			bills[25] += 1
		elif list_numbers[i] == 50:
			amount_25 = bills[25]
			if amount_25 > 0:
				bills[25] -= 1
				bills[50] += 1
			else:
				succesfull = False
				break
		else:
			amount_50 = bills[50]
			amount_25 = bills[25]
			if amount_50 > 0 and amount_25 > 0:
				bills[50] -= 1
				bills[25] -= 1
			elif amount_25 > 2:
				bills[25] -= 3
			else:
				succesfull = False
				break
	if succesfull == True:
		print('YES')
	else:
		print('NO')


x = y = count = 0
n = int(input())
ar = list(map(int, input().rstrip().split(' ')))
for i in ar:
	if i == 25:
		x += 1
		count += 1
	elif i == 50:
		y += 1
		if x >= 1:
			x -= 1
			count += 1
	elif x >= 1 and y >= 1:
		x -= 1
		y -= 1
		count += 1
	elif x >= 3:
		x -= 3
		count += 1
if count == n:
	print('YES')
else:
	print('NO')


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')
import math

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def abs(x):
	return x if x >= 0 else -x

def sumelem(x, start, end):
	sum = 0
	for i in range(start, end + 1):
		sum += x[i]
	return sum
for t in range(1):
	n = int(input())
	row = list(map(int, input().split()))
	box = {25: 0, 50: 0}
	flag = 1
	for i in row:
		if i == 100:
			if box[50] > 0 and box[25] > 0:
				box[50] -= 1
				box[25] -= 1
			elif box[25] >= 3:
				box[25] -= 3
			else:
				flag = 0
				break
		elif i == 50:
			if box[25] > 0:
				box[25] -= 1
				box[50] += 1
			else:
				flag = 0
				break
		else:
			box[25] += 1
	print('YES' if flag == 1 else 'NO')


n = int(input())
k = list(map(int, input().split()))
m = dict([(25, 0), (50, 0), (100, 0)])
for i in k:
	if i == 25:
		m[25] += 1
	elif i == 50:
		if m[25] > 0:
			m[25] -= 1
			m[50] += 1
		else:
			print('NO')
			exit()
	elif m[25] > 0 and m[50] > 0:
		m[25] -= 1
		m[50] -= 1
	elif m[25] >= 3:
		m[25] -= 3
	else:
		print('NO')
		exit()
print('YES')


n = input()
L = [int(x) for x in input().split()]
(h, f, t, a) = (0, 0, 0, 0)
for i in L:
	if i == 25:
		t += 1
	if i == 50:
		f += 1
		if t < 1:
			a += 1
			break
		else:
			t -= 1
	if i == 100:
		h += 1
		if t >= 3 or (t >= 1 and f >= 1):
			if t >= 1 and f >= 1:
				t -= 1
				f -= 1
			else:
				t -= 3
		else:
			a += 1
			break
if a == 0:
	print('YES')
if a > 0:
	print('NO')


n = int(input())
a = list(input().split())
cnt = {'25': 0, '50': 0, '100': 0}
mishe = True
for i in range(n):
	if a[i] == '25':
		cnt['25'] += 1
	elif a[i] == '50':
		cnt['25'] -= 1
		cnt['50'] += 1
	elif cnt['50'] > 0:
		cnt['50'] -= 1
		cnt['25'] -= 1
	else:
		cnt['25'] -= 3
	if cnt['25'] < 0:
		mishe = False
		break
if mishe:
	print('YES')
else:
	print('NO')


n = int(input())
que = list(map(int, input().split()))
flag = True
if que[0] == 25:
	cashier = 25
	fifty = 0
	i = 1
	while i < n:
		if que[i] == 25:
			cashier += 25
		elif que[i] == 50 and cashier >= 25:
			cashier -= 25
			fifty += 50
		elif que[i] == 100:
			if cashier >= 25 and fifty >= 50:
				cashier -= 25
				fifty -= 50
			elif cashier >= 75:
				cashier -= 75
			else:
				flag = False
				break
		else:
			flag = False
			break
		i += 1
	if flag:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
l = list(map(int, input().split()))
twentyfive = 0
fifty = 0
for x in l:
	if x == 25:
		twentyfive += 1
	elif x == 50:
		if twentyfive >= 1:
			fifty += 1
			twentyfive -= 1
		else:
			print('NO')
			exit(0)
	elif x == 100:
		if twentyfive >= 1 and fifty >= 1:
			fifty -= 1
			twentyfive -= 1
		elif twentyfive >= 3:
			twentyfive -= 3
		else:
			print('NO')
			exit(0)
print('YES')


N = int(input())
A = list(map(int, input().split()))
hundred = 0
fifty = 0
twenty_five = 0
valid = True
for a in A:
	change = a - 25
	target_hundreds = min(change // 100, hundred)
	change -= target_hundreds * 100
	target_fifty = min(change // 50, fifty)
	change -= target_fifty * 50
	target_twenty_five = min(change // 25, twenty_five)
	change -= target_twenty_five * 25
	if change > 0:
		valid = False
		break
	else:
		hundred -= target_hundreds
		fifty -= target_fifty
		twenty_five -= target_twenty_five
		if a == 25:
			twenty_five += 1
		if a == 50:
			fifty += 1
		if a == 100:
			hundred += 1
print('YES' if valid else 'NO')


n = int(input())
money = [int(i) for i in input().split()]
(a25, a50) = (0, 0)
answer = 'YES'
for i in range(n):
	if money[i] == 25:
		a25 += 1
	elif money[i] == 50:
		if a25 >= 1:
			a25 -= 1
			a50 += 1
		else:
			answer = 'NO'
			break
	elif a25 >= 1 and a50 >= 1:
		a25 -= 1
		a50 -= 1
	elif a25 >= 3:
		a25 -= 3
	else:
		answer = 'NO'
		break
print(answer)


import sys
n = int(sys.stdin.readline())
money = sys.stdin.readline()

def serve(n, money):
	money = money.strip().split()
	bills = {'25': 0, '50': 0}
	for bill in money:
		if bill == '25':
			bills[bill] += 1
		elif bill == '50':
			if bills['25'] >= 1:
				bills['25'] -= 1
				bills[bill] += 1
			else:
				return 'NO'
		elif bills['50'] >= 1 and bills['25'] >= 1:
			bills['50'] -= 1
			bills['25'] -= 1
		elif bills['25'] >= 3:
			bills['25'] -= 3
		else:
			return 'NO'
	return 'YES'

def doTest():
	assert serve(4, '25 25 50 50') == 'YES'
	assert serve(2, '25 100') == 'NO'
	assert serve(4, '50 50 25 25') == 'NO'
print(serve(n, money))


def cinemaLine():
	n = int(input())
	l = [int(x) for x in input().split()]
	d = {25: 0, 50: 0, 75: 0}
	for i in range(n):
		if l[i] - 25 > 0:
			change = l[i] - 25
			if change == 25:
				if d[25] == 0:
					print('NO')
					return
				else:
					d[25] -= 1
					d[50] += 1
					continue
			elif change == 75:
				if d[25] > 0 and d[50] > 0:
					d[25] -= 1
					d[50] -= 1
					continue
				elif d[25] // 3 > 0:
					d[25] -= 3
					continue
				else:
					print('NO')
					return
		else:
			d[25] += 1
	print('YES')
cinemaLine()


n = int(input())
rs = [int(x) for x in input().split()]
r25 = 0
r50 = 0
for i in range(n):
	if rs[i] == 25:
		r25 += 1
	elif rs[i] == 50:
		if r25 >= 1:
			r25 -= 1
			r50 += 1
		else:
			print('NO')
			break
	elif r50 >= 1 and r25 >= 1:
		r25 -= 1
		r50 -= 1
	elif r25 >= 3:
		r25 -= 3
	else:
		print('NO')
		break
else:
	print('YES')


n = int(input())
arr = list(map(int, input().split()))
a = 0
b = 0
c = 0
flag = True
for i in range(n):
	if arr[i] == 25:
		a += 1
		continue
	elif arr[i] == 50:
		b += 1
		if a < 1:
			flag = False
			break
		else:
			a -= 1
	else:
		if b == 0 and a < 3:
			flag = False
			break
		if b == 0 and a >= 3:
			a -= 3
			continue
		if b >= 1 and a < 1:
			flag = False
			break
		if b >= 1 and a >= 1:
			a -= 1
			b -= 1
			continue
if flag:
	print('YES')
else:
	print('NO')


def func(arr):
	tmp = {25: 0, 50: 0}
	for i in arr:
		if i == 25:
			tmp[25] += 1
		elif i == 50:
			if tmp[25] >= 1:
				tmp[25] -= 1
				tmp[50] += 1
			else:
				print('NO')
				return
		elif i == 100:
			if tmp[50] >= 1 and tmp[25] >= 1:
				tmp[50] -= 1
				tmp[25] -= 1
			elif tmp[25] >= 3:
				tmp[25] -= 3
			else:
				print('NO')
				return
	print('YES')

def main():
	k = int(input())
	cash = list(map(int, input().split()))
	func(cash)
main()


n = int(input())
bills = [int(t) for t in input().split()]
result = 'YES'
changes = {25: 0, 50: 0, 100: 0}
for bill in bills:
	changes[bill] += 1
	change = bill - 25
	if not change:
		continue
	elif change == 25:
		if changes[25]:
			changes[25] -= 1
			continue
		else:
			result = 'NO'
			break
	elif change == 75:
		if changes[25] and changes[50]:
			changes[25] -= 1
			changes[50] -= 1
			continue
		elif changes[25] >= 3:
			changes[25] -= 3
			continue
		else:
			result = 'NO'
			break
print(result)


n = int(input())
z = list(map(int, input().split()))
arr = [0, 0, 0]
status = True
for i in range(n):
	if z[i] == 25:
		arr[0] += 1
	elif z[i] == 50:
		arr[1] += 1
		if arr[0] > 0:
			arr[0] -= 1
		else:
			status = False
			break
	else:
		arr[2] += 1
		if arr[1] > 0 and arr[0] > 0:
			arr[1] -= 1
			arr[0] -= 1
		elif arr[0] > 2:
			arr[0] -= 3
		else:
			status = False
			break
if status:
	print('YES')
else:
	print('NO')


n = int(input())
s = input().split()
tf = 0
ft = 0
oh = 0
for i in s:
	if i == '25':
		tf += 1
	elif i == '50':
		tf -= 1
		ft += 1
	elif ft > 0:
		ft -= 1
		tf -= 1
	else:
		tf -= 3
	if tf < 0:
		print('NO')
		quit()
print('YES')


import math
num = int(input())
x = input()
lst = x.split()
newlst = list(map(int, lst))
reserve = 0
count = 0
exchange = [0, 0]
state = 'YES'
for i in newlst:
	if i == 25:
		exchange[0] += 1
	if i == 50:
		if exchange[0] > 0:
			exchange[0] -= 1
			exchange[1] += 1
		else:
			state = 'NO'
			break
	if i == 100:
		if exchange[1] > 0 and exchange[0] > 0:
			exchange[0] -= 1
			exchange[1] -= 1
			state = 'YES'
		elif exchange[0] > 2:
			exchange[0] -= 3
			state = 'YES'
		else:
			state = 'NO'
			break
print(state)


n = int(input())
bills = [int(_) for _ in input().split()]
(c25, c50, flag) = (0, 0, 1)
for i in bills:
	if i == 25:
		c25 += 1
	elif i == 50:
		if c25 == 0:
			flag = 0
			break
		else:
			c25 -= 1
			c50 += 1
	elif c25 > 0 and c50 > 0:
		c25 -= 1
		c50 -= 1
	elif c25 > 2:
		c25 -= 3
	else:
		flag = 0
		break
if flag:
	print('YES')
else:
	print('NO')


number_of_people = int(input())
money_list = list(map(int, input().split(' ')))
avilable_25 = 0
avilable_50 = 0
avilable_100 = 0
for money in money_list:
	if money == 25:
		avilable_25 = avilable_25 + 1
	elif money == 50 and avilable_25 >= 1:
		avilable_25 = avilable_25 - 1
		avilable_50 = avilable_50 + 1
	elif money == 100 and avilable_25 >= 1 and (avilable_50 >= 1):
		avilable_25 = avilable_25 - 1
		avilable_50 = avilable_50 - 1
		avilable_100 = avilable_100 + 1
	elif money == 100 and avilable_25 >= 3:
		avilable_25 = avilable_25 - 3
		avilable_100 = avilable_100 + 1
	else:
		print('NO')
		exit()
print('YES')


number_of_people = int(input())
money_per_person_list = map(int, input().split())
clerk_25_rubles_bank_notes_number = 0
clerk_50_rubles_bank_notes_number = 0
are_tickets_sold = True
for money_of_person in money_per_person_list:
	if money_of_person == 25:
		clerk_25_rubles_bank_notes_number += 1
	elif money_of_person == 50 and clerk_25_rubles_bank_notes_number > 0:
		clerk_25_rubles_bank_notes_number -= 1
		clerk_50_rubles_bank_notes_number += 1
	elif money_of_person == 100:
		if clerk_50_rubles_bank_notes_number > 0 and clerk_25_rubles_bank_notes_number > 0:
			clerk_50_rubles_bank_notes_number -= 1
			clerk_25_rubles_bank_notes_number -= 1
		elif clerk_25_rubles_bank_notes_number > 2:
			clerk_25_rubles_bank_notes_number -= 3
		else:
			are_tickets_sold = False
			break
	else:
		are_tickets_sold = False
		break
print('YES' if are_tickets_sold else 'NO')


def go():
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	s = m = 0
	for i in a:
		if i == 25:
			s += 1
		elif i == 50:
			if s >= 1:
				s -= 1
				m += 1
			else:
				return 'NO'
		elif i == 100:
			if s >= 1 and m >= 1:
				s -= 1
				m -= 1
			elif s >= 3:
				s -= 3
			else:
				return 'NO'
	return 'YES'
print(go())


input()
d = {25: 0, 50: 0}
a = list(map(int, input().split()))
res = 'YES'
s = 0
for i in a:
	if i != 25:
		if s < i - 25 or d[25] == 0:
			res = 'NO'
			break
		elif i == 50:
			d[25] -= 1
			s -= 25
		elif i == 100:
			if d[50] > 0:
				d[50] -= 1
				d[25] -= 1
			else:
				d[25] -= 3
			s -= 75
	if i != 100:
		s += i
		d[i] += 1
print(res)


money = {25: 0, 50: 0}
n = int(input())
line = list(map(int, input().split()))
printed = False
for i in line:
	if i == 25:
		money[25] += 1
		continue
	elif i == 50:
		if money[25] > 0:
			money[25] -= 1
			money[50] += 1
			continue
		else:
			print('NO')
			printed = True
			break
	if i == 100:
		if money[25] > 0 and money[50] > 0:
			money[25] -= 1
			money[50] -= 1
			continue
		elif money[25] > 2:
			money[25] -= 3
			continue
		else:
			print('NO')
			printed = True
			break
if money[25] == len(line):
	print('YES')
elif not printed:
	print('YES')


def string2list(x):
	x = x.split()
	i = 0
	for i in range(len(x)):
		x[i] = int(x[i])
	return x
B25 = 0
B50 = 0
B100 = 0
N = int(input())
tikets = string2list(input())
i = 0
Ans = 'YES'
while i < N:
	current = tikets[i]
	if current == 100:
		B100 = B100 + 1
	elif current == 50:
		B50 = B50 + 1
	elif current == 25:
		B25 = B25 + 1
	change = current - 25
	if not change == 0:
		b = 0
		while (b + 1) * 100 <= change and B100 > 0:
			B100 = B100 - 1
			b = b + 1
		change = change - b * 100
		b = 0
		while (b + 1) * 50 <= change and B50 > 0:
			B50 = B50 - 1
			b = b + 1
		change = change - b * 50
		b = 0
		while (b + 1) * 25 <= change and B25 > 0:
			B25 = B25 - 1
			b = b + 1
		change = change - b * 25
	if not change == 0:
		Ans = 'NO'
		break
	i = i + 1
print(Ans)


num_people = int(input())
bills = list(input().split())
bills25 = 0
bills50 = 0
output = True
for bill in bills:
	if bill == '25':
		bills25 += 1
	elif bill == '50':
		if bills25:
			bills25 -= 1
			bills50 += 1
		else:
			output = False
			break
	elif bills25:
		if bills50:
			bills50 -= 1
			bills25 -= 1
		elif bills25 > 2:
			bills25 -= 3
		else:
			output = False
			break
	else:
		output = False
		break
print('YES') if output else print('NO')


n = int(input())
a = [int(i) for i in input().split()]
d = {}
flag = True
for i in a:
	k = i - 25
	if k > 0:
		if k >= 50 and d.get(50, 0) > 0:
			r = k // 50
			k = k - r * 50
			d[50] -= r
		if k >= 25:
			if d.get(25, 0) > 0:
				r = k // 25
				s = k % 25
				if s != 0 or r > d[25]:
					flag = False
					break
				d[25] -= r
			else:
				flag = False
				break
		d[i] = d.get(i, 0) + 1
	else:
		d[i] = d.get(i, 0) + 1
if flag:
	print('YES')
else:
	print('NO')


def solution():
	num = int(input())
	notes = list(map(int, input().split()))
	if notes[0] == 50 or notes[0] == 100:
		return print('NO')
	fifty = 0
	twenty = 0
	for i in notes:
		if i == 25:
			twenty += 1
		elif i == 50 and twenty >= 1:
			twenty -= 1
			fifty += 1
		elif i == 100 and fifty >= 1 and (twenty >= 1):
			twenty -= 1
			fifty -= 1
		elif i == 100 and fifty < 1 and (twenty > 2):
			twenty -= 3
		else:
			return print('NO')
	return print('YES')
solution()


n = int(input())
l = list(map(int, input().split()))
(p, f, h) = (0, 0, 0)
flag = 0
for i in range(n):
	if l[i] == 25:
		p += 1
	elif l[i] == 50:
		f += 1
		if p > 0:
			p -= 1
		else:
			flag = 1
			break
	elif p >= 1 and f >= 1:
		p -= 1
		f -= 1
	elif f == 0 and p >= 3:
		p -= 3
	else:
		flag = 1
		break
if flag == 0:
	print('YES')
else:
	print('NO')


n = int(input())
line = str(input()).split()
line = [int(it) for it in line]
value25 = 0
value50 = 0
flag = True
for i in range(n):
	if line[i] == 25:
		value25 += 1
	elif line[i] == 50:
		value25 -= 1
		value50 += 1
	elif line[i] == 100:
		if value50 > 0:
			value25 -= 1
			value50 -= 1
		else:
			value25 -= 3
	if value25 < 0 or value50 < 0:
		flag = False
		break
if flag:
	print('YES')
else:
	print('NO')


def main():
	from sys import stdin, stdout, stderr
	ans = True
	(v25, v50) = (0, 0)
	next(stdin)
	for bill in map(int, stdin.readline().split()):
		if bill == 25:
			v25 += 1
		elif bill == 50 and v25:
			v25 -= 1
			v50 += 1
		elif bill == 100 and v25 and v50:
			v25 -= 1
			v50 -= 1
		elif bill == 100 and v25 > 2:
			v25 -= 3
		else:
			ans = False
	stdout.write('YES\n' if ans else 'NO\n')
main()


def cinema(array):
	n_25 = 0
	n_50 = 0
	for i in array:
		if i == 25:
			n_25 += 1
		elif i == 50:
			if n_25 <= 0:
				return 'NO'
			else:
				n_25 -= 1
				n_50 += 1
		elif i == 100:
			if n_25 >= 3 or (n_50 >= 1 and n_25 >= 1):
				if n_50 >= 1 and n_25 >= 1:
					n_50 -= 1
					n_25 -= 1
				else:
					n_25 -= 3
			else:
				return 'NO'
	return 'YES'
n = int(input())
array = list(map(int, input().split(' ')))
print(cinema(array))


l = int(input())
p = [int(x) for x in input().split(' ')]
t = 0
f = 0
h = 0
cond = True
for x in p:
	if x == 25:
		t += 1
	elif x == 50:
		if t >= 1:
			t -= 1
			f += 1
		else:
			cond = False
			break
	elif x == 100:
		if t >= 1 and f >= 1:
			t -= 1
			f -= 1
			h += 1
		elif t >= 3 and f == 0:
			t -= 3
			h += 1
		else:
			cond = False
			break
if not cond:
	print('NO')
else:
	print('YES')


from sys import stdin, stdout
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
for _ in range(1):
	n = nmbr()
	a = lst()
	c25 = c50 = 0
	f = 1
	for v in a:
		if v == 25:
			c25 += 1
		elif v == 50:
			c25 -= 1
			c50 += 1
		else:
			c25 -= 1
		if c25 < 0:
			f = 0
			break
	for v in a:
		if v == 100:
			if c25 >= 2:
				c25 -= 2
			elif c50 >= 1:
				c50 -= 1
			else:
				f = 0
				break
	print('YES' if f else 'NO')


x = int(input())
y = list(map(int, input().split()))
a = 0
b = 0
c = 1
for i in y:
	if i == 25:
		a += 1
	elif i == 50:
		if a == 0:
			c = 0
			break
		else:
			a -= 1
			b += 1
	elif i == 100:
		if a > 0 and b > 0:
			a -= 1
			b -= 1
		elif a >= 3:
			a -= 3
		else:
			c = 0
			break
if c == 0:
	print('NO')
else:
	print('YES')


input()
a = b = c = 0
res = 'YES'
for k in input().split():
	if k == '25':
		a += 1
	elif k == '50':
		if a == 0:
			res = 'NO'
			break
		else:
			b += 1
			a -= 1
	elif a > 0 and b > 0:
		a -= 1
		b -= 1
	elif a >= 3:
		a -= 3
	else:
		res = 'NO'
		break
print(res)


os = int(input())
kl = [int(k) for k in input().split(' ')]
r25 = 0
r50 = 0
wy = 'YES'
for i in range(os):
	if kl[i] == 25:
		r25 += 1
	if kl[i] == 50:
		if r25 >= 1:
			r50 += 1
			r25 -= 1
		else:
			wy = 'NO'
			break
	if kl[i] == 100:
		if r50 >= 1 and r25 >= 1:
			r50 -= 1
			r25 -= 1
			continue
		if r25 >= 3:
			r25 -= 3
		else:
			wy = 'NO'
			break
print(wy)


n = int(input())
line = list(map(int, input().split()))
x = y = z = 0
for c in line:
	if c == 25:
		x += 1
	elif c == 50:
		y += 1
		if x <= 0:
			print('NO')
			exit(0)
		x -= 1
	else:
		z += 1
		if y >= 1 and x >= 1:
			y -= 1
			x -= 1
		elif y == 0 and x >= 3:
			x -= 3
		else:
			print('NO')
			exit(0)
print('YES')


n = int(input())
L = [int(x) for x in input().split()]
spare = {25: 0, 50: 0, 100: 0}
c = 0
for i in L:
	if i == 25:
		spare[25] += 1
	elif i == 50:
		if spare[25] == 0:
			c = 1
			break
		else:
			spare[50] += 1
			spare[25] -= 1
	elif spare[25] >= 1 and spare[50] >= 1:
		spare[25] -= 1
		spare[50] -= 1
	elif spare[25] >= 3:
		spare[25] -= 3
	else:
		c = 1
		break
if c == 1:
	print('NO')
else:
	print('YES')


n = int(input())
x = [int(i) for i in input().split()]
y = [0] * 2
for i in range(n):
	if x[i] == 25:
		y[0] = y[0] + 1
	elif x[i] == 50:
		y[0] = y[0] - 1
		y[1] = y[1] + 1
	elif y[1] > 0:
		y[1] = y[1] - 1
		y[0] = y[0] - 1
	else:
		y[0] = y[0] - 3
	if y[0] < 0 or y[1] < 0:
		print('NO')
		raise SystemExit
print('YES')


x = int(input())
s = [int(n) for n in input().split()]
z = {'50': 0, '25': 0, '100': 0}
l = 0
for n in s:
	if n == 25:
		z['25'] += 1
	elif n == 50:
		if z['25'] >= 1:
			z['25'] -= 1
			z['50'] += 1
		else:
			l = 1
			print('NO')
			break
	elif z['25'] >= 1 and z['50'] >= 1:
		z['25'] -= 1
		z['50'] -= 1
		z['100'] += 1
	elif z['25'] >= 3:
		z['25'] -= 3
		z['100'] += 1
	else:
		l = 1
		print('NO')
		break
if l == 0:
	print('YES')


cash = {'25': 0, '50': 0}
n = int(input())
bills = input().split(' ')
for bill in bills:
	if bill == '25':
		cash['25'] += 1
	elif bill == '50':
		cash['50'] += 1
		cash['25'] -= 1
	elif bill == '100':
		if cash['50'] != 0:
			cash['50'] -= 1
			cash['25'] -= 1
		else:
			cash['25'] -= 3
	else:
		print('?!')
	if cash['25'] < 0 or cash['50'] < 0:
		print('NO')
		exit()
print('YES')


n = int(input())
flag = 0
i = 0
notes = [0] * 2
bills = list(map(int, input().split()))
while flag != 1 and i < len(bills):
	if bills[i] == 100:
		bills[i] -= 25
		if notes[1] != 0:
			notes[1] -= 1
			bills[i] -= 50
		quarter = bills[i] // 25
		if notes[0] >= quarter:
			notes[0] -= quarter
		else:
			flag = 1
	elif bills[i] == 50:
		if notes[0] >= 1:
			notes[0] -= 1
		else:
			flag = 1
		notes[1] += 1
	else:
		notes[0] += 1
	i += 1
if flag == 1:
	print('NO')
else:
	print('YES')


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
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 value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
n = Int()
a = array()
chutta = defaultdict(int)
for i in a:
	chutta[i] += 1
	balance = i - 25
	if balance > 25 and chutta[50] > 0:
		balance -= 50
		chutta[50] -= 1
	if balance > 0 and chutta[25] >= balance // 25:
		chutta[25] -= balance // 25
		balance = 0
	if balance != 0:
		print('NO')
		exit()
print('YES')


k = int(input())
arr = list(map(int, input().split()))
bil = 25
otv = 'YES'
if arr[0] == 100 or arr[0] == 50:
	print('NO')
else:
	mon = {25: 0, 50: 0, 100: 0}
	for el in arr:
		if el == 100 and (mon[50] >= 1 and mon[25] >= 1 or mon[25] >= 3):
			if mon[25] >= 3 and mon[50] == 0:
				mon[25] -= 3
				mon[100] += 1
			else:
				mon[50] -= 1
				mon[25] -= 1
				mon[100] += 1
		elif el == 50 and mon[25] >= 1:
			mon[25] -= 1
			mon[50] += 1
		elif el == 25:
			mon[25] += 1
		else:
			otv = 'NO'
			break
	print(otv)


n = int(input())
import sys
sta = {25: 0, 50: 0}
lis = [int(x) for x in input().split()]
for i in range(len(lis)):
	if lis[i] == 25:
		sta[25] += 1
	elif lis[i] == 50:
		if sta[25] >= 1:
			sta[25] -= 1
			sta[50] += 1
		else:
			print('NO')
			sys.exit()
	elif sta[50] >= 1 and sta[25] >= 1:
		sta[50] -= 1
		sta[25] -= 1
	elif sta[25] >= 3 and sta[50] < 1:
		sta[25] -= 3
	else:
		print('NO')
		sys.exit()
print('YES')


import sys
n = int(input())
a = list(map(int, input().split()))
d = dict()
d[25] = 0
d[50] = 0
for i in a:
	if i == 25:
		d[25] += 1
	elif i == 50:
		d[50] += 1
		if d[25] == 0:
			print('NO')
			sys.exit()
		d[25] -= 1
	elif d[25] == 0:
		print('NO')
		sys.exit()
	elif d[50] == 0 and d[25] < 3:
		print('NO')
		sys.exit()
	elif d[50] == 0:
		d[25] -= 3
	else:
		d[25] -= 1
		d[50] -= 1
print('YES')


n = int(input())
massiv = list(map(int, input().split()))
(c_25, c_50, c_100) = (0, 0, 0)
mes = ''
for i in massiv:
	if i == 25:
		c_25 += 1
	elif i == 50:
		if c_25 != 0:
			c_25 -= 1
			c_50 += 1
		else:
			mes = 'NO'
			break
	elif c_25 != 0 and c_50 != 0:
		c_50 -= 1
		c_25 -= 1
	elif c_25 >= 3:
		c_25 -= 3
		c_100 += 1
	else:
		mes = 'NO'
		break
	mes = 'YES'
print(mes)


t = int(input())
e = {}
e[25] = 0
e[50] = 0
c = input().split(' ')
d = 'YES'
for i in range(t):
	if c[i] == '25':
		e[25] += 1
	elif c[i] == '50':
		e[50] += 1
		e[25] -= 1
	elif e[50] > 0:
		e[50] -= 1
		e[25] -= 1
	else:
		e[25] -= 3
	if e[25] < 0 or e[50] < 0:
		d = 'NO'
print(d)


n = int(input())
arr = list(map(int, input().split()))
d = {25: 0, 50: 0}
f = 1
for i in arr:
	if i == 25:
		d[25] = d[25] + 1
	elif i == 50:
		if d[25] >= 1:
			d[25] = d[25] - 1
			d[50] = d[50] + 1
		else:
			f = 0
			break
	elif d[50] >= 1 and d[25] >= 1:
		d[25] = d[25] - 1
		d[50] = d[50] - 1
	elif d[25] >= 3:
		d[25] = d[25] - 3
	else:
		f = 0
		break
if f == 1:
	print('YES')
else:
	print('NO')


n = int(input())
s = input()
a = s.split()
for i in range(len(a)):
	a[i] = int(a[i])
i = 0
c25 = 0
c50 = 0
while i < n:
	if a[i] == 25:
		c25 += 1
		i += 1
	elif a[i] == 50:
		if c25 > 0:
			c50 += 1
			c25 -= 1
			i += 1
		else:
			print('NO')
			i = n + 1
	elif a[i] == 100:
		if c25 > 0 and c50 > 0:
			c25 -= 1
			c50 -= 1
			i += 1
		elif c25 > 2:
			c25 -= 3
			i += 1
		else:
			print('NO')
			i = n + 1
if i == n:
	print('YES')


n = int(input())
(*l,) = map(int, input().split())
d = {25: 0, 50: 0}
for i in range(n):
	if l[i] == 25:
		d[25] += 1
	elif l[i] == 50:
		if d[25]:
			d[25] -= 1
			d[50] += 1
		else:
			print('NO')
			break
	elif d[50] and d[25]:
		d[50] -= 1
		d[25] -= 1
	elif d[25] > 2:
		d[25] -= 3
	else:
		print('NO')
		break
else:
	print('YES')


n = int(input())
arr = [int(x) for x in input().split(' ')]
(TF, F) = (0, 0)
ans = 'YES'
for item in arr:
	if item == 25:
		TF += 1
	elif item == 50:
		if TF:
			TF -= 1
			F += 1
		else:
			ans = 'NO'
			break
	elif F and TF:
		F -= 1
		TF -= 1
	elif TF >= 3:
		TF -= 3
	else:
		ans = 'NO'
		break
print(ans)


n = int(input())
arr = list(map(int, input().split()))
possible = True
change25 = 0
change50 = 0
change100 = 0
for i in range(len(arr)):
	if arr[i] == 25:
		change25 += 1
	elif arr[i] == 50:
		if change25 >= 1:
			change25 -= 1
			change50 += 1
		else:
			possible = False
			break
	elif arr[i] == 100:
		if change50 >= 1 and change25 >= 1:
			change50 -= 1
			change25 -= 1
		elif change25 >= 3:
			change25 -= 3
		else:
			possible = False
			break
if possible:
	print('YES')
else:
	print('NO')


n = int(input())
q = [int(x) for x in input().split()]
c = [0] * 2
for x in q:
	if x == 25:
		c[0] += 1
		continue
	elif x == 50:
		if c[0] <= 0:
			print('NO')
			break
		else:
			c[0] -= 1
			c[1] += 1
	elif x == 100:
		if c[1] > 0 and c[0] > 0:
			c[1] -= 1
			c[0] -= 1
		elif c[1] == 0 and c[0] > 2:
			c[0] -= 3
		else:
			print('NO')
			break
else:
	print('YES')


n = int(input())
l = list(map(int, input().split()))
c = 0
d = 0
if l[0] > 25:
	print('NO')
	quit()
else:
	c += 1
for i in range(1, n):
	if l[i] == 25:
		c += 1
	elif l[i] == 50:
		if c > 0:
			c -= 1
			d += 1
		else:
			print('NO')
			quit()
	elif d > 0 and c > 0:
		c -= 1
		d -= 1
	elif d > 0 and c == 0:
		print('NO')
		quit()
	elif d == 0 and c == 0:
		print('NO')
		quit()
	elif c < 3:
		print('NO')
		quit()
	else:
		c -= 3
if c >= 0 and d >= 0:
	print('YES')
else:
	print('NO')


N = int(input())
L = list(map(int, input().split()))
d = {25: 0, 50: 0, 100: 0}
for l in L:
	if l == 25:
		d[25] += 1
	elif l == 50:
		if d[25] >= 1:
			d[25] -= 1
			d[50] += 1
		else:
			print('NO')
			exit()
	elif l == 100:
		if d[50] >= 1 and d[25] >= 1:
			d[50] -= 1
			d[25] -= 1
			d[100] += 1
		elif d[25] >= 3:
			d[25] -= 3
			d[100] += 1
		else:
			print('NO')
			exit()
print('YES')


input()
a = list(map(int, input().split()))
keep = {25: 0, 50: 0}
ans = 'YES'
for item in a:
	if item == 100:
		if keep[50] > 0 and keep[25] > 0:
			keep[25] -= 1
			keep[50] -= 1
		elif keep[25] >= 3:
			keep[25] -= 3
		else:
			ans = 'NO'
			break
	elif item == 50:
		if keep[25] > 0:
			keep[25] -= 1
			keep[50] += 1
		else:
			ans = 'NO'
			break
	else:
		keep[25] += 1
print(ans)


n = int(input())
list = [int(i) for i in input().split()]
chiller25 = 0
chiller50 = 0
chiller100 = 0
for i in range(n):
	if list[i] == 25:
		chiller25 += 25
	elif list[i] == 50:
		if chiller25 >= 25:
			chiller25 -= 25
			chiller50 += 50
		else:
			print('NO')
			exit()
	elif list[i] == 100:
		if chiller25 >= 25 and chiller50 >= 50:
			chiller100 += 100
			chiller25 -= 25
			chiller50 -= 50
		elif chiller25 >= 75:
			chiller25 -= 75
			chiller100 += 100
		else:
			print('NO')
			exit()
print('YES')


def main():
	n = read_int()
	A = read_ints()
	CG_25 = 0
	CG_50 = 1
	changes = [0, 0]

	def do_change(x, changes):
		if x == 25:
			changes[CG_25] += 1
			return True
		elif x == 50:
			if changes[CG_25] > 0:
				changes[CG_50] += 1
				changes[CG_25] -= 1
				return True
		elif x == 100:
			x -= 25
			if changes[CG_50] > 0:
				changes[CG_50] -= 1
				x -= 50
			if changes[CG_25] >= x // 25:
				changes[CG_25] -= x // 25
				return True
		return False
	for x in A:
		ret = do_change(x, changes)
		if ret is False:
			NO()
			return
	YES()
from collections import *
MOD = 998244353
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 read_int():
	return int(input())

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

def print_nums(nums):
	print(' '.join(map(str, nums)))

def YES():
	print('YES')

def Yes():
	print('Yes')

def NO():
	print('NO')

def No():
	print('No')

def fib(n):
	(a, b) = (0, 1)
	for _ in range(n):
		(a, b) = (b, a + b)
	return a

def fib_ns(n):
	assert n >= 1
	f = [0 for _ in range(n + 1)]
	f[0] = 0
	f[1] = 1
	for i in range(2, n + 1):
		f[i] = f[i - 1] + f[i - 2]
	return f

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

def xgcd(a, b):
	(x0, x1, y0, y1) = (0, 1, 1, 0)
	while a != 0:
		((q, a), b) = (divmod(b, a), a)
		(y0, y1) = (y1, y0 - q * y1)
		(x0, x1) = (x1, x0 - q * x1)
	return (b, x0, y0)

def modinv(a, m):
	(g, x, _) = xgcd(a, m)
	if g != 1:
		raise Exception('gcd(a, m) != 1')
	return x % m

def mod_add(x, y):
	x += y
	while x >= MOD:
		x -= MOD
	while x < 0:
		x += MOD
	return x

def mod_mul(x, y):
	return x * y % MOD

def mod_pow(x, y):
	if y == 0:
		return 1
	if y % 2:
		return mod_mul(x, mod_pow(x, y - 1))
	p = mod_pow(x, y // 2)
	return mod_mul(p, p)

def mod_inv(y):
	return mod_pow(y, MOD - 2)

def mod_div(x, y):
	return mod_mul(x, mod_inv(y))
main()


import sys
n = int(input())
a = [int(i) for i in input().split()]
m25 = 0
m50 = 0
for i in a:
	if i == 25:
		m25 += 1
	elif i == 50:
		if m25 < 1:
			print('NO')
			sys.exit()
		else:
			m25 -= 1
			m50 += 1
	elif m50 > 0 and m25 > 0:
		m50 -= 1
		m25 -= 1
	elif m25 > 2:
		m25 -= 3
	else:
		print('NO')
		sys.exit()
print('YES')


input()
bills = [int(i) for i in input().split(' ')]
k = 1
money = {25: 0, 50: 0}
for bill in bills:
	if bill == 25:
		money[25] += 1
	elif bill == 50:
		money[50] += 1
		if money[25] == 0:
			print('NO')
			k = 0
			break
		else:
			money[25] -= 1
	elif money[50] == 0:
		if money[25] < 3:
			print('NO')
			k = 0
			break
		else:
			money[25] -= 3
	else:
		money[50] -= 1
		if money[25] == 0:
			print('NO')
			k = 0
			break
		else:
			money[25] -= 1
if k == 1:
	print('YES')


t = int(input(''))
l = list(map(int, input('').split(' ')))
(a, b, c) = (0, 0, 0)
f = 0
for i in range(t):
	if l[i] == 25:
		a += 1
	elif l[i] == 50:
		if a >= 1:
			a -= 1
			b += 1
		else:
			f = 1
			break
	elif a >= 1 and b >= 1:
		a -= 1
		b -= 1
		c += 1
	elif a >= 3:
		a -= 3
		c += 1
	else:
		f = 1
		break
if f == 1:
	print('NO')
else:
	print('YES')


n = int(input())
mas = [*map(int, input().split())]
cashhas = [0, 0, 0]
for m in mas:
	if m == 25:
		cashhas[0] += m
	elif m == 50:
		if cashhas[0]:
			cashhas[0] -= 25
			cashhas[1] += m
		else:
			flag = False
			break
	elif m == 100:
		if cashhas[0] and cashhas[1]:
			cashhas[0] -= 25
			cashhas[1] -= 50
			cashhas[2] += m
		elif cashhas[0] >= 75:
			cashhas[0] -= 75
			cashhas[2] += m
		else:
			flag = False
			break
	if mas[-1] == m:
		flag = True
if flag:
	print('YES')
else:
	print('NO')


def cin(s):
	(s25, s50) = (0, 0)
	for i in s:
		if i == 25:
			s25 += 1
		elif i == 50:
			if s25 == 0:
				return 'NO'
			s50 += 1
			s25 -= 1
		elif s25 >= 3 or (s50 >= 1 and s25 >= 1):
			if s50 >= 1 and s25 >= 1:
				s25 -= 1
				s50 -= 1
			else:
				s25 -= 3
		else:
			return 'NO'
	return 'YES'
t = int(input())
s = list(map(int, input().split()))
print(cin(s))


n = int(input())
a = [int(x) for x in input().split()]
c25 = 0
c50 = 0
flag = 0
for i in range(n):
	if a[i] == 25:
		c25 += 1
	elif a[i] == 50:
		if c25 <= 0:
			flag = 1
			break
		else:
			c25 -= 1
			c50 += 1
	else:
		if c25 <= 0:
			flag = 1
			break
		if c50 > 0:
			c50 -= 1
			c25 -= 1
		elif c25 <= 2:
			flag = 1
			break
		else:
			c25 -= 3
if flag == 0:
	print('YES')
else:
	print('NO')


n = int(input())
bill = [int(j) for j in input().split()]
change = [0, 0]
k = 0
while k < n:
	if bill[k] == 25:
		change[0] += 1
		k += 1
	elif bill[k] == 50:
		if change[0] == 0:
			print('NO')
			break
		else:
			change[0] -= 1
			change[1] += 1
			k += 1
	elif bill[k] == 100:
		if change[0] >= 1 and change[1] >= 1:
			change[0] -= 1
			change[1] -= 1
			k += 1
		elif change[0] >= 3:
			change[0] -= 3
			k += 1
		else:
			print('NO')
			break
else:
	print('YES')


def fun(x):
	c1 = 0
	c2 = 0
	c3 = 0
	for i in range(len(x)):
		if x[i] - 25 == 25:
			if c1 < 1:
				print('NO')
				return
			c1 -= 1
		elif x[i] - 25 == 50:
			if c2 < 1 and c1 < 2:
				print('NO')
				return
			if c2 > 1:
				c2 -= 1
			else:
				c1 -= 2
		elif x[i] - 25 == 75:
			if c2 >= 1 and c1 >= 1:
				c2 -= 1
				c1 -= 1
			elif c1 >= 3:
				c1 -= 3
			else:
				print('NO')
				return
		if x[i] == 25:
			c1 += 1
		elif x[i] == 50:
			c2 += 1
		else:
			c3 += 1
	print('YES')
	return
l = int(input())
x = list(map(int, input().split()))
fun(x)


from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi

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

def fi():
	return float(stdin.readline())

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

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline()
n = ii()
a = li()
t = f = 0
for x in a:
	if x == 25:
		t += 1
	elif x == 50 and t:
		f += 1
		t -= 1
	elif x == 100 and t and f:
		t -= 1
		f -= 1
	elif x == 100 and t > 2:
		t -= 3
	else:
		print('NO')
		exit()
print('YES')


n = int(input())
a = list(map(int, input().split()))
ans = 'YES'
twoFive = 0
fifty = 0
hund = 0
for i in range(n):
	if a[i] == 25:
		twoFive += 1
	elif a[i] == 50:
		fifty += 1
		if twoFive >= 1:
			twoFive -= 1
		else:
			ans = 'NO'
			break
	else:
		hund += 1
		if fifty >= 1 and twoFive >= 1:
			fifty -= 1
			twoFive -= 1
		elif twoFive >= 3:
			twoFive -= 3
		else:
			ans = 'NO'
			break
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
dollars = [0, 0]
ans = 'YES'
for i in range(n):
	if a[i] == 25:
		dollars[0] += 1
	elif a[i] == 50:
		if dollars[0] == 0:
			ans = 'NO'
			break
		else:
			dollars[0] -= 1
			dollars[1] += 1
	elif (dollars[0] == 0 or dollars[1] == 0) and dollars[0] < 3:
		ans = 'NO'
		break
	elif dollars[1] >= 1:
		dollars[0] -= 1
		dollars[1] -= 1
	else:
		dollars[0] -= 3
print(ans)


n = int(input())
a = list(map(int, input().split()))

def fun(a, n):
	value = True
	n25 = 0
	n50 = 0
	for i in a:
		if i == 25:
			n25 += 1
		elif i == 50 and n25 >= 1:
			n50 += 1
			n25 -= 1
		elif i == 50 and n25 < 1:
			value = False
			return
		elif n50 >= 1 and n25 >= 1:
			n50 -= 1
			n25 -= 1
		elif n25 >= 3:
			n25 -= 3
		else:
			value = False
			return
	return value
if fun(a, n):
	print('YES')
else:
	print('NO')


def main():
	n = input()
	data = [int(x) for x in input().split()]
	(vc, cq) = (0, 0)
	for bill in data:
		if bill == 25:
			vc += 1
		elif bill == 50:
			vc -= 1
			cq += 1
		elif cq:
			cq -= 1
			vc -= 1
		else:
			vc -= 3
		if vc < 0 or cq < 0:
			return 'NO'
	return 'YES'
print(main())


def cinemaline(n, arr):
	c25 = 0
	c50 = 0
	c100 = 0
	for i in range(n):
		if arr[i] == 25:
			c25 = c25 + 1
		elif arr[i] == 50 and c25 >= 1:
			c50 = c50 + 1
			c25 = c25 - 1
		elif arr[i] == 100 and c25 >= 1 and (c50 >= 1):
			c25 = c25 - 1
			c50 = c50 - 1
			c100 = c100 + 1
		elif arr[i] == 100 and c25 >= 3:
			c25 = c25 - 3
			c100 = c100 + 1
		else:
			return 'NO'
	return 'YES'
n = int(input())
arr = [int(x) for x in input().split()]
print(cinemaline(n, arr))


n = int(input())
arr = [int(i) for i in input().split()]
data = {25: 0, 50: 0}
ok = 'YES'
for _ in arr:
	if _ == 25:
		data[_] += 1
	elif _ == 50:
		data[_] += 1
		if data[25] > 0:
			data[25] -= 1
		else:
			ok = 'NO'
			break
	elif data[50] > 0 and data[25] > 0:
		data[25] -= 1
		data[50] -= 1
	elif data[25] > 2:
		data[25] -= 3
	else:
		ok = 'NO'
		break
print(ok)


from collections import defaultdict
n = int(input())
q = list(map(int, input().split(' ')))
c = defaultdict(int)
for i in q:
	if i == 25:
		c[25] += 1
	elif i == 50:
		if not c[25] >= 1:
			print('NO')
			exit()
		else:
			c[50] += 1
			c[25] -= 1
	elif i == 100:
		if c[25] >= 1 and c[50] >= 1:
			c[25] -= 1
			c[50] -= 1
			c[100] += 1
		elif c[25] >= 3:
			c[25] -= 3
			c[100] += 1
		else:
			print('NO')
			exit()
print('YES')


n = int(input())
a = map(int, input().split())
(n25, n50, n100) = (0, 0, 0)
for i in range(n):
	v = next(a)
	if v == 25:
		n25 += 1
	elif v == 50:
		if n25 == 0:
			print('NO')
			exit(0)
		else:
			n25 -= 1
			n50 += 1
	elif v == 100:
		if n50 > 0 and n25 > 0:
			n25 -= 1
			n50 -= 1
			n100 += 1
		elif n25 >= 3:
			n25 -= 3
			n100 += 1
		else:
			print('NO')
			exit(0)
print('YES')


n = int(input())
l_r = list(map(int, input().split()))
l_b = list([0, 0, 0])
b = 0
for r in l_r:
	if r == 100:
		l_b[0] += 1
		if l_b[1] > 0:
			l_b[1] -= 1
			l_b[2] -= 1
		else:
			l_b[2] -= 3
	elif r == 50:
		l_b[1] += 1
		l_b[2] -= 1
	else:
		l_b[2] += 1
	if l_b[1] < 0 or l_b[2] < 0:
		print('NO')
		quit()
print('YES')


q = w = 0
n = int(input())
a = list(input().split())
for i in range(len(a)):
	if int(a[i]) == 25:
		q += 1
	elif int(a[i]) == 50:
		w += 1
		if q > 0:
			q -= 1
		else:
			print('NO')
			break
	elif w > 0 and q > 0:
		w -= 1
		q -= 1
	elif q > 2:
		q -= 3
	else:
		print('NO')
		break
else:
	print('YES')


input()
a = list(map(int, input().split()))
(cnt25, cnt50) = (0, 0)
for x in a:
	if x == 25:
		cnt25 += 1
	elif x == 50:
		cnt50 += 1
		cnt25 -= 1
		if cnt25 < 0:
			print('NO')
			exit(0)
	elif cnt50 > 0 and cnt25 > 0:
		cnt25 -= 1
		cnt50 -= 1
	else:
		cnt25 -= 3
		if cnt25 < 0:
			print('NO')
			exit(0)
print('YES')


n = int(input())
inp = input().split()
(t, f, h) = (0, 0, 0)
ok = True
for i in inp:
	i = int(i)
	if i == int(25):
		t += 1
	elif i == int(50):
		if t > 0:
			t -= 1
			f += 1
		else:
			ok = False
	elif i == int(100):
		if f > 0 and t > 0:
			f -= 1
			t -= 1
		elif t > 2:
			t -= 3
		else:
			ok = False
if ok:
	print('YES')
else:
	print('NO')


n = int(input())
l = list(map(int, input().split()))
b25 = 0
b50 = 0
lo = True
for b in l:
	if b == 25:
		b25 += 1
	elif b == 50:
		if b25 > 0:
			b25 -= 1
			b50 += 1
		else:
			lo = False
			print('NO')
			break
	elif b50 > 0 and b25 > 0:
		b50 -= 1
		b25 -= 1
	elif b25 > 2:
		b25 -= 3
	else:
		lo = False
		print('NO')
		break
if lo:
	print('YES')


n = int(input())
a = list(map(int, input().split()))
c25 = 0
c50 = 0
for i in range(n):
	if a[i] == 100:
		if c50 > 0:
			c50 -= 1
			a[i] -= 50
		while a[i] >= 25:
			a[i] -= 25
			c25 -= 1
		c25 += 1
	if a[i] == 25:
		c25 += 1
	if a[i] == 50:
		c50 += 1
		c25 -= 1
	if c25 < 0:
		print('NO')
		exit()
print('YES')


n = int(input())
arr = [int(i) for i in input().split()]
dic = {25: 0, 50: 0, 100: 0}
boo = True
for i in range(n):
	if arr[i] == 25:
		dic[25] += 1
	if arr[i] == 50 and dic[25] == 0:
		print('NO')
		boo = False
		break
	if arr[i] == 50 and dic[25] != 0:
		dic[25] -= 1
		dic[50] += 1
	if arr[i] == 100:
		if dic[25] < 3 and (dic[25] == 0 or dic[50] == 0):
			print('NO')
			boo = False
			break
		elif dic[25] != 0 and dic[50] != 0:
			dic[25] -= 1
			dic[50] -= 1
		else:
			dic[25] -= 3
if boo:
	print('YES')


N = int(input())
X = list(map(int, input().split()))
MyDict = {100: 0, 50: 0, 25: 0}
for i in range(N):
	Temp = X[i]
	X[i] -= 25
	for key in MyDict:
		Num = min(MyDict[key], X[i] // key)
		X[i] -= key * Num
		MyDict[key] -= Num
	if X[i] != 0:
		print('NO')
		exit()
	MyDict[Temp] += 1
print('YES')


input()
li = [int(x) for x in input().split()]
change = [0, 0]
for value in li:
	if value == 25:
		change[0] += 1
	elif value == 50:
		if change[0] > 0:
			change[0] -= 1
			change[1] += 1
		else:
			print('NO')
			break
	elif change[0] > 0:
		if change[1] > 0:
			change[0] -= 1
			change[1] -= 1
		elif change[0] > 2:
			change[0] -= 3
		else:
			print('NO')
			break
	else:
		print('NO')
		break
else:
	print('YES')


t = int(input())
l1 = list(map(int, input().strip().split()))[:t]
bal = 0
ct = 0
d1 = 0
d2 = 0
d3 = 0
for i in range(0, t):
	bal = bal + l1[i]
	if l1[i] == 25:
		d1 += 1
	if l1[i] == 50:
		d2 += 1
	if l1[i] == 100:
		d3 += 1
	x = l1[i] - 25
	if x > bal:
		ct += 1
		print('NO')
		break
	if x <= bal:
		if x == 75:
			if d1 == 0:
				ct += 1
				print('NO')
				break
			if d1 != 0:
				if d2 != 0:
					bal = bal - x
					d1 -= 1
					d2 -= 1
					continue
				if d2 == 0:
					if d1 >= 3:
						bal = bal - x
						d1 = d1 - 3
					else:
						ct += 1
						print('NO')
						break
		if x == 25:
			if d1 == 0:
				ct += 1
				print('NO')
				break
			else:
				bal = bal - x
				d1 -= 1
if ct == 0:
	print('YES')


def possible_change(l):
	twenty_fives = 0
	fivties = 0
	for currency in l:
		if currency == 25:
			twenty_fives += 1
		elif currency == 50:
			if twenty_fives >= 1:
				twenty_fives -= 1
				fivties += 1
			else:
				return 'NO'
		elif currency == 100:
			if twenty_fives >= 1 and fivties >= 1:
				fivties -= 1
				twenty_fives -= 1
			elif twenty_fives >= 3:
				twenty_fives -= 3
			else:
				return 'NO'
	return 'YES'

def main():
	first_line = input()
	first_line = first_line.split()
	n = int(first_line[0])
	l = input().split()
	for i in range(len(l)):
		l[i] = int(l[i])
	print(possible_change(l))
main()


def addDict(dict, num):
	if num not in dict:
		dict[num] = 1
	else:
		dict[num] += 1
n = int(input())
orders = list(map(int, input().split()))
dict = {}
for order in orders:
	if order == 25:
		addDict(dict, 25)
	elif order == 50:
		if 25 not in dict or dict[25] == 0:
			print('NO')
			exit()
		else:
			dict[25] -= 1
			addDict(dict, 50)
	elif order == 100:
		if 25 in dict and 50 in dict and (dict[25] > 0) and (dict[50] > 0):
			dict[25] -= 1
			dict[50] -= 1
		elif 25 in dict and dict[25] >= 3:
			dict[25] -= 3
		else:
			print('NO')
			exit()
		addDict(dict, 100)
print('YES')


n = int(input())
b = list(map(int, input().split()))
chng = [0, 0]
for i in range(n):
	if b[i] == 25:
		chng[0] += 1
	elif b[i] == 50:
		chng[1] += 1
		if chng[0] > 0:
			chng[0] -= 1
		else:
			print('NO')
			break
	elif chng[0] > 0 and chng[1] > 0:
		chng[0] -= 1
		chng[1] -= 1
	elif chng[0] > 2:
		chng[0] -= 3
	else:
		print('NO')
		break
else:
	print('YES')


n = int(input())
a = list(map(int, input().split(' ')))
twentyfives = 0
fifties = 0
hundreds = 0
success = True
for i in range(0, len(a)):
	if a[i] == 25:
		twentyfives += 1
	if a[i] == 50:
		if twentyfives > 0:
			twentyfives -= 1
		else:
			success = False
			break
		fifties += 1
	if a[i] == 100:
		if fifties > 0 and twentyfives > 0:
			fifties -= 1
			twentyfives -= 1
		elif twentyfives > 2:
			twentyfives -= 3
		else:
			success = False
			break
		hundreds += 1
if success:
	print('YES')
else:
	print('NO')


s = 0
s1 = 0
s2 = 0
s3 = 0
n = int(input())
a = list(map(int, input().split()))
for i in range(0, n):
	s = a[i]
	if s == 25:
		s1 = s1 + 1
	elif s == 50 and s1 >= 1:
		s1 = s1 - 1
		s2 = s2 + 1
	elif s == 50 and s1 < 1:
		s3 = 1
		break
	elif s == 100:
		if s2 >= 1 and s1 >= 1:
			s2 = s2 - 1
			s1 = s1 - 1
		elif s1 >= 3:
			s1 = s1 - 3
		else:
			s3 = 1
			break
if s3 == 1:
	print('NO')
else:
	print('YES')


n = int(input())
a = [int(x) for x in input().split()]
in_bank = {50: 0, 25: 0}
failed = False
for i in range(n):
	if a[i] == 25:
		in_bank[25] += 1
	elif a[i] == 50:
		in_bank[50] += 1
		in_bank[25] -= 1
		if in_bank[25] < 0:
			failed = True
			break
	elif in_bank[50] > 0 and in_bank[25] > 0:
		in_bank[50] -= 1
		in_bank[25] -= 1
	elif in_bank[25] >= 3:
		in_bank[25] -= 3
	else:
		failed = True
		break
if failed:
	print('NO')
else:
	print('YES')


n = int(input())
a = list(map(int, input().split()))
s = 0
d = 0
for i in a:
	if i == 25:
		s += 1
	if i == 50:
		if s == 0:
			print('NO')
			return
		else:
			s -= 1
			d += 1
	if i == 100:
		if d > 0 and s > 0:
			s -= 1
			d -= 1
		elif s > 2:
			s -= 3
		else:
			print('NO')
			return
print('YES')


banknotes_25 = 0
banknotes_50 = 0
banknotes_100 = 0
n = int(input())
bills = list(map(int, input().split()))
for bill in bills:
	if bill == 25:
		banknotes_25 += 1
	if bill == 50:
		if banknotes_25 == 0:
			print('NO')
			break
		else:
			banknotes_50 += 1
			banknotes_25 -= 1
	if bill == 100:
		if banknotes_50 == 0 and banknotes_25 < 3 or banknotes_25 == 0:
			print('NO')
			break
		elif banknotes_25 != 0 and banknotes_50 != 0:
			banknotes_100 += 1
			banknotes_25 -= 1
			banknotes_50 -= 1
		else:
			banknotes_100 += 1
			banknotes_25 -= 3
else:
	print('YES')


n = int(input())
l = list(map(int, input().split()))
c1 = 0
c2 = 0
c3 = 0
cond = True
for i in range(n):
	if l[i] == 25:
		c1 += 1
	elif l[i] == 50:
		if c1 >= 1:
			c1 -= 1
			c2 += 1
		else:
			print('NO')
			break
	elif l[i] == 100:
		if c1 >= 1 and c2 >= 1:
			c1 -= 1
			c2 -= 1
		elif c2 == 0 and c1 >= 3:
			c1 -= 3
		else:
			print('NO')
			break
else:
	print('YES')


n = int(input())
cnt = [0] * 110
s = ''
s = input()
s = s.split()
for i in range(n):
	a = int(s[i])
	cnt[a] += 1
	if a == 50:
		if cnt[25] >= 1:
			cnt[25] -= 1
		else:
			print('NO')
			exit(0)
	elif a == 100:
		if cnt[50] >= 1 and cnt[25] >= 1:
			cnt[50] -= 1
			cnt[25] -= 1
		elif cnt[25] >= 3:
			cnt[25] -= 3
		else:
			print('NO')
			exit(0)
print('YES')


_ = input()
small = 0
med = 0
for x in map(int, input().split()):
	if x == 25:
		small += 1
	elif x == 50:
		if small == 0:
			print('NO')
			break
		small -= 1
		med += 1
	elif med >= 1 and small >= 1:
		small -= 1
		med -= 1
	elif med == 0 and small >= 3:
		small -= 3
	else:
		print('NO')
		break
else:
	print('YES')


n = int(input())
d = dict()
a = list(map(int, input().split()))
result = 'YES'
for i in a:
	if i == 25:
		d[i] = d.get(i, 0) + 1
	elif i == 50:
		if d.get(25, 0) > 0:
			d[25] -= 1
			d[50] = d.get(50, 0) + 1
		else:
			result = 'NO'
			break
	elif i == 100:
		if d.get(50, 0) and d.get(25, 0):
			d[50] -= 1
			d[25] -= 1
			d[100] = d.get(100, 0) + 1
		elif d.get(25, 0) >= 3:
			d[25] -= 3
			d[100] = d.get(100, 0) + 1
		else:
			result = 'NO'
			break
print(result)


from sys import stdin, stdout, setrecursionlimit
input = stdin.readline
flush = stdout.flush
OUT = []

def write(item, sep=' '):
	if type(item) is int:
		OUT.append(str(item))
	elif type(item) is list:
		if type(item[0]) is int:
			OUT.append(sep.join(map(str, item)))
		else:
			OUT.append(sep.join(item))
	else:
		OUT.append(item)

def PRINT():
	print('\n'.join(OUT))
GI = lambda : int(input())
GS = lambda : input()[:-1]
gi = lambda : list(map(int, input().split()))
gs = lambda : input().split()
n = GI()
arr = gi()
bad = 0
question = 0
for i in arr:
	if i == 25:
		bad += 1
	elif i == 50:
		if bad == 0:
			write('NO')
			break
		bad -= 1
		question += 1
	elif question > 0 < bad:
		question -= 1
		bad -= 1
	elif bad > 2:
		bad -= 3
	else:
		write('NO')
		break
else:
	write('YES')
PRINT()


import sys
input = sys.stdin.readline
n = int(input())

def cashier(money, payment):
	if payment == 25:
		money[0] += 1
	elif payment == 50:
		if money[0]:
			money[0] -= 1
			money[1] += 1
		else:
			return False
	elif money[0] and money[1]:
		money[0] -= 1
		money[1] -= 1
		money[2] += 1
	elif money[0] > 2:
		money[0] -= 3
		money[2] += 1
	else:
		return False
	return True
money = [0] * 3
for payment in map(int, input().split()):
	if cashier(money, payment):
		continue
	else:
		print('NO')
		sys.exit()
print('YES')


n = int(input())
e = input()
a = [int(x) for x in e.split()]
(f, ff) = (0, 0)
flag = 1
for i in a:
	if i == 25:
		f += 1
	if i == 50:
		f -= 1
		ff += 1
		if f < 0:
			flag = 0
			break
	if i == 100:
		if ff >= 1:
			if f >= 1:
				ff -= 1
				f -= 1
			else:
				flag = 0
				break
		elif f < 3:
			flag = 0
			break
		else:
			f -= 3
if flag == 0:
	print('NO')
else:
	print('YES')


def solve():
	n = int(input())
	lst = list(map(int, input().split()))
	(c25, c50, c100) = (0, 0, 0)
	if lst[0] == 50 or lst[0] == 100:
		print('NO')
		return
	for i in range(len(lst)):
		if lst[i] == 25:
			c25 += 1
		elif lst[i] == 50:
			c50 += 1
			c25 -= 1
			if c25 < 0:
				c25 -= 100
				print('NO')
				return
		elif lst[i] == 100:
			if c50 > 0 and c25 > 0:
				c50 -= 1
				c25 -= 1
			elif c50 == 0 and c25 > 0:
				c25 -= 3
				if c25 < 0:
					c25 -= 100
					print('NO')
					return
			else:
				c25 -= 100
				print('NO')
				return
	if c25 >= 0:
		print('YES')
solve()


import math
_ = input()
customers = [int(i) for i in input().split(' ')]
cost = 25
bills = [100, 50, 25]
register = {100: 0, 50: 0, 25: 0}
possible = True
for customer in customers:
	diff = customer - cost
	count = diff
	for bill in bills:
		while register[bill] > 0 and diff - bill >= 0:
			diff -= bill
			register[bill] -= 1
	if diff > 0:
		possible = False
		break
	register[customer] += 1
if possible:
	print('YES')
else:
	print('NO')


n = int(input())
line = list(map(int, input().split()))
coins = {25: 0, 50: 0, 100: 0}
ans = 'YES'
for el in line:
	coins[el] += 1
	if el == 50:
		if coins[25] == 0:
			ans = 'NO'
			break
		else:
			coins[25] -= 1
	elif el == 100:
		if coins[50] * coins[25] > 0:
			coins[50] -= 1
			coins[25] -= 1
		elif coins[25] >= 3:
			coins[25] -= 3
		else:
			ans = 'NO'
			break
print(ans)


n = int(input())
a = list(map(int, input().split()))
n1 = 0
n2 = 0
n3 = 0
ans = True
for i in a:
	if i == 25:
		n1 += 1
	elif i == 50:
		if n1 > 0:
			n1 -= 1
			n2 += 1
		else:
			print('NO')
			ans = False
			break
	elif n2 >= 1 and n1 >= 1:
		n3 += 1
		n2 -= 1
		n1 -= 1
	elif n2 == 0 and n1 >= 3:
		n3 += 1
		n1 -= 3
	else:
		print('NO')
		ans = False
		break
if ans:
	print('YES')


from sys import *
from bisect import bisect_left
input = lambda : stdin.readline()
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)
n = int(input())
arr = int_arr()
dic = {25: 0, 50: 0, 100: 0}
for i in range(n):
	if arr[i] == 100:
		dic[100] += 1
		if dic[50] and dic[25]:
			dic[50] -= 1
			dic[25] -= 1
		elif dic[25] >= 3:
			dic[25] -= 3
		else:
			print('NO')
			break
	elif arr[i] == 50:
		dic[50] += 1
		if dic[25]:
			dic[25] -= 1
		else:
			print('NO')
			break
	else:
		dic[25] += 1
else:
	print('YES')


n = int(input())
A = list(map(int, input().split()))
cur1 = 0
cur2 = 0
cur3 = 0
p = 1
for i in range(len(A)):
	if A[i] == 25:
		cur1 += 1
	elif A[i] == 50:
		if cur1 == 0:
			print('NO')
			p = 0
			break
		else:
			cur1 -= 1
			cur2 += 1
	elif cur2 >= 1 and cur1 >= 1:
		cur2 -= 1
		cur1 -= 1
		cur3 += 1
	elif cur1 >= 3:
		cur1 -= 3
		cur3 += 1
	else:
		print('NO')
		p = 0
		break
if p:
	print('YES')


(a, b) = (input(), list(map(int, input().split())))
fifties = 0
twenties = 0
yes = 'YES'
for i in b:
	if i == 25:
		twenties += 1
	elif i == 50:
		if twenties > 0:
			twenties -= 1
			fifties += 1
		else:
			yes = 'NO'
	elif twenties > 0 and fifties > 0:
		twenties -= 1
		fifties -= 1
	elif twenties > 2:
		twenties -= 3
	else:
		yes = 'NO'
print(yes)


n = int(input())
str = input().split(' ')
sum = []
k1 = 0
k2 = 0
result = 'NO'
for k in range(len(str)):
	if str[k] == '25':
		k1 += 1
	if str[k] == '50':
		k2 += 1
		k1 += -1
	if str[k] == '100':
		if k2 <= 0:
			k1 += -3
		else:
			k1 += -1
			k2 += -1
	if k1 < 0 or k2 < 0:
		result = 'NO'
		break
	else:
		result = 'YES'
print(result)


def p():
	n = int(input())
	a = list(map(int, input().split()))
	(q, w) = (0, 0)
	for i in range(n):
		if a[i] == 25:
			q += 1
		elif a[i] == 50:
			if q >= 1:
				w += 1
				q -= 1
			else:
				return 'NO'
		elif q >= 1 and w >= 1:
			q -= 1
			w -= 1
		elif q >= 3:
			q -= 3
		else:
			return 'NO'
	return 'YES'
print(p())


def cinema_line(x):
	a = {25: 0, 50: 0, 100: 0}
	ans = 'YES'
	for i in x:
		a[i] += i
		if i != 25:
			if i == 50:
				if a[25] > 0:
					a[25] -= 25
				else:
					ans = 'NO'
			if i == 100:
				if a[25] > 0 and a[50] > 0:
					a[25] -= 25
					a[50] -= 50
				elif a[25] > 50:
					a[25] -= 75
				else:
					ans = 'NO'
	return ans
n = int(input())
b = list(map(int, input().split()))
print(cinema_line(b))


n = int(input())
lol25 = 0
lol50 = 0
arr = list(map(int, input().split()))
for k in arr:
	if k == 25:
		lol25 += 1
	elif k == 50:
		lol25 -= 1
		lol50 += 1
	elif lol50 > 0:
		lol50 -= 1
		lol25 -= 1
	else:
		lol25 -= 3
	if lol25 < 0:
		print('NO')
		exit()
print('YES')


n = int(input())
arr = list(map(int, input().split()))
n25 = 0
n50 = 0
poss = True
for i in range(n):
	if arr[i] == 25:
		n25 += 1
	elif arr[i] == 50:
		n50 += 1
		n25 -= 1
	elif n50 > 0:
		n25 -= 1
		n50 -= 1
	else:
		n25 -= 3
	if n25 < 0 or n50 < 0:
		poss = False
print('NO' if not poss else 'YES')


from sys import stdin, exit
n = int(stdin.readline().rstrip())
l = list(map(int, stdin.readline().split()))
(c1, c2, c3) = (0, 0, 0)
for i in range(n):
	if l[i] == 25:
		c1 += 1
	elif l[i] == 50 and c1 > 0:
		c1 -= 1
		c2 += 1
	elif l[i] == 100:
		if c1 > 0 and c2 > 0:
			c1 -= 1
			c2 -= 1
		elif c1 > 2:
			c1 -= 3
		else:
			print('NO')
			exit()
	else:
		print('NO')
		exit()
print('YES')


def f(l):
	a25count = 0
	a50count = 0
	for x in l:
		if x == 25:
			a25count += 1
		elif x == 50:
			if a25count == 0:
				return 'NO'
			else:
				a50count += 1
				a25count -= 1
		elif x == 100:
			if a50count > 0 and a25count > 0:
				a50count -= 1
				a25count -= 1
			elif a25count > 2:
				a25count -= 3
			else:
				return 'NO'
	return 'YES'
n = int(input())
print(f([int(x) for x in input().split()]))


n = int(input())
a = list(map(int, input().strip().split()))
b = 0
c = 0
d = 0
e = 0
if a[0] != 25:
	print('NO')
else:
	for i in range(n):
		if a[i] == 25:
			b = b + 1
		elif a[i] == 50:
			c = c + 1
			b = b - 1
		elif a[i] == 100:
			d = d + 1
			if c > 0:
				c = c - 1
				b = b - 1
			else:
				b = b - 3
		if c < 0 or b < 0 or d < 0:
			e = 1
			break
	if e == 0:
		print('YES')
	if e == 1:
		print('NO')


n = int(input())
a = list(map(int, input().split()))
sum = 0
if a[0] == 50 or a[0] == 100:
	print('NO')
	exit()
else:
	count25 = 0
	count50 = 0
	for i in a:
		if sum < 0:
			print('NO')
			exit()
		if i == 25:
			count25 += 1
		if i == 50:
			count25 -= 1
			count50 += 1
		if i == 100:
			if count50 >= 1 and count25 >= 1:
				count25 -= 1
				count50 -= 1
			else:
				count25 -= 3
	if count25 < 0 or count50 < 0:
		print('NO')
	else:
		print('YES')


import sys
f = sys.stdin
n = int(f.readline())
a = [int(i) for i in f.readline().strip().split(' ')]
note = {25: 0, 50: 0, 100: 0}
for i in a:
	if i == 25:
		note[25] += 1
	elif i == 50:
		if note[25] > 0:
			note[25] -= 1
			note[50] += 1
		else:
			print('NO')
			break
	elif i == 100:
		if note[50] > 0 and note[25] > 0:
			note[50] -= 1
			note[25] -= 1
			note[100] += 1
		elif note[25] > 2:
			note[25] -= 3
			note[100] += 1
		else:
			print('NO')
			break
else:
	print('YES')


n = int(input())
lst = list(map(int, input().rstrip().split()))
cnt25 = 0
cnt50 = 0
cnt100 = 0
sold = 0
for i in range(n):
	if lst[i] == 25:
		sold += 1
		cnt25 += 1
	elif lst[i] == 50:
		if cnt25 > 0:
			sold += 1
			cnt50 += 1
			cnt25 -= 1
		else:
			print('NO')
			break
	elif lst[i] == 100:
		if cnt50 > 0 and cnt25 > 0:
			cnt50 -= 1
			cnt25 -= 1
			sold += 1
		elif cnt25 > 2:
			cnt25 -= 3
			sold += 1
		else:
			print('NO')
			break
if sold == n:
	print('YES')


def f(query):
	d = {25: 0, 50: 0}
	for i in query:
		if i == '25':
			d[25] += 1
		elif i == '50':
			if d[25] == 0:
				return 'NO'
			d[50] += 1
			d[25] -= 1
		elif d[50] != 0 and d[25] != 0:
			d[50] -= 1
			d[25] -= 1
		elif d[25] > 2:
			d[25] -= 3
		else:
			return 'NO'
	return 'YES'
input()
print(f(input().split()))


import math
mod = 1000000007

def power(a, b):
	res = 1
	b = b % (mod - 1)
	while b > 0:
		if b % 2 != 0:
			res = res % mod * (a % mod) % mod
		b = b // 2
		a = a % mod
		a = a * a % mod
	res = res % mod
	return res
n = int(input())
a = [int(i) for i in input().split()]
a1 = 0
b = 0
c = 0
f = 1
for i in range(n):
	if a[i] == 50:
		if a1 > 0:
			a1 -= 1
			b += 1
		else:
			f = 0
			break
	elif a[i] == 100:
		if a1 > 0 and b > 0:
			a1 -= 1
			b -= 1
			c += 1
		elif a1 >= 3:
			a1 -= 3
			c += 1
		else:
			f = 0
			break
	else:
		a1 += 1
if f == 0:
	print('NO')
else:
	print('YES')


n = int(input())
a = list(map(int, input().split()))
x = y = z = 0
c = 0
for i in range(n):
	if a[i] == 25:
		x += 1
	elif a[i] == 50:
		if x > 0:
			y += 1
			x -= 1
		elif x <= 0:
			c = 1
			print('NO')
			break
	elif a[i] == 100:
		if y > 0:
			if x > 0:
				x -= 1
				y -= 1
				z += 1
			elif x <= 0:
				c = 1
				print('NO')
				break
		elif y < 1:
			if x >= 3:
				x -= 3
				z += 1
			else:
				c = 1
				print('NO')
				break
if c != 1:
	print('YES')


n = int(input())
c25 = 0
c50 = 0
b = True
for s in input().split():
	x = int(s)
	if x == 25:
		c25 += 1
	elif x == 50 and c25 > 0:
		c50 += 1
		c25 -= 1
	elif x == 100:
		if c50 > 0 and c25 > 0:
			c50 -= 1
			c25 -= 1
		elif c25 > 2:
			c25 -= 3
		else:
			b = False
			break
	else:
		b = False
		break
if b:
	print('YES')
else:
	print('NO')


n = int(input())
l = list(map(int, input().split(' ')))
(tf, ff, hh) = (0, 0, 0)
f = 1
for i in range(len(l)):
	if l[i] == 25:
		tf += 1
	elif l[i] == 50:
		if tf > 0:
			tf -= 1
			ff += 1
		else:
			print('NO')
			f = 0
			break
	elif l[i] == 100:
		if tf >= 1 and ff >= 1:
			tf -= 1
			ff -= 1
			hh += 1
		elif tf >= 3:
			tf -= 3
			hh += 1
		else:
			print('NO')
			f = 0
			break
if f == 1:
	print('YES')


n = int(input())
l = [int(i) for i in input().split()]
f = 1
req = -100
have_25_50 = [0] * 20
for i in l:
	if i == 25:
		have_25_50[0] += 1
	elif i == 50:
		if have_25_50[0] == 0:
			f = 0
			break
		have_25_50[1] += 1
		have_25_50[0] -= 1
	elif i == 100:
		if have_25_50[0] == 0:
			f = 0
			break
		have_25_50[0] -= 1
		if have_25_50[1] >= 1:
			have_25_50[1] -= 1
		elif have_25_50[0] >= 2:
			have_25_50[0] -= 2
		else:
			f = 0
			break
if f:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
notes = dict()
for i in (25, 50, 100):
	notes[i] = 0
isPossible = True
for i in a:
	if i == 25:
		notes[i] += 1
	elif i == 50:
		if notes[25] >= 1:
			notes[i] += 1
			notes[25] -= 1
		else:
			isPossible = False
			break
	elif notes[25] >= 1 and notes[50] >= 1:
		notes[i] += 1
		notes[25] -= 1
		notes[50] -= 1
	elif notes[25] >= 3:
		notes[i] += 1
		notes[25] -= 3
	else:
		isPossible = False
		break
if isPossible:
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
c = 0
c25 = 0
c50 = 0
for i in a:
	if i == 25:
		c25 += 1
	elif i == 50:
		if c25 >= 1:
			c25 -= 1
			c50 += 1
		else:
			print('NO')
			exit(0)
	elif c25 >= 1 and c50 >= 1:
		c50 -= 1
		c25 -= 1
	elif c25 >= 3:
		c25 -= 3
	else:
		print('NO')
		exit(0)
print('YES')


n = int(input())
line = [int(x) for x in input().split()]
bill = [0, 0, 0]
if line[0] != 25:
	print('NO')
else:
	judge = True
	for i in line:
		if i == 25:
			bill[0] += 1
		elif i == 50:
			bill[0] -= 1
			bill[1] += 1
			if bill[0] < 0:
				print('NO')
				judge = False
				break
		else:
			bill[2] += 1
			left = 100 - 50 * min(1, bill[1]) - 25
			bill[1] -= min(1, bill[1])
			bill[0] -= left // 25
			if bill[0] < 0:
				print('NO')
				judge = False
				break
	if judge == True:
		print('YES')


def main():
	n = int(input())
	ip = [int(item) for item in input().split(' ')]
	twentyFive = 0
	fifty = 0
	hunny = 0
	change = 0
	for i in range(len(ip)):
		if ip[i] == 100:
			if fifty >= 1 and twentyFive >= 1:
				fifty -= 1
				twentyFive -= 1
			elif twentyFive >= 3:
				twentyFive -= 3
			else:
				ret()
			hunny += 1
		elif ip[i] == 50:
			if twentyFive >= 1:
				twentyFive -= 1
			else:
				ret()
			fifty += 1
		else:
			twentyFive += 1
	print('YES')

def ret():
	print('NO')
	exit()
main()


dic = {25: 0, 50: 0, 100: 0}
n = int(input())
for i in input().split():
	if i == '25':
		dic[25] += 1
	elif i == '50':
		if dic[25] > 0:
			dic[25] -= 1
			dic[50] += 1
		else:
			print('NO')
			break
	elif dic[50] > 0 and dic[25] > 0:
		dic[25] -= 1
		dic[50] -= 1
		dic[100] += 1
	elif dic[25] > 2:
		dic[25] -= 3
		dic[100] += 1
	else:
		print('NO')
		break
else:
	print('YES')


n = int(input())
l = list(map(int, input().split()))
a25 = 0
a50 = 0
answer = 'YES'
for i in l:
	if i == 25:
		a25 += 1
	elif i == 50:
		if a25 == 0:
			answer = 'NO'
			break
		else:
			a25 -= 1
			a50 += 1
	elif a50 > 0 and a25 > 0:
		a50 -= 1
		a25 -= 1
	elif a25 > 2:
		a25 -= 3
	else:
		answer = 'NO'
		break
print(answer)


x = int(input())
stri = input().split()
bill = [int(p) for p in stri]
temp = 0
rem = [0, 0, 0]
for x in bill:
	if bill[0] != 25:
		temp = 0
		break
	if x == 25:
		rem[0] = rem[0] + 25
		temp = 1
	elif x == 50:
		if rem[0] != 0:
			rem[0] -= 25
			temp = 1
			rem[1] += 50
		else:
			temp = 0
			break
	else:
		if rem[1] >= 50 and rem[0] >= 25:
			rem[0] -= 25
			rem[1] -= 50
			temp = 1
		elif rem[0] >= 75:
			rem[0] -= 75
			temp = 1
		else:
			temp = 0
			break
		rem[2] = rem[2] + 100
if temp == 0:
	print('NO')
else:
	print('YES')


import math, os, sys
import string, re
from itertools import *
from collections import Counter
from operator import mul

def inputint():
	return int(input())

def inputarray(func=int):
	return map(func, input().split())

def inputarray2(n, func=int):
	for _ in range(n):
		yield func(input())
n = inputint()
A = map(lambda x: x // 25, inputarray())
(x25, x50) = (0, 0)
for v in A:
	if v == 1:
		x25 = x25 + 1
	elif v == 2:
		x50 = x50 + 1
		x25 = x25 - 1
	elif x50 > 0:
		x50 = x50 - 1
		x25 = x25 - 1
	else:
		x25 = x25 - 3
	if x25 < 0 or x50 < 0:
		print('NO')
		quit()
print('YES')


input()
c = [0] * 4
for i in input().split():
	if i == '50':
		if c[0] > 0:
			c[0] -= 1
		else:
			print('NO')
			quit()
	elif i == '100':
		if c[0] > 0 and c[1] > 0:
			c[0] -= 1
			c[1] -= 1
		elif c[0] >= 3:
			c[0] -= 3
		else:
			print('NO')
			quit()
	c[int(i) // 25 - 1] += 1
print('YES')


n = int(input())
a = list(map(int, input().split()))
dem25 = 0
dem50 = 0
check = True
for i in a:
	if i == 25:
		dem25 += 1
	elif i == 50:
		dem25 -= 1
		dem50 += 1
	elif dem50:
		dem50 -= 1
		dem25 -= 1
	else:
		dem25 -= 3
	if dem25 < 0:
		check = False
		break
print(['NO', 'YES'][check])


n = int(input())
x = y = z = 0
price = input().split()
for i in range(0, n, 1):
	if price[i] == '25':
		x += 2
	elif price[i] == '50':
		y += 1
	elif y:
		y -= 1
	else:
		x -= 2
	x -= 1
	if x < 0 or y < 0:
		z = 1
if z:
	print('NO')
else:
	print('YES')


n = int(input())
l = list(map(int, input().split()))
(p25, p50) = (0, 0)
for i in range(n):
	if l[i] == 25:
		p25 += 1
	else:
		if l[i] == 50:
			p50 += 1
			p25 -= 1
		elif p50 != 0:
			p50 -= 1
			p25 -= 1
		else:
			p25 -= 3
		if p25 < 0:
			print('NO')
			break
else:
	print('YES')


n = int(input())
line = list(map(int, input().split()))
twentyfive = 0
fifty = 0
if line[0] != 25:
	print('NO')
else:
	i = 0
	while i < n:
		if line[i] == 25:
			twentyfive += 1
		elif line[i] == 50:
			if twentyfive > 0:
				twentyfive -= 1
				fifty += 1
			else:
				print('NO')
				break
		elif twentyfive > 0 and fifty > 0:
			fifty -= 1
			twentyfive -= 1
		elif twentyfive >= 3 and fifty == 0:
			twentyfive -= 3
		else:
			print('NO')
			break
		i = i + 1
	if i == n:
		print('YES')


n = int(input())
a = input().split()
(x, y, z) = (0, 0, 0)
for i in range(0, n):
	a[i] = int(a[i])
	if a[i] == 25:
		x += 1
	if a[i] == 50:
		if x - 1 < 0:
			print('NO')
			exit()
		x -= 1
		y += 1
	if a[i] == 100:
		if not (x >= 3 or (x >= 1 and y >= 1)):
			print('NO')
			exit()
		if x >= 1 and y >= 1:
			x -= 1
			y -= 1
		else:
			x -= 3
		z += 1
print('YES')


a = int(input())
b = list(map(int, input().split()))
twf = 0
ft = 0
x = False
for i in range(len(b)):
	if b[i] == 25:
		twf = twf + 1
	elif b[i] == 50:
		if twf > 0:
			ft = ft + 1
			twf = twf - 1
		elif x == False:
			print('NO')
			x = True
	elif b[i] == 100:
		if ft > 0 and twf > 0:
			ft = ft - 1
			twf = twf - 1
		elif twf > 2:
			twf = twf - 3
		elif x == False:
			print('NO')
			x = True
if x == False:
	print('YES')


n = int(input())
a = list(map(int, input().split()))
dol25 = 0
dol50 = 0
ans = True
for x in a:
	if x == 50 and dol25 >= 1:
		dol50 += 1
		dol25 -= 1
		continue
	elif x == 100 and dol25 >= 1 and (dol50 >= 1):
		dol50 -= 1
		dol25 -= 1
		continue
	elif x == 100 and dol25 >= 3:
		dol25 -= 3
		continue
	elif x == 25:
		dol25 += 1
		continue
	ans = False
	break
if ans:
	print('YES')
else:
	print('NO')


n = int(input())
lis = list(map(int, input().split()))
count25 = 0
count50 = 0
b = True
for i in lis:
	if i == 25:
		count25 += 1
	elif i == 50:
		if count25 > 0:
			count25 -= 1
			count50 += 1
		else:
			print('NO')
			b = False
			break
	elif count50 > 0 and count25 > 0:
		count25 -= 1
		count50 -= 1
	elif count25 > 2:
		count25 -= 3
	else:
		print('NO')
		b = False
		break
if b:
	print('YES')


n = int(input())
a = b = c = 0
for i in map(int, input().split()):
	if i == 25:
		a += 1
	elif i == 50:
		b += 1
		a -= 1
	elif b:
		a -= 1
		b -= 1
	else:
		a -= 3
	if a < 0 or b < 0:
		c = 1
print(['YES', 'NO'][c == 1])


n = int(input())
flag = 1
bills = list(map(int, input().split()))
if bills[0] != 25:
	flag = 0
else:
	sum25 = 1
	sum50 = 0
	sum100 = 0
	for i in range(1, len(bills)):
		if bills[i] == 25:
			sum25 += 1
			continue
		elif bills[i] == 50:
			sum50 += 1
			if sum25 < 1:
				flag = 0
				break
			else:
				sum25 -= 1
				continue
		if bills[i] == 100:
			sum100 += 1
			if sum50 and sum25:
				sum50 -= 1
				sum25 -= 1
				continue
			elif sum50 < 1:
				if sum25 >= 3:
					sum25 -= 3
					continue
				else:
					flag = 0
					break
			else:
				flag = 0
				break
if flag:
	print('YES')
else:
	print('NO')


from sys import stdin

def main():
	x = int(stdin.readline().strip())
	lin = [int(u) for u in stdin.readline().strip().split()]
	b1 = 0
	b2 = 0
	flag = True
	for i in lin:
		if i == 25:
			b1 += 1
		elif i == 50:
			if b1 > 0:
				b1 -= 1
				b2 += 1
			else:
				print('NO')
				flag = False
				break
		elif i == 100:
			if b2 > 0 and b1 > 0:
				b2 -= 1
				b1 -= 1
			elif b1 >= 3:
				b1 -= 3
			else:
				print('NO')
				flag = False
				break
	if flag:
		print('YES')
main()


from sys import stdin

def main():
	n = int(stdin.readline().strip())
	n25 = n50 = 0
	for x in map(int, stdin.readline().strip().split()):
		if x == 25:
			n25 += 1
		elif x == 50:
			if n25:
				n25 -= 1
				n50 += 1
			else:
				return 'NO'
		elif n25:
			n25 -= 1
			if n50:
				n50 -= 1
			elif n25 > 1:
				n25 -= 2
			else:
				return 'NO'
		else:
			return 'NO'
	return 'YES'
print(main())


input()
cur = [0, 0]
for x in [int(x) for x in input().split()]:
	if x == 25:
		cur[0] += 1
	elif x == 50:
		if cur[0]:
			cur[0] -= 1
			cur[1] += 1
		else:
			print('NO')
			exit(0)
	elif cur[1] and cur[0]:
		cur[1] -= 1
		cur[0] -= 1
	elif cur[0] >= 3:
		cur[0] -= 3
	else:
		print('NO')
		exit(0)
print('YES')


I = lambda : map(int, input().split())
n = int(input())
a = I()
(h, h5) = (0, 0)
for i in a:
	if i > 25:
		if i == 100:
			if h5 != 0 and h != 0:
				h5 -= 50
				h -= 25
			elif h5 == 0 and h >= 75:
				h -= 75
			else:
				print('NO')
				exit(0)
		elif i == 50:
			if h < 25:
				print('NO')
				exit(0)
			else:
				h -= 25
				h5 += 50
	else:
		h += i
print('YES')


from sys import stdin
n = int(input())
l = list(map(int, stdin.readline().split()))
a = 0
b = 0
ans = 'YES'
if l[0] == 25:
	for e in l:
		if e == 25:
			a += 1
		elif e == 50:
			b += 1
			if a - 1 >= 0:
				a -= 1
			else:
				ans = 'NO'
				break
		elif a - 1 >= 0 and b - 1 >= 0:
			a -= 1
			b -= 1
		elif a - 3 >= 0:
			a -= 3
		else:
			ans = 'NO'
			break
	print(ans)
else:
	print('NO')


n = int(input())
s = list(map(int, input().split()))
(t, f) = (0, 0)
if s[0] != 25:
	print('NO')
else:
	for x in s:
		if x == 25:
			t += 1
		elif x == 50:
			if t >= 1:
				t -= 1
				f += 1
			else:
				print('NO')
				quit()
		elif f >= 1 and t >= 1:
			f -= 1
			t -= 1
		elif t >= 3:
			t -= 3
		else:
			print('NO')
			quit()
	print('YES')


n = int(input())
nums = [int(j) for j in input().split()]
(tf, f, h) = (0, 0, 0)
output = 'YES'
for j in range(n):
	t = nums[j]
	while nums[j] - 100 >= 25 and h > 0:
		nums[j] -= 100
		h -= 1
	while nums[j] - 50 >= 25 and f > 0:
		nums[j] -= 50
		f -= 1
	while nums[j] - 25 >= 25 and tf > 0:
		tf -= 1
		nums[j] -= 25
	if t == 25:
		tf += 1
	elif t == 50:
		f += 1
	else:
		h += 1
	if nums[j] != 25:
		output = 'NO'
		break
print(output)


x = int(input())
l = list(map(int, input().split()))
t = 0
f = 0
h = 0
for i in l:
	if i == 25:
		t += 1
	elif i == 50:
		if t >= 1:
			t -= 1
			f += 1
		else:
			break
	elif i == 100:
		if f >= 1 and t >= 1:
			f -= 1
			t -= 1
		elif t >= 3:
			t -= 3
		else:
			break
	h += 1
if h == x:
	print('YES')
else:
	print('NO')


input()
bills_25 = bills_50 = 0
for bill in input().split():
	if bill == '25':
		bills_25 += 1
	elif bill == '50':
		if bills_25:
			(bills_25, bills_50) = (bills_25 - 1, bills_50 + 1)
		else:
			print('NO')
			break
	elif bills_25:
		bills_25 -= 1
		if bills_50:
			bills_50 -= 1
		elif bills_25 >= 2:
			bills_25 -= 2
		else:
			print('NO')
			break
	else:
		print('NO')
		break
else:
	print('YES')


n = int(input())
data = [int(i) for i in input().split()]

def solve(data):
	s_25 = 0
	s_50 = 0
	s_100 = 0
	for i in range(len(data)):
		if data[i] == 25:
			s_25 += 1
		elif data[i] == 50 and s_25 >= 1:
			s_25 -= 1
			s_50 += 1
		elif data[i] == 100 and s_25 >= 1 and (s_50 >= 1):
			s_25 -= 1
			s_50 -= 1
			s_100 += 1
		elif data[i] == 100 and s_25 >= 3:
			s_25 -= 3
			s_100 += 1
		else:
			return False
	return True
print('YES' if solve(data) else 'NO')


n = int(input())
l = list(map(int, input().split(' ')))
c25 = 0
c50 = 0
good = True
for i in range(n):
	if l[i] == 25:
		c25 += 1
		needed = 0
	elif l[i] == 50:
		c50 += 1
		needed = 25
	else:
		needed = 75
	if needed > 0:
		if needed == 25:
			if c25 > 0:
				c25 -= 1
			else:
				good = False
				break
		elif c25 > 0 and c50 > 0:
			c25 -= 1
			c50 -= 1
		elif c25 > 2:
			c25 -= 3
		else:
			good = False
			break
if good:
	print('YES')
else:
	print('NO')