


"""simple docstring"""






import os
import string
import sys


_lowerCamelCase     =  1 << 8

_lowerCamelCase     =  {
    'tab': ord('\t'),
    'newline': ord('\r'),
    'esc': 27,
    'up': 65 + ARROW_KEY_FLAG,
    'down': 66 + ARROW_KEY_FLAG,
    'right': 67 + ARROW_KEY_FLAG,
    'left': 68 + ARROW_KEY_FLAG,
    'mod_int': 91,
    'undefined': sys.maxsize,
    'interrupt': 3,
    'insert': 50,
    'delete': 51,
    'pg_up': 53,
    'pg_down': 54,
}

_lowerCamelCase     =  KEYMAP['up']
_lowerCamelCase     =  KEYMAP['left']

if sys.platform == "win32":
	_lowerCamelCase     =  []
	_lowerCamelCase     =  {
	    b'\xe0H': KEYMAP['up'] - ARROW_KEY_FLAG,
	    b'\x00H': KEYMAP['up'] - ARROW_KEY_FLAG,
	    b'\xe0P': KEYMAP['down'] - ARROW_KEY_FLAG,
	    b'\x00P': KEYMAP['down'] - ARROW_KEY_FLAG,
	    b'\xe0M': KEYMAP['right'] - ARROW_KEY_FLAG,
	    b'\x00M': KEYMAP['right'] - ARROW_KEY_FLAG,
	    b'\xe0K': KEYMAP['left'] - ARROW_KEY_FLAG,
	    b'\x00K': KEYMAP['left'] - ARROW_KEY_FLAG,
	}

for i in range(10):
	_lowerCamelCase     =  ord(str(i))


def __lowercase     (      ):
				if os.name == "nt":
								import msvcrt

								SCREAMING_SNAKE_CASE__     							=				"mbcs"
								# Flush the keyboard buffer
								while msvcrt.kbhit():
												msvcrt.getch()
								if len(lowerCamelCase_  ) == 0:
												# Read the keystroke
												SCREAMING_SNAKE_CASE__     							=				msvcrt.getch()

												# If it is a prefix char, get second part
												if ch in (b"\x00", b"\xe0"):
																SCREAMING_SNAKE_CASE__     							=				ch + msvcrt.getch()
																# Translate actual Win chars to bullet char types
																try:
																				SCREAMING_SNAKE_CASE__     							=				chr(WIN_KEYMAP[cha]  )
																				WIN_CH_BUFFER.append(chr(KEYMAP["mod_int"]  )  )
																				WIN_CH_BUFFER.append(lowerCamelCase_  )
																				if ord(lowerCamelCase_  ) in (
																				    KEYMAP["insert"] - 1 << 9,
																				    KEYMAP["delete"] - 1 << 9,
																				    KEYMAP["pg_up"] - 1 << 9,
																				    KEYMAP["pg_down"] - 1 << 9,
																				):
																								WIN_CH_BUFFER.append(chr(126  )  )
																				SCREAMING_SNAKE_CASE__     							=				chr(KEYMAP["esc"]  )
																except KeyError:
																				SCREAMING_SNAKE_CASE__     							=				cha[1]
												else:
																SCREAMING_SNAKE_CASE__     							=				ch.decode(lowerCamelCase_  )
								else:
												SCREAMING_SNAKE_CASE__     							=				WIN_CH_BUFFER.pop(0  )
				elif os.name == "posix":
								import termios
								import tty

								SCREAMING_SNAKE_CASE__     							=				sys.stdin.fileno()
								SCREAMING_SNAKE_CASE__     							=				termios.tcgetattr(lowerCamelCase_  )
								try:
												tty.setraw(lowerCamelCase_  )
												SCREAMING_SNAKE_CASE__     							=				sys.stdin.read(1  )
								finally:
												termios.tcsetattr(lowerCamelCase_						,					termios.TCSADRAIN						,					lowerCamelCase_  )
				return ch


def __lowercase     (      ):
				SCREAMING_SNAKE_CASE__     							=				get_raw_chars()
				if ord(lowerCamelCase_  ) in [KEYMAP["interrupt"], KEYMAP["newline"]]:
								return char

				elif ord(lowerCamelCase_  ) == KEYMAP["esc"]:
								SCREAMING_SNAKE_CASE__     							=				get_raw_chars()
								if ord(lowerCamelCase_  ) == KEYMAP["mod_int"]:
												SCREAMING_SNAKE_CASE__     							=				get_raw_chars()
												if ord(lowerCamelCase_  ) >= KEYMAP["arrow_begin"] - ARROW_KEY_FLAG and ord(lowerCamelCase_  ) <= KEYMAP["arrow_end"] - ARROW_KEY_FLAG:
																return chr(ord(lowerCamelCase_  ) + ARROW_KEY_FLAG  )
												else:
																return KEYMAP["undefined"]
								else:
												return get_raw_chars()

				else:
								if char in string.printable:
												return char
								else:
												return KEYMAP["undefined"]




"""simple docstring"""






from __future__ import annotations

from collections.abc import Sequence
from typing import Literal


def __lowercase     (      lowerCamelCase_  :      str						,					lowerCamelCase_  :      str  ):
				SCREAMING_SNAKE_CASE__     							=				list(lowerCamelCase_  )
				SCREAMING_SNAKE_CASE__     							=				list(lowerCamelCase_  )
				SCREAMING_SNAKE_CASE__     							=				0
				for i in range(len(lowerCamelCase_  )  ):
								if lista[i] != lista[i]:
												count += 1
												SCREAMING_SNAKE_CASE__     							=				"_"
				if count > 1:
								return False
				else:
								return "".join(lowerCamelCase_  )


