#include <bits/stdc++.h>
int main() {
  int N;
  while (~scanf("%d", &N)) {
    int a = 0, b = 0, c = 0, d, flag = 1;
    for (int i = 0; i < N; i++) {
      scanf("%d", &d);
      if (d == 25) {
        a++;
      } else if (d == 50) {
        a--;
        if (a < 0) flag = 0;
        b++;
      } else if (d == 100) {
        a--;
        if (b > 0)
          b--;
        else
          a -= 2;
        if (b < 0) flag = 0;
        if (a < 0) flag = 0;
        c++;
      }
    }
    if (flag == 0)
      printf("NO\n");
    else
      printf("YES\n");
  }
  return 0;
}
