private static String solve ( Scanner in ) {
  int n = in . nextInt ( ) ;
  in . nextLine ( ) ;
  int [ ] a = new int [ n ] ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    String s = in . nextLine ( ) ;
    int j = n - 1 ;
    while ( s . charAt ( j ) == '0' && j > 0 ) j -- ;
    a [ i ] = j ;
  }
  int res = 0 ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    int j = i ;
    while ( a [ j ] > i ) j ++ ;
    int t = a [ j ] ;
    for ( int k = j ;
    k > i ;
    k -- ) a [ k ] = a [ k - 1 ] ;
    a [ i ] = t ;
    res += ( j - i ) ;
  }
  return "" + res ;
}

private static String solve ( Scanner in ) { int n = in . nextInt ( ) ; in . nextLine ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { String s = in . nextLine ( ) ; int j = n - 1 ; while ( s . charAt ( j ) == '0' && j > 0 ) j -- ; a [ i ] = j ; } int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int j = i ; while ( a [ j ] > i ) j ++ ; int t = a [ j ] ; for ( int k = j ; k > i ; k -- ) a [ k ] = a [ k - 1 ] ; a [ i ] = t ; res += ( j - i ) ; } return " " + res ; }
(method_declaration (modifiers) type: (type_identifier) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier))) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (expression_statement (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)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (while_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal)) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) body: (expression_statement (update_expression (identifier)))) (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))) (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: (identifier))) (while_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))) body: (expression_statement (update_expression (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (identifier)))) (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: (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: (identifier)) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))))))) (return_statement (binary_expression left: (string_literal) right: (identifier)))))