#include <bits/stdc++.h>
using namespace std;
int main() {
  int size, x, rest25 = 0, rest50 = 0;
  string answer = "YES";
  cin >> size;
  for (int i = 0; i < size; i++) {
    cin >> x;
    if (x == 25)
      rest25++;
    else if (x == 50)
      rest25--, rest50++;
    else if (x == 100)
      if (rest50 > 0)
        rest50--, rest25--;
      else
        rest25 -= 3;
    if (rest25 < 0 || rest50 < 0) answer = "NO";
  }
  cout << answer << endl;
  return 0;
}
