



'''simple docstring'''




import math
from itertools import permutations


def     lowerCAmelCase_       (     _lowerCamelCase:       int ):

		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 ):
		__SCREAMING_SNAKE_CASE	:		Dict   	=		0, len(_lowerCamelCase ) - 1
		while left <= right:
				__SCREAMING_SNAKE_CASE	:		Any   	=		(left + right) // 2
				if prime_list[middle] == target:
						return True
				elif prime_list[middle] < target:
						__SCREAMING_SNAKE_CASE	:		List[Any]   	=		middle + 1
				else:
						__SCREAMING_SNAKE_CASE	:		Dict   	=		middle - 1

		return False


def     lowerCAmelCase_       (     ):
		__SCREAMING_SNAKE_CASE	:		Union[str, Any]   	=		[n for n in range(10_01	,				1_00_00	,				2 ) if is_prime(_lowerCamelCase )]
		__SCREAMING_SNAKE_CASE	:		int   	=		[]

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

				for prime_member in permutations(list(str(_lowerCamelCase ) ) ):
						__SCREAMING_SNAKE_CASE	:		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 )

		__SCREAMING_SNAKE_CASE	:		Any   	=		[]
		for candidate in candidates:
				__SCREAMING_SNAKE_CASE	:		Optional[Any]   	=		len(_lowerCamelCase )
				__SCREAMING_SNAKE_CASE	:		Optional[int]   	=		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]] ) )
												__SCREAMING_SNAKE_CASE	:		int   	=		True

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

		__SCREAMING_SNAKE_CASE	:		List[Any]   	=		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

import random
from collections.abc import Iterable
from typing import Any, Generic, TypeVar

UpperCamelCase__	:     str    =			TypeVar('''T''', bound=bool)






class 						_UpperCamelCase  (							Generic[T]   ):


			'''simple docstring'''

			def __init__(							self					:			str							,					lowerCAmelCase__					:			T						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE	:		T   	=		value
					__SCREAMING_SNAKE_CASE	:		RandomizedHeapNode[T] | None   	=		None
					__SCREAMING_SNAKE_CASE	:		RandomizedHeapNode[T] | None   	=		None

			@property
			def UpperCamelCase__ (							self					:			Any						):





					"""simple docstring"""






					return self._value



			@staticmethod
			def UpperCamelCase__ (							lowerCAmelCase__					:			RandomizedHeapNode[T] | None							,					lowerCAmelCase__					:			RandomizedHeapNode[T] | None						):





					"""simple docstring"""






					if not roota:
							return roota

					if not roota:
							return roota

					if roota.value > roota.value:
							__SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE	:		List[str]   	=		roota, roota

					if random.choice([True, False]						):
							__SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE	:		Tuple   	=		roota.right, roota.left

					__SCREAMING_SNAKE_CASE	:		Tuple   	=		RandomizedHeapNode.merge(roota.left							,					lowerCAmelCase__						)

					return roota






class 						_UpperCamelCase  (							Generic[T]   ):


			'''simple docstring'''

			def __init__(							self					:			Optional[int]							,					lowerCAmelCase__					:			Iterable[T] | None = ()						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE	:		RandomizedHeapNode[T] | None   	=		None

					if data:
							for item in data:
									self.insert(lowerCAmelCase__						)

			def UpperCamelCase__ (							self					:			Dict							,					lowerCAmelCase__					:			T						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE	:		Dict   	=		RandomizedHeapNode.merge(self._root							,					RandomizedHeapNode(lowerCAmelCase__						)						)

			def UpperCamelCase__ (							self					:			Union[str, Any]						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE	:		Tuple   	=		self.top()

					if self._root is None:
							return None

					__SCREAMING_SNAKE_CASE	:		Union[str, Any]   	=		RandomizedHeapNode.merge(self._root.left							,					self._root.right						)

					return result

			def UpperCamelCase__ (							self					:			Union[str, Any]						):





					"""simple docstring"""






					if not self._root:
							raise IndexError("""Can't get top element for the empty heap."""						)
					return self._root.value

			def UpperCamelCase__ (							self					:			List[Any]						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE	:		List[str]   	=		None

			def UpperCamelCase__ (							self					:			Optional[Any]						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE	:		int   	=		[]
					while self:
							result.append(self.pop()						)

					return result



			def __bool__(							self					:			List[Any]						):





					"""simple docstring"""






					return self._root is not None


if __name__ == "__main__":
						import doctest

						doctest.testmod()