#include <bits/stdc++.h>
int main() {
  int n, money, c25 = 0, c50 = 0, flag = 1;
  scanf("%d", &n);
  while (n--) {
    scanf("%d", &money);
    if (money == 25)
      ++c25;
    else if (money == 50) {
      if (c25 > 0) {
        --c25;
        ++c50;
      } else {
        flag = 0;
        printf("NO");
        break;
      }
    } else if (money == 100) {
      if (c25 > 0 && c50 > 0) {
        --c25;
        --c50;
      } else if (c25 >= 3)
        c25 -= 3;
      else {
        flag = 0;
        printf("NO");
        break;
      }
    }
  }
  if (flag == 1) printf("YES");
  return 0;
}
