





'''simple docstring'''




import re
import time
from typing import Optional

import IPython.display as disp

from ..trainer_callback import TrainerCallback
from ..trainer_utils import IntervalStrategy, has_length




def 						__lowerCamelCase			(	UpperCAmelCase_							)   ->int:
	snake_case__	       =   int(UpperCAmelCase_							)
	snake_case__       ,  snake_case__       ,  snake_case__	       =   t // 36_00, (t // 60) % 60, t % 60
	return f'''{h}:{m:02d}:{s:02d}''' if h != 0 else f'''{m:02d}:{s:02d}'''




def 						__lowerCamelCase			(	UpperCAmelCase_					,				UpperCAmelCase_					,				UpperCAmelCase_					,				UpperCAmelCase_					,				UpperCAmelCase_=3_00							)   ->Optional[Any]:
	# docstyle-ignore
	return f'''
    <div>
      {prefix}
      <progress value=\'{value}\' max=\'{total}\' style=\'width:{width}px; height:20px; vertical-align: middle;\'></progress>
      {label}
    </div>
    '''




def 						__lowerCamelCase			(	UpperCAmelCase_							)   ->Optional[Any]:
	snake_case__	       =   '<table border="1" class="dataframe">\n'
	html_code += """  <thead>\n <tr style="text-align: left;">\n"""
	for i in items[0]:
		html_code += f'''      <th>{i}</th>\n'''
	html_code += "    </tr>\n  </thead>\n  <tbody>\n"
	for line in items[1:]:
		html_code += "    <tr>\n"
		for elt in line:
			snake_case__	       =   f'''{elt:.6f}''' if isinstance(UpperCAmelCase_					,				UpperCAmelCase_							) else str(UpperCAmelCase_							)
			html_code += f'''      <td>{elt}</td>\n'''
		html_code += "    </tr>\n"
	html_code += "  </tbody>\n</table><p>"
	return html_code






class 				__snake_case     :
	__lowerCAmelCase       						=  5
	__lowerCAmelCase       						=  0.2





	def __init__(		self      ,       UpperCamelCase_      ,       UpperCamelCase_ = None      ,       UpperCamelCase_ = True      ,       UpperCamelCase_ = None      ,       UpperCamelCase_ = 300      ,       )      ->		str:
		snake_case__	       =   total
		snake_case__	       =   '' if prefix is None else prefix
		snake_case__	       =   leave
		snake_case__	       =   parent
		snake_case__	       =   width
		snake_case__	       =   None
		snake_case__	       =   None
		snake_case__	       =   None





	def   _snake_case   (		self      ,       UpperCamelCase_      ,       UpperCamelCase_ = False      ,       UpperCamelCase_ = None		)      ->		List[Any]:
		snake_case__	       =   value
		if comment is not None:
			snake_case__	       =   comment
		if self.last_value is None:
			snake_case__	       =   snake_case__	       =   time.time()
			snake_case__	       =   snake_case__	       =   value
			snake_case__	       =   snake_case__	       =   None
			snake_case__	       =   self.warmup
			snake_case__	       =   1
			self.update_bar(UpperCamelCase_		)
		elif value <= self.last_value and not force_update:
			return
		elif force_update or self.first_calls > 0 or value >= min(self.last_value + self.wait_for      ,       self.total		):
			if self.first_calls > 0:
				self.first_calls -= 1
			snake_case__	       =   time.time()
			snake_case__	       =   current_time - self.start_time
			# We could have value = self.start_value if the update is called twixe with the same start value.
			if value > self.start_value:
				snake_case__	       =   self.elapsed_time / (value - self.start_value)
			else:
				snake_case__	       =   None
			if value >= self.total:
				snake_case__	       =   self.total
				snake_case__	       =   None
				if not self.leave:
					self.close()
			elif self.average_time_per_item is not None:
				snake_case__	       =   self.average_time_per_item * (self.total - value)
			self.update_bar(UpperCamelCase_		)
			snake_case__	       =   value
			snake_case__	       =   current_time
			if self.average_time_per_item is None:
				snake_case__	       =   1
			else:
				snake_case__	       =   max(int(self.update_every / self.average_time_per_item		)      ,       1		)





	def   _snake_case   (		self      ,       UpperCamelCase_      ,       UpperCamelCase_=None		)      ->		Dict:
		snake_case__	       =   ' ' * (len(str(self.total		)		) - len(str(UpperCamelCase_		)		)) + str(UpperCamelCase_		)
		if self.elapsed_time is None:
			snake_case__	       =   F'''[{spaced_value}/{self.total} : < :'''
		elif self.predicted_remaining is None:
			snake_case__	       =   F'''[{spaced_value}/{self.total} {format_time(self.elapsed_time		)}'''
		else:
			snake_case__	       =   (
			    F'''[{spaced_value}/{self.total} {format_time(self.elapsed_time		)} <'''
			    F''' {format_time(self.predicted_remaining		)}'''
			)
			self.label += F''', {1/self.average_time_per_item:.2f} it/s'''
		self.label += "]" if self.comment is None or len(self.comment		) == 0 else F''', {self.comment}]'''
		self.display()





	def   _snake_case   (		self		)      ->		int:
		snake_case__	       =   html_progress_bar(self.value      ,       self.total      ,       self.prefix      ,       self.label      ,       self.width		)
		if self.parent is not None:
			# If this is a child bar, the parent will take care of the display.
			self.parent.display()
			return
		if self.output is None:
			snake_case__	       =   disp.display(disp.HTML(self.html_code		)      ,       display_id=UpperCamelCase_		)
		else:
			self.output.update(disp.HTML(self.html_code		)		)





	def   _snake_case   (		self		)      ->		Tuple:
		if self.parent is None and self.output is not None:
			self.output.update(disp.HTML(''		)		)






