public static void main ( String [ ] args ) throws IOException {
  int n = Integer . parseInt ( br . readLine ( ) ) ;
  int [ ] arr = new int [ n ] ;
  int [ ] arr1 = new int [ n ] ;
  String [ ] sr = br . readLine ( ) . split ( " " ) ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    arr [ i ] = next ( sr , i ) ;
  }
  int k = arr [ 0 ] ;
  if ( k == 0 ) k = arr [ 1 ] ;
  sr = br . readLine ( ) . split ( " " ) ;
  int j = 0 ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    arr1 [ i ] = next ( sr , i ) ;
    if ( arr1 [ i ] == k ) j = i ;
  }
  int i = 0 ;
  while ( i < n ) {
    j = j % n ;
    if ( arr [ i ] == 0 ) i ++ ;
    if ( arr1 [ j ] == 0 ) {
      j ++ ;
      j = j % n ;
    }
    if ( i < n ) {
      if ( arr [ i ] != arr1 [ j ] ) {
        System . out . println ( "NO" ) ;
        return ;
      }
    }
    i ++ ;
    j ++ ;
  }
  System . out . println ( "YES" ) ;
}

public static void main ( String [ ] args ) throws IOException { int n = Integer . parseInt ( br . readLine ( ) ) ; int [ ] arr = new int [ n ] ; int [ ] arr1 = new int [ n ] ; String [ ] sr = br . readLine ( ) . split ( " ▁ " ) ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = next ( sr , i ) ; } int k = arr [ 0 ] ; if ( k == 0 ) k = arr [ 1 ] ; sr = br . readLine ( ) . split ( " ▁ " ) ; int j = 0 ; for ( int i = 0 ; i < n ; i ++ ) { arr1 [ i ] = next ( sr , i ) ; if ( arr1 [ i ] == k ) j = i ; } int i = 0 ; while ( i < n ) { j = j % n ; if ( arr [ i ] == 0 ) i ++ ; if ( arr1 [ j ] == 0 ) { j ++ ; j = j % n ; } if ( i < n ) { if ( arr [ i ] != arr1 [ j ] ) { System . out . println ( " NO " ) ; return ; } } i ++ ; j ++ ; } System . out . println ( " YES " ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) (throws (type_identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (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: (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: (type_identifier) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list (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: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (decimal_integer_literal))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) name: (identifier) arguments: (argument_list (string_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: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))) consequence: (expression_statement (assignment_expression left: (identifier) right: (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) body: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) consequence: (expression_statement (update_expression (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) consequence: (block (expression_statement (update_expression (identifier))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (identifier)))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))) (return_statement))))) (expression_statement (update_expression (identifier))) (expression_statement (update_expression (identifier))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal))))))