Problem 200 counts components; this one measures them. The scan, the
four neighbours and the sink-before-you-recurse rule are unchanged — the single
edit is the return type. void becomes int,
and every call owes its caller 1 + down + up + right + left. The sum is
assembled on the way down and collapses on the way back up; watch the returns land.
1 + is free: the visit that counted the island already existed, it just threw its result away. Sinking before the four calls is what keeps every cell in exactly one summand — a cell already sunk returns 0, so it is added once and never again.