class 				__snake_case     (					__magic_name__							):





	def __init__(		self      ,       UpperCamelCase_      ,       UpperCamelCase_=None		)      ->		Any:
		super().__init__(UpperCamelCase_		)
		snake_case__	       =   None if column_names is None else [column_names]
		snake_case__	       =   None





	def   _snake_case   (		self		)      ->		Any:
		snake_case__	       =   html_progress_bar(self.value      ,       self.total      ,       self.prefix      ,       self.label      ,       self.width		)
		if self.inner_table is not None:
			self.html_code += text_to_html_table(self.inner_table		)
		if self.child_bar is not None:
			self.html_code += self.child_bar.html_code
		if self.output is None:
			snake_case__	       =   disp.display(disp.HTML(self.html_code		)      ,       display_id=UpperCamelCase_		)
		else:
			self.output.update(disp.HTML(self.html_code		)		)





	def   _snake_case   (		self      ,       UpperCamelCase_		)      ->		Union[str, Any]:
		if self.inner_table is None:
			snake_case__	       =   [list(values.keys()		), list(values.values()		)]
		else:
			snake_case__	       =   self.inner_table[0]
			if len(self.inner_table		) == 1:
				# We give a chance to update the column names at the first iteration
				for key in values.keys():
					if key not in columns:
						columns.append(UpperCamelCase_		)
				snake_case__	       =   columns
			self.inner_table.append([values[c] for c in columns]		)





	def   _snake_case   (		self      ,       UpperCamelCase_      ,       UpperCamelCase_=None      ,       UpperCamelCase_=300		)      ->		List[str]:
		snake_case__	       =   NotebookProgressBar(UpperCamelCase_      ,       prefix=UpperCamelCase_      ,       parent=self      ,       width=UpperCamelCase_		)
		return self.child_bar





	def   _snake_case   (		self		)      ->		Union[str, Any]:
		snake_case__	       =   None
		self.display()






