

from __future__ import annotations

from collections.abc import Iterable
from dataclasses import dataclass
from typing import Any


class     lowerCamelCase_   :
	_lowerCAmelCase       		=  ('''_front''', '''_back''', '''_len''')


	@dataclass
	class     lowerCamelCase_   :
		_lowerCAmelCase       		=  None
		_lowerCAmelCase       		=  None
		_lowerCAmelCase       		=  None



	class     lowerCamelCase_   :
		_lowerCAmelCase       		=  ('''_cur''',)




		def __init__( self     ,     _UpperCAmelCase       ):
				__UpperCAmelCase  :     Tuple		=    cur




		def __iter__( self       ):
				return self




		def 						a					( self       ):
				if self._cur is None:
						# finished iterating
						raise StopIteration
				__UpperCAmelCase  :     str		=    self._cur.val
				__UpperCAmelCase  :     Dict		=    self._cur.next_node

				return val




	def __init__( self     ,     _UpperCAmelCase = None       ):
			__UpperCAmelCase  :     Any		=    None
			__UpperCAmelCase  :     Any		=    None
			__UpperCAmelCase  :     int		=    0

			if iterable is not None:
					# append every value to the deque
					for val in iterable:
							self.append(_UpperCAmelCase       )




	def 						a					( self     ,     _UpperCAmelCase       ):
			__UpperCAmelCase  :     Optional[Any]		=    self._Node(_UpperCAmelCase     ,     _UpperCAmelCase     ,     _UpperCAmelCase       )
			if self.is_empty():
					# front = back
					__UpperCAmelCase  :     Dict		=    node
					__UpperCAmelCase  :     List[str]		=    1
			else:
					# connect nodes
					__UpperCAmelCase  :     Any		=    node
					__UpperCAmelCase  :     Tuple		=    self._back
					__UpperCAmelCase  :     Optional[Any]		=    node  # assign new back to the new node

					self._len += 1

					# make sure there were no errors
					assert not self.is_empty(), "Error on appending value."




	def 						a					( self     ,     _UpperCAmelCase       ):
			__UpperCAmelCase  :     Optional[Any]		=    self._Node(_UpperCAmelCase     ,     _UpperCAmelCase     ,     _UpperCAmelCase       )
			if self.is_empty():
					# front = back
					__UpperCAmelCase  :     str		=    node
					__UpperCAmelCase  :     List[str]		=    1
			else:
					# connect nodes
					__UpperCAmelCase  :     List[str]		=    self._front
					__UpperCAmelCase  :     Any		=    node
					__UpperCAmelCase  :     Dict		=    node  # assign new front to the new node

					self._len += 1

					# make sure there were no errors
					assert not self.is_empty(), "Error on appending value."




	def 						a					( self     ,     _UpperCAmelCase       ):
			for val in iterable:
					self.append(_UpperCAmelCase       )




	def 						a					( self     ,     _UpperCAmelCase       ):
			for val in iterable:
					self.appendleft(_UpperCAmelCase       )




	def 						a					( self       ):
			assert not self.is_empty(), "Deque is empty."

			__UpperCAmelCase  :     List[Any]		=    self._back
			__UpperCAmelCase  :     Optional[int]		=    self._back.prev_node  # set new back
			# drop the last node - python will deallocate memory automatically
			__UpperCAmelCase  :     int		=    None

			self._len -= 1

			return topop.val




	def 						a					( self       ):
			assert not self.is_empty(), "Deque is empty."

			__UpperCAmelCase  :     List[Any]		=    self._front
			__UpperCAmelCase  :     Union[str, Any]		=    self._front.next_node  # set new front and drop the first node
			__UpperCAmelCase  :     Union[str, Any]		=    None

			self._len -= 1

			return topop.val




	def 						a					( self       ):
			return self._front is None




	def __len__( self       ):
			return self._len




	def __eq__( self     ,     _UpperCAmelCase       ):

			if not isinstance(_UpperCAmelCase     ,     _UpperCAmelCase       ):
					return NotImplemented

			__UpperCAmelCase  :     List[str]		=    self._front
			__UpperCAmelCase  :     str		=    other._front

			# if the length of the dequeues are not the same, they are not equal
			if len(self       ) != len(_UpperCAmelCase       ):
					return False

			while me is not None and oth is not None:
					# compare every value
					if me.val != oth.val:
							return False
					__UpperCAmelCase  :     Any		=    me.next_node
					__UpperCAmelCase  :     str		=    oth.next_node

			return True




	def __iter__( self       ):
			return Deque._Iterator(self._front       )




	def __repr__( self       ):
			__UpperCAmelCase  :     int		=    []
			__UpperCAmelCase  :     Dict		=    self._front
			while aux is not None:
					# append the values in a list to display
					values_list.append(aux.val       )
					__UpperCAmelCase  :     List[str]		=    aux.next_node

			return F"[{', '.join(repr(_UpperCAmelCase       ) for val in values_list       )}]"


if __name__ == "__main__":
						import doctest

						doctest.testmod()








import math
from itertools import permutations





def    _snake_case		(snake_case_				:    int     )       ->		bool:

  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(snake_case_     ) + 1     )						,					6     ):
    if number % i == 0 or number % (i + 2) == 0:
      return False
  return True





def    _snake_case		(snake_case_				:    int						,					snake_case_				:    list     )       ->		bool:
  __UpperCAmelCase, __UpperCAmelCase  :     Any		=    0, len(snake_case_     ) - 1
  while left <= right:
    __UpperCAmelCase  :     List[str]		=    (left + right) // 2
    if prime_list[middle] == target:
      return True
    elif prime_list[middle] < target:
      __UpperCAmelCase  :     Tuple		=    middle + 1
    else:
      __UpperCAmelCase  :     Tuple		=    middle - 1

  return False





def    _snake_case		()       ->		str:
  __UpperCAmelCase  :     List[Any]		=    [n for n in range(1001						,					1_0000						,					2     ) if is_prime(snake_case_     )]
  __UpperCAmelCase  :     Tuple		=    []

  for number in prime_list:
    __UpperCAmelCase  :     List[str]		=    []

    for prime_member in permutations(list(str(snake_case_     )     )     ):
      __UpperCAmelCase  :     Dict		=    int(''.join(snake_case_     )     )

      if prime % 2 == 0:
        continue

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

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

  __UpperCAmelCase  :     Optional[int]		=    []
  for candidate in candidates:
    __UpperCAmelCase  :     int		=    len(snake_case_     )
    __UpperCAmelCase  :     List[Any]		=    False

    for i in range(snake_case_     ):
      for j in range(i + 1						,					snake_case_     ):
        for k in range(j + 1						,					snake_case_     ):
          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  :     Any		=    True

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

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

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


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





