
from itertools import permutations





def 		SCREAMING_SNAKE_CASE__      ( __lowerCAmelCase = 5							):
    if gon_side < 3 or gon_side > 5:
        raise ValueError("gon_side must be in the range [3, 5]"							)

    # Since it's 16, we know 10 is on the outer ring
    # Put the big numbers at the end so that they are never the first number
    snake_case__  =			list(range(gon_side + 1      ,						0      ,						-1							)							)
    snake_case__  =			list(range(gon_side + 2      ,						gon_side * 2 + 1							)							)

    for perm in permutations(small_numbers + big_numbers							):
        snake_case__  =			generate_gon_ring(__lowerCAmelCase      ,						list(__lowerCAmelCase							)							)
        if is_magic_gon(__lowerCAmelCase							):
            return int("".join(str(__lowerCAmelCase							) for n in numbers							)							)

    snake_case__  =			F"""Magic {gon_side}-gon ring is impossible"""
    raise ValueError(__lowerCAmelCase							)





def 		SCREAMING_SNAKE_CASE__      ( __lowerCAmelCase      ,						__lowerCAmelCase							):
    snake_case__  =			[0] * (gon_side * 3)
    snake_case__  =			perm[0:3]
    perm.append(perm[1]							)

    snake_case__  =			1 if gon_side < 5 else 2

    for i in range(1      ,						len(__lowerCAmelCase							) // 3 + magic_number							):
        snake_case__  =			perm[2 * i + 1]
        snake_case__  =			result[3 * i - 1]
        snake_case__  =			perm[2 * i + 2]

    return result





def 		SCREAMING_SNAKE_CASE__      ( __lowerCAmelCase							):
    if len(__lowerCAmelCase							) % 3 != 0:
        raise ValueError("a gon ring should have a length that is a multiple of 3"							)

    if min(numbers[::3]							) != numbers[0]:
        return False

    snake_case__  =			sum(numbers[:3]							)

    return all(sum(numbers[i : i + 3]							) == total for i in range(3      ,						len(__lowerCAmelCase							)      ,						3							)							)


if __name__ == "__main__":
     print(solution())


from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
__magic_name__           =					[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]





def 		SCREAMING_SNAKE_CASE__      ( __lowerCAmelCase							):
    return [int(__lowerCAmelCase							) for c in F"""{ruleset:08}"""[:8]]





def 		SCREAMING_SNAKE_CASE__      ( __lowerCAmelCase      ,						__lowerCAmelCase      ,						__lowerCAmelCase							):
    snake_case__  =			len(cells[0]							)  # 31
    snake_case__  =			[]
    for i in range(__lowerCAmelCase							):
        # Get the neighbors of each cell
        # Handle neighbours outside bounds by using 0 as their value
        snake_case__  =			0 if i == 0 else cells[time][i - 1]
        snake_case__  =			0 if i == population - 1 else cells[time][i + 1]
        # Define a new cell and add it to the new generation
        snake_case__  =			7 - int(F"""{left_neighbor}{cells[time][i]}{right_neighbor}"""      ,						2							)
        next_generation.append(rule[situation]							)
    return next_generation





def 		SCREAMING_SNAKE_CASE__      ( __lowerCAmelCase							):
    snake_case__  =			Image.new("RGB"      ,						(len(cells[0]							), len(__lowerCAmelCase							))							)
    snake_case__  =			img.load()
    # Generates image
    for w in range(img.width							):
        for h in range(img.height							):
            snake_case__  =			255 - int(255 * cells[h][w]							)
            snake_case__  =			(color, color, color)
    return img


if __name__ == "__main__":
     __magic_name__           =					bin(int(input('''Rule:\n''').strip()))[2:]
     __magic_name__           =					format_ruleset(int(rule_num))
     for time in range(16):
          CELLS.append(new_generation(CELLS, rule, time))
     __magic_name__           =					generate_image(CELLS)
     # Uncomment to save the image
     # img.save(f"rule_{rule_num}.png")
     img.show()



