#include <bits/stdc++.h>
using namespace std;
int a[1000000];
int main() {
  int n, i, j, s1 = 0, s2 = 0, p = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    if (a[i] == 25) {
      s1++;
      continue;
    }
    if (a[i] == 50) {
      s1--;
      s2++;
    }
    if (a[i] == 100) {
      if (s2 <= 0) {
        if (s1 >= 3)
          s1 = s1 - 3;
        else
          p = 1;
      } else if (s2 >= 1) {
        if (s1 >= 1) {
          s1--;
          s2--;
        } else
          p = 1;
      }
    }
    if (p == 1) {
      printf("NO\n");
      break;
    } else if (s1 < 0) {
      p = 1;
      printf("NO\n");
      break;
    }
  }
  if (p == 0) printf("YES\n");
  return 0;
}
