static double solve ( int mask ) {
  if ( mask == ( 1 << N ) - 1 ) {
    return 0 ;
  }
  if ( memo [ mask ] < - 0.5 ) {
    double res = 0.0 ;
    for ( int index = 0 ;
    index < N ;
    index ++ ) {
      for ( int wait = 0 ;
      wait < N ;
      wait ++ ) {
        int exactIndex = ( index + wait ) % N ;
        if ( ( mask >> exactIndex & 1 ) == 0 ) {
          res += ( N - wait + solve ( mask | 1 << exactIndex ) ) / N ;
          break ;
        }
      }
    }
    memo [ mask ] = res ;
  }
  return memo [ mask ] ;
}

static double solve ( int mask ) { if ( mask == ( 1 << N ) - 1 ) { return 0 ; } if ( memo [ mask ] < - 0.5 ) { double res = 0.0 ; for ( int index = 0 ; index < N ; index ++ ) { for ( int wait = 0 ; wait < N ; wait ++ ) { int exactIndex = ( index + wait ) % N ; if ( ( mask >> exactIndex & 1 ) == 0 ) { res += ( N - wait + solve ( mask | 1 << exactIndex ) ) / N ; break ; } } } memo [ mask ] = res ; } return memo [ mask ] ; }
(method_declaration (modifiers) type: (floating_point_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (decimal_integer_literal) right: (identifier))) right: (decimal_integer_literal)))) consequence: (block (return_statement (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (unary_expression operand: (decimal_floating_point_literal)))) consequence: (block (local_variable_declaration type: (floating_point_type) declarator: (variable_declarator name: (identifier) value: (decimal_floating_point_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 (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: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal))) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (method_invocation name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (binary_expression left: (decimal_integer_literal) right: (identifier))))))) right: (identifier)))) (break_statement))))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))))) (return_statement (array_access array: (identifier) index: (identifier)))))