#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  int count25 = 0;
  int count50 = 0;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] == 25) {
      count25++;
    } else if (arr[i] == 50) {
      if (count25 > 0) {
        count25--;
        count50++;
      } else {
        ans = -1;
      }
    } else if (arr[i] == 100) {
      if ((count25 > 0 && count50 > 0) || (count25 >= 3 && count50 == 0)) {
        if (count50 == 0) {
          count25--;
          count25--;
          count25--;
        } else {
          count25--;
          count50--;
        }
      } else {
        ans = -1;
      }
    }
  }
  if (ans == -1) {
    cout << "NO";
  } else {
    cout << "YES";
  }
  cout << endl;
  return 0;
}
