public static void main ( String args [ ] ) throws Exception {
  Scanner cin = new Scanner ( System . in ) ;
  int N = cin . nextInt ( ) ;
  int a [ ] = new int [ N ] ;
  for ( int i = 0 ;
  i < N ;
  i ++ ) {
    a [ i ] = cin . nextInt ( ) ;
  }
  Queue < Integer > queue = new LinkedList < Integer > ( ) ;
  int [ ] dis = new int [ N ] ;
  boolean [ ] visited = new boolean [ N ] ;
  for ( int i = 0 ;
  i < N ;
  i ++ ) {
    dis [ i ] = - 1 ;
    visited [ 0 ] = false ;
  }
  visited [ 0 ] = true ;
  dis [ 0 ] = 0 ;
  queue . add ( 0 ) ;
  while ( ! queue . isEmpty ( ) ) {
    int e = queue . poll ( ) ;
    int ahead = e + 1 , back = e - 1 ;
    if ( ahead >= 0 && ahead < N && ! visited [ ahead ] ) {
      queue . add ( ahead ) ;
      visited [ ahead ] = true ;
      dis [ ahead ] = dis [ e ] + 1 ;
    }
    if ( back >= 0 && back < N && ! visited [ back ] ) {
      if ( back >= 0 && back < N && ! visited [ back ] ) {
        queue . add ( back ) ;
        visited [ back ] = true ;
        dis [ back ] = dis [ e ] + 1 ;
      }
    }
    int target = a [ e ] - 1 ;
    if ( ! visited [ target ] ) {
      if ( ! visited [ target ] ) {
        queue . add ( target ) ;
        visited [ target ] = true ;
        dis [ target ] = dis [ e ] + 1 ;
      }
    }
  }
  for ( int i = 0 ;
  i < N ;
  i ++ ) {
    if ( i == N ) System . out . println ( dis [ i ] ) ;
    System . out . print ( dis [ i ] + " " ) ;
  }
}

public static void main ( String args [ ] ) throws Exception { Scanner cin = new Scanner ( System . in ) ; int N = cin . nextInt ( ) ; int a [ ] = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = cin . nextInt ( ) ; } Queue < Integer > queue = new LinkedList < Integer > ( ) ; int [ ] dis = new int [ N ] ; boolean [ ] visited = new boolean [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { dis [ i ] = - 1 ; visited [ 0 ] = false ; } visited [ 0 ] = true ; dis [ 0 ] = 0 ; queue . add ( 0 ) ; while ( ! queue . isEmpty ( ) ) { int e = queue . poll ( ) ; int ahead = e + 1 , back = e - 1 ; if ( ahead >= 0 && ahead < N && ! visited [ ahead ] ) { queue . add ( ahead ) ; visited [ ahead ] = true ; dis [ ahead ] = dis [ e ] + 1 ; } if ( back >= 0 && back < N && ! visited [ back ] ) { if ( back >= 0 && back < N && ! visited [ back ] ) { queue . add ( back ) ; visited [ back ] = true ; dis [ back ] = dis [ e ] + 1 ; } } int target = a [ e ] - 1 ; if ( ! visited [ target ] ) { if ( ! visited [ target ] ) { queue . add ( target ) ; visited [ target ] = true ; dis [ target ] = dis [ e ] + 1 ; } } } for ( int i = 0 ; i < N ; i ++ ) { if ( i == N ) System . out . println ( dis [ i ] ) ; System . out . print ( dis [ i ] + " ▁ " ) ; } }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier) dimensions: (dimensions))) (throws (type_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: (integral_type) declarator: (variable_declarator name: (identifier) dimensions: (dimensions) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier))))) (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: (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: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier))))) (local_variable_declaration type: (array_type element: (boolean_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (boolean_type) dimensions: (dimensions_expr (identifier))))) (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: (unary_expression operand: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (false))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (true))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (decimal_integer_literal))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal)))) (while_statement condition: (parenthesized_expression (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) body: (block (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: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (decimal_integer_literal))) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (identifier))) right: (unary_expression operand: (array_access array: (identifier) index: (identifier))))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (true))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (identifier))) right: (unary_expression operand: (array_access array: (identifier) index: (identifier))))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (identifier))) right: (unary_expression operand: (array_access array: (identifier) index: (identifier))))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (true))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal)))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (unary_expression operand: (array_access array: (identifier) index: (identifier)))) consequence: (block (if_statement condition: (parenthesized_expression (unary_expression operand: (array_access array: (identifier) index: (identifier)))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (true))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (array_access array: (identifier) index: (identifier)) 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 (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (identifier)))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (string_literal)))))))))