#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int s1 = 0, s2 = 0;
  int a;
  bool b = 1;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    if (a == 25)
      s1++;
    else if (a == 50) {
      if (s1 > 0) {
        s1--;
        s2++;
      } else {
        b = 0;
      }
    } else if (a == 100) {
      if (s2 > 0 && s1 > 0) {
        s2--;
        s1--;
      } else if (s1 > 2) {
        s1 -= 3;
      } else {
        b = 0;
      }
    }
  }
  if (b)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
