private static final long solve ( long [ ] a ) {
  long sum [ ] = new long [ n ] ;
  sum [ 0 ] = a [ 0 ] ;
  long res = 0 ;
  for ( int i = 1 ;
  i < n ;
  i ++ ) {
    sum [ i ] = a [ i ] + sum [ i - 1 ] ;
    if ( sum [ i - 1 ] > 0 ) {
      long t = - sum [ i - 1 ] - 1 ;
      if ( a [ i ] > t ) {
        res += a [ i ] - t ;
        a [ i ] = t ;
      }
    }
    else {
      long t = - sum [ i - 1 ] + 1 ;
      if ( a [ i ] < t ) {
        res += t - a [ i ] ;
        a [ i ] = t ;
      }
    }
    sum [ i ] = a [ i ] + sum [ i - 1 ] ;
  }
  return res ;
}

private static final long solve ( long [ ] a ) { long sum [ ] = new long [ n ] ; sum [ 0 ] = a [ 0 ] ; long res = 0 ; for ( int i = 1 ; i < n ; i ++ ) { sum [ i ] = a [ i ] + sum [ i - 1 ] ; if ( sum [ i - 1 ] > 0 ) { long t = - sum [ i - 1 ] - 1 ; if ( a [ i ] > t ) { res += a [ i ] - t ; a [ i ] = t ; } } else { long t = - sum [ i - 1 ] + 1 ; if ( a [ i ] < t ) { res += t - a [ i ] ; a [ i ] = t ; } } sum [ i ] = a [ i ] + sum [ i - 1 ] ; } return res ; }
(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 (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (array_access array: (identifier) index: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (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 (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (decimal_integer_literal))) consequence: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (unary_expression operand: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier)))))) alternative: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (unary_expression operand: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal)))) right: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal)))))))) (return_statement (identifier))))