#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k;
  cin >> n;
  int a_25 = 0;
  int a_50 = 0;
  bool b = true;
  while (n > 0) {
    cin >> k;
    if (k == 100) {
      if (a_50 > 0 && a_25 > 0) {
        a_50--;
        a_25--;
      } else if (a_25 >= 3) {
        a_25 -= 3;
      } else {
        b = false;
        break;
      }
    }
    if (k == 50) {
      if (a_25 > 0) {
        a_25--;
        a_50++;
      } else {
        b = false;
        break;
      }
    }
    if (k == 25) {
      a_25++;
    }
    n--;
  }
  if (b == 1) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
