'''simple docstring'''


import math
from itertools import permutations


def    _lowerCamelCase       ( lowerCamelCase_   :				int  ):



     """simple docstring"""





     if 1 < number < 4:
          # 2 and 3 are primes
          return True
     elif number < 2 or number % 2 == 0 or number % 3 == 0:
          # Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
          return False

     # All primes number are in format of 6k +/- 1
     for i in range(5      ,	int(math.sqrt(lowerCamelCase_  ) + 1  )      ,	6  ):
          if number % i == 0 or number % (i + 2) == 0:
               return False
     return True


def    _lowerCamelCase       ( lowerCamelCase_   :				int      ,	lowerCamelCase_   :				list  ):



     """simple docstring"""





     UpperCAmelCase_  ,     UpperCAmelCase_				:  Optional[Any]  = 0, len(lowerCamelCase_  ) - 1
     while left <= right:
          UpperCAmelCase_				:  Dict  = (left + right) // 2
          if prime_list[middle] == target:
               return True
          elif prime_list[middle] < target:
               UpperCAmelCase_				:  int  = middle + 1
          else:
               UpperCAmelCase_				:  int  = middle - 1

     return False


def    _lowerCamelCase       ( ):



     """simple docstring"""





     UpperCAmelCase_				:  Dict  = [n for n in range(1001      ,	10000      ,	2  ) if is_prime(lowerCamelCase_  )]
     UpperCAmelCase_				:  Tuple  = []

     for number in prime_list:
          UpperCAmelCase_				:  Tuple  = []

          for prime_member in permutations(list(str(lowerCamelCase_  )  )  ):
               UpperCAmelCase_				:  Dict  = int(''.join(lowerCamelCase_  )  )

               if prime % 2 == 0:
                    continue

               if search(lowerCamelCase_      ,	lowerCamelCase_  ):
                    tmp_numbers.append(lowerCamelCase_  )

          tmp_numbers.sort()
          if len(lowerCamelCase_  ) >= 3:
               candidates.append(lowerCamelCase_  )

     UpperCAmelCase_				:  Optional[Any]  = []
     for candidate in candidates:
          UpperCAmelCase_				:  Any  = len(lowerCamelCase_  )
          UpperCAmelCase_				:  Tuple  = False

          for i in range(lowerCamelCase_  ):
               for j in range(i + 1      ,	lowerCamelCase_  ):
                    for k in range(j + 1      ,	lowerCamelCase_  ):
                         if (
                             abs(candidate[i] - candidate[j]  )
                             == abs(candidate[j] - candidate[k]  )
                             and len({candidate[i], candidate[j], candidate[k]}  ) == 3
                         ):
                              passed.append(
                                  sorted([candidate[i], candidate[j], candidate[k]]  )  )
                              UpperCAmelCase_				:  Tuple  = True

                         if found:
                              break
                    if found:
                         break
               if found:
                    break

     UpperCAmelCase_				:  Dict  = set()
     for seq in passed:
          answer.add(''.join([str(lowerCamelCase_  ) for i in seq]  )  )

     return max(int(lowerCamelCase_  ) for x in answer  )


if __name__ == "__main__":
 print(solution())







'''simple docstring'''


from __future__ import annotations

snake_case__	:     str      =    [2, 1, 4, 5, 6, 0, 8, 9, 1, 2, 0, 6, 4, 2, 0, 6, 5, 3, 2, 7]






class 	__SCREAMING_SNAKE_CASE		:







  '''simple docstring'''






  def __init__(					self ,						snake_case_		):




       '''simple docstring'''

       UpperCAmelCase_				:  int  = -1
       UpperCAmelCase_				:  int  = -1
       UpperCAmelCase_				:  list[int]  = [-1] * length
       UpperCAmelCase_				:  Node | None  = None
       UpperCAmelCase_				:  Node | None  = None






  def __repr__(					self		):




       '''simple docstring'''

       return F'''Node(min_value={self.minn} max_value={self.maxx})'''







