#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  queue<int> arr;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    arr.push(temp);
  }
  int move = 0;
  int a25 = 0, a50 = 0, a100 = 0, flag = 0;
  while (move < n) {
    int bill = arr.front();
    if (bill == 25) {
      a25++;
    } else if (bill == 50) {
      if (a25 > 0) {
        a50++;
        a25--;
      } else {
        flag = -1;
        break;
      }
    } else if (bill == 100) {
      if (a25 >= 1 && a50 >= 1) {
        a25--;
        a50--;
      } else if (a25 >= 3) {
        a25 -= 3;
      } else {
        flag = -1;
        break;
      }
    }
    move++;
    arr.pop();
  }
  if (flag == -1) {
    cout << "NO";
  } else {
    cout << "YES";
  }
}
