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