#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v;
  int change25 = 0;
  int change50 = 0;
  while (n--) {
    int x;
    cin >> x;
    v.push_back(x);
  }
  if (v[0] != 25) {
    cout << "NO" << endl;
    return 0;
  }
  for (int i = 0; i < v.size(); ++i) {
    if (v[i] == 25) {
      change25 += 25;
    }
    if (v[i] == 50) {
      change25 = change25 - (v[i] - 25);
      change50 += 50;
    }
    if (v[i] == 100) {
      if (change50 != 0 && change50 > 0) {
        change50 = change50 - 50;
        change25 = change25 - 25;
      } else {
        change25 = change25 - 75;
      }
    }
    if (change25 < 0) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}
