#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[100001];
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  bool flag = 1;
  int n25 = 0, n50 = 0, n100 = 0;
  for (int i = 0; i < n; ++i) {
    if (flag) {
      if (a[i] == 25)
        ++n25;
      else if (a[i] == 50) {
        ++n50;
        if (n25 == 0)
          flag = 0;
        else
          --n25;
      } else {
        ++n100;
        if (n50 && n25)
          --n50, --n25;
        else if (n25 > 2)
          n25 -= 3;
        else
          flag = 0;
      }
    }
  }
  cout << (flag ? "YES" : "NO") << endl;
}
