"""simple docstring"""


from typing import Optional, Union

import torch
from torch import nn
from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss

from ...activations import ACTaFN
from ...modeling_outputs import BaseModelOutputWithPoolingAndNoAttention, ImageClassifierOutputWithNoAttention
from ...modeling_utils import PreTrainedModel
from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
from .configuration_mobilenet_va import MobileNetVaConfig


a				=logging.get_logger(__name__)


# General docstring
a				='MobileNetV1Config'

# Base docstring
a				='google/mobilenet_v1_1.0_224'
a				=[1, 1024, 7, 7]

# Image classification docstring
a				='google/mobilenet_v1_1.0_224'
a				='tabby, tabby cat'


a				=[
    'google/mobilenet_v1_1.0_224',
    'google/mobilenet_v1_0.75_192',
    # See all MobileNetV1 models at https://huggingface.co/models?filter=mobilenet_v1
]





def      lowerCamelCase_					(   __lowerCAmelCase  ,       __lowerCAmelCase  ,       __lowerCAmelCase=None							)				->   int:




						'''simple docstring'''



						lowerCamelCase__   ={}

						if isinstance(__lowerCAmelCase  ,       __lowerCAmelCase							):
												lowerCamelCase__   =model.mobilenet_va
						else:
												lowerCamelCase__   =model

						lowerCamelCase__   ="MobilenetV1/Conv2d_0/"
						lowerCamelCase__   =backbone.conv_stem.convolution.weight
						lowerCamelCase__   =backbone.conv_stem.normalization.bias
						lowerCamelCase__   =backbone.conv_stem.normalization.weight
						lowerCamelCase__   =backbone.conv_stem.normalization.running_mean
						lowerCamelCase__   =backbone.conv_stem.normalization.running_var

						for i in range(13							):
												lowerCamelCase__   =i + 1
												lowerCamelCase__   =i * 2

												lowerCamelCase__   =backbone.layer[pt_index]
												lowerCamelCase__   =F'''MobilenetV1/Conv2d_{tf_index}_depthwise/'''
												lowerCamelCase__   =pointer.convolution.weight
												lowerCamelCase__   =pointer.normalization.bias
												lowerCamelCase__   =pointer.normalization.weight
												lowerCamelCase__   =pointer.normalization.running_mean
												lowerCamelCase__   =pointer.normalization.running_var

												lowerCamelCase__   =backbone.layer[pt_index + 1]
												lowerCamelCase__   =F'''MobilenetV1/Conv2d_{tf_index}_pointwise/'''
												lowerCamelCase__   =pointer.convolution.weight
												lowerCamelCase__   =pointer.normalization.bias
												lowerCamelCase__   =pointer.normalization.weight
												lowerCamelCase__   =pointer.normalization.running_mean
												lowerCamelCase__   =pointer.normalization.running_var

						if isinstance(__lowerCAmelCase  ,       __lowerCAmelCase							):
												lowerCamelCase__   ="MobilenetV1/Logits/Conv2d_1c_1x1/"
												lowerCamelCase__   =model.classifier.weight
												lowerCamelCase__   =model.classifier.bias

						return tf_to_pt_map





def      lowerCamelCase_					(   __lowerCAmelCase  ,       __lowerCAmelCase  ,       __lowerCAmelCase							)				->   str:




						'''simple docstring'''



						try:
												import numpy as np
												import tensorflow as tf
						except ImportError:
												logger.error(
												    "Loading a TensorFlow models in PyTorch, requires TensorFlow to be installed. Please see "
												    "https://www.tensorflow.org/install/ for installation instructions."							)
												raise

						# Load weights from TF model
						lowerCamelCase__   =tf.train.list_variables(__lowerCAmelCase							)
						lowerCamelCase__   ={}
						for name, shape in init_vars:
												logger.info(F'''Loading TF weight {name} with shape {shape}'''							)
												lowerCamelCase__   =tf.train.load_variable(__lowerCAmelCase  ,       __lowerCAmelCase							)
												lowerCamelCase__   =array

						# Build TF to PyTorch weights loading map
						lowerCamelCase__   =_build_tf_to_pytorch_map(__lowerCAmelCase  ,       __lowerCAmelCase  ,       __lowerCAmelCase							)

						for name, pointer in tf_to_pt_map.items():
												logger.info(F'''Importing {name}'''							)
												if name not in tf_weights:
																		logger.info(F'''{name} not in tf pre-trained weights, skipping'''							)
																		continue

												lowerCamelCase__   =tf_weights[name]

												if "depthwise_weights" in name:
																		logger.info("Transposing depthwise"							)
																		lowerCamelCase__   =np.transpose(__lowerCAmelCase  ,       (2, 3, 0, 1)							)
												elif "weights" in name:
																		logger.info("Transposing"							)
																		if len(pointer.shape							) == 2:  # copying into linear layer
																								lowerCamelCase__   =array.squeeze().transpose()
																		else:
																								lowerCamelCase__   =np.transpose(__lowerCAmelCase  ,       (3, 2, 0, 1)							)

												if pointer.shape != array.shape:
																		raise ValueError(F'''Pointer shape {pointer.shape} and array shape {array.shape} mismatched'''							)

												logger.info(F'''Initialize PyTorch weight {name} {array.shape}'''							)
												lowerCamelCase__   =torch.from_numpy(__lowerCAmelCase							)

												tf_weights.pop(__lowerCAmelCase  ,       __lowerCAmelCase							)
												tf_weights.pop(name + "/RMSProp"  ,       __lowerCAmelCase							)
												tf_weights.pop(name + "/RMSProp_1"  ,       __lowerCAmelCase							)
												tf_weights.pop(name + "/ExponentialMovingAverage"  ,       __lowerCAmelCase							)

						logger.info(F'''Weights not copied to PyTorch model: {', '.join(tf_weights.keys()							)}'''							)
						return model





