






"""simple docstring"""



import itertools
import string
from collections.abc import Generator, Iterable




def      _lowerCAmelCase		(							UpperCAmelCase__       :					Iterable[str],						UpperCAmelCase__       :					int      )		->Generator[tuple[str, ...], None, None]:
						A__						:  List[str]		  =  iter(UpperCAmelCase__      )
						while True:
												A__						:  int		  =  tuple(itertools.islice(UpperCAmelCase__,						UpperCAmelCase__      )      )
												if not chunk:
																		return
												yield chunk




def      _lowerCAmelCase		(							UpperCAmelCase__       :					str      )		->str:
						A__						:  Union[str, Any]		  =  """""".join([c.upper() for c in dirty if c in string.ascii_letters]      )
						A__						:  Optional[Any]		  =  """"""

						if len(UpperCAmelCase__      ) < 2:
												return dirty

						for i in range(len(UpperCAmelCase__      ) - 1      ):
												clean += dirty[i]

												if dirty[i] == dirty[i + 1]:
																		clean += "X"

						clean += dirty[-1]

						if len(UpperCAmelCase__      ) & 1:
												clean += "X"

						return clean




def      _lowerCAmelCase		(							UpperCAmelCase__       :					str      )		->list[str]:
						# I and J are used interchangeably to allow
						# us to use a 5x5 table (25 letters)
						A__						:  List[Any]		  =  """ABCDEFGHIKLMNOPQRSTUVWXYZ"""
						# we're using a list instead of a '2d' array because it makes the math
						# for setting up the table and doing the actual encoding/decoding simpler
						A__						:  Optional[Any]		  =  []

						# copy key chars into the table if they are in `alphabet` ignoring duplicates
						for char in key.upper():
												if char not in table and char in alphabet:
																		table.append(UpperCAmelCase__      )

    # fill the rest of the table in with the remaining alphabet chars
						for char in alphabet:
												if char not in table:
																		table.append(UpperCAmelCase__      )

						return table




def      _lowerCAmelCase		(							UpperCAmelCase__       :					str,						UpperCAmelCase__       :					str      )		->str:
						A__						:  Optional[int]		  =  generate_table(UpperCAmelCase__      )
						A__						:  str		  =  prepare_input(UpperCAmelCase__      )
						A__						:  Optional[Any]		  =  """"""

						# https://en.wikipedia.org/wiki/Playfair_cipher#Description
						for chara, chara in chunker(UpperCAmelCase__,						2      ):
												A__  ,  A__						:  Dict		  =  divmod(table.index(UpperCAmelCase__      ),						5      )
												A__  ,  A__						:  Union[str, Any]		  =  divmod(table.index(UpperCAmelCase__      ),						5      )

												if rowa == rowa:
																		ciphertext += table[rowa * 5 + (cola + 1) % 5]
																		ciphertext += table[rowa * 5 + (cola + 1) % 5]
												elif cola == cola:
																		ciphertext += table[((rowa + 1) % 5) * 5 + cola]
																		ciphertext += table[((rowa + 1) % 5) * 5 + cola]
												else:  # rectangle
																		ciphertext += table[rowa * 5 + cola]
																		ciphertext += table[rowa * 5 + cola]

						return ciphertext




def      _lowerCAmelCase		(							UpperCAmelCase__       :					str,						UpperCAmelCase__       :					str      )		->str:
						A__						:  Optional[Any]		  =  generate_table(UpperCAmelCase__      )
						A__						:  Any		  =  """"""

						# https://en.wikipedia.org/wiki/Playfair_cipher#Description
						for chara, chara in chunker(UpperCAmelCase__,						2      ):
												A__  ,  A__						:  List[Any]		  =  divmod(table.index(UpperCAmelCase__      ),						5      )
												A__  ,  A__						:  str		  =  divmod(table.index(UpperCAmelCase__      ),						5      )

												if rowa == rowa:
																		plaintext += table[rowa * 5 + (cola - 1) % 5]
																		plaintext += table[rowa * 5 + (cola - 1) % 5]
												elif cola == cola:
																		plaintext += table[((rowa - 1) % 5) * 5 + cola]
																		plaintext += table[((rowa - 1) % 5) * 5 + cola]
												else:  # rectangle
																		plaintext += table[rowa * 5 + cola]
																		plaintext += table[rowa * 5 + cola]

						return plaintext














"""simple docstring"""



from timeit import timeit




def      _lowerCAmelCase		(							UpperCAmelCase__       :					int      )		->int:
						if number < 0:
												raise ValueError("""the value of input must not be negative"""      )
						A__						:  Optional[int]		  =  0
						while number:
												number &= number - 1
												result += 1
						return result




def      _lowerCAmelCase		(							UpperCAmelCase__       :					int      )		->int:
						if number < 0:
												raise ValueError("""the value of input must not be negative"""      )
						A__						:  Tuple		  =  0
						while number:
												if number % 2 == 1:
																		result += 1
												number >>= 1
						return result




def      _lowerCAmelCase		(							)		->None:

						def do_benchmark(UpperCAmelCase__       :					int      ) -> None:
												A__						:  Optional[int]		  =  """import __main__ as z"""
												print(f'Benchmark when {number = }:'      )
												print(f'{get_set_bits_count_using_modulo_operator(UpperCAmelCase__      ) = }'      )
												A__						:  Any		  =  timeit("""z.get_set_bits_count_using_modulo_operator(25)""",						setup=UpperCAmelCase__      )
												print(f'timeit() runs in {timing} seconds'      )
												print(f'{get_set_bits_count_using_brian_kernighans_algorithm(UpperCAmelCase__      ) = }'      )
												A__						:  List[str]		  =  timeit(
												    """z.get_set_bits_count_using_brian_kernighans_algorithm(25)""",						setup=UpperCAmelCase__,						)
												print(f'timeit() runs in {timing} seconds'      )

						for number in (2_5, 3_7, 5_8, 0):
												do_benchmark(UpperCAmelCase__      )
												print()


if __name__ == "__main__":
						import doctest

						doctest.testmod()
						benchmark()






