






'''simple docstring'''
import io
import itertools
import json
from dataclasses import dataclass
from typing import Optional

import pyarrow as pa
import pyarrow.json as paj

import datasets
from datasets.table import table_cast
from datasets.utils.file_utils import readline


UpperCamelCase__ =			datasets.utils.logging.get_logger(__name__)


@dataclass
class        _UpperCAmelCase						(		datasets.BuilderConfig			):
    __lowerCamelCase:   Optional[datasets.Features]		       =    None
    __lowerCamelCase:   str		       =    "utf-8"
    __lowerCamelCase:   Optional[str]		       =    None
    __lowerCamelCase:   Optional[str]		       =    None
    __lowerCamelCase:   bool		       =    True  # deprecated
    __lowerCamelCase:   Optional[int]		       =    None  # deprecated
    __lowerCamelCase:   int		       =    10 << 20  # 10MB
    __lowerCamelCase:   Optional[bool]		       =    None


class        _UpperCAmelCase						(		datasets.ArrowBasedBuilder			):
    __lowerCamelCase:   int		       =    JsonConfig




    def 				lowerCAmelCase__				(			self  :       List[str]			):






       '''simple docstring'''






       if self.config.block_size is not None:
          logger.warning("The JSON loader parameter `block_size` is deprecated. Please use `chunksize` instead"			)
          lowercase_	:    Dict           =     self.config.block_size
       if self.config.use_threads is not True:
          logger.warning(
              "The JSON loader parameter `use_threads` is deprecated and doesn't have any effect anymore."			)
       if self.config.newlines_in_values is not None:
          raise ValueError("The JSON loader parameter `newlines_in_values` is no longer supported"			)
       return datasets.DatasetInfo(features=self.config.features			)




    def 				lowerCAmelCase__				(			self  :       List[Any]  ,     a  :       Optional[Any]			):






       '''simple docstring'''






       if not self.config.data_files:
          raise ValueError(f"""At least one data file must be specified, but got data_files={self.config.data_files}"""			)
       lowercase_	:    List[str]           =     dl_manager.download_and_extract(self.config.data_files			)
       if isinstance(a  ,     (str, list, tuple)			):
          lowercase_	:    int           =     data_files
          if isinstance(a  ,     a			):
             lowercase_	:    str           =     [files]
          lowercase_	:    Optional[Any]           =     [dl_manager.iter_files(a			) for file in files]
          return [datasets.SplitGenerator(name=datasets.Split.TRAIN  ,     gen_kwargs={"files": files}			)]
       lowercase_	:    Optional[int]           =     []
       for split_name, files in data_files.items():
          if isinstance(a  ,     a			):
             lowercase_	:    Dict           =     [files]
          lowercase_	:    Any           =     [dl_manager.iter_files(a			) for file in files]
          splits.append(datasets.SplitGenerator(name=a  ,     gen_kwargs={"files": files}			)			)
       return splits




    def 				lowerCAmelCase__				(			self  :       Optional[int]  ,     a  :       pa.Table			):






       '''simple docstring'''






       if self.config.features is not None:
          # adding missing columns
          for column_name in set(self.config.features			) - set(pa_table.column_names			):
             lowercase_	:    List[Any]           =     self.config.features.arrow_schema.field(a			).type
             lowercase_	:    List[Any]           =     pa_table.append_column(a  ,     pa.array([None] * len(a			)  ,     type=a			)			)
          # more expensive cast to support nested structures with keys in a different order
          # allows str <-> int/float or str to Audio for example
          lowercase_	:    str           =     table_cast(a  ,     self.config.features.arrow_schema			)
       return pa_table





    def 				lowerCAmelCase__				(			self  :       Optional[Any]  ,     a  :       Optional[Any]			):






       '''simple docstring'''






       for file_idx, file in enumerate(itertools.chain.from_iterable(a			)			):
          # If the file is one json object and if we need to look at the list of items in one specific field
          if self.config.field is not None:
             with open(a  ,     encoding=self.config.encoding  ,     errors=self.config.encoding_errors			) as f:
                lowercase_	:    List[Any]           =     json.load(a			)

             # We keep only the field we are interested in
             lowercase_	:    Any           =     dataset[self.config.field]

             # We accept two format: a list of dicts or a dict of lists
             if isinstance(a  ,     (list, tuple)			):
                lowercase_	:    int           =     set().union(*[row.keys() for row in dataset]			)
                lowercase_	:    str           =     {col: [row.get(a			) for row in dataset] for col in keys}
             else:
                lowercase_	:    List[Any]           =     dataset
             lowercase_	:    Optional[Any]           =     pa.Table.from_pydict(a			)
             yield file_idx, self._cast_table(a			)

          # If the file has one json object per line
          else:
             with open(a  ,     "rb"			) as f:
                lowercase_	:    Optional[int]           =     0
                # Use block_size equal to the chunk size divided by 32 to leverage multithreading
                # Set a default minimum value of 16kB if the chunk size is really small
                lowercase_	:    str           =     max(self.config.chunksize // 3_2  ,     1_6 << 1_0			)
                lowercase_	:    Optional[Any]           =     (
                    self.config.encoding_errors if self.config.encoding_errors is not None else "strict"
                )
                while True:
                   lowercase_	:    Optional[int]           =     f.read(self.config.chunksize			)
                   if not batch:
                      break
                   # Finish current line
                   try:
                      batch += f.readline()
                   except (AttributeError, io.UnsupportedOperation):
                      batch += readline(a			)
                   # PyArrow only accepts utf-8 encoded bytes
                   if self.config.encoding != "utf-8":
                      lowercase_	:    int           =     batch.decode(self.config.encoding  ,     errors=a			).encode("utf-8"			)
                   try:
                      while True:
                         try:
                            lowercase_	:    Union[str, Any]           =     paj.read_json(
                                io.BytesIO(a			)  ,     read_options=paj.ReadOptions(block_size=a			)			)
                            break
                         except (pa.ArrowInvalid, pa.ArrowNotImplementedError) as e:
                            if (
                                isinstance(a  ,     pa.ArrowInvalid			)
                                and "straddling" not in str(a			)
                                or block_size > len(a			)
                            ):
                               raise
                            else:
                               # Increase the block size in case it was too small.
                               # The block size will be reset for the next file.
                               logger.debug(
                                   f"""Batch of {len(a			)} bytes couldn't be parsed with block_size={block_size}. Retrying with block_size={block_size * 2}."""			)
                               block_size *= 2
                   except pa.ArrowInvalid as e:
                      try:
                         with open(
                             a  ,     encoding=self.config.encoding  ,     errors=self.config.encoding_errors			) as f:
                            lowercase_	:    int           =     json.load(a			)
                      except json.JSONDecodeError:
                         logger.error(f"""Failed to read file '{file}' with error {type(a			)}: {e}"""			)
                         raise e
                      # If possible, parse the file as a list of json objects and exit the loop
                      if isinstance(a  ,     a			):  # list is the only sequence type supported in JSON
                         try:
                            lowercase_	:    List[str]           =     set().union(*[row.keys() for row in dataset]			)
                            lowercase_	:    Optional[int]           =     {col: [row.get(a			) for row in dataset] for col in keys}
                            lowercase_	:    int           =     pa.Table.from_pydict(a			)
                         except (pa.ArrowInvalid, AttributeError) as e:
                            logger.error(f"""Failed to read file '{file}' with error {type(a			)}: {e}"""			)
                            raise ValueError(f"""Not able to read records in the JSON file at {file}."""			) from None
                         yield file_idx, self._cast_table(a			)
                         break
                      else:
                         logger.error(f"""Failed to read file '{file}' with error {type(a			)}: {e}"""			)
                         raise ValueError(
                             f"""Not able to read records in the JSON file at {file}. """
                             f"""You should probably indicate the field of the JSON file containing your records. """
                             f"""This JSON file contain the following fields: {str(list(dataset.keys()			)			)}. """
                             f"""Select the correct one and provide it as `field='XXX'` to the dataset loading method. """			) from None
                        # Uncomment for debugging (will print the Arrow table size and elements)
                        # logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
                        # logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
                   yield (file_idx, batch_idx), self._cast_table(a			)
                   batch_idx += 1












'''simple docstring'''
def 		__SCREAMING_SNAKE_CASE					(  _UpperCamelCase							):


   """simple docstring"""




   lowercase_	:    Any           =     False
   while is_sorted is False:  # Until all the indices are traversed keep looping
      lowercase_	:    List[str]           =     True
      for i in range(0						,		len(_UpperCamelCase							) - 1						,		2							):  # iterating over all even indices
         if input_list[i] > input_list[i + 1]:
            lowercase_    ,		lowercase_	:    Union[str, Any]           =     input_list[i + 1], input_list[i]
            # swapping if elements not in order
            lowercase_	:    Any           =     False

      for i in range(1						,		len(_UpperCamelCase							) - 1						,		2							):  # iterating over all odd indices
         if input_list[i] > input_list[i + 1]:
            lowercase_    ,		lowercase_	:    Tuple           =     input_list[i + 1], input_list[i]
            # swapping if elements not in order
            lowercase_	:    List[Any]           =     False
   return input_list


if __name__ == "__main__":
 print('Enter list to be sorted')
 UpperCamelCase__ =			[int(x) for x in input().split()]
 # inputing elements of the list in one line
 UpperCamelCase__ =			odd_even_sort(input_list)
 print('The sorted list is')
 print(sorted_list)