class 				__snake_case     (					__magic_name__							):





	def __init__(		self		)      ->		Union[str, Any]:
		snake_case__	       =   None
		snake_case__	       =   None
		snake_case__	       =   False





	def   _snake_case   (		self      ,       UpperCamelCase_      ,       UpperCamelCase_      ,       UpperCamelCase_      ,       **UpperCamelCase_		)      ->		Union[str, Any]:
		snake_case__	       =   'Epoch' if args.evaluation_strategy == IntervalStrategy.EPOCH else 'Step'
		snake_case__	       =   0
		snake_case__	       =   0
		snake_case__	       =   [self.first_column] + ['Training Loss']
		if args.evaluation_strategy != IntervalStrategy.NO:
			column_names.append('Validation Loss'		)
		snake_case__	       =   NotebookTrainingTracker(state.max_steps      ,       UpperCamelCase_		)





	def   _snake_case   (		self      ,       UpperCamelCase_      ,       UpperCamelCase_      ,       UpperCamelCase_      ,       **UpperCamelCase_		)      ->		Tuple:
		snake_case__	       =   int(state.epoch		) if int(state.epoch		) == state.epoch else F'''{state.epoch:.2f}'''
		self.training_tracker.update(
		    state.global_step + 1      ,       comment=F'''Epoch {epoch}/{state.num_train_epochs}'''      ,       force_update=self._force_next_update      ,       )
		snake_case__	       =   False





	def   _snake_case   (		self      ,       UpperCamelCase_      ,       UpperCamelCase_      ,       UpperCamelCase_      ,       UpperCamelCase_=None      ,       **UpperCamelCase_		)      ->		List[str]:
		if not has_length(UpperCamelCase_		):
			return
		if self.prediction_bar is None:
			if self.training_tracker is not None:
				snake_case__	       =   self.training_tracker.add_child(len(UpperCamelCase_		)		)
			else:
				snake_case__	       =   NotebookProgressBar(len(UpperCamelCase_		)		)
			self.prediction_bar.update(1		)
		else:
			self.prediction_bar.update(self.prediction_bar.value + 1		)





	def   _snake_case   (		self      ,       UpperCamelCase_      ,       UpperCamelCase_      ,       UpperCamelCase_      ,       **UpperCamelCase_		)      ->		Union[str, Any]:
		if self.prediction_bar is not None:
			self.prediction_bar.close()
		snake_case__	       =   None





	def   _snake_case   (		self      ,       UpperCamelCase_      ,       UpperCamelCase_      ,       UpperCamelCase_      ,       UpperCamelCase_=None      ,       **UpperCamelCase_		)      ->		int:
		# Only for when there is no evaluation
		if args.evaluation_strategy == IntervalStrategy.NO and "loss" in logs:
			snake_case__	       =   {'Training Loss': logs['loss']}
			# First column is necessarily Step sine we're not in epoch eval strategy
			snake_case__	       =   state.global_step
			self.training_tracker.write_line(UpperCamelCase_		)





	def   _snake_case   (		self      ,       UpperCamelCase_      ,       UpperCamelCase_      ,       UpperCamelCase_      ,       UpperCamelCase_=None      ,       **UpperCamelCase_		)      ->		str:
		if self.training_tracker is not None:
			snake_case__	       =   {'Training Loss': 'No log', 'Validation Loss': 'No log'}
			for log in reversed(state.log_history		):
				if "loss" in log:
					snake_case__	       =   log['loss']
					break

			if self.first_column == "Epoch":
				snake_case__	       =   int(state.epoch		)
			else:
				snake_case__	       =   state.global_step
			snake_case__	       =   'eval'
			for k in metrics:
				if k.endswith('_loss'		):
					snake_case__	       =   re.sub(R'\_loss$'      ,       ''      ,       UpperCamelCase_		)
			snake_case__	       =   metrics.pop('total_flos'      ,       UpperCamelCase_		)
			snake_case__	       =   metrics.pop('epoch'      ,       UpperCamelCase_		)
			snake_case__	       =   metrics.pop(F'''{metric_key_prefix}_runtime'''      ,       UpperCamelCase_		)
			snake_case__	       =   metrics.pop(F'''{metric_key_prefix}_samples_per_second'''      ,       UpperCamelCase_		)
			snake_case__	       =   metrics.pop(F'''{metric_key_prefix}_steps_per_second'''      ,       UpperCamelCase_		)
			snake_case__	       =   metrics.pop(F'''{metric_key_prefix}_jit_compilation_time'''      ,       UpperCamelCase_		)
			for k, v in metrics.items():
				if k == F'''{metric_key_prefix}_loss''':
					snake_case__	       =   v
				else:
					snake_case__	       =   k.split('_'		)
					snake_case__	       =   ' '.join([part.capitalize() for part in splits[1:]]		)
					snake_case__	       =   v
			self.training_tracker.write_line(UpperCamelCase_		)
			self.training_tracker.remove_child()
			snake_case__	       =   None
			# Evaluation takes a long time so we should force the next update.
			snake_case__	       =   True





	def   _snake_case   (		self      ,       UpperCamelCase_      ,       UpperCamelCase_      ,       UpperCamelCase_      ,       **UpperCamelCase_		)      ->		str:
		self.training_tracker.update(
		    state.global_step      ,       comment=F'''Epoch {int(state.epoch		)}/{state.num_train_epochs}'''      ,       force_update=UpperCamelCase_		)
		snake_case__	       =   None










'''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""")



