






'''simple docstring'''







from typing import Optional, Tuple

import flax.linen as nn
import jax
import jax.numpy as jnp
from configuration_hybrid_clip import HybridCLIPConfig
from flax.core.frozen_dict import FrozenDict

from transformers import FLAX_MODEL_MAPPING, FlaxCLIPVisionModel
from transformers.modeling_flax_utils import FlaxPreTrainedModel
from transformers.models.clip.modeling_flax_clip import FlaxCLIPOutput
from transformers.utils import logging


_A      :     Any       	=logging.get_logger(__name__)

class _lowercase      (							nn.Module						):
							a							 =			42
							a							 =			jnp.floataa




							def 						lowerCamelCase_							(				self:							int	):
														lowerCamelCase__   :      Optional[Any]			    =			self.config.text_config
														lowerCamelCase__   :      List[str]			    =			self.config.vision_config

														lowerCamelCase__   :      int			    =			self.config.projection_dim
														lowerCamelCase__   :      Dict			    =			text_config.hidden_size
														lowerCamelCase__   :      Dict			    =			vision_config.hidden_size

														lowerCamelCase__   :      Dict			    =			FLAX_MODEL_MAPPING[self.config.text_config.__class__].module_class
														lowerCamelCase__   :      Union[str, Any]			    =			FLAX_MODEL_MAPPING.get(self.config.vision_config.__class__     ,				UpperCamelCase__	).module_class

														lowerCamelCase__   :      Any			    =			text_module(UpperCamelCase__     ,				dtype=self.dtype	)
														lowerCamelCase__   :      Union[str, Any]			    =			vision_module(UpperCamelCase__     ,				dtype=self.dtype	)

														lowerCamelCase__   :      Optional[Any]			    =			nn.Dense(
														    self.projection_dim     ,				dtype=self.dtype     ,				kernel_init=jax.nn.initializers.normal(0.02	)     ,				use_bias=UpperCamelCase__     ,				)
														lowerCamelCase__   :      str			    =			nn.Dense(
														    self.projection_dim     ,				dtype=self.dtype     ,				kernel_init=jax.nn.initializers.normal(0.02	)     ,				use_bias=UpperCamelCase__     ,				)
														lowerCamelCase__   :      Optional[int]			    =			self.param("""logit_scale"""     ,				jax.nn.initializers.ones     ,				[]	)




							def __call__(				self:							Any     ,				UpperCamelCase__:							Optional[int]=None     ,				UpperCamelCase__:							int=None     ,				UpperCamelCase__:							int=None     ,				UpperCamelCase__:							int=None     ,				UpperCamelCase__:							Dict=None     ,				UpperCamelCase__:							bool = True     ,				UpperCamelCase__:							Tuple=None     ,				UpperCamelCase__:							List[Any]=None     ,				UpperCamelCase__:							Union[str, Any]=None     ,				):
														lowerCamelCase__   :      List[str]			    =			return_dict if return_dict is not None else self.config.return_dict

														lowerCamelCase__   :      Union[str, Any]			    =			self.vision_model(
														    pixel_values=UpperCamelCase__     ,				deterministic=UpperCamelCase__     ,				output_attentions=UpperCamelCase__     ,				output_hidden_states=UpperCamelCase__     ,				return_dict=UpperCamelCase__     ,				)

														lowerCamelCase__   :      List[str]			    =			self.text_model(
														    input_ids=UpperCamelCase__     ,				attention_mask=UpperCamelCase__     ,				token_type_ids=UpperCamelCase__     ,				position_ids=UpperCamelCase__     ,				deterministic=UpperCamelCase__     ,				output_attentions=UpperCamelCase__     ,				output_hidden_states=UpperCamelCase__     ,				return_dict=UpperCamelCase__     ,				)

														lowerCamelCase__   :      Dict			    =			vision_outputs[1]
														lowerCamelCase__   :      Union[str, Any]			    =			self.visual_projection(UpperCamelCase__	)

														lowerCamelCase__   :      Optional[Any]			    =			text_outputs[1]
														lowerCamelCase__   :      int			    =			self.text_projection(UpperCamelCase__	)

														# normalized features
														lowerCamelCase__   :      Union[str, Any]			    =			image_embeds / jnp.linalg.norm(UpperCamelCase__     ,				axis=-1     ,				keepdims=UpperCamelCase__	)
														lowerCamelCase__   :      Optional[int]			    =			text_embeds / jnp.linalg.norm(UpperCamelCase__     ,				axis=-1     ,				keepdims=UpperCamelCase__	)

														# cosine similarity as logits
														lowerCamelCase__   :      Tuple			    =			jnp.exp(self.logit_scale	)
														lowerCamelCase__   :      Tuple			    =			jnp.matmul(UpperCamelCase__     ,				image_embeds.T	) * logit_scale
														lowerCamelCase__   :      List[str]			    =			logits_per_text.T

														if not return_dict:
																					return (logits_per_image, logits_per_text, text_embeds, image_embeds, text_outputs, vision_outputs)

														return FlaxCLIPOutput(
														    logits_per_image=UpperCamelCase__     ,				logits_per_text=UpperCamelCase__     ,				text_embeds=UpperCamelCase__     ,				image_embeds=UpperCamelCase__     ,				text_model_output=UpperCamelCase__     ,				vision_model_output=UpperCamelCase__     ,				)



