#include <bits/stdc++.h>
using namespace std;
const int N = 105;
bool compare(const pair<int, int>& i, const pair<int, int>& j) {
  return i.second < j.second;
}
void solve() {
  int n;
  cin >> n;
  int tf = 0, f = 0;
  int flag = 1;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x == 25)
      tf++;
    else if (x == 50) {
      f++;
      if (tf != 0)
        tf--;
      else {
        flag = 0;
        break;
      }
    } else {
      if (tf != 0 and f != 0) {
        tf--;
        f--;
      } else if (f == 0 and tf >= 3) {
        tf -= 3;
      } else {
        flag = 0;
        break;
      }
    }
  }
  if (flag)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  for (int i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
