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