static int maxlenAP ( int a [ ] , int n , int d ) {
  HashMap < Integer , Integer > m = new HashMap < Integer , Integer > ( ) ;
  int maxt = 1 ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    if ( m . containsKey ( a [ i ] - i * d ) ) {
      int freq = m . get ( a [ i ] - i * d ) ;
      freq ++ ;
      m . put ( a [ i ] - i * d , freq ) ;
    }
    else {
      m . put ( a [ i ] - i * d , 1 ) ;
    }
  }
  for ( Entry < Integer , Integer > val : m . entrySet ( ) ) {
    if ( maxt < val . getValue ( ) ) maxt = val . getValue ( ) ;
  }
  return maxt ;
}

static int maxlenAP ( int a [ ] , int n , int d ) { HashMap < Integer , Integer > m = new HashMap < Integer , Integer > ( ) ; int maxt = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( m . containsKey ( a [ i ] - i * d ) ) { int freq = m . get ( a [ i ] - i * d ) ; freq ++ ; m . put ( a [ i ] - i * d , freq ) ; } else { m . put ( a [ i ] - i * d , 1 ) ; } } for ( Entry < Integer , Integer > val : m . entrySet ( ) ) { if ( maxt < val . getValue ( ) ) maxt = val . getValue ( ) ; } return maxt ; }
(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)) (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 (type_identifier) (type_identifier))) arguments: (argument_list)))) (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 (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (identifier) right: (identifier)))))) consequence: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (identifier) right: (identifier))))))) (expression_statement (update_expression (identifier))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (identifier) right: (identifier))) (identifier))))) alternative: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (identifier) right: (identifier))) (decimal_integer_literal)))))))) (enhanced_for_statement type: (generic_type (type_identifier) (type_arguments (type_identifier) (type_identifier))) name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) consequence: (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))))) (return_statement (identifier))))