#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n;
  vector<int> v;
  int a[3] = {0};
  for (int i = 0; i < n; i++) {
    cin >> m;
    v.push_back(m);
  }
  int d = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] == 25) {
      a[0]++;
    } else if (v[i] == 50) {
      if (a[0] > 0) {
        a[0]--;
        a[1]++;
      } else {
        cout << "NO";
        return 0;
      }
    } else {
      if (a[0] > 0 && a[1] > 0) {
        a[2]++;
        a[1]--;
        a[0]--;
      } else if (a[0] > 2) {
        a[0] -= 3;
        a[2]++;
      } else {
        cout << "NO";
        return 0;
      }
    }
  }
  cout << "YES";
  return 0;
}
