public static void main ( String [ ] args ) throws Exception {
  int [ ] arr = new int [ 1 << 22 ] ;
  long [ ] cost = new long [ 1 << 20 ] ;
  for ( int i = 1 ;
  i < ( 1 << 20 ) ;
  i ++ ) {
    cost [ i ] = cost [ i - 1 ] + i * i ;
  }
  Scanner s = new Scanner ( new File ( "C.in" ) ) ;
  int T = s . nextInt ( ) ;
  for ( int tc = 1 ;
  tc <= T ;
  tc ++ ) {
    int C = s . nextInt ( ) ;
    Arrays . fill ( arr , 0 ) ;
    for ( int i = 0 ;
    i < C ;
    i ++ ) arr [ s . nextInt ( ) + 2000000 ] = s . nextInt ( ) ;
    long ans = 0 ;
    boolean ok = false ;
    while ( ! ok ) {
      ok = true ;
      for ( int i = 0 ;
      i < 4000000 ;
      i ++ ) {
        if ( arr [ i ] > 1 ) {
          ok = false ;
          int j = i ;
          while ( arr [ j ] >= arr [ i ] ) j ++ ;
          j -- ;
          if ( ( j - i ) % 2 == 1 ) j -- ;
          int v = arr [ i ] ;
          int val = v * ( j - i + 1 ) ;
          int loc = ( i + j ) / 2 ;
          ans -= v * cost [ ( j - i + 1 ) / 2 ] ;
          ans += cost [ val / 2 ] ;
          for ( int k = i ;
          k <= j ;
          k ++ ) arr [ k ] -= v ;
          for ( int shift = 0 ;
          shift <= val / 2 ;
          shift ++ ) {
            if ( shift == 0 && val % 2 == 1 ) arr [ loc ] ++ ;
            if ( shift > 0 ) {
              arr [ loc + shift ] ++ ;
              arr [ loc - shift ] ++ ;
            }
          }
        }
      }
    }
    System . out . println ( "Case #" + tc + ": " + ans ) ;
  }
}

public static void main ( String [ ] args ) throws Exception { int [ ] arr = new int [ 1 << 22 ] ; long [ ] cost = new long [ 1 << 20 ] ; for ( int i = 1 ; i < ( 1 << 20 ) ; i ++ ) { cost [ i ] = cost [ i - 1 ] + i * i ; } Scanner s = new Scanner ( new File ( " C . in " ) ) ; int T = s . nextInt ( ) ; for ( int tc = 1 ; tc <= T ; tc ++ ) { int C = s . nextInt ( ) ; Arrays . fill ( arr , 0 ) ; for ( int i = 0 ; i < C ; i ++ ) arr [ s . nextInt ( ) + 2000000 ] = s . nextInt ( ) ; long ans = 0 ; boolean ok = false ; while ( ! ok ) { ok = true ; for ( int i = 0 ; i < 4000000 ; i ++ ) { if ( arr [ i ] > 1 ) { ok = false ; int j = i ; while ( arr [ j ] >= arr [ i ] ) j ++ ; j -- ; if ( ( j - i ) % 2 == 1 ) j -- ; int v = arr [ i ] ; int val = v * ( j - i + 1 ) ; int loc = ( i + j ) / 2 ; ans -= v * cost [ ( j - i + 1 ) / 2 ] ; ans += cost [ val / 2 ] ; for ( int k = i ; k <= j ; k ++ ) arr [ k ] -= v ; for ( int shift = 0 ; shift <= val / 2 ; shift ++ ) { if ( shift == 0 && val % 2 == 1 ) arr [ loc ] ++ ; if ( shift > 0 ) { arr [ loc + shift ] ++ ; arr [ loc - shift ] ++ ; } } } } } System . out . println ( " Case ▁ # " + tc + " : ▁ " + ans ) ; } }
(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: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (binary_expression left: (decimal_integer_literal) right: (decimal_integer_literal)))))) (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 (binary_expression left: (decimal_integer_literal) 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: (parenthesized_expression (binary_expression left: (decimal_integer_literal) right: (decimal_integer_literal)))) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (binary_expression left: (identifier) right: (identifier))))))) (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)))) (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)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (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: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) (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: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (false))) (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: (array_access array: (identifier) index: (identifier)))) body: (expression_statement (update_expression (identifier)))) (expression_statement (update_expression (identifier))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (decimal_integer_literal)) right: (decimal_integer_literal))) consequence: (expression_statement (update_expression (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (array_access array: (identifier) index: (binary_expression left: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal))) right: (decimal_integer_literal)))))) (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))))) (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: (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: (binary_expression left: (identifier) right: (decimal_integer_literal))) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (decimal_integer_literal)))) consequence: (expression_statement (update_expression (array_access array: (identifier) index: (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (expression_statement (update_expression (array_access array: (identifier) index: (binary_expression left: (identifier) right: (identifier))))) (expression_statement (update_expression (array_access array: (identifier) index: (binary_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: (binary_expression left: (string_literal) right: (identifier)) right: (string_literal)) right: (identifier)))))))))