


'''simple docstring'''


import argparse

import torch
from flax.training.checkpoints import restore_checkpoint

from transformers import FNetConfig, FNetForPreTraining
from transformers.utils import logging


logging.set_verbosity_info()






def 			__lowerCAmelCase			(__lowerCAmelCase   ,			__lowerCAmelCase   ,			__lowerCAmelCase ):
		_UpperCAmelCase		:							List[str]             =   FNetConfig.from_json_file(__lowerCAmelCase )
		print(F"""Building PyTorch model from configuration: {config}""" )
		_UpperCAmelCase		:							Optional[int]             =   FNetForPreTraining(__lowerCAmelCase )

		_UpperCAmelCase		:							Dict             =   restore_checkpoint(__lowerCAmelCase   ,			__lowerCAmelCase )
		_UpperCAmelCase		:							List[str]             =   checkpoint_dict['target']

		# Embeddings
		# Position IDs
		_UpperCAmelCase		:							int             =   fnet_pretraining_model.state_dict()

		_UpperCAmelCase		:							Dict             =   state_dict['fnet.embeddings.position_ids']
		_UpperCAmelCase		:							Optional[int]             =   {'fnet.embeddings.position_ids': position_ids}
		# Embedding Layers
		_UpperCAmelCase		:							Tuple             =   torch.tensor(
		    pretrained_model_params["encoder"]["embedder"]["word"]["embedding"] )
		_UpperCAmelCase		:							List[Any]             =   torch.tensor(
		    pretrained_model_params["encoder"]["embedder"]["position"]["embedding"][0] )
		_UpperCAmelCase		:							int             =   torch.tensor(
		    pretrained_model_params["encoder"]["embedder"]["type"]["embedding"] )
		_UpperCAmelCase		:							Tuple             =   torch.tensor(
		    pretrained_model_params["encoder"]["embedder"]["hidden_mapping_in"]["kernel"] ).T
		_UpperCAmelCase		:							List[Any]             =   torch.tensor(
		    pretrained_model_params["encoder"]["embedder"]["hidden_mapping_in"]["bias"] )
		_UpperCAmelCase		:							Optional[int]             =   torch.tensor(
		    pretrained_model_params["encoder"]["embedder"]["layer_norm"]["scale"] )
		_UpperCAmelCase		:							List[Any]             =   torch.tensor(
		    pretrained_model_params["encoder"]["embedder"]["layer_norm"]["bias"] )

		# Encoder Layers
		for layer in range(config.num_hidden_layers ):
				_UpperCAmelCase		:							Dict             =   torch.tensor(
				    pretrained_model_params["encoder"][F"""encoder_{layer}"""]["mixing_layer_norm"]["scale"] )
				_UpperCAmelCase		:							Tuple             =   torch.tensor(
				    pretrained_model_params["encoder"][F"""encoder_{layer}"""]["mixing_layer_norm"]["bias"] )

				_UpperCAmelCase		:							Tuple             =   torch.tensor(
				    pretrained_model_params["encoder"][F"""feed_forward_{layer}"""]["intermediate"]["kernel"] ).T
				_UpperCAmelCase		:							str             =   torch.tensor(
				    pretrained_model_params["encoder"][F"""feed_forward_{layer}"""]["intermediate"]["bias"] )

				_UpperCAmelCase		:							Any             =   torch.tensor(
				    pretrained_model_params["encoder"][F"""feed_forward_{layer}"""]["output"]["kernel"] ).T
				_UpperCAmelCase		:							Tuple             =   torch.tensor(
				    pretrained_model_params["encoder"][F"""feed_forward_{layer}"""]["output"]["bias"] )

				_UpperCAmelCase		:							Optional[Any]             =   torch.tensor(
				    pretrained_model_params["encoder"][F"""encoder_{layer}"""]["output_layer_norm"]["scale"] )
				_UpperCAmelCase		:							Dict             =   torch.tensor(
				    pretrained_model_params["encoder"][F"""encoder_{layer}"""]["output_layer_norm"]["bias"] )

		# Pooler Layers
		_UpperCAmelCase		:							Dict             =   torch.tensor(pretrained_model_params["encoder"]["pooler"]["kernel"] ).T
		_UpperCAmelCase		:							str             =   torch.tensor(pretrained_model_params["encoder"]["pooler"]["bias"] )

		# Masked LM Layers
		_UpperCAmelCase		:							int             =   torch.tensor(
		    pretrained_model_params["predictions_dense"]["kernel"] ).T
		_UpperCAmelCase		:							Any             =   torch.tensor(
		    pretrained_model_params["predictions_dense"]["bias"] )
		_UpperCAmelCase		:							str             =   torch.tensor(
		    pretrained_model_params["predictions_layer_norm"]["scale"] )
		_UpperCAmelCase		:							List[str]             =   torch.tensor(
		    pretrained_model_params["predictions_layer_norm"]["bias"] )
		_UpperCAmelCase		:							str             =   torch.tensor(
		    pretrained_model_params["encoder"]["embedder"]["word"]["embedding"] )
		_UpperCAmelCase		:							Union[str, Any]             =   torch.tensor(
		    pretrained_model_params["predictions_output"]["output_bias"] )
		_UpperCAmelCase		:							int             =   torch.tensor(pretrained_model_params["predictions_output"]["output_bias"] )

		# Seq Relationship Layers
		_UpperCAmelCase		:							Any             =   torch.tensor(
		    pretrained_model_params["classification"]["output_kernel"] )
		_UpperCAmelCase		:							Optional[Any]             =   torch.tensor(
		    pretrained_model_params["classification"]["output_bias"] )

		# Load State Dict
		fnet_pretraining_model.load_state_dict(__lowerCAmelCase )

		# Save PreTrained
		print(F"""Saving pretrained model to {save_path}""" )
		fnet_pretraining_model.save_pretrained(__lowerCAmelCase )


