Products of matrices

Write a program that, given a sequence of square matrices m₁, …, m_(n),
prints in which order the matrices must be multiplied exactly once so
that the the result is as big as possible. We consider that the matrices
are to be compared in lexicographical order, from top to bottom and from
left to right.

Input

Input consists of a natural number n > 0, followed by m₁, …, m_(n). All
the matrices have size 2 × 2, and their four elements (natural numbers
between 0 and 9) appear in one or more lines.

Output

Print the order in which the matrices must be multiplied exactly once so
that the result is maximum, following the format of the examples. If
there is more than one way to obtain the same result, choose the
lexicographically smallest, comparing the matrices from left to right.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T12:15:09.309Z

© Jutge.org, 2006–2026.
https://jutge.org
