#include <bits/stdc++.h>
using namespace std;
int main() {
  int k25 = 0, k50 = 0, n;
  cin >> n;
  bool f = 1;
  for (int i = 0; i < n; i++) {
    int q;
    cin >> q;
    if (q == 25)
      k25++;
    else if (q == 50) {
      if (k25) {
        k25--;
        k50++;
      } else
        f = 0;
    } else {
      if (k50 && k25) {
        k25--;
        k50--;
      } else if (k25 >= 3)
        k25 -= 3;
      else
        f = 0;
    }
  }
  if (f)
    cout << "YES";
  else
    cout << "NO";
}
