public static long solve ( long sum , long ans ) {
  for ( int i = 1 ;
  i < n ;
  i ++ ) {
    long num = nums [ i ] ;
    if ( sum > 0 ) {
      sum += num ;
      if ( sum >= 0 ) {
        ans += sum + 1 ;
        sum = - 1 ;
      }
    }
    else if ( sum < 0 ) {
      sum += num ;
      if ( sum <= 0 ) {
        ans += - sum + 1 ;
        sum = 1 ;
      }
    }
  }
  return ans ;
}

public static long solve ( long sum , long ans ) { for ( int i = 1 ; i < n ; i ++ ) { long num = nums [ i ] ; if ( sum > 0 ) { sum += num ; if ( sum >= 0 ) { ans += sum + 1 ; sum = - 1 ; } } else if ( sum < 0 ) { sum += num ; if ( sum <= 0 ) { ans += - sum + 1 ; sum = 1 ; } } } return ans ; }
(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))) 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: (array_access array: (identifier) index: (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (unary_expression operand: (decimal_integer_literal))))))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (unary_expression operand: (identifier)) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))))))))) (return_statement (identifier))))