#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int h = 0;
  int t = 0;
  int f = 0;
  int c = 0;
  while (n-- && c != 1) {
    int a;
    cin >> a;
    if (a == 25) {
      t++;
    } else if (a == 50) {
      if (t > 0) {
        t--;
        f++;
      } else {
        c = 1;
      }
    } else {
      if (t >= 3 || (t > 0 && f > 0)) {
        if (t > 0 && f > 0) {
          t--;
          f--;
          h++;
        } else {
          t = t - 3;
          h++;
        }
      } else {
        c = 1;
      }
    }
  }
  if (c == 1) {
    cout << "NO";
  } else {
    cout << "YES";
  }
  return 0;
}
