





'''simple docstring'''




from __future__ import annotations

from PIL import Image

# Define glider example
a__					:			Optional[int]          =     [
    [0, 1, 0, 0, 0, 0, 0, 0],
    [0, 0, 1, 0, 0, 0, 0, 0],
    [1, 1, 1, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
]

# Define blinker example
a__					:			List[Any]          =     [[0, 1, 0], [0, 1, 0], [0, 1, 0]]




def 						__lowerCamelCase			(	UpperCAmelCase_							)   ->list[list[int]]:
	snake_case__	       =   []
	for i in range(len(UpperCAmelCase_							)							):
		snake_case__	       =   []
		for j in range(len(cells[i]							)							):
			# Get the number of live neighbours
			snake_case__	       =   0
			if i > 0 and j > 0:
				neighbour_count += cells[i - 1][j - 1]
			if i > 0:
				neighbour_count += cells[i - 1][j]
			if i > 0 and j < len(cells[i]							) - 1:
				neighbour_count += cells[i - 1][j + 1]
			if j > 0:
				neighbour_count += cells[i][j - 1]
			if j < len(cells[i]							) - 1:
				neighbour_count += cells[i][j + 1]
			if i < len(UpperCAmelCase_							) - 1 and j > 0:
				neighbour_count += cells[i + 1][j - 1]
			if i < len(UpperCAmelCase_							) - 1:
				neighbour_count += cells[i + 1][j]
			if i < len(UpperCAmelCase_							) - 1 and j < len(cells[i]							) - 1:
				neighbour_count += cells[i + 1][j + 1]

			# Rules of the game of life (excerpt from Wikipedia):
			# 1. Any live cell with two or three live neighbours survives.
			# 2. Any dead cell with three live neighbours becomes a live cell.
			# 3. All other live cells die in the next generation.
			#    Similarly, all other dead cells stay dead.
			snake_case__	       =   cells[i][j] == 1
			if (
			    (alive and 2 <= neighbour_count <= 3)
			    or not alive
			    and neighbour_count == 3
			):
				next_generation_row.append(1							)
			else:
				next_generation_row.append(0							)

		next_generation.append(UpperCAmelCase_							)
	return next_generation




def 						__lowerCamelCase			(	UpperCAmelCase_					,				UpperCAmelCase_							)   ->list[Image.Image]:
	snake_case__	       =   []
	for _ in range(UpperCAmelCase_							):
		# Create output image
		snake_case__	       =   Image.new('RGB'					,				(len(cells[0]							), len(UpperCAmelCase_							))							)
		snake_case__	       =   img.load()

		# Save cells to image
		for x in range(len(UpperCAmelCase_							)							):
			for y in range(len(cells[0]							)							):
				snake_case__	       =   2_55 - cells[y][x] * 2_55
				snake_case__	       =   (colour, colour, colour)

        # Save image
		images.append(UpperCAmelCase_							)
		snake_case__	       =   new_generation(UpperCAmelCase_							)
	return images


if __name__ == "__main__":
			a__					:			Any          =     generate_images(GLIDER, 16)
			images[0].save('''out.gif''', save_all=True, append_images=images[1:])










'''simple docstring'''




from collections import Counter
from timeit import timeit




def 						__lowerCamelCase			(	UpperCAmelCase_ = ""					,				)   ->bool:
	return sum(c % 2 for c in Counter(input_str.replace(' '					,				''							).lower()							).values()							) < 2




def 						__lowerCamelCase			(	UpperCAmelCase_ = ""							)   ->bool:
	if len(UpperCAmelCase_							) == 0:
		return True
	snake_case__	       =   input_str.replace(' '					,				''							).lower()
	# character_freq_dict: Stores the frequency of every character in the input string
	snake_case__	       =   {}

	for character in lower_case_input_str:
		snake_case__	       =   character_freq_dict.get(UpperCAmelCase_					,				0							) + 1
	snake_case__	       =   0

	for character_count in character_freq_dict.values():
		if character_count % 2:
			odd_char += 1
	if odd_char > 1:
		return False
	return True




def 						__lowerCamelCase			(	UpperCAmelCase_ = ""							)   ->None:
	print('\nFor string = '					,				UpperCAmelCase_					,				':'							)
	print(
	    '> can_string_be_rearranged_as_palindrome_counter()'					,				'\tans ='					,				can_string_be_rearranged_as_palindrome_counter(UpperCAmelCase_							)					,				'\ttime ='					,				timeit(
	        'z.can_string_be_rearranged_as_palindrome_counter(z.check_str)'					,				setup='import __main__ as z'					,				)					,				'seconds'					,				)
	print(
	    '> can_string_be_rearranged_as_palindrome()'					,				'\tans ='					,				can_string_be_rearranged_as_palindrome(UpperCAmelCase_							)					,				'\ttime ='					,				timeit(
	        'z.can_string_be_rearranged_as_palindrome(z.check_str)'					,				setup='import __main__ as z'					,				)					,				'seconds'					,				)


if __name__ == "__main__":
			a__					:			str          =     input(
			    '''Enter string to determine if it can be rearranged as a palindrome or not: '''
			).strip()
			benchmark(check_str)
			a__					:			List[Any]          =     can_string_be_rearranged_as_palindrome_counter(check_str)
			print(f"""{check_str} can {'' if status else 'not '}be rearranged as a palindrome""")



