#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, x = 0, y = 0, z = 0, a, sum = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a;
    if (a == 25) x++;
    if (a == 50) {
      y++;
      x--;
    }
    if (a == 100) {
      z++;
      x--;
      if (y >= 1)
        y--;
      else
        x = x - 2;
    }
    if (x < 0) {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
}
