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