from sys import stdin


def parse_point(s):
    x, y = s.split(",")
    return int(x), int(y)


def sign(x):
    return -1 if x < 0 else 1 if x > 0 else 0


def generate_rocks(line):
    points = [parse_point(t) for t in line.split(" -> ")]
    ax, ay = points.pop()
    yield ax, ay

    while points:
        bx, by = points.pop()

        dx = sign(bx - ax)
        dy = sign(by - ay)

        assert dx * dy == 0 and dx + dy != 0

        while (ax, ay) != (bx, by):
            ax += dx
            ay += dy

            yield ax, ay


def print_grid(grid):
    min_x = min(x for x, y in grid)
    min_y = min(y for x, y in grid)

    max_x = max(x for x, y in grid)
    max_y = max(y for x, y in grid)

    for y in range(min_y, max_y + 1):
        print("".join(grid.get((x, y), ".") for x in range(min_x, max_x + 1)))


def main():
    grid = {}

    for line in stdin:
        for p in generate_rocks(line):
            grid[p] = "#"

    max_y = max(y for x, y in grid)

    while True:
        ax, ay = 500, 0

        while ay < max_y:
            for bx, by in (ax, ay + 1), (ax - 1, ay + 1), (ax + 1, ay + 1):
                if (bx, by) not in grid:
                    ax, ay = bx, by
                    break
            else:
                grid[ax, ay] = "o"
                break
        else:
            break

    print(sum(c == "o" for c in grid.values()))


if __name__ == "__main__":
    main()
