#include <bits/stdc++.h>
int main() {
  int i, n, money[100000], count25, count50, flag;
  while (scanf("%d", &n) != EOF) {
    count25 = 0;
    count50 = 0;
    flag = 0;
    for (i = 0; i < n; i++) scanf("%d", &money[i]);
    for (i = 0; i < n; i++) {
      if (money[i] == 25) count25++;
      if (money[i] == 50) {
        count25--;
        count50++;
      }
      if (money[i] == 100) {
        if (count50 > 0) {
          count50--;
          count25--;
        } else
          count25 -= 3;
      }
      if (count25 < 0 || count50 < 0) flag = 1;
    }
    if (flag)
      printf("NO\n");
    else
      printf("YES\n");
  }
  return 0;
}
