static long f ( long num ) {
  HashSet < Long > h = new HashSet < > ( ) ;
  int res = 0 , flag = 1 ;
  while ( num > 0 ) {
    long n = num % 10 ;
    if ( ! h . contains ( n ) ) {
      h . add ( n ) ;
      num /= 10 ;
      res += n ;
    }
    else {
      flag = 0 ;
      break ;
    }
  }
  if ( flag == 0 ) {
    return - 1 ;
  }
  return res ;
}

static long f ( long num ) { HashSet < Long > h = new HashSet < > ( ) ; int res = 0 , flag = 1 ; while ( num > 0 ) { long n = num % 10 ; if ( ! h . contains ( n ) ) { h . add ( n ) ; num /= 10 ; res += n ; } else { flag = 0 ; break ; } } if ( flag == 0 ) { return - 1 ; } return res ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (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)) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (expression_statement (assignment_expression left: (identifier) right: (identifier)))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (break_statement))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (return_statement (unary_expression operand: (decimal_integer_literal))))) (return_statement (identifier))))