static public void main ( String [ ] args ) {
  Scanner scan = new Scanner ( System . in ) ;
  int size = scan . nextInt ( ) ;
  List < String > list = new ArrayList < > ( size ) ;
  for ( int i = 0 ;
  i < size ;
  i ++ ) {
    list . add ( scan . next ( ) ) ;
  }
  list . sort ( naturalOrder ( ) ) ;
  int start = 9999 ;
  int end = - 1 ;
  for ( String data : list ) {
    String [ ] record = data . split ( "-" ) ;
    int rainStart = Integer . parseInt ( record [ 0 ] ) ;
    int rainEnd = Integer . parseInt ( record [ 1 ] ) ;
    rainStart -= rainStart % 5 ;
    if ( rainEnd % 5 > 0 ) {
      rainEnd += 5 - rainEnd % 5 ;
    }
    if ( rainEnd % 100 == 60 ) {
      rainEnd += 40 ;
    }
    if ( rainStart > end ) {
      if ( start != 9999 ) {
        System . out . println ( String . format ( "%04d" , start ) + "-" + String . format ( "%04d" , end ) ) ;
      }
      start = rainStart ;
      end = - 1 ;
    }
    if ( end < rainEnd ) {
      end = rainEnd ;
    }
  }
  System . out . println ( String . format ( "%04d" , start ) + "-" + String . format ( "%04d" , end ) ) ;
  scan . close ( ) ;
}

static public void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int size = scan . nextInt ( ) ; List < String > list = new ArrayList < > ( size ) ; for ( int i = 0 ; i < size ; i ++ ) { list . add ( scan . next ( ) ) ; } list . sort ( naturalOrder ( ) ) ; int start = 9999 ; int end = - 1 ; for ( String data : list ) { String [ ] record = data . split ( " - " ) ; int rainStart = Integer . parseInt ( record [ 0 ] ) ; int rainEnd = Integer . parseInt ( record [ 1 ] ) ; rainStart -= rainStart % 5 ; if ( rainEnd % 5 > 0 ) { rainEnd += 5 - rainEnd % 5 ; } if ( rainEnd % 100 == 60 ) { rainEnd += 40 ; } if ( rainStart > end ) { if ( start != 9999 ) { System . out . println ( String . format ( " % 04d " , start ) + " - " + String . format ( " % 04d " , end ) ) ; } start = rainStart ; end = - 1 ; } if ( end < rainEnd ) { end = rainEnd ; } } System . out . println ( String . format ( " % 04d " , start ) + " - " + String . format ( " % 04d " , end ) ) ; scan . close ( ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (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: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list (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 (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation name: (identifier) arguments: (argument_list))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (unary_expression operand: (decimal_integer_literal)))) (enhanced_for_statement type: (type_identifier) name: (identifier) value: (identifier) body: (block (local_variable_declaration type: (array_type element: (type_identifier) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (decimal_integer_literal)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (decimal_integer_literal)))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (decimal_integer_literal) right: (binary_expression left: (identifier) right: (decimal_integer_literal))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal) (identifier))) right: (string_literal)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal) (identifier))))))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (unary_expression operand: (decimal_integer_literal)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal) (identifier))) right: (string_literal)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal) (identifier))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))