def dfs(y,x):
global n,l,r,cnt,swich
# 상하좌우에 대해서 탐색
for i in range(4):
ny = y + dy[i]
nx = x + dx[i]
# 인덱싱 범위 안이고, 인구차이 수가 문제조건 해당이고, 방문하지 않았다면
if 0 <= ny < n and 0 <= nx < n and l <= abs(arr[y][x] - arr[ny][nx]) <= r and not visited[ny][nx]:
swich = 'on'
locs.append((ny,nx))
cnt += arr[ny][nx]
visited[ny][nx] = True
dfs(ny,nx)
return
n,l,r = map(int,input().split())
arr = [list(map(int,input().split())) for _ in range(n)]
visited = [[False for _ in range(n)] for __ in range(n)]
dy = [-1,1,0,0]
dx = [0,0,-1,1]
swich = 'on'
rst = 0
while swich == 'on':
swich = 'off'
visited = [[False for _ in range(n)] for __ in range(n)]
for y in range(n):
for x in range(n):
locs = []
if not visited[y][x]:
visited[y][x] = True
cnt = arr[y][x]
locs.append((y,x))
dfs(y,x)
for ny,nx in locs:
arr[ny][nx] = cnt//len(locs)
if swich == 'on':
rst += 1
print(rst)