function visible(x, y) { if (x == 1 || x == right) return 1; if (y == 1 || y == bottom) return 1; for (xx = x-1; xx >= 1; --xx) { if (m[xx,y] >= m[x,y]) break; } if (!xx) return 1; for (xx = x+1; xx <= right; ++xx) { if (m[xx,y] >= m[x,y]) break; } if (xx > right) return 1; for (yy = y-1; yy >= 1; --yy) { if (m[x,yy] >= m[x,y]) break; } if (!yy) return 1; for (yy = y+1; yy <= bottom; ++yy) { if (m[x,yy] >= m[x,y]) break; } if (yy > bottom) return 1; return 0; } BEGIN { FS = ""; } { for (x = 1; x <= NF; ++x) { m[x,NR] = $x; } right = NF; bottom = NR; } END { for (x = 1; x <= right; ++x) { for (y = 1; y <= bottom; ++y) { if (visible(x, y)) vis++; } } print vis; }