#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t, a = 0, b = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> t;
    if (t == 25)
      a++;
    else if (t == 50) {
      b++;
      a--;
      if (a < 0 || b < 0) {
        cout << "NO" << endl;
        return 0;
      }
    } else if (t == 100) {
      if (b - 1 < 0) {
        a -= 3;
      } else {
        b--;
        a--;
      }
      if (a < 0) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
  return 0;
}
