#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long i, n, sum = 0, flag = 0;
  cin >> n;
  long long arr[n];
  map<long long, long long> mp;
  for (i = 0; i < n; i++) {
    cin >> arr[i];
    mp[arr[i]]++;
    if (arr[i] == 50) {
      if (mp[25] > 0)
        mp[25]--;
      else
        flag = 1;
    }
    if (arr[i] == 100) {
      if (mp[50] > 0 && mp[25] > 0) {
        mp[50]--;
        mp[25]--;
      } else if (mp[25] >= 3) {
        mp[25] -= 3;
      } else
        flag = 1;
    }
  }
  if (flag == 1)
    cout << "NO\n";
  else
    cout << "YES\n";
  return 0;
}
