'''simple docstring'''
from itertools import permutations







def 							__UpperCamelCase   (				__UpperCAmelCase     :				int = 5 )       ->  int:
  if gon_side < 3 or gon_side > 5:
    raise ValueError('''gon_side must be in the range [3, 5]''' )

  # Since it's 16, we know 10 is on the outer ring
  # Put the big numbers at the end so that they are never the first number
  lowercase							:       Dict											=      list(range(gon_side + 1   ,      0   ,      -1 ) )
  lowercase							:       Optional[int]											=      list(range(gon_side + 2   ,      gon_side * 2 + 1 ) )

  for perm in permutations(small_numbers + big_numbers ):
    lowercase							:       List[Any]											=      generate_gon_ring(__UpperCAmelCase   ,      list(__UpperCAmelCase ) )
    if is_magic_gon(__UpperCAmelCase ):
      return int(''''''.join(str(__UpperCAmelCase ) for n in numbers ) )

  lowercase							:       Tuple											=      f"""Magic {gon_side}-gon ring is impossible"""
  raise ValueError(__UpperCAmelCase )







def 							__UpperCamelCase   (				__UpperCAmelCase     :				int   ,      __UpperCAmelCase     :				list[int] )       ->  list[int]:
  lowercase							:       List[str]											=      [0] * (gon_side * 3)
  lowercase							:       List[Any]											=      perm[0:3]
  perm.append(perm[1] )

  lowercase							:       List[str]											=      1 if gon_side < 5 else 2

  for i in range(1   ,      len(__UpperCAmelCase ) // 3 + magic_number ):
    lowercase							:       Optional[Any]											=      perm[2 * i + 1]
    lowercase							:       Any											=      result[3 * i - 1]
    lowercase							:       Optional[int]											=      perm[2 * i + 2]

  return result







def 							__UpperCamelCase   (				__UpperCAmelCase     :				list[int] )       ->  bool:
  if len(__UpperCAmelCase ) % 3 != 0:
    raise ValueError('''a gon ring should have a length that is a multiple of 3''' )

  if min(numbers[::3] ) != numbers[0]:
    return False

  lowercase							:       List[str]											=      sum(numbers[:3] )

  return all(sum(numbers[i : i + 3] ) == total for i in range(3   ,      len(__UpperCAmelCase )   ,      3 ) )


if __name__ == "__main__":
 print(solution())
'''simple docstring'''
import csv
import dataclasses
import json
from dataclasses import dataclass
from typing import List, Optional, Union

from ...utils import is_tf_available, is_torch_available, logging


_A		:			Any	      =logging.get_logger(__name__)




@dataclass
class _lowerCAmelCase :
      UpperCAmelCase_  :	str
      UpperCAmelCase_  :	str
      UpperCAmelCase_  :	Optional[str]     =					None
      UpperCAmelCase_  :	Optional[str]     =					None







      def     lowerCamelCase__			(     self    ):
        return json.dumps(dataclasses.asdict(self    )     ,						indent=2    ) + "\n"





@dataclass(frozen=snake_case				)
class _lowerCAmelCase :
      UpperCAmelCase_  :	List[int]
      UpperCAmelCase_  :	Optional[List[int]]     =					None
      UpperCAmelCase_  :	Optional[List[int]]     =					None
      UpperCAmelCase_  :	Optional[Union[int, float]]     =					None







      def     lowerCamelCase__			(     self    ):
        return json.dumps(dataclasses.asdict(self    )    ) + "\n"





class _lowerCAmelCase :







      def     lowerCamelCase__			(     self     ,						lowercase    ):
        raise NotImplementedError()







      def     lowerCamelCase__			(     self     ,						lowercase    ):
        raise NotImplementedError()







      def     lowerCamelCase__			(     self     ,						lowercase    ):
        raise NotImplementedError()







      def     lowerCamelCase__			(     self     ,						lowercase    ):
        raise NotImplementedError()







      def     lowerCamelCase__			(     self    ):
        raise NotImplementedError()







      def     lowerCamelCase__			(     self     ,						lowercase    ):
        if len(self.get_labels()    ) > 1:
          lowercase							:       Tuple											=      self.get_labels()[int(example.label    )]
        return example







      @classmethod
      def     lowerCamelCase__			(     cls     ,						lowercase     ,						lowercase=None    ):
        with open(lowercase     ,						'''r'''     ,						encoding='''utf-8-sig'''    ) as f:
          return list(csv.reader(lowercase     ,						delimiter='''\t'''     ,						quotechar=lowercase    )    )





class _lowerCAmelCase (  snake_case				):







      def __init__(     self     ,						lowercase=None     ,						lowercase=None     ,						lowercase="classification"     ,						lowercase=False    ):
        lowercase							:       Tuple											=      [] if labels is None else labels
        lowercase							:       Optional[int]											=      [] if examples is None else examples
        lowercase							:       Tuple											=      mode
        lowercase							:       Any											=      verbose







      def __len__(     self    ):
        return len(self.examples    )







      def __getitem__(     self     ,						lowercase    ):
        if isinstance(lowercase     ,						lowercase    ):
          return SingleSentenceClassificationProcessor(labels=self.labels     ,						examples=self.examples[idx]    )
        return self.examples[idx]







      @classmethod
      def     lowerCamelCase__			(     cls     ,						lowercase     ,						lowercase=""     ,						lowercase=0     ,						lowercase=1     ,						lowercase=None     ,						lowercase=False     ,						**lowercase    ):
        lowercase							:       int											=      cls(**lowercase    )
        processor.add_examples_from_csv(
            lowercase     ,						split_name=lowercase     ,						column_label=lowercase     ,						column_text=lowercase     ,						column_id=lowercase     ,						skip_first_row=lowercase     ,						overwrite_labels=lowercase     ,						overwrite_examples=lowercase     ,						)
        return processor







      @classmethod
      def     lowerCamelCase__			(     cls     ,						lowercase     ,						lowercase=None     ,						**lowercase    ):
        lowercase							:       Dict											=      cls(**lowercase    )
        processor.add_examples(lowercase     ,						labels=lowercase    )
        return processor







      def     lowerCamelCase__			(     self     ,						lowercase     ,						lowercase=""     ,						lowercase=0     ,						lowercase=1     ,						lowercase=None     ,						lowercase=False     ,						lowercase=False     ,						lowercase=False     ,						):
        lowercase							:       Union[str, Any]											=      self._read_tsv(lowercase    )
        if skip_first_row:
          lowercase							:       Tuple											=      lines[1:]
        lowercase							:       Dict											=      []
        lowercase							:       Tuple											=      []
        lowercase							:       List[str]											=      []
        for i, line in enumerate(lowercase    ):
          texts.append(line[column_text]    )
          labels.append(line[column_label]    )
          if column_id is not None:
            ids.append(line[column_id]    )
          else:
            lowercase							:       Dict											=      F"""{split_name}-{i}""" if split_name else str(lowercase    )
            ids.append(lowercase    )

        return self.add_examples(
            lowercase     ,						lowercase     ,						lowercase     ,						overwrite_labels=lowercase     ,						overwrite_examples=lowercase    )







      def     lowerCamelCase__			(     self     ,						lowercase     ,						lowercase=None     ,						lowercase=None     ,						lowercase=False     ,						lowercase=False    ):
        if labels is not None and len(lowercase    ) != len(lowercase    ):
          raise ValueError(
              F"""Text and labels have mismatched lengths {len(lowercase    )} and {len(lowercase    )}"""    )
        if ids is not None and len(lowercase    ) != len(lowercase    ):
          raise ValueError(F"""Text and ids have mismatched lengths {len(lowercase    )} and {len(lowercase    )}"""    )
        if ids is None:
          lowercase							:       Optional[Any]											=      [None] * len(lowercase    )
        if labels is None:
          lowercase							:       Dict											=      [None] * len(lowercase    )
        lowercase							:       int											=      []
        lowercase							:       Optional[Any]											=      set()
        for text_or_text_and_label, label, guid in zip(lowercase     ,						lowercase     ,						lowercase    ):
          if isinstance(lowercase     ,						(tuple, list)    ) and label is None:
            lowercase							,			lowercase							:       Optional[Any]											=      text_or_text_and_label
          else:
            lowercase							:       Tuple											=      text_or_text_and_label
          added_labels.add(lowercase    )
          examples.append(InputExample(guid=lowercase     ,						text_a=lowercase     ,						text_b=lowercase     ,						label=lowercase    )    )

        # Update examples
        if overwrite_examples:
          lowercase							:       List[str]											=      examples
        else:
          self.examples.extend(lowercase    )

        # Update labels
        if overwrite_labels:
          lowercase							:       Dict											=      list(lowercase    )
        else:
          lowercase							:       Tuple											=      list(set(self.labels    ).union(lowercase    )    )

        return self.examples







      def     lowerCamelCase__			(     self     ,						lowercase     ,						lowercase=None     ,						lowercase=False     ,						lowercase=0     ,						lowercase=True     ,						lowercase=None     ,						):
        if max_length is None:
          lowercase							:       Optional[Any]											=      tokenizer.max_len

        lowercase							:       int											=      {label: i for i, label in enumerate(self.labels    )}

        lowercase							:       str											=      []
        for ex_index, example in enumerate(self.examples    ):
          if ex_index % 1_0000 == 0:
            logger.info(F"""Tokenizing example {ex_index}"""    )

          lowercase							:       Optional[int]											=      tokenizer.encode(
              example.text_a     ,						add_special_tokens=lowercase     ,						max_length=min(lowercase     ,						tokenizer.max_len    )     ,						)
          all_input_ids.append(lowercase    )

        lowercase							:       int											=      max(len(lowercase    ) for input_ids in all_input_ids    )

        lowercase							:       Dict											=      []
        for ex_index, (input_ids, example) in enumerate(zip(lowercase     ,						self.examples    )    ):
          if ex_index % 1_0000 == 0:
            logger.info(F"""Writing example {ex_index}/{len(self.examples    )}"""    )
          # The mask has 1 for real tokens and 0 for padding tokens. Only real
          # tokens are attended to.
          lowercase							:       List[Any]											=      [1 if mask_padding_with_zero else 0] * len(lowercase    )

          # Zero-pad up to the sequence length.
          lowercase							:       List[Any]											=      batch_length - len(lowercase    )
          if pad_on_left:
            lowercase							:       Optional[int]											=      ([pad_token] * padding_length) + input_ids
            lowercase							:       Any											=      ([0 if mask_padding_with_zero else 1] * padding_length) + attention_mask
          else:
            lowercase							:       int											=      input_ids + ([pad_token] * padding_length)
            lowercase							:       List[str]											=      attention_mask + ([0 if mask_padding_with_zero else 1] * padding_length)

          if len(lowercase    ) != batch_length:
            raise ValueError(F"""Error with input length {len(lowercase    )} vs {batch_length}"""    )
          if len(lowercase    ) != batch_length:
            raise ValueError(F"""Error with input length {len(lowercase    )} vs {batch_length}"""    )

          if self.mode == "classification":
            lowercase							:       Dict											=      label_map[example.label]
          elif self.mode == "regression":
            lowercase							:       Optional[int]											=      float(example.label    )
          else:
            raise ValueError(self.mode    )

          if ex_index < 5 and self.verbose:
            logger.info('''*** Example ***'''    )
            logger.info(F"""guid: {example.guid}"""    )
            logger.info(F"""input_ids: {" ".join([str(lowercase    ) for x in input_ids]    )}"""    )
            logger.info(F"""attention_mask: {" ".join([str(lowercase    ) for x in attention_mask]    )}"""    )
            logger.info(F"""label: {example.label} (id = {label})"""    )

          features.append(InputFeatures(input_ids=lowercase     ,						attention_mask=lowercase     ,						label=lowercase    )    )

        if return_tensors is None:
          return features
        elif return_tensors == "tf":
          if not is_tf_available():
            raise RuntimeError('''return_tensors set to \'tf\' but TensorFlow 2.0 can\'t be imported'''    )
          import tensorflow as tf

          def gen():
            for ex in features:
              yield ({"input_ids": ex.input_ids, "attention_mask": ex.attention_mask}, ex.label)

          lowercase							:       Any											=      tf.data.Dataset.from_generator(
              lowercase     ,						({'''input_ids''': tf.intaa, '''attention_mask''': tf.intaa}, tf.intaa)     ,						({'''input_ids''': tf.TensorShape([None]    ), '''attention_mask''': tf.TensorShape([None]    )}, tf.TensorShape([]    ))     ,						)
          return dataset
        elif return_tensors == "pt":
          if not is_torch_available():
            raise RuntimeError('''return_tensors set to \'pt\' but PyTorch can\'t be imported'''    )
          import torch
          from torch.utils.data import TensorDataset

          lowercase							:       Any											=      torch.tensor([f.input_ids for f in features]     ,						dtype=torch.long    )
          lowercase							:       List[str]											=      torch.tensor([f.attention_mask for f in features]     ,						dtype=torch.long    )
          if self.mode == "classification":
            lowercase							:       int											=      torch.tensor([f.label for f in features]     ,						dtype=torch.long    )
          elif self.mode == "regression":
            lowercase							:       Tuple											=      torch.tensor([f.label for f in features]     ,						dtype=torch.float    )

          lowercase							:       int											=      TensorDataset(lowercase     ,						lowercase     ,						lowercase    )
          return dataset
        else:
          raise ValueError('''return_tensors should be one of \'tf\' or \'pt\''''    )