public static void main ( String [ ] args ) {
  Scanner scan = new Scanner ( System . in ) ;
  int N = scan . nextInt ( ) ;
  int [ ] t = new int [ N ] ;
  for ( int i = 0 ;
  i < N ;
  i ++ ) {
    t [ i ] = scan . nextInt ( ) ;
  }
  scan . close ( ) ;
  if ( N == 1 ) {
    System . out . println ( t [ 0 ] ) ;
  }
  else if ( N == 2 ) {
    System . out . println ( Math . max ( t [ 0 ] , t [ 1 ] ) ) ;
  }
  else if ( N == 3 ) {
    Arrays . sort ( t ) ;
    System . out . println ( Math . max ( t [ 0 ] + t [ 1 ] , t [ 2 ] ) ) ;
  }
  else {
    Arrays . sort ( t ) ;
    if ( t [ 3 ] >= t [ 0 ] + t [ 1 ] + t [ 2 ] ) {
      System . out . println ( t [ 3 ] ) ;
      return ;
    }
    if ( t [ 0 ] + t [ 3 ] > t [ 0 ] + t [ 1 ] + t [ 2 ] ) {
      System . out . println ( t [ 0 ] + t [ 1 ] + t [ 2 ] ) ;
      return ;
    }
    System . out . println ( Math . max ( t [ 0 ] + t [ 3 ] , t [ 1 ] + t [ 2 ] ) ) ;
  }
}

public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; int [ ] t = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { t [ i ] = scan . nextInt ( ) ; } scan . close ( ) ; if ( N == 1 ) { System . out . println ( t [ 0 ] ) ; } else if ( N == 2 ) { System . out . println ( Math . max ( t [ 0 ] , t [ 1 ] ) ) ; } else if ( N == 3 ) { Arrays . sort ( t ) ; System . out . println ( Math . max ( t [ 0 ] + t [ 1 ] , t [ 2 ] ) ) ; } else { Arrays . sort ( t ) ; if ( t [ 3 ] >= t [ 0 ] + t [ 1 ] + t [ 2 ] ) { System . out . println ( t [ 3 ] ) ; return ; } if ( t [ 0 ] + t [ 3 ] > t [ 0 ] + t [ 1 ] + t [ 2 ] ) { System . out . println ( t [ 0 ] + t [ 1 ] + t [ 2 ] ) ; return ; } System . out . println ( Math . max ( t [ 0 ] + t [ 3 ] , t [ 1 ] + t [ 2 ] ) ) ; } }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) 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 object: (identifier) name: (identifier) arguments: (argument_list)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (decimal_integer_literal)))))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (decimal_integer_literal)) (array_access array: (identifier) index: (decimal_integer_literal)))))))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (array_access array: (identifier) index: (decimal_integer_literal))) (array_access array: (identifier) index: (decimal_integer_literal)))))))) alternative: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (array_access array: (identifier) index: (decimal_integer_literal))) right: (array_access array: (identifier) index: (decimal_integer_literal))))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (decimal_integer_literal))))) (return_statement))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (array_access array: (identifier) index: (decimal_integer_literal))) right: (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (array_access array: (identifier) index: (decimal_integer_literal))) right: (array_access array: (identifier) index: (decimal_integer_literal))))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (array_access array: (identifier) index: (decimal_integer_literal))) right: (array_access array: (identifier) index: (decimal_integer_literal)))))) (return_statement))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (array_access array: (identifier) index: (decimal_integer_literal))) (binary_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (array_access array: (identifier) index: (decimal_integer_literal))))))))))))))