#include <bits/stdc++.h>
using namespace std;
void func() {
  int n, am25 = 0, am50 = 0, am100 = 0, x;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x == 25) {
      am25++;
      continue;
    } else if (x == 50) {
      if (am25 > 0) {
        am25--;
        am50++;
      } else {
        cout << "NO";
        return;
      }
    } else {
      if (am50 > 0 && am25 > 0) {
        am50--;
        am25--;
      } else if (am25 >= 3) {
        am25 -= 3;
      } else {
        cout << "NO";
        return;
      }
    }
  }
  cout << "YES";
}
int main() {
  func();
  return 0;
}