def    _lowerCamelCase       ( lowerCamelCase_   :				list[int]  ):



     """simple docstring"""





     UpperCAmelCase_				:  List[str]  = Node(len(lowerCamelCase_  )  )
     UpperCAmelCase_  ,     UpperCAmelCase_				:  Any  = min(lowerCamelCase_  ), max(lowerCamelCase_  )
     # Leaf node case where the node contains only one unique value
     if root.minn == root.maxx:
          return root
     UpperCAmelCase_				:  str  = (root.minn + root.maxx) // 2

     UpperCAmelCase_				:  list[int]  = []
     UpperCAmelCase_				:  list[int]  = []

     for index, num in enumerate(lowerCamelCase_  ):
          if num <= pivot:
               left_arr.append(lowerCamelCase_  )
          else:
               right_arr.append(lowerCamelCase_  )
          UpperCAmelCase_				:  Tuple  = len(lowerCamelCase_  )
     UpperCAmelCase_				:  Optional[Any]  = build_tree(lowerCamelCase_  )
     UpperCAmelCase_				:  Optional[Any]  = build_tree(lowerCamelCase_  )
     return root


def    _lowerCamelCase       ( lowerCamelCase_   :				Node | None      ,	lowerCamelCase_   :				int      ,	lowerCamelCase_   :				int  ):



     """simple docstring"""





     if index < 0 or node is None:
          return 0
     # Leaf node cases
     if node.minn == node.maxx:
          return index + 1 if node.minn == num else 0
     UpperCAmelCase_				:  Any  = (node.minn + node.maxx) // 2
     if num <= pivot:
          # go the left subtree and map index to the left subtree
          return rank_till_index(node.left      ,	lowerCamelCase_      ,	node.map_left[index] - 1  )
     else:
          # go to the right subtree and map index to the right subtree
          return rank_till_index(node.right      ,	lowerCamelCase_      ,	index - node.map_left[index]  )


def    _lowerCamelCase       ( lowerCamelCase_   :				Node | None      ,	lowerCamelCase_   :				int      ,	lowerCamelCase_   :				int      ,	lowerCamelCase_   :				int  ):



     """simple docstring"""





     if start > end:
          return 0
     UpperCAmelCase_				:  int  = rank_till_index(lowerCamelCase_      ,	lowerCamelCase_      ,	lowerCamelCase_  )
     UpperCAmelCase_				:  List[Any]  = rank_till_index(lowerCamelCase_      ,	lowerCamelCase_      ,	start - 1  )
     return rank_till_end - rank_before_start


def    _lowerCamelCase       ( lowerCamelCase_   :				Node | None      ,	lowerCamelCase_   :				int      ,	lowerCamelCase_   :				int      ,	lowerCamelCase_   :				int  ):



     """simple docstring"""





     if index > (end - start) or start > end or node is None:
          return -1
     # Leaf node case
     if node.minn == node.maxx:
          return node.minn
     # Number of elements in the left subtree in interval [start, end]
     UpperCAmelCase_				:  Tuple  = node.map_left[end] - (
         node.map_left[start - 1] if start else 0
     )
     if num_elements_in_left_tree > index:
          return quantile(
              node.left      ,	lowerCamelCase_      ,	(node.map_left[start - 1] if start else 0)      ,	node.map_left[end] - 1      ,	)
     else:
          return quantile(
              node.right      ,	index - num_elements_in_left_tree      ,	start - (node.map_left[start - 1] if start else 0)      ,	end - node.map_left[end]      ,	)


def    _lowerCamelCase       ( lowerCamelCase_   :				Node | None      ,	lowerCamelCase_   :				int      ,	lowerCamelCase_   :				int      ,	lowerCamelCase_   :				int      ,	lowerCamelCase_   :				int  ):



     """simple docstring"""





     if (
         start > end
         or node is None
         or start_num > end_num
         or node.minn > end_num
         or node.maxx < start_num
     ):
          return 0
     if start_num <= node.minn and node.maxx <= end_num:
          return end - start + 1
     UpperCAmelCase_				:  Any  = range_counting(
         node.left      ,	(node.map_left[start - 1] if start else 0)      ,	node.map_left[end] - 1      ,	lowerCamelCase_      ,	lowerCamelCase_      ,	)
     UpperCAmelCase_				:  List[str]  = range_counting(
         node.right      ,	start - (node.map_left[start - 1] if start else 0)      ,	end - node.map_left[end]      ,	lowerCamelCase_      ,	lowerCamelCase_      ,	)
     return left + right


if __name__ == "__main__":
 import doctest

 doctest.testmod()






