#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, sum, sum1, sum2, sum3;
  sum = 0;
  sum1 = 1;
  sum2 = 0;
  sum3 = 0;
  cin >> n;
  int *arr = new int[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  if (arr[0] != 25) {
    cout << "NO" << endl;
    return 0;
  } else
    for (int j = 1; j < n; j++) {
      if (arr[j] == 25) {
        sum1++;
      } else if (arr[j] == 50) {
        sum2++;
        if (sum1 >= 1) {
          sum1--;
        } else {
          cout << "NO" << endl;
          return 0;
        }
      } else if (arr[j] == 100) {
        sum3++;
        if ((sum2 >= 1 && sum1 >= 1)) {
          sum2--;
          sum1--;
        } else if (sum1 >= 3)
          sum1 -= 3;
        else {
          cout << "NO" << endl;
          return 0;
        }
      }
    }
  cout << "YES" << endl;
  return 0;
}
