Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/matritsa-lokal-maksimumlar

Local maximums

Medium 1000 ms 128 MB 57%
Share

An integer matrix of size $n \times m$ is given. An element is a local maximum if it is strictly greater than all its neighbours — the cells above, below, to the left and to the right (those inside the matrix); a single element with no neighbours counts too. Find the number of local maximums in the matrix.

Local maximums that are greater than all their neighbours

Input

The first line contains two positive integers $n$ and $m$. Each of the next $n$ lines contains $m$ integers.

Output

One integer — the number of local maximums.

Note

$1 \le n, m \le 200$
$-1000 \le a_{i,j} \le 1000$

Examples

Input #1
3 3
1 2 1
4 0 3
1 5 1
Output #1
4
Input #2
1 1
7
Output #2
1

Sign in to submit a solution

Signing up is free and takes a minute.