#include <bits/stdc++.h>
using namespace std;
bool check(int &f, int &t, int &flag) {
  if (f > 0 && t > 0) {
    f--;
    t--;
    return true;
  } else if (t >= 3) {
    t -= 3;
    return true;
  } else {
    flag = 0;
    return false;
  }
}
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; ++i) cin >> arr[i];
  int t = 0, f = 0;
  int flag = 1;
  for (int i = 0; i < n; ++i) {
    if (arr[i] == 25)
      t++;
    else if (arr[i] == 50) {
      f++;
      if (t < 1) {
        flag = 0;
        break;
      } else {
        t--;
      }
    } else {
      if (!check(f, t, flag)) {
        if (flag == 0) {
          break;
        }
      }
    }
  }
  if (flag == 0)
    cout << "NO";
  else
    cout << "YES";
}
