#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, i;
  cin >> n;
  int arr[100005];
  for (i = 0; i < n; i++) cin >> arr[i];
  int c25 = 0, c50 = 0, f = 1;
  for (i = 0; i < n; i++) {
    if (arr[i] == 25)
      ++c25;
    else if (arr[i] == 50) {
      ++c50;
      if (c25 > 0)
        --c25;
      else {
        f = 0;
        break;
      }
    } else {
      if (c50 > 0 && c25 > 0) {
        --c50;
        --c25;
      } else if (c25 >= 3)
        c25 -= 3;
      else {
        f = 0;
        break;
      }
    }
  }
  if (f == 1)
    cout << "YES";
  else
    cout << "NO";
}