def __lowercase     (      lowerCamelCase_  :      list[str]  ):
				SCREAMING_SNAKE_CASE__     							=				[]
				while True:
								SCREAMING_SNAKE_CASE__     							=				["$"] * len(lowerCamelCase_  )
								SCREAMING_SNAKE_CASE__     							=				[]
								for i in range(len(lowerCamelCase_  )  ):
												for j in range(i + 1						,					len(lowerCamelCase_  )  ):
																SCREAMING_SNAKE_CASE__     							=				compare_string(binary[i]						,					binary[j]  )
																if k is False:
																				SCREAMING_SNAKE_CASE__     							=				"*"
																				SCREAMING_SNAKE_CASE__     							=				"*"
																				temp.append("X"  )
								for i in range(len(lowerCamelCase_  )  ):
												if checka[i] == "$":
																pi.append(binary[i]  )
								if len(lowerCamelCase_  ) == 0:
												return pi
								SCREAMING_SNAKE_CASE__     							=				list(set(lowerCamelCase_  )  )


def __lowercase     (      lowerCamelCase_  :      int						,					lowerCamelCase_  :      Sequence[float]  ):
				SCREAMING_SNAKE_CASE__     							=				[]
				for minterm in minterms:
								SCREAMING_SNAKE_CASE__     							=				""
								for _ in range(lowerCamelCase_  ):
												SCREAMING_SNAKE_CASE__     							=				str(minterm % 2  ) + string
												minterm //= 2
								temp.append(lowerCamelCase_  )
				return temp


def __lowercase     (      lowerCamelCase_  :      str						,					lowerCamelCase_  :      str						,					lowerCamelCase_  :      int  ):
				SCREAMING_SNAKE_CASE__     							=				list(lowerCamelCase_  )
				SCREAMING_SNAKE_CASE__     							=				list(lowerCamelCase_  )
				SCREAMING_SNAKE_CASE__     							=				0
				for i in range(len(lowerCamelCase_  )  ):
								if lista[i] != lista[i]:
												count_n += 1
				return count_n == count


def __lowercase     (      lowerCamelCase_  :      list[list[int]]						,					lowerCamelCase_  :      list[str]  ):
				SCREAMING_SNAKE_CASE__     							=				[]
				SCREAMING_SNAKE_CASE__     							=				[0] * len(lowerCamelCase_  )
				for i in range(len(chart[0]  )  ):
								SCREAMING_SNAKE_CASE__     							=				0
								SCREAMING_SNAKE_CASE__     							=				-1
								for j in range(len(lowerCamelCase_  )  ):
												if chart[j][i] == 1:
																count += 1
																SCREAMING_SNAKE_CASE__     							=				j
								if count == 1:
												SCREAMING_SNAKE_CASE__     							=				1
				for i in range(len(lowerCamelCase_  )  ):
								if select[i] == 1:
												for j in range(len(chart[0]  )  ):
																if chart[i][j] == 1:
																				for k in range(len(lowerCamelCase_  )  ):
																								SCREAMING_SNAKE_CASE__     							=				0
												temp.append(prime_implicants[i]  )
				while True:
								SCREAMING_SNAKE_CASE__     							=				0
								SCREAMING_SNAKE_CASE__     							=				-1
								SCREAMING_SNAKE_CASE__     							=				0
								for i in range(len(lowerCamelCase_  )  ):
												SCREAMING_SNAKE_CASE__     							=				chart[i].count(1  )
												if count_n > max_n:
																SCREAMING_SNAKE_CASE__     							=				count_n
																SCREAMING_SNAKE_CASE__     							=				i

								if max_n == 0:
												return temp

								temp.append(prime_implicants[rem]  )

								for i in range(len(chart[0]  )  ):
												if chart[rem][i] == 1:
																for j in range(len(lowerCamelCase_  )  ):
																				SCREAMING_SNAKE_CASE__     							=				0


def __lowercase     (      lowerCamelCase_  :      list[str]						,					lowerCamelCase_  :      list[str]  ):
				SCREAMING_SNAKE_CASE__     							=				[[0 for x in range(len(lowerCamelCase_  )  )] for x in range(len(lowerCamelCase_  )  )]
				for i in range(len(lowerCamelCase_  )  ):
								SCREAMING_SNAKE_CASE__     							=				prime_implicants[i].count("_"  )
								for j in range(len(lowerCamelCase_  )  ):
												if is_for_table(prime_implicants[i]						,					binary[j]						,					lowerCamelCase_  ):
																SCREAMING_SNAKE_CASE__     							=				1

				return chart


def __lowercase     (      ):
				SCREAMING_SNAKE_CASE__     							=				int(input("Enter the no. of variables\n"  )  )
				SCREAMING_SNAKE_CASE__     							=				[
				    float(lowerCamelCase_  )
				    for x in input(
				        "Enter the decimal representation of Minterms 'Spaces Separated'\n"  ).split()
				]
				SCREAMING_SNAKE_CASE__     							=				decimal_to_binary(lowerCamelCase_						,					lowerCamelCase_  )

				SCREAMING_SNAKE_CASE__     							=				check(lowerCamelCase_  )
				print("Prime Implicants are:"  )
				print(lowerCamelCase_  )
				SCREAMING_SNAKE_CASE__     							=				prime_implicant_chart(lowerCamelCase_						,					lowerCamelCase_  )

				SCREAMING_SNAKE_CASE__     							=				selection(lowerCamelCase_						,					lowerCamelCase_  )
				print("Essential Prime Implicants are:"  )
				print(lowerCamelCase_  )


if __name__ == "__main__":
	import doctest

	doctest.testmod()
	main()
