from sys import stdin def rot(a): return [list(t) for t in zip(*a[::-1])] def flatten(a): return sum(vis, []) grid = [[int(c) for c in line.strip()] for line in stdin] vis = [[0 for _ in a] for a in grid] for _ in range(4): for trees, to in zip(grid, vis): highest = -1 for i in range(len(trees)): if highest < trees[i]: highest = trees[i] to[i] += 1 grid = rot(grid) vis = rot(vis) print(len([c for c in flatten(vis) if c > 0]))