#include <bits/stdc++.h>
using namespace std;
int n;
int a, b, c = 0;
int main() {
  while (scanf("%d", &n) != EOF) {
    int x;
    bool fff = 0;
    a = b = c = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d", &x);
      if (fff) continue;
      if (x == 25)
        a++;
      else if (x == 50)
        b++;
      else if (x == 100)
        c++;
      if (x == 50) {
        a--;
        if (a < 0) fff = 1;
      } else if (x == 100) {
        if (b >= 1 && a >= 1) {
          b--;
          a--;
        } else if (a >= 3) {
          a -= 3;
        } else
          fff = 1;
      }
    }
    if (fff)
      puts("NO");
    else
      puts("YES");
  }
  return 0;
}
