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