class _lowercase      (							_lowercase						):
							a							 =			HybridCLIPConfig
							a							 =			FlaxHybridCLIPModule




							def __init__(				self:							Union[str, Any]     ,				UpperCamelCase__:							HybridCLIPConfig     ,				UpperCamelCase__:							Optional[Tuple] = None     ,				UpperCamelCase__:							int = 0     ,				UpperCamelCase__:							jnp.dtype = jnp.floataa     ,				**UpperCamelCase__:							Tuple     ,				):
														if input_shape is None:
																					lowerCamelCase__   :      int			    =			((1, 1), (1, config.vision_config.image_size, config.vision_config.image_size, 3))

														lowerCamelCase__   :      Optional[Any]			    =			self.module_class(config=UpperCamelCase__     ,				dtype=UpperCamelCase__     ,				**UpperCamelCase__	)
														super().__init__(UpperCamelCase__     ,				UpperCamelCase__     ,				input_shape=UpperCamelCase__     ,				seed=UpperCamelCase__     ,				dtype=UpperCamelCase__	)




							def 						lowerCamelCase_							(				self:							Union[str, Any]     ,				UpperCamelCase__:							jax.random.PRNGKey     ,				UpperCamelCase__:							Tuple     ,				UpperCamelCase__:							FrozenDict = None	):
														# init input tensor
														lowerCamelCase__   :      Dict			    =			jnp.zeros(input_shape[0]     ,				dtype="""i4"""	)
														lowerCamelCase__   :      Dict			    =			jnp.broadcast_to(jnp.arange(jnp.atleast_ad(UpperCamelCase__	).shape[-1]	)     ,				input_shape[0]	)
														lowerCamelCase__   :      Union[str, Any]			    =			jnp.ones_like(UpperCamelCase__	)
														lowerCamelCase__   :      Optional[Any]			    =			jnp.ones_like(UpperCamelCase__	)

														lowerCamelCase__   :      Optional[Any]			    =			jax.random.normal(UpperCamelCase__     ,				input_shape[1]	)

														lowerCamelCase__    ,						lowerCamelCase__   :      Any			    =			jax.random.split(UpperCamelCase__	)
														lowerCamelCase__   :      int			    =			{"""params""": params_rng, """dropout""": dropout_rng}

														return self.module.init(UpperCamelCase__     ,				UpperCamelCase__     ,				UpperCamelCase__     ,				UpperCamelCase__     ,				UpperCamelCase__     ,				UpperCamelCase__	)["params"]




							def __call__(				self:							Union[str, Any]     ,				UpperCamelCase__:							Optional[int]     ,				UpperCamelCase__:							List[Any]     ,				UpperCamelCase__:							Any=None     ,				UpperCamelCase__:							str=None     ,				UpperCamelCase__:							int=None     ,				UpperCamelCase__:							dict = None     ,				UpperCamelCase__:							jax.random.PRNGKey = None     ,				UpperCamelCase__:							bool = False     ,				UpperCamelCase__:							Optional[bool] = None     ,				UpperCamelCase__:							Optional[bool] = None     ,				UpperCamelCase__:							Optional[bool] = None     ,				):
														lowerCamelCase__   :      Dict			    =			output_attentions if output_attentions is not None else self.config.output_attentions
														lowerCamelCase__   :      List[str]			    =			(
														    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
														)
														lowerCamelCase__   :      Union[str, Any]			    =			return_dict if return_dict is not None else self.config.return_dict

														if position_ids is None:
																					lowerCamelCase__   :      Union[str, Any]			    =			jnp.broadcast_to(jnp.arange(jnp.atleast_ad(UpperCamelCase__	).shape[-1]	)     ,				input_ids.shape	)

														if token_type_ids is None:
																					lowerCamelCase__   :      Optional[int]			    =			jnp.zeros_like(UpperCamelCase__	)

														if attention_mask is None:
																					lowerCamelCase__   :      Tuple			    =			jnp.ones_like(UpperCamelCase__	)

														# Handle any PRNG if needed
														lowerCamelCase__   :      Optional[int]			    =			{}
														if dropout_rng is not None:
																					lowerCamelCase__   :      Tuple			    =			dropout_rng

														return self.module.apply(
														    {"""params""": params or self.params}     ,				jnp.array(UpperCamelCase__     ,				dtype="""i4"""	)     ,				jnp.array(UpperCamelCase__     ,				dtype=jnp.floataa	)     ,				jnp.array(UpperCamelCase__     ,				dtype="""i4"""	)     ,				jnp.array(UpperCamelCase__     ,				dtype="""i4"""	)     ,				jnp.array(UpperCamelCase__     ,				dtype="""i4"""	)     ,				not train     ,				UpperCamelCase__     ,				UpperCamelCase__     ,				UpperCamelCase__     ,				rngs=UpperCamelCase__     ,				)




							def 						lowerCamelCase_							(				self:							str     ,				UpperCamelCase__:							Optional[int]     ,				UpperCamelCase__:							Dict=None     ,				UpperCamelCase__:							List[str]=None     ,				UpperCamelCase__:							Any=None     ,				UpperCamelCase__:							dict = None     ,				UpperCamelCase__:							jax.random.PRNGKey = None     ,				UpperCamelCase__:							Optional[Any]=False     ,				):
														if position_ids is None:
																					lowerCamelCase__   :      Dict			    =			jnp.broadcast_to(jnp.arange(jnp.atleast_ad(UpperCamelCase__	).shape[-1]	)     ,				input_ids.shape	)

														if token_type_ids is None:
																					lowerCamelCase__   :      Optional[Any]			    =			jnp.zeros_like(UpperCamelCase__	)

														if attention_mask is None:
																					lowerCamelCase__   :      Tuple			    =			jnp.ones_like(UpperCamelCase__	)

														# Handle any PRNG if needed
														lowerCamelCase__   :      Dict			    =			{}
														if dropout_rng is not None:
																					lowerCamelCase__   :      List[str]			    =			dropout_rng

														def _get_features(UpperCamelCase__:							Optional[int]     ,				UpperCamelCase__:							Optional[Any]     ,				UpperCamelCase__:							List[Any]     ,				UpperCamelCase__:							int     ,				UpperCamelCase__:							List[str]     ,				UpperCamelCase__:							Any	):
																					lowerCamelCase__   :      Any			    =			module.text_model(
																					    input_ids=UpperCamelCase__     ,				attention_mask=UpperCamelCase__     ,				position_ids=UpperCamelCase__     ,				token_type_ids=UpperCamelCase__     ,				deterministic=UpperCamelCase__     ,				)
																					lowerCamelCase__   :      Tuple			    =			text_outputs[1]
																					lowerCamelCase__   :      Any			    =			module.text_projection(UpperCamelCase__	)
																					return text_features

														return self.module.apply(
														    {"""params""": params or self.params}     ,				jnp.array(UpperCamelCase__     ,				dtype="""i4"""	)     ,				jnp.array(UpperCamelCase__     ,				dtype="""i4"""	)     ,				jnp.array(UpperCamelCase__     ,				dtype="""i4"""	)     ,				jnp.array(UpperCamelCase__     ,				dtype="""i4"""	)     ,				not train     ,				method=_get_features     ,				rngs=UpperCamelCase__     ,				)




							def 						lowerCamelCase_							(				self:							Union[str, Any]     ,				UpperCamelCase__:							List[Any]     ,				UpperCamelCase__:							dict = None     ,				UpperCamelCase__:							jax.random.PRNGKey = None     ,				UpperCamelCase__:							str=False	):
														lowerCamelCase__   :      Optional[Any]			    =			{}
														if dropout_rng is not None:
																					lowerCamelCase__   :      Any			    =			dropout_rng

														def _get_features(UpperCamelCase__:							int     ,				UpperCamelCase__:							Tuple     ,				UpperCamelCase__:							Union[str, Any]	):
																					lowerCamelCase__   :      str			    =			module.vision_model(pixel_values=UpperCamelCase__     ,				deterministic=UpperCamelCase__	)
																					lowerCamelCase__   :      Optional[int]			    =			vision_outputs[1]  # pooled_output
																					lowerCamelCase__   :      Optional[Any]			    =			module.visual_projection(UpperCamelCase__	)
																					return image_features

														return self.module.apply(
														    {"""params""": params or self.params}     ,				jnp.array(UpperCamelCase__     ,				dtype=jnp.floataa	)     ,				not train     ,				method=_get_features     ,				rngs=UpperCamelCase__     ,				)




							@classmethod
							def 						lowerCamelCase_							(				cls:							Any     ,				UpperCamelCase__:							str = None     ,				UpperCamelCase__:							str = None     ,				*UpperCamelCase__:							int     ,				**UpperCamelCase__:							Dict     ,				):
														lowerCamelCase__   :      str			    =			{
														    argument[len("""text_"""	) :]: value for argument, value in kwargs.items() if argument.startswith("""text_"""	)
														}

														lowerCamelCase__   :      Tuple			    =			{
														    argument[len("""vision_"""	) :]: value for argument, value in kwargs.items() if argument.startswith("""vision_"""	)
														}

														# remove text, vision kwargs from kwargs
														for key in kwargs_text.keys():
																					del kwargs["text_" + key]
														for key in kwargs_vision.keys():
																					del kwargs["vision_" + key]

														# Load and initialize the text and vision model
														lowerCamelCase__   :      Optional[Any]			    =			kwargs_text.pop("""model"""     ,				UpperCamelCase__	)
														if text_model is None:
																					assert (
																					    text_model_name_or_path is not None
																					), "If `model` is not defined as an argument, a `text_model_name_or_path` has to be defined"
																					from transformers import FlaxAutoModel

																					if "config" not in kwargs_text:
																												from transformers import AutoConfig

																												lowerCamelCase__   :      Optional[int]			    =			AutoConfig.from_pretrained(UpperCamelCase__	)
																												lowerCamelCase__   :      Tuple			    =			text_config

																					lowerCamelCase__   :      Dict			    =			FlaxAutoModel.from_pretrained(UpperCamelCase__     ,				*UpperCamelCase__     ,				**UpperCamelCase__	)

														lowerCamelCase__   :      int			    =			kwargs_vision.pop("""model"""     ,				UpperCamelCase__	)
														if vision_model is None:
																					assert (
																					    vision_model_name_or_path is not None
																					), "If `model` is not defined as an argument, a `vision_model_name_or_path` has to be defined"
																					from transformers import FlaxAutoModel

																					if "config" not in kwargs_vision:
																												from transformers import AutoConfig

																												lowerCamelCase__   :      Tuple			    =			AutoConfig.from_pretrained(UpperCamelCase__	)
																												lowerCamelCase__   :      int			    =			vision_config

																					lowerCamelCase__   :      Dict			    =			FlaxAutoModel.from_pretrained(UpperCamelCase__     ,				*UpperCamelCase__     ,				**UpperCamelCase__	)

														# instantiate config with corresponding kwargs
														lowerCamelCase__   :      Union[str, Any]			    =			kwargs.pop("""dtype"""     ,				jnp.floataa	)
														lowerCamelCase__   :      Union[str, Any]			    =			HybridCLIPConfig.from_text_vision_configs(text_model.config     ,				vision_model.config     ,				**UpperCamelCase__	)

														# init model
														lowerCamelCase__   :      int			    =			cls(UpperCamelCase__     ,				*UpperCamelCase__     ,				dtype=UpperCamelCase__     ,				**UpperCamelCase__	)

														if vision_config.model_type == "clip":
																					lowerCamelCase__   :      Dict			    =			vision_model.params["""vision_model"""]
																					lowerCamelCase__   :      List[str]			    =			vision_model.params["""visual_projection"""]["""kernel"""]
														else:
																					lowerCamelCase__   :      str			    =			vision_model.params

														lowerCamelCase__   :      Tuple			    =			text_model.params

														return model









