#B4314. Reassembling the Rubik's Cube

    ID: 11970 Type: Default 1000ms 256MiB

Reassembling the Rubik's Cube

Reassembling the Rubik's Cube

A standard Rubik's Cube is composed of $8$ corner pieces, $12$ edge pieces, and $1$ center (axis).

You are given $n$ damaged Rubik's Cubes. For each cube, you are provided with three integers:

  • $a$: the number of broken corner pieces,
  • $e$: the number of broken edge pieces,
  • $c$: a flag indicating whether the center is broken (1 for broken, 0 for intact).

The process to recycle the cubes is as follows:

  1. Disassemble all pieces (corners, edges, and the center) from each cube and discard any broken parts.
  2. Restick all remaining pieces (the original colors no longer matter).
  3. Reassemble complete Rubik's Cubes using $8$ corner pieces, $12$ edge pieces, and $1$ center for each cube.

Determine the maximum number of complete cubes that can be reassembled from the salvaged parts.

inputFormat

The first line contains an integer nn (1n1051 \leq n \leq 10^5), the number of damaged Rubik's Cubes. Each of the next nn lines contains three integers aa, ee, and cc, where:

  • aa is the number of broken corner pieces in that cube (0a80 \leq a \leq 8),
  • ee is the number of broken edge pieces in that cube (0e120 \leq e \leq 12),
  • cc is a flag (either 0 or 1) indicating if the center is broken (1 means broken, 0 means intact).

All values are space-separated.

outputFormat

Output a single integer — the maximum number of complete Rubik's Cubes that can be reassembled from the salvaged parts.

sample

1
1 2 0
0