if __name__ == "__main__":
						lowerCamelCase__     						=  argparse.ArgumentParser()
						# Required parameters
						parser.add_argument(
						    '--flax_checkpoint_path', default=None, type=str, required=True, help='Path to the TensorFlow checkpoint path.'
						)
						parser.add_argument(
						    '--fnet_config_file',
						    default=None,
						    type=str,
						    required=True,
						    help=(
						        'The config json file corresponding to the pre-trained FNet model. \n'
						        'This specifies the model architecture.'
						    ),
						)
						parser.add_argument('--save_path', default=None, type=str, required=True, help='Path to the output model.')
						lowerCamelCase__     						=  parser.parse_args()
						convert_flax_checkpoint_to_pytorch(args.flax_checkpoint_path, args.fnet_config_file, args.save_path)









from __future__ import annotations

class   UpperCAmelCase    :






   def __init__(						self :							List[Any]    ,       UpperCamelCase_ :							int  )->      None:
     _lowercase:			Optional[Any]      =     data
     _lowercase:			Optional[int]      =     None

class   UpperCAmelCase    :






   def __init__(						self :							Optional[Any]  )->      Union[str, Any]:
     _lowercase:			List[str]      =     None






   def 			_a    (						self :							List[Any]    ,       UpperCamelCase_ :							int  )->      int:
     _lowercase:			Any      =     Node(UpperCamelCase_  )
     _lowercase:			List[Any]      =     self.head
     _lowercase:			List[str]      =     new_node
     return self.head.data






   def 			_a    (						self :							Tuple  )->      int | None:
     _lowercase:			List[str]      =     self.head
     _lowercase:			str      =     self.head
     if self.head:
       while fast_pointer and fast_pointer.next:
         _lowercase:			Optional[int]      =     fast_pointer.next.next
         _lowercase:			Tuple      =     slow_pointer.next
       return slow_pointer.data
     else:
       print('No element found.'  )
       return None


if __name__ == "__main__":
   UpperCAmelCase__    :							Union[str, Any]       		=     LinkedList()
   for _ in range(int(input().strip())):
      UpperCAmelCase__    :							List[Any]       		=     int(input().strip())
      link.push(data)
   print(link.middle_element())
