#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
void solve() {
  int n;
  cin >> n;
  map<int, int> m;
  m.insert(make_pair(25, 0));
  m.insert(make_pair(50, 0));
  m.insert(make_pair(100, 0));
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x == 25)
      m[0] += 1;
    else if (x == 50) {
      m[1] += 1;
      if (m[0] >= 1)
        m[0] -= 1;
      else {
        cout << "NO";
        return;
      }
    } else {
      m[2] += 1;
      if (m[1] >= 1 && m[0] >= 1) {
        m[1] -= 1;
        m[0] -= 1;
      } else if (m[0] >= 3)
        m[0] -= 3;
      else {
        cout << "NO";
        return;
      }
    }
  }
  cout << "YES";
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) solve();
  return 0;
}
