#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, i, j, k, a, b, c, d;
  while (scanf("%ld", &n) == 1) {
    int val = 1;
    long tf = 0, fif = 0, hun = 0;
    for (i = 0; i < n; i++) {
      scanf("%ld", &a);
      if (a == 25)
        tf++;
      else if (a == 50 && tf == 0)
        val = 0;
      else if (a == 50 && tf != 0) {
        fif++;
        tf--;
      } else if (a == 100 && fif != 0 && tf == 0)
        val = 0;
      else if (a == 100 && tf < 3 && fif == 0)
        val = 0;
      else if (a == 100 && (tf >= 3 || fif != 0) && tf != 0) {
        hun++;
        if (fif) {
          fif--;
          tf--;
        } else
          tf = tf - 3;
      }
    }
    if (val)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
