#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, no, sum1 = 0, sum2 = 0, flag = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &no);
    if (no == 25)
      sum1++;
    else if (no == 50) {
      sum1--;
      sum2++;
    } else {
      if (sum2 > 0) {
        sum2--, sum1--;
      } else
        sum1 -= 3;
    }
    if (sum1 < 0) flag = 1;
  }
  if (flag)
    printf("NO\n");
  else
    printf("YES\n");
  return 0;
}
