#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, num25 = 0, num50 = 0, num100 = 0;
  bool flag = 0;
  cin >> n;
  while (n--) {
    cin >> a;
    if (a == 25)
      num25++;
    else if (a == 50) {
      (num25) ? num25-- : flag = 1;
      num50++;
    } else if (a == 100) {
      if (num50) {
        num50--;
        (num25) ? num25-- : flag = 1;
      } else {
        (num25) ? num25-- : flag = 1;
        (num25) ? num25-- : flag = 1;
        (num25) ? num25-- : flag = 1;
      }
      num100++;
    }
  }
  if (flag)
    cout << "NO\n";
  else
    cout << "YES\n";
  return 0;
}