def      lowerCamelCase_					(   __lowerCAmelCase  ,       __lowerCAmelCase							)				->   torch.Tensor:




						'''simple docstring'''



						lowerCamelCase__   , lowerCamelCase__   =features.shape[-2:]
						lowerCamelCase__   , lowerCamelCase__   =conv_layer.stride
						lowerCamelCase__   , lowerCamelCase__   =conv_layer.kernel_size

						if in_height % stride_height == 0:
												lowerCamelCase__   =max(kernel_height - stride_height  ,       0							)
						else:
												lowerCamelCase__   =max(kernel_height - (in_height % stride_height)  ,       0							)

						if in_width % stride_width == 0:
												lowerCamelCase__   =max(kernel_width - stride_width  ,       0							)
						else:
												lowerCamelCase__   =max(kernel_width - (in_width % stride_width)  ,       0							)

						lowerCamelCase__   =pad_along_width // 2
						lowerCamelCase__   =pad_along_width - pad_left
						lowerCamelCase__   =pad_along_height // 2
						lowerCamelCase__   =pad_along_height - pad_top

						lowerCamelCase__   =(pad_left, pad_right, pad_top, pad_bottom)
						return nn.functional.pad(__lowerCAmelCase  ,       __lowerCAmelCase  ,       "constant"  ,       0.0							)






class   __UpperCAmelCase		(      nn.Module      ):

				def __init__( self      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase      ,					_lowerCamelCase = 1      ,					_lowerCamelCase = 1      ,					_lowerCamelCase = False      ,					_lowerCamelCase = True      ,					_lowerCamelCase = True      ,					):
										super().__init__()
										lowerCamelCase__   =config

										if in_channels % groups != 0:
																raise ValueError(F'''Input channels ({in_channels}) are not divisible by {groups} groups.''' )
										if out_channels % groups != 0:
																raise ValueError(F'''Output channels ({out_channels}) are not divisible by {groups} groups.''' )

										lowerCamelCase__   =0 if config.tf_padding else int((kernel_size - 1) / 2 )

										lowerCamelCase__   =nn.Convad(
										    in_channels=_lowerCamelCase      ,					out_channels=_lowerCamelCase      ,					kernel_size=_lowerCamelCase      ,					stride=_lowerCamelCase      ,					padding=_lowerCamelCase      ,					groups=_lowerCamelCase      ,					bias=_lowerCamelCase      ,					padding_mode="zeros"      ,					)

										if use_normalization:
																lowerCamelCase__   =nn.BatchNormad(
																    num_features=_lowerCamelCase      ,					eps=config.layer_norm_eps      ,					momentum=0.9_9_9_7      ,					affine=_lowerCamelCase      ,					track_running_stats=_lowerCamelCase      ,					)
										else:
																lowerCamelCase__   =None

										if use_activation:
																if isinstance(_lowerCamelCase      ,					_lowerCamelCase ):
																						lowerCamelCase__   =ACTaFN[use_activation]
																elif isinstance(config.hidden_act      ,					_lowerCamelCase ):
																						lowerCamelCase__   =ACTaFN[config.hidden_act]
																else:
																						lowerCamelCase__   =config.hidden_act
										else:
																lowerCamelCase__   =None






				def 						_a      ( self      ,					_lowerCamelCase ):
										if self.config.tf_padding:
																lowerCamelCase__   =apply_tf_padding(_lowerCamelCase      ,					self.convolution )
										lowerCamelCase__   =self.convolution(_lowerCamelCase )
										if self.normalization is not None:
																lowerCamelCase__   =self.normalization(_lowerCamelCase )
										if self.activation is not None:
																lowerCamelCase__   =self.activation(_lowerCamelCase )
										return features






