




'''simple docstring'''





import math
from itertools import permutations





def UpperCAmelCase    (       UpperCAmelCase_						):

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





def UpperCAmelCase    (       UpperCAmelCase_   ,	UpperCAmelCase_						):
    _a       , _a				:							Union[str, Any]							       =      0, len(UpperCAmelCase_						) - 1
    while left <= right:
        _a				:							Optional[Any]							       =      (left + right) // 2
        if prime_list[middle] == target:
            return True
        elif prime_list[middle] < target:
            _a				:							Tuple							       =      middle + 1
        else:
            _a				:							str							       =      middle - 1

    return False





def UpperCAmelCase    (       ):
    _a				:							List[str]							       =      [n for n in range(1_001   ,	10_000   ,	2						) if is_prime(UpperCAmelCase_						)]
    _a				:							List[str]							       =      []

    for number in prime_list:
        _a				:							Optional[Any]							       =      []

        for prime_member in permutations(list(str(UpperCAmelCase_						)						)						):
            _a				:							List[Any]							       =      int("""""".join(UpperCAmelCase_						)						)

            if prime % 2 == 0:
                continue

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

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

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

        for i in range(UpperCAmelCase_						):
            for j in range(i + 1   ,	UpperCAmelCase_						):
                for k in range(j + 1   ,	UpperCAmelCase_						):
                    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]]						)						)
                        _a				:							str							       =      True

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

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

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


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





from __future__ import annotations

from collections.abc import Iterator
from typing import Any

class 					__UpperCamelCase					:







	def __init__( self:			Optional[Any]	,			__UpperCamelCase:			Any   ):

						'''simple docstring'''





						__magic_name__				=     data
						__magic_name__				=     None







	def __str__( self:			Optional[int]   ):

						'''simple docstring'''





						return F'{self.data}'




class 					__UpperCamelCase					:







	def __init__( self:			List[Any]   ):

						'''simple docstring'''





						__magic_name__				=     None
						__magic_name__				=     None







	def __iter__( self:			str   ):

						'''simple docstring'''





						__magic_name__				=     self.front
						while node:
											yield node.data
											__magic_name__				=     node.next







	def __len__( self:			Any   ):

						'''simple docstring'''





						return len(tuple(iter(self   )   )   )







	def __str__( self:			List[str]   ):

						'''simple docstring'''





						return " <- ".join(str(__UpperCamelCase   ) for item in self   )







	def 						_SCREAMING_SNAKE_CASE				( self:			Any   ):

						'''simple docstring'''





						return len(self   ) == 0







	def 						_SCREAMING_SNAKE_CASE				( self:			Any	,			__UpperCamelCase:			Any   ):

						'''simple docstring'''





						__magic_name__				=     Node(__UpperCamelCase   )
						if self.is_empty():
											__magic_name__				=     __magic_name__				=     node
						else:
											assert isinstance(self.rear	,			__UpperCamelCase   )
											__magic_name__				=     node
											__magic_name__				=     node







	def 						_SCREAMING_SNAKE_CASE				( self:			Any   ):

						'''simple docstring'''





						if self.is_empty():
											raise IndexError('dequeue from empty queue'   )
						assert isinstance(self.front	,			__UpperCamelCase   )
						__magic_name__				=     self.front
						__magic_name__				=     self.front.next
						if self.front is None:
											__magic_name__				=     None
						return node.data







	def 						_SCREAMING_SNAKE_CASE				( self:			Tuple   ):

						'''simple docstring'''





						__magic_name__				=     __magic_name__				=     None


if __name__ == "__main__":
						from doctest import testmod

						testmod()




