#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, s1 = 0, s2 = 0, s3 = 0, flag = 0;
  do {
    cin >> n;
  } while (n < 1 or n > pow(10, 5));
  int *a = new int[n];
  for (i = 0; i < n; i++) {
    do {
      cin >> a[i];
    } while (a[i] != 25 and a[i] != 50 and a[i] != 100);
    if (a[i] == 25) s1 += 1;
    if (a[i] == 50) {
      s1 -= 1;
      if (s1 < 0)
        flag = 1;
      else {
        s2 += 1;
      }
    }
    if (a[i] == 100) {
      if (s2 > 0 and s1 > 0) {
        s1 -= 1;
        s2 -= 1;
        s3 += 1;
      } else {
        if (s2 <= 0 and s1 >= 3) {
          s1 -= 3;
          s3 += 1;
        } else
          flag = 1;
      }
    }
  }
  if (flag == 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
