#include <bits/stdc++.h>
using namespace std;
int main() {
  long long num;
  cin >> num;
  vector<long long> arr(num);
  for (long long i = 0; i < num; i++) cin >> arr[i];
  long long change_25 = 0, change_50 = 0, trigger = 0;
  for (long long i = 0; i < num; i++) {
    if (arr[i] == 50) {
      if (change_25 > 0) {
        change_25--;
      } else {
        trigger = 1;
        break;
      }
      change_50 += 1;
    } else if (arr[i] == 100) {
      if ((change_25 > 0 && change_50 > 0)) {
        change_25--;
        change_50--;
      } else if (change_25 >= 3) {
        change_25 = change_25 - 3;
      } else {
        trigger = 1;
        break;
      }
    } else {
      change_25 += 1;
    }
  }
  if (trigger == 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
