






from dataclasses import dataclass

_a       =    '''0.1'''
_a       =    '''Lucia Harcekova'''





@dataclass
class __lowerCamelCase					:





	"""simple docstring"""






	UpperCamelCase__								= 42
	UpperCamelCase__								= 42
	UpperCamelCase__								= 42

	def __repr__(				self       ):
							"""simple docstring"""







							return F"""({self.offset}, {self.length}, {self.indicator})"""





class __lowerCamelCase					:





	"""simple docstring"""






	def __init__(				self			,       UpperCAmelCase = 13			,       UpperCAmelCase = 6       ):
							"""simple docstring"""







							_UpperCAmelCase							   =     window_size
							_UpperCAmelCase							   =     lookahead_buffer_size
							_UpperCAmelCase							   =     self.window_size - self.lookahead_buffer_size

	def 			UpperCamelCase       (				self			,       UpperCAmelCase       ):
							"""simple docstring"""







							_UpperCAmelCase							   =     []
							_UpperCAmelCase							   =     ''

							# while there are still characters in text to compress
							while text:
													# find the next encoding phrase
													# - triplet with offset, length, indicator (the next encoding character)
													_UpperCAmelCase							   =     self._find_encoding_token(UpperCAmelCase			,       UpperCAmelCase       )

													# update the search buffer:
													# - add new characters from text into it
													# - check if size exceed the max search buffer size, if so, drop the
													#   oldest elements
													search_buffer += text[: token.length + 1]
													if len(UpperCAmelCase       ) > self.search_buffer_size:
																			_UpperCAmelCase							   =     search_buffer[-self.search_buffer_size :]

													# update the text
													_UpperCAmelCase							   =     text[token.length + 1 :]

													# append the token to output
													output.append(UpperCAmelCase       )

							return output

	def 			UpperCamelCase       (				self			,       UpperCAmelCase       ):
							"""simple docstring"""







							_UpperCAmelCase							   =     ''

							for token in tokens:
													for _ in range(token.length       ):
																			output += output[-token.offset]
													output += token.indicator

							return output

	def 			UpperCamelCase       (				self			,       UpperCAmelCase			,       UpperCAmelCase       ):
							"""simple docstring"""







							if not text:
													raise ValueError('We need some text to work with.'       )

							# Initialise result parameters to default values
							_UpperCAmelCase   ,					_UpperCAmelCase							   =     0, 0

							if not search_buffer:
													return Token(UpperCAmelCase			,       UpperCAmelCase			,       text[length]       )

							for i, character in enumerate(UpperCAmelCase       ):
													_UpperCAmelCase							   =     len(UpperCAmelCase       ) - i
													if character == text[0]:
																			_UpperCAmelCase							   =     self._match_length_from_index(UpperCAmelCase			,       UpperCAmelCase			,       0			,       UpperCAmelCase       )
																			# if the found length is bigger than the current or if it's equal,
																			# which means it's offset is smaller: update offset and length
																			if found_length >= length:
																									_UpperCAmelCase   ,					_UpperCAmelCase							   =     found_offset, found_length

							return Token(UpperCAmelCase			,       UpperCAmelCase			,       text[length]       )

	def 			UpperCamelCase       (				self			,       UpperCAmelCase			,       UpperCAmelCase			,       UpperCAmelCase			,       UpperCAmelCase       ):
							"""simple docstring"""







							if not text or text[text_index] != window[window_index]:
													return 0
							return 1 + self._match_length_from_index(
							    UpperCAmelCase			,       window + text[text_index]			,       text_index + 1			,       window_index + 1       )


if __name__ == "__main__":
		from doctest import testmod

		testmod()
		# Initialize compressor class
		_a       =    LZaaCompressor(window_size=13, lookahead_buffer_size=6)

		# Example
		_a       =    '''cabracadabrarrarrad'''
		_a       =    lzaa_compressor.compress(TEXT)
		print(lzaa_compressor.compress('''ababcbababaa'''))
		_a       =    lzaa_compressor.decompress(compressed_text)
		assert decompressed_text == TEXT, "The LZ77 algorithm returned the invalid result."








def __A       ( __lowerCAmelCase = 100					,						__lowerCAmelCase = 100      )->    int:





						"""simple docstring"""



						return max(
						    sum(int(__lowerCAmelCase      ) for x in str(base**power      )      )
						    for base in range(__lowerCAmelCase      )
						    for power in range(__lowerCAmelCase      )      )


# Tests
if __name__ == "__main__":
		import doctest

		doctest.testmod()
