#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a;
  cin >> n;
  int sum = 0, cnt = 0, t5 = 0, ft = 0, hd = 0, counter = 0;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }
  for (int i = 0; i < n; i++) {
    if (v[i] == 25) {
      t5++;
    }
    if (v[i] == 50) {
      if (t5 > 0) {
        t5--;
        ft++;
      } else
        cnt = 1;
    }
    if (v[i] == 100) {
      if (ft > 0 && t5 > 0) {
        ft--;
        t5--;
      } else if (t5 >= 3) {
        t5 -= 3;
      } else
        cnt = 1;
    }
  }
  if (cnt == 1)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
}
