static int maxValue ( int a [ ] , int n ) {
  HashMap < Integer , Integer > first = new HashMap < > ( ) ;
  HashMap < Integer , Integer > last = new HashMap < > ( ) ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    first . put ( a [ i ] , 0 ) ;
    last . put ( a [ i ] , 0 ) ;
  }
  int [ ] pr = new int [ n ] ;
  pr [ 0 ] = a [ 0 ] ;
  for ( int i = 1 ;
  i < n ;
  i ++ ) {
    pr [ i ] = pr [ i - 1 ] + a [ i ] ;
    if ( Integer . parseInt ( String . valueOf ( first . get ( a [ i ] ) ) ) == 0 ) first . put ( a [ i ] , i ) ;
    last . put ( a [ i ] , i ) ;
  }
  int ans = 0 ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    int start = Integer . parseInt ( String . valueOf ( first . get ( a [ i ] ) ) ) ;
    int end = Integer . parseInt ( String . valueOf ( last . get ( a [ i ] ) ) ) ;
    if ( start != 0 ) ans = Math . max ( ans , pr [ end ] - pr [ start - 1 ] ) ;
  }
  return ans ;
}

static int maxValue ( int a [ ] , int n ) { HashMap < Integer , Integer > first = new HashMap < > ( ) ; HashMap < Integer , Integer > last = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { first . put ( a [ i ] , 0 ) ; last . put ( a [ i ] , 0 ) ; } int [ ] pr = new int [ n ] ; pr [ 0 ] = a [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { pr [ i ] = pr [ i - 1 ] + a [ i ] ; if ( Integer . parseInt ( String . valueOf ( first . get ( a [ i ] ) ) ) == 0 ) first . put ( a [ i ] , i ) ; last . put ( a [ i ] , i ) ; } int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int start = Integer . parseInt ( String . valueOf ( first . get ( a [ i ] ) ) ) ; int end = Integer . parseInt ( String . valueOf ( last . get ( a [ i ] ) ) ) ; if ( start != 0 ) ans = Math . max ( ans , pr [ end ] - pr [ start - 1 ] ) ; } return ans ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier) dimensions: (dimensions)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier) (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list)))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier) (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list)))) (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 (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (decimal_integer_literal)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (decimal_integer_literal)))))) (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))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (array_access array: (identifier) index: (decimal_integer_literal)))) (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: (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (array_access array: (identifier) index: (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))))))) right: (decimal_integer_literal))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (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 (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))))))))))) (return_statement (identifier))))