#!/usr/bin/env python3 import sys def parse(): G = [] for l in sys.stdin: G.append([int(x) for x in l.strip()]) return G def safeget(G, i, j): if i < 0 or j < 0 or i >= len(G) or j >= len(G[0]): return None return G[i][j] def score(G, i0, j0): s = 0 stk = [(i0, j0)] while stk: (i, j) = stk.pop() height = G[i][j] if height == 9: s += 1 continue for pos in [(i+1,j),(i-1,j),(i,j-1),(i,j+1)]: next = safeget(G, pos[0], pos[1]) if next == height + 1: stk.append(pos) return s def sol(G): tot = 0 for i in range(len(G)): for j in range(len(G[0])): if G[i][j] == 0: tot += score(G, i, j) return tot if __name__ == '__main__': G = parse() print(sol(G))