#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for (long long int i = 0; i < n; i++) cin >> a[i];
  long long int c25 = 0, c50 = 0, c100 = 0, flag = 1;
  for (long long int i = 0; i < n; i++) {
    if (a[i] == 25) {
      c25++;
    } else if (a[i] == 50) {
      c25--;
      c50++;
      if (c25 < 0) {
        flag = 0;
        break;
      }
    } else {
      c100++;
      if (c50 > 0) {
        c50--;
        if (c25 > 0)
          c25--;
        else {
          flag = 0;
          break;
        }
      } else {
        c25 -= 3;
        c100++;
        if (c25 < 0) {
          flag = 0;
          break;
        }
      }
    }
  }
  if (flag)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
