



import math
from itertools import permutations



def 				_lowerCAmelCase      (_lowerCAmelCase):

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

					return False



def 				_lowerCAmelCase      ():
					UpperCamelCase_											=				[n for n in range(10_01				,		1_00_00				,		2) if is_prime(_lowerCAmelCase)]
					UpperCamelCase_											=				[]

					for number in prime_list:
										UpperCamelCase_											=				[]

										for prime_member in permutations(list(str(_lowerCAmelCase))):
															UpperCamelCase_											=				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_											=				[]
					for candidate in candidates:
										UpperCamelCase_											=				len(_lowerCAmelCase)
										UpperCamelCase_											=				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_											=				True

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

					UpperCamelCase_											=				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())





from typing import List, Optional, Tuple, Union

from . import logging
from .import_utils import is_torch_available, is_torch_version


if is_torch_available():
	import torch

UpperCAmelCase				:							Any								=logging.get_logger(__name__)  # pylint: disable=invalid-name

try:
	from torch._dynamo import allow_in_graph as maybe_allow_in_graph
except (ImportError, ModuleNotFoundError):



	def 				_lowerCAmelCase      (cls):
						return cls



def 				_lowerCAmelCase      (_lowerCAmelCase				,		_lowerCAmelCase = None				,		_lowerCAmelCase = None				,		_lowerCAmelCase = None				,		_lowerCAmelCase = None				,		):
					UpperCamelCase_											=				device
					UpperCamelCase_											=				shape[0]

					UpperCamelCase_											=				layout or torch.strided
					UpperCamelCase_											=				device or torch.device("cpu")

					if generator is not None:
										UpperCamelCase_											=				generator.device.type if not isinstance(_lowerCAmelCase				,		_lowerCAmelCase) else generator[0].device.type
										if gen_device_type != device.type and gen_device_type == "cpu":
															UpperCamelCase_											=				"cpu"
															if device != "mps":
																				logger.info(
																				    f"""The passed generator was created on 'cpu' even though a tensor on {device} was expected."""
																				    f""" Tensors will be created on 'cpu' and then moved to {device}. Note that one can probably"""
																				    f""" slighly speed up this function by passing a generator that was created on the {device} device.""")
										elif gen_device_type != device.type and gen_device_type == "cuda":
															raise ValueError(f"""Cannot generate a {device} tensor from a generator of type {gen_device_type}.""")

					if isinstance(_lowerCAmelCase				,		_lowerCAmelCase):
										UpperCamelCase_											=				(1,) + shape[1:]
										UpperCamelCase_											=				[
										    torch.randn(_lowerCAmelCase				,		generator=generator[i]				,		device=_lowerCAmelCase				,		dtype=_lowerCAmelCase				,		layout=_lowerCAmelCase)
										    for i in range(_lowerCAmelCase)
										]
										UpperCamelCase_											=				torch.cat(_lowerCAmelCase				,		dim=0).to(_lowerCAmelCase)
					else:
										UpperCamelCase_											=				torch.randn(_lowerCAmelCase				,		generator=_lowerCAmelCase				,		device=_lowerCAmelCase				,		dtype=_lowerCAmelCase				,		layout=_lowerCAmelCase).to(_lowerCAmelCase)

					return latents






def 				_lowerCAmelCase      (_lowerCAmelCase):
					if is_torch_version("<"				,		"2.0.0") or not hasattr(_lowerCAmelCase				,		"_dynamo"):
										return False
					return isinstance(_lowerCAmelCase				,		torch._dynamo.eval_frame.OptimizedModule)
