#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, x, change = 0, change2 = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    if (x == 25) {
      change++;
      continue;
    } else if (x == 50 && change > 0) {
      change2++;
      change--;
      continue;
    } else if (change > 0) {
      if (change2) {
        x -= 50;
        change2--;
      }
      change -= ((x / 25) - 1);
      continue;
    }
    cout << "NO" << endl;
    return 0;
  }
  if (change >= 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}
