corona crisis

0

0 votes
Problem

An antidote has been developed for the corona crisis. This antidote is conjuctive, i.e. If it is given to a person, 
then the person who is connected to this person will also be cured. Two people X and Y are connected if X and Y are 
adjacent or if there exists a person Z such that X and Z are connected and Z and Y are connected.

So, for every connected group of people we need one antidote. This antidotes strength must be equal to the highest infected 
person in the group.

Your task is to calculate the number of antidotes of different strengths needed.

CONSTRAINTS: 

5<N<500

INPUT
First line contains the size of the grid N. 
Next contains the NxN grid.

OUTPUT
Print 4 integers, the number of antidotes required of strength 2, 3, 4 and 5.

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

here 0 means that grid is empty 

1 means a healthy person is their

2,3,4 and 5 is the severity of the infected person.

Editor Image

?