'''simple docstring'''







from __future__ import annotations





def 					SCREAMING_SNAKE_CASE_			(UpperCamelCase							,     UpperCamelCase ) ->			Dict:
							lowerCamelCase__   :      List[str]			    =			0
							lowerCamelCase__   :      Tuple			    =			len(UpperCamelCase ) - 1
							while left <= right:
														lowerCamelCase__   :      List[str]			    =			(left + right) // 2
														if left == right:
																					if sorted_list[middle] < item:
																												lowerCamelCase__   :      Any			    =			middle + 1
																					break
														elif sorted_list[middle] < item:
																					lowerCamelCase__   :      Optional[Any]			    =			middle + 1
														else:
																					lowerCamelCase__   :      Dict			    =			middle - 1
							sorted_list.insert(UpperCamelCase							,     UpperCamelCase )
							return sorted_list





def 					SCREAMING_SNAKE_CASE_			(UpperCamelCase							,     UpperCamelCase ) ->			Tuple:
							lowerCamelCase__   :      Any			    =			[]
							while left and right:
														if left[0][0] < right[0][0]:
																					result.append(left.pop(0 ) )
														else:
																					result.append(right.pop(0 ) )
							return result + left + right





def 					SCREAMING_SNAKE_CASE_			(UpperCamelCase ) ->			Any:
							lowerCamelCase__   :      Optional[Any]			    =			len(UpperCamelCase )
							if length <= 1:
														return list_ad
							lowerCamelCase__   :      Tuple			    =			length // 2
							return merge(sortlist_ad(list_ad[:middle] )							,     sortlist_ad(list_ad[middle:] ) )





