#Lutece2338. Linear Algebra
Linear Algebra
Migrated from Lutece 2338 Linear Algebra
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
Cjj is learning linear algebra. He thinks matrix multiplication is very interesting.
As we know, given two matrices and , the product is defined if and only if the number of columns in equals the number of rows in . In more detail, if is an matrix and is an matrix, the product is an matrix.
This extends naturally to the product of any number of matrices. That is, if are matrices such that the number of columns in equals the number of rows in for , then the product is . The number of rows in the product equals the number of rows in . The number of columns in the product equals the number of columns in .
After learning matrix multiplication, Cjj writes down matrices . They can be multiplied together as . But evil Macaron_lin wants to destroy his work, so he rearranges the order of these matrices. Now given the rearranged matrices, can you help Cjj calculate their product? To simplify the problem, we just give you the number of rows and columns in a matrix, and you just need to calculate the number of elements in the product.
Input
The first line contains an integer () — the number of matrices.
The next lines describe the matrices. The -th line contains two intergers and (), which means the -th matrix has rows and columns. Please note that the order of matrices is rearranged.
It is guaranteed that there is at least one possible solution.
Output
Print the number of elements in the product. If there are multiple solutions, print the maximum one.
Samples
3
2 3
1 2
3 4
4
2
1 2
2 1
4
Note
In the fisrt sample, is a matrix, is a matrix, and is a matrix. The product is an matrix. There are elements in the product.
In the second sample, there are two solutions:
- is a matrix, and is a matrix. The product is a matrix. There is element in the product.
- is a matrix, and is a matrix. The product is a matrix. There are elements in the product.
The maximum number is .
Resources
电子科技大学第十一届 ACM 趣味程序设计竞赛