#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  vector<int> c(n);
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  int bal = 0;
  int flag = 0;
  int cnt25 = 0, cnt50 = 0, cnt100 = 0;
  for (int i = 0; i < n; i++) {
    if (c[i] == 25) {
      cnt25++;
    }
    if (c[i] == 50) {
      cnt50++;
      if (cnt25 != 0) {
        cnt25--;
        continue;
      }
      flag = 1;
      break;
    }
    if (c[i] == 100) {
      cnt100++;
      if (cnt25 != 0 && cnt50 != 0) {
        cnt25--;
        cnt50--;
      } else if (cnt25 >= 3) {
        cnt25 -= 3;
      } else {
        flag = 1;
        break;
      }
    }
  }
  if (flag == 1) {
    cout << "NO";
  } else
    cout << "YES";
  return 0;
}