def 					SCREAMING_SNAKE_CASE_			(UpperCamelCase ) ->			list[int]:

							if len(UpperCamelCase ) <= 1:
														return collection
							lowerCamelCase__   :      int			    =			[]
							lowerCamelCase__   :      int			    =			False
							for i in range(0							,     len(UpperCamelCase )							,     2 ):
														if i == len(UpperCamelCase ) - 1:
																					lowerCamelCase__   :      List[Any]			    =			True
														else:
																					if collection[i] < collection[i + 1]:
																												two_paired_list.append([collection[i], collection[i + 1]] )
																					else:
																												two_paired_list.append([collection[i + 1], collection[i]] )
							lowerCamelCase__   :      List[Any]			    =			sortlist_ad(UpperCamelCase )
							lowerCamelCase__   :      List[Any]			    =			[i[0] for i in sorted_list_ad]
							result.append(sorted_list_ad[-1][1] )
							if has_last_odd_item:
														lowerCamelCase__   :      int			    =			collection[-1]
														lowerCamelCase__   :      str			    =			binary_search_insertion(UpperCamelCase							,     UpperCamelCase )
							lowerCamelCase__   :      Any			    =			False
							for i in range(len(UpperCamelCase ) - 1 ):
														if result[i] == collection[-1] and has_last_odd_item:
																					lowerCamelCase__   :      Any			    =			True
														lowerCamelCase__   :      Dict			    =			sorted_list_ad[i][1]
														# If last_odd_item is inserted before the item's index,
														# you should forward index one more.
														if is_last_odd_item_inserted_before_this_index:
																					lowerCamelCase__   :      List[str]			    =			result[: i + 2] + binary_search_insertion(result[i + 2 :]							,     UpperCamelCase )
														else:
																					lowerCamelCase__   :      Dict			    =			result[: i + 1] + binary_search_insertion(result[i + 1 :]							,     UpperCamelCase )

							return result


if __name__ == "__main__":
			_A      :     Tuple       	=input('''Enter numbers separated by a comma:\n''').strip()
			_A      :     List[Any]       	=[int(item) for item in user_input.split(''',''')]
			print(merge_insertion_sort(unsorted))

