#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int t;
  int a = 0, b = 0, c = 0;
  int flag = 0;
  for (int i = 0; i < (n); i++) {
    cin >> t;
    if (t == 25) {
      a++;
    } else if (t == 50) {
      if (a <= 0) {
        cout << "NO" << endl;
        return 0;
      } else {
        a--;
        b++;
      }
    } else if (t == 100) {
      if (a > 0 && b > 0) {
        a--;
        b--;
        c++;
      } else if (a >= 3) {
        a -= 3;
        c++;
      } else {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
}
