
import math
import time

from transformers import Trainer, is_torch_tpu_available
from transformers.trainer_utils import PredictionOutput, speed_metrics


if is_torch_tpu_available(check_device=False):
						import torch_xla.core.xla_model as xm
						import torch_xla.debug.metrics as met
class  lowercase__(				UpperCAmelCase							):



	"""simple docstring"""




	def __init__(       self  :			str       ,							*SCREAMING_SNAKE_CASE_  :			Optional[int]       ,							SCREAMING_SNAKE_CASE_  :			Dict=None       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]=None       ,							**SCREAMING_SNAKE_CASE_  :			str       )       ->     int:
					super().__init__(*SCREAMING_SNAKE_CASE_       ,							**SCREAMING_SNAKE_CASE_       )
					lowercase_       =					eval_examples
					lowercase_       =					post_process_function
	def 						_lowercase  (       self  :			Optional[int]       ,							SCREAMING_SNAKE_CASE_  :			List[str]=None       ,							SCREAMING_SNAKE_CASE_  :			str=None       ,							SCREAMING_SNAKE_CASE_  :			int=None       ,							SCREAMING_SNAKE_CASE_  :			str = "eval"       )       ->     Union[str, Any]:
					lowercase_       =					self.eval_dataset if eval_dataset is None else eval_dataset
					lowercase_       =					self.get_eval_dataloader(SCREAMING_SNAKE_CASE_       )
					lowercase_       =					self.eval_examples if eval_examples is None else eval_examples

					# Temporarily disable metric computation, we will do it in the loop here.
					lowercase_       =					self.compute_metrics
					lowercase_       =					None
					lowercase_       =					self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
					lowercase_       =					time.time()
					try:
									lowercase_       =					eval_loop(
									    SCREAMING_SNAKE_CASE_       ,							description='''Evaluation'''       ,							prediction_loss_only=True if compute_metrics is None else None       ,							ignore_keys=SCREAMING_SNAKE_CASE_       ,							metric_key_prefix=SCREAMING_SNAKE_CASE_       ,							)
					finally:
									lowercase_       =					compute_metrics
					lowercase_       =					self.args.eval_batch_size * self.args.world_size
					if f'''{metric_key_prefix}_jit_compilation_time''' in output.metrics:
									start_time += output.metrics[f'''{metric_key_prefix}_jit_compilation_time''']
					output.metrics.update(
					    speed_metrics(
					        SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       ,							num_samples=output.num_samples       ,							num_steps=math.ceil(output.num_samples / total_batch_size       )       ,							)       )
					if self.post_process_function is not None and self.compute_metrics is not None and self.args.should_save:
									# Only the main node write the results by default
									lowercase_       =					self.post_process_function(SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       ,							output.predictions       )
									lowercase_       =					self.compute_metrics(SCREAMING_SNAKE_CASE_       )

									# Prefix all keys with metric_key_prefix + '_'
									for key in list(metrics.keys()       ):
													if not key.startswith(f'''{metric_key_prefix}_'''       ):
																	lowercase_       =					metrics.pop(SCREAMING_SNAKE_CASE_       )
									metrics.update(output.metrics       )
					else:
									lowercase_       =					output.metrics

					if self.args.should_log:
									# Only the main node log the results by default
									self.log(SCREAMING_SNAKE_CASE_       )

					if self.args.tpu_metrics_debug or self.args.debug:
									# tpu-comment: Logging debug metrics for PyTorch/XLA (compile, execute times, ops, etc.)
									xm.master_print(met.metrics_report()       )

					lowercase_       =					self.callback_handler.on_evaluate(self.args       ,							self.state       ,							self.control       ,							SCREAMING_SNAKE_CASE_       )
					return metrics




	def 						_lowercase  (       self  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			Dict       ,							SCREAMING_SNAKE_CASE_  :			int=None       ,							SCREAMING_SNAKE_CASE_  :			str = "test"       )       ->     Optional[Any]:
					lowercase_       =					self.get_test_dataloader(SCREAMING_SNAKE_CASE_       )

					# Temporarily disable metric computation, we will do it in the loop here.
					lowercase_       =					self.compute_metrics
					lowercase_       =					None
					lowercase_       =					self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop
					lowercase_       =					time.time()
					try:
									lowercase_       =					eval_loop(
									    SCREAMING_SNAKE_CASE_       ,							description='''Prediction'''       ,							prediction_loss_only=True if compute_metrics is None else None       ,							ignore_keys=SCREAMING_SNAKE_CASE_       ,							metric_key_prefix=SCREAMING_SNAKE_CASE_       ,							)
					finally:
									lowercase_       =					compute_metrics
					lowercase_       =					self.args.eval_batch_size * self.args.world_size
					if f'''{metric_key_prefix}_jit_compilation_time''' in output.metrics:
									start_time += output.metrics[f'''{metric_key_prefix}_jit_compilation_time''']
					output.metrics.update(
					    speed_metrics(
					        SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       ,							num_samples=output.num_samples       ,							num_steps=math.ceil(output.num_samples / total_batch_size       )       ,							)       )

					if self.post_process_function is None or self.compute_metrics is None:
									return output

					lowercase_       =					self.post_process_function(SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_       ,							output.predictions       ,							'''predict'''       )
					lowercase_       =					self.compute_metrics(SCREAMING_SNAKE_CASE_       )

					# Prefix all keys with metric_key_prefix + '_'
					for key in list(metrics.keys()       ):
									if not key.startswith(f'''{metric_key_prefix}_'''       ):
													lowercase_       =					metrics.pop(SCREAMING_SNAKE_CASE_       )
					metrics.update(output.metrics       )
					return PredictionOutput(predictions=predictions.predictions       ,							label_ids=predictions.label_ids       ,							metrics=SCREAMING_SNAKE_CASE_       )






def 				a						(							snake_case__:					list					):


				'''simple docstring'''

				if len(snake_case__					) <= 1:
								return [tuple(snake_case__					)]

				lowercase_       =					[]

				def generate(snake_case__:					int						,   snake_case__:					list					):
								if k == 1:
												res.append(tuple(arr[:]					)					)
												return

								generate(k - 1						,   snake_case__					)

								for i in range(k - 1					):
												if k % 2 == 0:  # k is even
																lowercase_  ,	lowercase_       =					arr[k - 1], arr[i]
												else:  # k is odd
																lowercase_  ,	lowercase_       =					arr[k - 1], arr[0]
												generate(k - 1						,   snake_case__					)

				generate(len(snake_case__					)						,   snake_case__					)
				return res


if __name__ == "__main__":
						__a  			=					input('Enter numbers separated by a comma:\n').strip()
						__a  			=					[int(item) for item in user_input.split(',')]
						print(heaps(arr))




