#include <bits/stdc++.h>
using namespace std;
long long parent[1000001];
long long result[1000005];
map<int, list<int>> g;
long long getPoints(int p, int t) {
  return max((3 * p) / 10, (p - (p / 250) * t));
}
struct Score {
  int p, t;
};
bool chc(Score a, Score b) {
  if (a.p == b.p) {
    return a.t < b.t;
  } else {
    return a.p < b.p;
  }
}
void solve() {
  int n;
  cin >> n;
  int tf = 0, fifty = 0;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    int x = a[i];
    if (x == 25) {
      tf++;
    } else if (x == 50) {
      if (tf == 0) {
        cout << "NO\n";
        return;
      } else {
        tf--;
      }
      fifty++;
    } else if (x == 100) {
      if (fifty > 0 && tf > 0) {
        fifty--;
        tf--;
      } else if (tf > 2) {
        tf = tf - 3;
      } else {
        cout << "NO\n";
        return;
      }
    }
  }
  cout << "YES\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
