#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
using namespace std;
int n, l, r, arr[55][55], dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 },ans;
int main()
{
cin >> n >> l >> r;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
scanf("%d", &arr[i][j]);
}
}
while (1) {
int visit[55][55] = { 0 };
int num = 0,chk=0,cnt=0;
int cal[2510][2] = { 0 };
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (visit[i][j] == 0) {
cnt++;
queue<pair<int, int>> q;
q.push({ i,j });
visit[i][j] = cnt;
while (!q.empty()) {
int x, y;
x = q.front().first;
y = q.front().second;
cal[cnt][0]++;
cal[cnt][1] = cal[cnt][1] + arr[x][y];
q.pop();
for (int z = 0; z < 4; z++) {
int kx, ky,dis=0;
kx = x + dx[z];
ky = y + dy[z];
if (kx < 0 || kx >= n || ky < 0 || ky >= n || visit[kx][ky] != 0) continue;
dis = abs(arr[x][y] - arr[kx][ky]);
if (dis >= l && dis <= r) {
chk = 1;
q.push({ kx,ky });
visit[kx][ky] = cnt;
}
}
}
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (visit[i][j] != 0) {
arr[i][j] = cal[visit[i][j]][1] / cal[visit[i][j]][0];
}
}
}
if (chk == 0) break;
ans++;
}
printf("%d", ans);
return 0;
}