#include <bits/stdc++.h>
using namespace std;
long long int a, b, c, d, e, f, g, i, j, k, l, m, n, o, p, q, r, s, t, x, y, z;
string s1, s2, s3;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  vector<long long int> v;
  cin >> n;
  long long int a[n], b[155] = {0};
  p = 0;
  for (i = 0; i < n; i = i + 1) {
    cin >> a[i];
    if (a[0] != 25 && p == 0) {
      p = 1;
    } else if (a[i] == 25) {
      b[25]++;
    } else if (a[i] == 50) {
      if (b[25] > 0) {
        b[25]--;
      } else {
        p = 1;
      }
      b[50]++;
    } else {
      if (b[50] >= 1 && b[25] >= 1) {
        b[50]--, b[25]--;
      } else if (b[50] < 1 && b[25] >= 3) {
        b[25] -= 3;
      } else
        p = 1;
    }
  }
  if (p)
    cout << "NO";
  else
    cout << "YES";
}