class   __UpperCAmelCase		(      __lowerCAmelCase      ):
				A__ :  List[Any]    				=			MobileNetVaConfig
				A__ :  Optional[Any]    				=			load_tf_weights_in_mobilenet_va
				A__ :  Dict    				=			'''mobilenet_v1'''
				A__ :  str    				=			'''pixel_values'''
				A__ :  List[Any]    				=			False

				def 						_a      ( self      ,					_lowerCamelCase ):
										if isinstance(_lowerCamelCase      ,					(nn.Linear, nn.Convad) ):
																module.weight.data.normal_(mean=0.0      ,					std=self.config.initializer_range )
																if module.bias is not None:
																						module.bias.data.zero_()
										elif isinstance(_lowerCamelCase      ,					nn.BatchNormad ):
																module.bias.data.zero_()
																module.weight.data.fill_(1.0 )





a				=r'\n    This model is a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass. Use it\n    as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage and\n    behavior.\n\n    Parameters:\n        config ([`MobileNetV1Config`]): Model configuration class with all the parameters of the model.\n            Initializing with a config file does not load the weights associated with the model, only the\n            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model weights.\n'

a				=r'\n    Args:\n        pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See\n            [`MobileNetV1ImageProcessor.__call__`] for details.\n        output_hidden_states (`bool`, *optional*):\n            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for\n            more detail.\n        return_dict (`bool`, *optional*):\n            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.\n'






@add_start_docstrings(
    '''The bare MobileNetV1 model outputting raw hidden-states without any specific head on top.''' , __lowerCAmelCase , )
class   __UpperCAmelCase		(      __lowerCAmelCase      ):

				def __init__( self      ,					_lowerCamelCase      ,					_lowerCamelCase = True ):
										super().__init__(_lowerCamelCase )
										lowerCamelCase__   =config

										lowerCamelCase__   =32
										lowerCamelCase__   =max(int(depth * config.depth_multiplier )      ,					config.min_depth )

										lowerCamelCase__   =MobileNetVaConvLayer(
										    _lowerCamelCase      ,					in_channels=config.num_channels      ,					out_channels=_lowerCamelCase      ,					kernel_size=3      ,					stride=2      ,					)

										lowerCamelCase__   =[1, 2, 1, 2, 1, 2, 1, 1, 1, 1, 1, 2, 1]

										lowerCamelCase__   =nn.ModuleList()
										for i in range(13 ):
																lowerCamelCase__   =out_channels

																if strides[i] == 2 or i == 0:
																						depth *= 2
																						lowerCamelCase__   =max(int(depth * config.depth_multiplier )      ,					config.min_depth )

																self.layer.append(
																    MobileNetVaConvLayer(
																        _lowerCamelCase      ,					in_channels=_lowerCamelCase      ,					out_channels=_lowerCamelCase      ,					kernel_size=3      ,					stride=strides[i]      ,					groups=_lowerCamelCase      ,					) )

																self.layer.append(
																    MobileNetVaConvLayer(
																        _lowerCamelCase      ,					in_channels=_lowerCamelCase      ,					out_channels=_lowerCamelCase      ,					kernel_size=1      ,					) )

										lowerCamelCase__   =nn.AdaptiveAvgPoolad((1, 1) ) if add_pooling_layer else None

										# Initialize weights and apply final processing
										self.post_init()

				def 						_a      ( self      ,					_lowerCamelCase ):
										raise NotImplementedError






				@add_start_docstrings_to_model_forward(_lowerCamelCase )
				@add_code_sample_docstrings(
				    checkpoint=_CHECKPOINT_FOR_DOC      ,					output_type=_lowerCamelCase      ,					config_class=_CONFIG_FOR_DOC      ,					modality="vision"      ,					expected_output=_EXPECTED_OUTPUT_SHAPE      ,					)
				def 						_a      ( self      ,					_lowerCamelCase = None      ,					_lowerCamelCase = None      ,					_lowerCamelCase = None      ,					):
										lowerCamelCase__   =(
										    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
										)
										lowerCamelCase__   =return_dict if return_dict is not None else self.config.use_return_dict

										if pixel_values is None:
																raise ValueError("You have to specify pixel_values" )

										lowerCamelCase__   =self.conv_stem(_lowerCamelCase )

										lowerCamelCase__   =() if output_hidden_states else None

										for i, layer_module in enumerate(self.layer ):
																lowerCamelCase__   =layer_module(_lowerCamelCase )

																if output_hidden_states:
																						lowerCamelCase__   =all_hidden_states + (hidden_states,)

										lowerCamelCase__   =hidden_states

										if self.pooler is not None:
																lowerCamelCase__   =torch.flatten(self.pooler(_lowerCamelCase )      ,					start_dim=1 )
										else:
																lowerCamelCase__   =None

										if not return_dict:
																return tuple(v for v in [last_hidden_state, pooled_output, all_hidden_states] if v is not None )

										return BaseModelOutputWithPoolingAndNoAttention(
										    last_hidden_state=_lowerCamelCase      ,					pooler_output=_lowerCamelCase      ,					hidden_states=_lowerCamelCase      ,					)






