#include <bits/stdc++.h>
const int INF = 2000000000;
const double PI = 3.14159265358979323846;
const unsigned long long MOD = 100000000000000000;
using namespace std;
int main() {
  int a[2] = {0};
  int n;
  cin >> n;
  for (int i(0); i < n; i++) {
    int b;
    cin >> b;
    if (b == 25) {
      a[0]++;
    }
    if (b == 50) {
      if (a[0] > 0) {
        a[0]--;
        a[1]++;
      } else {
        cout << "NO";
        return 0;
      }
    }
    if (b == 100) {
      if (a[0] > 0 && a[1] > 0) {
        a[0]--;
        a[1]--;
      } else {
        if (a[0] >= 3) {
          a[0] -= 3;
        } else {
          cout << "NO";
          return 0;
        }
      }
    }
  }
  cout << "YES";
}
