static long help ( int [ ] a ) {
  if ( a [ 0 ] != 0 ) return 0 ;
  int maxDist = 0 ;
  for ( int w : a ) maxDist = Math . max ( maxDist , w ) ;
  int [ ] rec = new int [ maxDist + 1 ] ;
  for ( int w : a ) rec [ w ] ++ ;
  if ( rec [ 0 ] != 1 ) return 0 ;
  for ( int i = 1 ;
  i <= maxDist ;
  i ++ ) {
    if ( rec [ i ] < 1 ) return 0 ;
  }
  long [ ] dp = new long [ maxDist + 1 ] ;
  dp [ 0 ] = 1 ;
  for ( int i = 1 ;
  i <= maxDist ;
  i ++ ) {
    long base = power ( 2 , rec [ i - 1 ] ) - 1 ;
    dp [ i ] = power ( base , rec [ i ] ) * dp [ i - 1 ] % mod ;
    long sameLayer = ( ( long ) rec [ i ] ) * ( ( long ) rec [ i ] - 1 ) / 2 ;
    dp [ i ] = dp [ i ] * power ( 2 , sameLayer ) % mod ;
  }
  return dp [ maxDist ] ;
}

static long help ( int [ ] a ) { if ( a [ 0 ] != 0 ) return 0 ; int maxDist = 0 ; for ( int w : a ) maxDist = Math . max ( maxDist , w ) ; int [ ] rec = new int [ maxDist + 1 ] ; for ( int w : a ) rec [ w ] ++ ; if ( rec [ 0 ] != 1 ) return 0 ; for ( int i = 1 ; i <= maxDist ; i ++ ) { if ( rec [ i ] < 1 ) return 0 ; } long [ ] dp = new long [ maxDist + 1 ] ; dp [ 0 ] = 1 ; for ( int i = 1 ; i <= maxDist ; i ++ ) { long base = power ( 2 , rec [ i - 1 ] ) - 1 ; dp [ i ] = power ( base , rec [ i ] ) * dp [ i - 1 ] % mod ; long sameLayer = ( ( long ) rec [ i ] ) * ( ( long ) rec [ i ] - 1 ) / 2 ; dp [ i ] = dp [ i ] * power ( 2 , sameLayer ) % mod ; } return dp [ maxDist ] ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (integral_type) dimensions: (dimensions)) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (decimal_integer_literal))) consequence: (return_statement (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (enhanced_for_statement type: (integral_type) name: (identifier) value: (identifier) body: (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (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 (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (enhanced_for_statement type: (integral_type) name: (identifier) value: (identifier) body: (expression_statement (update_expression (array_access array: (identifier) index: (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (decimal_integer_literal))) consequence: (return_statement (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 (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) consequence: (return_statement (decimal_integer_literal))))) (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 (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (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 (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (decimal_integer_literal) (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))))) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (binary_expression left: (method_invocation name: (identifier) arguments: (argument_list (identifier) (array_access array: (identifier) index: (identifier)))) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (binary_expression left: (parenthesized_expression (cast_expression type: (integral_type) value: (array_access array: (identifier) index: (identifier)))) right: (parenthesized_expression (binary_expression left: (cast_expression type: (integral_type) value: (array_access array: (identifier) index: (identifier))) right: (decimal_integer_literal)))) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation name: (identifier) arguments: (argument_list (decimal_integer_literal) (identifier)))) right: (identifier)))))) (return_statement (array_access array: (identifier) index: (identifier)))))