public static void process ( ) throws IOException {
  int n = ni ( ) ;
  int p [ ] = new int [ n ] ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    p [ i ] = ni ( ) ;
  }
  int a = 0 , b = 0 , c = 0 ;
  boolean f = true ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    if ( p [ i ] == 25 ) {
      a ++ ;
      continue ;
    }
    else {
      if ( p [ i ] == 50 ) {
        if ( a > 0 ) {
          a -- ;
          b ++ ;
          continue ;
        }
        else {
          f = false ;
          break ;
        }
      }
      else {
        if ( b >= 1 && a >= 1 ) {
          b -- ;
          a -- ;
          c ++ ;
          continue ;
        }
        else if ( a >= 3 ) {
          a -= 3 ;
          c ++ ;
          continue ;
        }
        else {
          f = false ;
          break ;
        }
      }
    }
  }
  if ( f ) {
    pn ( "YES" ) ;
  }
  else {
    pn ( "NO" ) ;
  }
}

public static void process ( ) throws IOException { int n = ni ( ) ; int p [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { p [ i ] = ni ( ) ; } int a = 0 , b = 0 , c = 0 ; boolean f = true ; for ( int i = 0 ; i < n ; i ++ ) { if ( p [ i ] == 25 ) { a ++ ; continue ; } else { if ( p [ i ] == 50 ) { if ( a > 0 ) { a -- ; b ++ ; continue ; } else { f = false ; break ; } } else { if ( b >= 1 && a >= 1 ) { b -- ; a -- ; c ++ ; continue ; } else if ( a >= 3 ) { a -= 3 ; c ++ ; continue ; } else { f = false ; break ; } } } } if ( f ) { pn ( " YES " ) ; } else { pn ( " NO " ) ; } }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters) (throws (type_identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation name: (identifier) arguments: (argument_list)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (boolean_type) declarator: (variable_declarator name: (identifier) value: (true))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) consequence: (block (expression_statement (update_expression (identifier))) (continue_statement)) alternative: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (update_expression (identifier))) (expression_statement (update_expression (identifier))) (continue_statement)) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (false))) (break_statement)))) alternative: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (block (expression_statement (update_expression (identifier))) (expression_statement (update_expression (identifier))) (expression_statement (update_expression (identifier))) (continue_statement)) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (update_expression (identifier))) (continue_statement)) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (false))) (break_statement)))))))))) (if_statement condition: (parenthesized_expression (identifier)) consequence: (block (expression_statement (method_invocation name: (identifier) arguments: (argument_list (string_literal))))) alternative: (block (expression_statement (method_invocation name: (identifier) arguments: (argument_list (string_literal))))))))