#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int count25 = 0, count50 = 0, count100 = 0;
  for (int i = 0; i < n; i++) {
    int num;
    cin >> num;
    if (num == 25)
      count25++;
    else if (num == 50)
      if (count25 > 0) {
        count25--;
        count50++;
      } else {
        cout << "NO";
        return 0;
      }
    else {
      if (count50 > 0 && count25 > 0) {
        count100++;
        count50--;
        count25--;
      } else if (count25 >= 3) {
        count25 -= 3;
        count100++;
      } else {
        cout << "NO";
        return 0;
      }
    }
  }
  cout << "YES";
}
