public static void main ( String [ ] args ) throws IOException {
  BufferedReader br = new BufferedReader ( new FileReader ( "A-large.in" ) ) ;
  PrintStream ps = new PrintStream ( new FileOutputStream ( "A-large.out" ) ) ;
  int cases = Integer . parseInt ( br . readLine ( ) ) ;
  for ( int itr = 1 ;
  itr <= cases ;
  itr ++ ) {
    int size = Integer . parseInt ( br . readLine ( ) ) ;
    int [ ] board = new int [ size ] ;
    for ( int i = 0 ;
    i < size ;
    i ++ ) {
      String s = br . readLine ( ) ;
      for ( int j = 0 ;
      j < size ;
      j ++ ) if ( s . charAt ( j ) == '1' ) board [ i ] = j ;
    }
    int out = 0 ;
    boolean done = false ;
    while ( ! done ) {
      done = true ;
      for ( int i = 0 ;
      i < size ;
      i ++ ) {
        if ( board [ i ] > i ) {
          done = false ;
          int s = 0 ;
          for ( int j = i + 1 ;
          j < size ;
          j ++ ) if ( board [ j ] <= i ) {
            s = j ;
            break ;
          }
          for ( int j = s ;
          j > i ;
          j -- ) {
            int t = board [ j ] ;
            board [ j ] = board [ j - 1 ] ;
            board [ j - 1 ] = t ;
            out ++ ;
          }
        }
      }
    }
    ps . println ( "Case #" + itr + ": " + out ) ;
  }
  br . close ( ) ;
  ps . close ( ) ;
}

public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new FileReader ( " A - large . in " ) ) ; PrintStream ps = new PrintStream ( new FileOutputStream ( " A - large . out " ) ) ; int cases = Integer . parseInt ( br . readLine ( ) ) ; for ( int itr = 1 ; itr <= cases ; itr ++ ) { int size = Integer . parseInt ( br . readLine ( ) ) ; int [ ] board = new int [ size ] ; for ( int i = 0 ; i < size ; i ++ ) { String s = br . readLine ( ) ; for ( int j = 0 ; j < size ; j ++ ) if ( s . charAt ( j ) == '1' ) board [ i ] = j ; } int out = 0 ; boolean done = false ; while ( ! done ) { done = true ; for ( int i = 0 ; i < size ; i ++ ) { if ( board [ i ] > i ) { done = false ; int s = 0 ; for ( int j = i + 1 ; j < size ; j ++ ) if ( board [ j ] <= i ) { s = j ; break ; } for ( int j = s ; j > i ; j -- ) { int t = board [ j ] ; board [ j ] = board [ j - 1 ] ; board [ j - 1 ] = t ; out ++ ; } } } } ps . println ( " Case ▁ # " + itr + " : ▁ " + out ) ; } br . close ( ) ; ps . close ( ) ; }
(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: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (object_creation_expression type: (type_identifier) arguments: (argument_list (string_literal))))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (object_creation_expression type: (type_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 (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (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: (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))))) (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: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (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: (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal))) consequence: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (boolean_type) declarator: (variable_declarator name: (identifier) value: (false))) (while_statement condition: (parenthesized_expression (unary_expression operand: (identifier))) body: (block (expression_statement (assignment_expression left: (identifier) right: (true))) (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: (array_access array: (identifier) index: (identifier)) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (false))) (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: (binary_expression left: (identifier) right: (decimal_integer_literal)))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (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: (identifier))) (break_statement)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) 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)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (identifier))) (expression_statement (update_expression (identifier))))))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (binary_expression left: (string_literal) right: (identifier)) right: (string_literal)) right: (identifier))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))