5. (informatics) In a square matrix of size $N \times N$, all cells are filled with numbers from 1 to 5. A connected component in the matrix is defined as a set of cells that are filled with the same number, and between any two cells in the set, a path can be constructed. Cells can only be connected in a path if they are adjacent horizontally or vertically.

In other words, a connected component of the matrix is a connected shape, where the cells are filled with the same number.

For a given matrix, the task is to find the connected component consisting of the largest number of cells.

| 1 | 2 | 5 | 3 | 5 | 2 |
| :--- | :--- | :--- | :--- | :--- | :--- |
| 1 | 2 | 5 | 5 | 5 | 2 |
| 1 | 2 | 2 | 2 | 4 | 5 |
| 1 | 2 | 5 | 2 | 5 | 5 |
| 1 | 3 | 5 | 2 | 5 | 5 |
| 1 | 3 | 5 | 5 | 4 | 4 |

In the first line of the input data, there is an integer $N$ such that $1 \leq N \leq 10$. In the next $N$ lines, there are $N$ integers separated by spaces, each number is within the range from 1 to 5. The output should be a single number - the number of cells in the largest connected component of the matrix.

Examples of input data and program results:

| Example input data |  |  |  | Example result |  |  |
| :--- | :--- | :--- | :--- | :--- | :--- | :--- |
| 6 |  |  |  |  |  |  |
| 1 | 2 | 5 | 3 | 5 | 2 |  |
| 1 | 2 | 5 | 5 | 5 | 2 |  |
| 1 | 2 | 2 | 2 | 4 | 5 |  |
| 1 | 2 | 5 | 2 | 5 | 5 |  |
| 1 | 3 | 5 | 2 | 5 | 5 |  |
| 1 | 3 | 5 | 5 | 4 | 4 |  |

## Comments on the informatics problem:

The solution to the problem is a program code written in any traditional programming language, with the language specified. In the case of the impossibility of writing code in a traditional programming language, a correct algorithm of the program, presented in the form of a flowchart or pseudocode, can be accepted as a partial solution.

The program should read input data from the standard input stream (as if these data are entered from the keyboard) and output results to the standard output stream (as if these data are printed on the screen). The program should work correctly with the input data described in the problem conditions. The correctness of the input data is guaranteed, and it is not necessary to check it additionally within the program (if the problem states that an integer from 0 to 1000 is input, there is no need to additionally check whether, for example, a text string or a number outside this range is entered).

The program should output only the answer required by the problem (which may be accompanied by a brief textual formatting or without it). Any other output of results during the program's operation will be considered an error. For better understanding of the problem conditions and formats of input and output data, the problem is accompanied by several examples of correct input data and the correct result of the program's operation, provided in the section “examples of input data and program results”.

The written program should work efficiently, that is, compute the correct answer as quickly as possible. Programs that are written significantly inefficiently, that is, taking significantly more time than efficient solutions, will be considered an incomplete solution.

The program code should be written clearly, neatly, with indentation and a reasonable amount of comments in the program code. Minor syntactic errors in the code are allowed, provided that they do not affect the overall readability and understanding of the code. An untidy (unreadable) program code and/or a large number of syntactic errors may result in a reduced overall score for the problem.

## Example of solution formatting (program code):

```
{pascal} // indication of the language in which the program is written
program MyProg;
var:
begin
    {read input data} // comment in the body of the program
readln (a,b);
    ..
    {main body of the program}
    *.
    {output the answer}
writeln('The desired number: ',x);
end.
```
# Solution.

program prog11;

var n,i,j,k,l:integer;

a,b:array[0..11,0..11] of integer;

m,mc,mmax:integer;

begin

{initialize the array}

for i:=0 to 11 do

for j:=0 to 11 do

```
a[i,j]:=0;
{read input data}
readln(N);
for i:=1 to N do
    begin
    for j:=1 to N do
        read(a[i,j]);
    readln;
end;
mmax:=0;{current value of the maximum component power}
{form a connected component from each element of the matrix}
for k:=1 to N do
for l:=1 to N do
    begin
    {initialize the auxiliary array}
        for i:=0 to 11 do
            for j:=0 to 11 do
                b[i,j]:=0;
    b[k,1]:=1;{add the first element of the component}
    m:=1;{current component power}
    mc:=1;{current increment power at the algorithm step}
    while mc>0 do{while new elements were added on the previous step}
    begin
        mc:=0;
        for i:=1 to N do
            for j:=1 to N do
            if (b[i,j]=0) then{element not added to the connected component}
                if ((b[i,j-1]=1) and (a[i,j-1]=a[i,j]))
                or ((b[i,j+1]=1) and (a[i,j+1]=a[i,j]))
                or ((b[i-1,j]=1) and (a[i-1,j]=a[i,j]))
                or ((b[i+1,j]=1) and (a[i+1,j]=a[i,j]))
            then{there is a neighbor in the connected component and the cell values match}
                begin {add the element to the connected component}
                    b[i,j]:=1;
                    inc(m);
```

inc(mc)

end;

end;

if m>mmax then mmax:=m; {check and update the maximum}

end;

writeln(mmax); {output the answer}

end.