#include <bits/stdc++.h>
using namespace std;
int main() {
  bool noChange = false;
  int arr[100005];
  int n, k25, k50, k100;
  k25 = k50 = 0;
  scanf("%d", &n);
  for (int i = 0; i <= n - 1; i++) {
    scanf("%d", &arr[i]);
    if (arr[i] == 25)
      k25++;
    else if (arr[i] == 50) {
      if (k25 > 0) {
        k25--;
        k50++;
      } else {
        printf("NO\n");
        return 0;
      }
    } else if (arr[i] == 100) {
      if (k25 > 0 && k50 > 0) {
        k25--;
        k50--;
      } else if (k25 >= 3) {
        k25 -= 3;
      } else {
        printf("NO\n");
        return 0;
      }
    }
  }
  printf("YES\n");
}
