from itertools import cycle
from sys import maxsize, stdin


ROCKS_STR = """
    ####

    .#.
    ###
    .#.

    ..#
    ..#
    ###

    #
    #
    #
    #

    ##
    ##
"""


ROCKS = [rock.split() for rock in ROCKS_STR.split("\n\n")]


def collides(a, b, dx, dy):
    return any((x + dx, y + dy) in b for x, y in a)


def print_grids(grids, offsets, chars="#@"):
    min_x = 1
    min_y = -1

    max_x = 7
    max_y = -1

    for grid, (dx, dy) in zip(grids, offsets):
        for x, y in grid:
            min_x = min(min_x, x + dx)
            min_y = min(min_y, y + dy)

            max_x = max(max_x, x + dx)
            max_y = max(max_y, y + dy)

    for y in range(min_y, max_y + 1):
        line = []

        for x in range(min_x, max_x + 1):
            c = "."

            for i, (grid, (dx, dy)) in enumerate(zip(grids, offsets)):
                if (x - dx, y - dy) in grid:
                    c = chars[i % len(chars)]
                    break

            line.append(c)

        print("".join(line))


def get_snapshot(grid, min_y, height):
    return "\n".join(
        "".join(".#"[(x, y) in grid] for x in range(1, 8))
        for y in range(min_y, min_y + height)
    )


def solve(jet_pattern, rock_count):
    time_iter = iter(range(maxsize))

    chamber_grid = set()

    min_y = 0
    max_y = -1

    bottom_count = 0
    cycle_length = 0

    seen = {}

    for i in range(rock_count):
        rock = ROCKS[i % len(ROCKS)]

        rock_width = len(rock[0])
        rock_height = len(rock)

        rock_grid = {
            (x, y) for y, l in enumerate(rock) for x, c in enumerate(l) if c == "#"
        }

        x = 3
        y = min_y - 3 - rock_height

        # print()
        # print("---")
        # print()
        # print_grids([chamber_grid, rock_grid], [(0, 0), (x, y)])

        for time in time_iter:
            jet_char = jet_pattern[time % len(jet_pattern)]
            dx = -1 if jet_char == "<" else 1

            new_x = x + dx

            if new_x < 1 or new_x + rock_width > 8:
                new_x = x
            elif collides(rock_grid, chamber_grid, new_x, y):
                new_x = x

            x = new_x
            new_y = y + 1
            resting = False

            if collides(rock_grid, chamber_grid, x, new_y):
                new_y = y
                resting = True
            elif new_y + rock_height > 0:
                new_y = y
                resting = True

            y = new_y

            # print()
            # print(jet_char)
            # print()
            # print_grids([chamber_grid, rock_grid], [(0, 0), (x, y)])

            if resting:
                for dx, dy in rock_grid:
                    min_y = min(min_y, y + dy)
                    chamber_grid.add((x + dx, y + dy))

                # print()
                # print_grids([chamber_grid], [(0, 0)])

                snapshot = get_snapshot(chamber_grid, min_y, 7)
                count = i + 1

                if snapshot in seen:
                    if cycle_length != count - seen[snapshot]:
                        bottom_count = seen[snapshot]
                        cycle_length = count - bottom_count

                seen[snapshot] = count
                break

    return max_y - min_y + 1, bottom_count, cycle_length


def main():
    jet_pattern = stdin.read().strip()

    result, bottom_count, cycle_length = solve(jet_pattern, 2022)
    print(result)

    cycle_count, top_count = divmod(1000000000000 - bottom_count, cycle_length)

    bottom_height = solve(jet_pattern, bottom_count)[0]
    cycle_height = solve(jet_pattern, bottom_count + cycle_length)[0] - bottom_height
    top_height = solve(jet_pattern, bottom_count + top_count)[0] - bottom_height

    print(bottom_height + cycle_count * cycle_height + top_height)


if __name__ == "__main__":
    main()
