static int solve ( int N , int M , int last , boolean petya ) {
  int next ;
  if ( N == 0 ) {
    if ( M == 0 ) {
      return 0 ;
    }
    else {
      next = 1 ;
    }
  }
  else {
    if ( M == 0 ) {
      next = 0 ;
    }
    else {
      if ( petya ) {
        next = last ;
      }
      else {
        next = 1 - last ;
      }
    }
  }
  if ( next == 0 ) {
    N -- ;
  }
  else {
    M -- ;
  }
  int diff = ( last == next ) ? 1 : 0 ;
  return diff + solve ( N , M , next , ! petya ) ;
}

static int solve ( int N , int M , int last , boolean petya ) { int next ; if ( N == 0 ) { if ( M == 0 ) { return 0 ; } else { next = 1 ; } } else { if ( M == 0 ) { next = 0 ; } else { if ( petya ) { next = last ; } else { next = 1 - last ; } } } if ( next == 0 ) { N -- ; } else { M -- ; } int diff = ( last == next ) ? 1 : 0 ; return diff + solve ( N , M , next , ! petya ) ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (boolean_type) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (return_statement (decimal_integer_literal))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))))) alternative: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))) alternative: (block (if_statement condition: (parenthesized_expression (identifier)) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier)))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (decimal_integer_literal) right: (identifier)))))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (update_expression (identifier)))) alternative: (block (expression_statement (update_expression (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (ternary_expression condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (decimal_integer_literal) alternative: (decimal_integer_literal)))) (return_statement (binary_expression left: (identifier) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier) (unary_expression operand: (identifier))))))))