public static void main ( String [ ] args ) {
  Scanner sc = new Scanner ( System . in ) ;
  long n = sc . nextLong ( ) ;
  ArrayList < Integer > res = new ArrayList < Integer > ( ) ;
  int k ;
  for ( k = 40 ;
  k >= 0 ;
  k -- ) {
    if ( n >= ( 1L << k ) - 1 ) break ;
  }
  for ( int i = 1 ;
  i <= k ;
  i ++ ) res . add ( i ) ;
  n -= ( 1L << k ) - 1 ;
  for ( int i = k - 1 ;
  i >= 0 ;
  i -- ) {
    if ( n < ( 1L << i ) ) continue ;
    k ++ ;
    res . add ( i , k ) ;
    n -= 1L << i ;
  }
  System . out . println ( 2 * res . size ( ) ) ;
  for ( int x : res ) System . out . print ( x + " " ) ;
  for ( int i = 1 ;
  i <= res . size ( ) ;
  i ++ ) System . out . print ( i + " " ) ;
  System . out . println ( ) ;
}

public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; ArrayList < Integer > res = new ArrayList < Integer > ( ) ; int k ; for ( k = 40 ; k >= 0 ; k -- ) { if ( n >= ( 1L << k ) - 1 ) break ; } for ( int i = 1 ; i <= k ; i ++ ) res . add ( i ) ; n -= ( 1L << k ) - 1 ; for ( int i = k - 1 ; i >= 0 ; i -- ) { if ( n < ( 1L << i ) ) continue ; k ++ ; res . add ( i , k ) ; n -= 1L << i ; } System . out . println ( 2 * res . size ( ) ) ; for ( int x : res ) System . out . print ( x + " ▁ " ) ; for ( int i = 1 ; i <= res . size ( ) ; i ++ ) System . out . print ( i + " ▁ " ) ; System . out . println ( ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (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: (integral_type) declarator: (variable_declarator name: (identifier))) (for_statement init: (assignment_expression left: (identifier) right: (decimal_integer_literal)) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (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: (break_statement)))) (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: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (decimal_integer_literal) right: (identifier))) right: (decimal_integer_literal)))) (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: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (decimal_integer_literal) right: (identifier))))) consequence: (continue_statement)) (expression_statement (update_expression (identifier))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (decimal_integer_literal) right: (identifier)))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (decimal_integer_literal) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (enhanced_for_statement type: (integral_type) name: (identifier) value: (identifier) body: (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (string_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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) update: (update_expression (identifier)) body: (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (string_literal)))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list)))))