@add_start_docstrings(
    '''
    MobileNetV1 model with an image classification head on top (a linear layer on top of the pooled features), e.g. for
    ImageNet.
    ''' , __lowerCAmelCase , )
class   __UpperCAmelCase		(      __lowerCAmelCase      ):

				def __init__( self      ,					_lowerCamelCase ):
										super().__init__(_lowerCamelCase )

										lowerCamelCase__   =config.num_labels
										lowerCamelCase__   =MobileNetVaModel(_lowerCamelCase )

										lowerCamelCase__   =self.mobilenet_va.layer[-1].convolution.out_channels

										# Classifier head
										lowerCamelCase__   =nn.Dropout(config.classifier_dropout_prob      ,					inplace=_lowerCamelCase )
										lowerCamelCase__   =nn.Linear(_lowerCamelCase      ,					config.num_labels ) if config.num_labels > 0 else nn.Identity()

										# Initialize weights and apply final processing
										self.post_init()






				@add_start_docstrings_to_model_forward(_lowerCamelCase )
				@add_code_sample_docstrings(
				    checkpoint=_IMAGE_CLASS_CHECKPOINT      ,					output_type=_lowerCamelCase      ,					config_class=_CONFIG_FOR_DOC      ,					expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT      ,					)
				def 						_a      ( self      ,					_lowerCamelCase = None      ,					_lowerCamelCase = None      ,					_lowerCamelCase = None      ,					_lowerCamelCase = None      ,					):
										lowerCamelCase__   =return_dict if return_dict is not None else self.config.use_return_dict

										lowerCamelCase__   =self.mobilenet_va(_lowerCamelCase      ,					output_hidden_states=_lowerCamelCase      ,					return_dict=_lowerCamelCase )

										lowerCamelCase__   =outputs.pooler_output if return_dict else outputs[1]

										lowerCamelCase__   =self.classifier(self.dropout(_lowerCamelCase ) )

										lowerCamelCase__   =None
										if labels is not None:
																if self.config.problem_type is None:
																						if self.num_labels == 1:
																												lowerCamelCase__   ="regression"
																						elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
																												lowerCamelCase__   ="single_label_classification"
																						else:
																												lowerCamelCase__   ="multi_label_classification"

																if self.config.problem_type == "regression":
																						lowerCamelCase__   =MSELoss()
																						if self.num_labels == 1:
																												lowerCamelCase__   =loss_fct(logits.squeeze()      ,					labels.squeeze() )
																						else:
																												lowerCamelCase__   =loss_fct(_lowerCamelCase      ,					_lowerCamelCase )
																elif self.config.problem_type == "single_label_classification":
																						lowerCamelCase__   =CrossEntropyLoss()
																						lowerCamelCase__   =loss_fct(logits.view(-1      ,					self.num_labels )      ,					labels.view(-1 ) )
																elif self.config.problem_type == "multi_label_classification":
																						lowerCamelCase__   =BCEWithLogitsLoss()
																						lowerCamelCase__   =loss_fct(_lowerCamelCase      ,					_lowerCamelCase )

										if not return_dict:
																lowerCamelCase__   =(logits,) + outputs[2:]
																return ((loss,) + output) if loss is not None else output

										return ImageClassifierOutputWithNoAttention(
										    loss=_lowerCamelCase      ,					logits=_lowerCamelCase      ,					hidden_states=outputs.hidden_states      ,					)



"""simple docstring"""


def      lowerCamelCase_					(   __lowerCAmelCase							)				->   list:




						'''simple docstring'''



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

						lowerCamelCase__   =[]

						def generate(__lowerCAmelCase  ,       __lowerCAmelCase							):
												lowerCamelCase__   =[0] * n
												res.append(tuple(__lowerCAmelCase							)							)

												lowerCamelCase__   =0
												while i < n:
																		if c[i] < i:
																								if i % 2 == 0:
																														lowerCamelCase__   , lowerCamelCase__   =arr[i], arr[0]
																								else:
																														lowerCamelCase__   , lowerCamelCase__   =arr[i], arr[c[i]]
																								res.append(tuple(__lowerCAmelCase							)							)
																								c[i] += 1
																								lowerCamelCase__   =0
																		else:
																								lowerCamelCase__   =0
																								i += 1

						generate(len(__lowerCAmelCase							)  ,       __lowerCAmelCase							)
						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))


