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