#include <bits/stdc++.h>
int cnt25, cnt50;
int n;
int main() {
  scanf("%d", &n);
  bool solved = true;
  for (int i = 0; i < n; ++i) {
    int t;
    scanf("%d", &t);
    if (t == 25) ++cnt25;
    if (t == 50) {
      if (cnt25 == 0) {
        solved = false;
        break;
      }
      --cnt25;
      ++cnt50;
    }
    if (t == 100) {
      if ((cnt25 == 0 || cnt50 == 0))
        if (cnt25 < 3) {
          solved = false;
          break;
        }
      if (cnt50) {
        --cnt50;
        --cnt25;
      } else {
        cnt25 -= 3;
      }
    }
  }
  printf("%s\n", solved ? "YES" : "NO");
}
