#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, tf = 0, f = 0, hun = 0;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 25)
      tf++;
    else if (a[i] == 50) {
      f++;
      tf--;
    } else {
      hun++;
      if (f >= 1) {
        f--;
        tf--;
      } else
        tf = tf - 3;
    }
    if (tf < 0) {
      cout << "NO";
      break;
    }
  }
  if (tf >= 0) cout << "YES";
  return 0;
}
