#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int maxn = 100100;
const double eps = 1e-6;
int n, m;
int main() {
  cin >> n;
  int ok = 1, s25 = 0, s50 = 0, s100 = 0;
  for (int i = 0; i < n; i++) {
    cin >> m;
    if (m == 25) {
      s25++;
    }
    if (m == 50) {
      if (s25 > 0) {
        s25--;
        s50++;
      } else {
        ok = 0;
      }
    }
    if (m == 100) {
      int ok50 = 0;
      if (s50 > 0) {
        s50--;
        ok50 = 1;
      } else if (s25 > 2) {
        s25 -= 3;
        s100++;
      } else {
        ok = 0;
      }
      if (ok50) {
        if (s25 > 0) {
          s25--;
          s100++;
        } else {
          ok = 0;
        }
      }
    }
  }
  if (ok)
    cout << "YES" << endl;
  else {
    cout << "NO" << endl;
  }
}
