#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 19;
long long n, a[MAXN];
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  long long r100 = 0, r50 = 0, r25 = 0;
  bool hp = false;
  for (int i = 0; i < n; i++) {
    if (a[i] == 25) r25++;
    if (a[i] == 50 and r25 > 0) {
      r25--;
      r50++;
      a[i] = 0;
    }
    if (a[i] == 100) {
      if (r25 >= 1 and r50 >= 1) {
        r25--;
        r50--;
        a[i] = 0;
      } else if (r25 > 2 and r50 <= 0) {
        r25 -= 3;
        a[i] = 0;
      } else
        hp = true;
    }
    if (a[i] == 50 and r25 <= 0) hp = true;
  }
  if (hp == false)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  cerr << "r25"
       << " : " << r25 << "  "
       << "r50"
       << " : " << r50 << endl;
  ;
  return 0;
}
