Cow Matrix


Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 256M

Problem type
Allowed languages
C++, Python

Problem Description

Every morning, when Farmer John`s cows are being milked, they stand in a grid with R rows and C columns.

Each cow is marked with an uppercase letter representing its breed, so all cows together form a character matrix of R rows and C columns.

Given the matrix formed by all cows, find the area of its smallest covering rectangle.

A submatrix is called a covering submatrix if, when repeated/tiled infinitely in both directions, it can cover the entire original matrix.

Input Format
Line 1: Two integers R and C, separated by a space.
Lines 2 to R+1: Each line contains C characters with no spaces, depicting the matrix.

Output Format
Output the area of the smallest covering submatrix. (Area of one character = 1)

Data Range
1 ≤ R ≤ 10000
1 ≤ C ≤ 75

Input Sample:

2 5
ABABA
ABABA

Output Sample:

2

Hint
In the sample, the smallest covering submatrix is "AB", which has area 2.


Comments

There are no comments at the moment.