public static void main ( final String [ ] parameters ) {
  Scanner input = new Scanner ( System . in ) ;
  int totalLines = input . nextInt ( ) ;
  String [ ] players = new String [ totalLines ] ;
  int [ ] scores = new int [ totalLines ] ;
  HashMap < String , Integer > scoreBoard = new HashMap < > ( ) ;
  for ( int index = 0 ;
  index < totalLines ;
  index ++ ) {
    players [ index ] = input . next ( ) ;
    scores [ index ] = input . nextInt ( ) ;
    scoreBoard . put ( players [ index ] , scoreBoard . getOrDefault ( players [ index ] , 0 ) + scores [ index ] ) ;
  }
  HashSet < String > winners = new HashSet < > ( ) ;
  int maximumScore = Integer . MIN_VALUE ;
  for ( String key : scoreBoard . keySet ( ) ) {
    if ( scoreBoard . get ( key ) > maximumScore ) {
      winners . clear ( ) ;
      winners . add ( key ) ;
      maximumScore = scoreBoard . get ( key ) ;
    }
    else if ( scoreBoard . get ( key ) == maximumScore ) {
      winners . add ( key ) ;
    }
  }
  scoreBoard . clear ( ) ;
  String result = "" ;
  for ( int index = 0 ;
  index < totalLines ;
  index ++ ) {
    String player = players [ index ] ;
    int playerScore = scoreBoard . getOrDefault ( player , 0 ) + scores [ index ] ;
    if ( playerScore >= maximumScore && winners . contains ( player ) ) {
      result = player ;
      break ;
    }
    scoreBoard . put ( player , playerScore ) ;
  }
  System . out . println ( result ) ;
}

public static void main ( final String [ ] parameters ) { Scanner input = new Scanner ( System . in ) ; int totalLines = input . nextInt ( ) ; String [ ] players = new String [ totalLines ] ; int [ ] scores = new int [ totalLines ] ; HashMap < String , Integer > scoreBoard = new HashMap < > ( ) ; for ( int index = 0 ; index < totalLines ; index ++ ) { players [ index ] = input . next ( ) ; scores [ index ] = input . nextInt ( ) ; scoreBoard . put ( players [ index ] , scoreBoard . getOrDefault ( players [ index ] , 0 ) + scores [ index ] ) ; } HashSet < String > winners = new HashSet < > ( ) ; int maximumScore = Integer . MIN_VALUE ; for ( String key : scoreBoard . keySet ( ) ) { if ( scoreBoard . get ( key ) > maximumScore ) { winners . clear ( ) ; winners . add ( key ) ; maximumScore = scoreBoard . get ( key ) ; } else if ( scoreBoard . get ( key ) == maximumScore ) { winners . add ( key ) ; } } scoreBoard . clear ( ) ; String result = " " ; for ( int index = 0 ; index < totalLines ; index ++ ) { String player = players [ index ] ; int playerScore = scoreBoard . getOrDefault ( player , 0 ) + scores [ index ] ; if ( playerScore >= maximumScore && winners . contains ( player ) ) { result = player ; break ; } scoreBoard . put ( player , playerScore ) ; } System . out . println ( result ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter (modifiers) 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: (type_identifier) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (type_identifier) dimensions: (dimensions_expr (identifier))))) (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))))) (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 (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (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 (array_access array: (identifier) index: (identifier)) (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)) (decimal_integer_literal))) right: (array_access array: (identifier) index: (identifier)))))))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (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: (integral_type) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (enhanced_for_statement type: (type_identifier) name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (identifier))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (identifier))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (string_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: (type_identifier) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (decimal_integer_literal))) right: (array_access array: (identifier) index: (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (break_statement))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier)))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))