n = int(input())
inp = list(map(int, input().split()))
s = True
cnt_25 = 0
cnt_50 = 0
for i in inp:
if i==25:
cnt_25 += 1
elif i==50 and cnt_25>0:
cnt_25-=1
cnt_50 += 1
elif i==100:
if (cnt_25 > 0 and cnt_50 > 0):
cnt_25 -= 1
cnt_50 -= 1
elif (cnt_25>2):
cnt_25 -= 3
else:
s = False
break
else:
s = False
break
print("YES" if s else "NO")
#include<bits/stdc++.h>
#define fastin cin.tie(0); cout.tie(0); cin.sync_with_stdio(0); cout.sync_with_stdio(0);
#define ll long long
#define int long long
#define endl '\n'
#define loop(i,start,n) for(int i=start;i<n;i++)
#define sz(a) a.size()
#define all(v) v.begin(), v.end()
using namespace std;
void solve()
{
int n,x,a25=0,a50=0,a100=0; cin >> n;
bool flag=1;
loop(i,0,n)
{
cin >> x;
if(x==25) a25++;
else
{
if(x==50)
{
if(a25==0)
{
flag=0;
continue;
}
else
{
a25--;
a50++;
}
}
else
{
if(a25<1)
{
flag=0;
continue;
}
else if(a50==0 && a25<3)
{
flag=0;
continue;
}
else
{
if(a50>0)
{
a50--;
a25--;
a100++;
}
else
{
a25-=3;
a100++;
}
}
}
}
}
flag? cout << "YES\n" : cout << "NO\n";
}
signed main()
{
fastin;
int tc = 1; //cin >> tc;
while (tc--)
solve();
}
1159A - A pile of stones | 508A - Pasha and Pixels |
912A - Tricky Alchemy | 1249A - Yet Another Dividing into Teams |
1713C - Build Permutation | 1699A - The Third Three Number Problem |
1617B - GCD Problem | 841A - Generous Kefa |
1690B - Array Decrements | 1692C - Where's the Bishop |
104A - Blackjack | 1438A - Specific Tastes of Andre |
1711C - Color the Picture | 1194C - From S To T |
110B - Lucky String | 1114A - Got Any Grapes |
224B - Array | 125B - Simple XML |
567B - Berland National Library | 431B - Shower Line |
282C - XOR and OR | 1582B - Luntik and Subsequences |
609A - Флеш-карты | 1207A - There Are Two Types Of Burgers |
371C - Hamburgers | 343B - Alternating Current |
758B - Blown Garland | 1681B - Card Trick |
1592A - Gamer Hemose | 493D - Vasya and Chess |