




"""simple docstring"""





import math
from itertools import permutations

def 						lowerCAmelCase							(	lowerCamelCase						):
						'''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 ,     lowerCamelCase						):
						'''simple docstring'''


						snake_case__     ,		snake_case__    :   str							     =   0, len(_lowerCAmelCase						) - 1
						while left <= right:
												snake_case__    :   List[str]							     =   (left + right) // 2
												if prime_list[middle] == target:
																		return True
												elif prime_list[middle] < target:
																		snake_case__    :   str							     =   middle + 1
												else:
																		snake_case__    :   Dict							     =   middle - 1

						return False

def 						lowerCAmelCase							(	):
						'''simple docstring'''


						snake_case__    :   int							     =   [n for n in range(1001 ,     10000 ,     2						) if is_prime(_lowerCAmelCase						)]
						snake_case__    :   Dict							     =   []

						for number in prime_list:
												snake_case__    :   Dict							     =   []

												for prime_member in permutations(list(str(_lowerCAmelCase						)						)						):
																		snake_case__    :   List[str]							     =   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						)

						snake_case__    :   List[Any]							     =   []
						for candidate in candidates:
												snake_case__    :   Any							     =   len(_lowerCAmelCase						)
												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]]						)						)
																																				snake_case__    :   Union[str, Any]							     =   True

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

						snake_case__    :   str							     =   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"""





def 						lowerCAmelCase							(	lowerCamelCase						):
						'''simple docstring'''


						return int(lowerCamelCase						) if x - int(lowerCamelCase						) <= 0 else int(lowerCamelCase						) + 1


if __name__ == "__main__":
							import doctest

							doctest.testmod()


