#include <bits/stdc++.h>
using namespace std;
vector<long long int> prime;
unordered_set<long long int> stprime;
void sieve(long long int n) {
  bool p[n + 1];
  memset(p, true, sizeof(p));
  for (long long int i = 2; i * i <= n; i++) {
    if (p[i]) {
      for (int j = i * i; j <= n; j += i) {
        p[j] = false;
      }
    }
  }
  for (long long int i = 2; i <= n; i++) {
    if (p[i]) {
      prime.push_back(i);
      stprime.insert(i);
    }
  }
}
void solve() {
  long long int n;
  cin >> n;
  long long int t = 0, f = 0;
  bool flag = true;
  for (int i = 0; i < n; i++) {
    long long int a;
    cin >> a;
    if (a == 25) {
      t++;
    } else if (a == 50 && t >= 1) {
      f++;
      t--;
    } else if (a == 100) {
      if (f >= 1 && t >= 1) {
        f--;
        t--;
      } else if (t >= 3) {
        t -= 3;
      } else {
        flag = false;
      }
    } else {
      flag = false;
    }
  }
  if (flag) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
