#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  if (a[0] == 50 || a[0] == 100) {
    cout << "NO";
    return 0;
  } else {
    int t = 0, f = 0, h = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == 25)
        t++;
      else if (a[i] == 50) {
        f++;
        t--;
        if (t < 0) {
          cout << "NO";
          return 0;
        }
      } else if (a[i] == 100) {
        if (t >= 3 && f == 0)
          t = t - 3;
        else {
          f--;
          t--;
          if (f < 0 || t < 0) {
            cout << "NO";
            return 0;
          }
        }
      }
    }
    cout << "YES";
  }
}
