#include <bits/stdc++.h>
using namespace std;
void input_output() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
bool is_prime(long long n) {
  if (n < 2) return false;
  long long i;
  for (i = 2; i < (long long)sqrt(n) + 1; ++i) {
    if (n % i == 0) return false;
  }
  return true;
}
bool is_palindrome(string s) {
  int i;
  for (i = 0; i < (int)s.size() / 2; ++i) {
    if (s[i] != s[s.size() - i - 1]) return false;
  }
  return true;
}
int no_of_primes = 10;
vector<bool> prime(no_of_primes + 1, true);
vector<int> prime_nums;
void sieve_of_erat() {
  prime[0] = false;
  prime[1] = false;
  int i, j;
  for (i = 2; i < (int)sqrt(no_of_primes) + 1; ++i) {
    if (prime[i] == false) continue;
    j = 2 * i;
    while (j <= no_of_primes) {
      prime[j] = false;
      j += i;
    }
  }
  for (i = 0; i < no_of_primes + 1; ++i) {
    if (prime[i] == true) prime_nums.push_back(i);
  }
}
void swap(int &a, int &b) {
  int temp = a;
  a = b;
  b = temp;
}
bool sort_rev(int a, int b) { return a > b; }
void solve() {
  int n;
  cin >> n;
  int arr[n];
  int i, j;
  for (i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  int change[3] = {0};
  for (i = 0; i < n; ++i) {
    if (arr[i] == 25) {
      ++change[0];
    } else if (arr[i] == 50) {
      if (change[0] >= 1)
        --change[0], ++change[1];
      else
        break;
    } else if (arr[i] == 100) {
      if (change[1] >= 1 && change[0] >= 1)
        --change[0], --change[1], ++change[2];
      else if (change[0] >= 3)
        change[0] -= 3, ++change[2];
      else
        break;
    }
  }
  if (i == n)
    cout << "YES";
  else
    cout << "NO";
  cout << '\n';
}
int32_t main() {
  input_output();
  solve();
  return 0;
}
