static Vector < Integer > Diffs ( int [ ] a , int k ) {
  Vector < Integer > out = new Vector < Integer > ( ) ;
  int [ ] inc , dec ;
  inc = new int [ a . length ] ;
  dec = new int [ a . length ] ;
  int inc_sum = 0 ;
  int dec_sum = 0 ;
  for ( int i = 0 ;
  i < a . length ;
  ++ i ) {
    for ( int j = i - 1 ;
    j >= 0 && j > i - k && a [ j + 1 ] > a [ j ] ;
    -- j ) {
      ++ inc [ j ] ;
      ++ inc_sum ;
    }
    for ( int j = i - 1 ;
    j >= 0 && j > i - k && a [ j + 1 ] < a [ j ] ;
    -- j ) {
      ++ dec [ j ] ;
      ++ dec_sum ;
    }
    if ( i >= k - 1 ) {
      if ( i >= k ) {
        inc_sum -= inc [ i - k ] ;
        dec_sum -= dec [ i - k ] ;
      }
      out . add ( inc_sum - dec_sum ) ;
    }
  }
  return out ;
}

static Vector < Integer > Diffs ( int [ ] a , int k ) { Vector < Integer > out = new Vector < Integer > ( ) ; int [ ] inc , dec ; inc = new int [ a . length ] ; dec = new int [ a . length ] ; int inc_sum = 0 ; int dec_sum = 0 ; for ( int i = 0 ; i < a . length ; ++ i ) { for ( int j = i - 1 ; j >= 0 && j > i - k && a [ j + 1 ] > a [ j ] ; -- j ) { ++ inc [ j ] ; ++ inc_sum ; } for ( int j = i - 1 ; j >= 0 && j > i - k && a [ j + 1 ] < a [ j ] ; -- j ) { ++ dec [ j ] ; ++ dec_sum ; } if ( i >= k - 1 ) { if ( i >= k ) { inc_sum -= inc [ i - k ] ; dec_sum -= dec [ i - k ] ; } out . add ( inc_sum - dec_sum ) ; } } return out ; }
(method_declaration (modifiers) type: (generic_type (type_identifier) (type_arguments (type_identifier))) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (integral_type) dimensions: (dimensions)) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (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 (type_identifier))) arguments: (argument_list)))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier)) declarator: (variable_declarator name: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (field_access object: (identifier) field: (identifier)))))) (expression_statement (assignment_expression left: (identifier) right: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (field_access object: (identifier) field: (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (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: (field_access object: (identifier) field: (identifier))) update: (update_expression (identifier)) body: (block (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (decimal_integer_literal)))) condition: (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (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)))) update: (update_expression (identifier)) body: (block (expression_statement (update_expression (array_access array: (identifier) index: (identifier)))) (expression_statement (update_expression (identifier))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (decimal_integer_literal)))) condition: (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (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)))) update: (update_expression (identifier)) body: (block (expression_statement (update_expression (array_access array: (identifier) index: (identifier)))) (expression_statement (update_expression (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (identifier))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier))))))))) (return_statement (identifier))))