
'''simple docstring'''





import importlib.metadata
import subprocess
import sys


def     UpperCamelCase      (					__lowerCamelCase  :				List[str] = False					):
       snake_case :     str           =   False
       if "IPython" in sys.modules:
              snake_case :     Union[str, Any]           =   "google.colab" in str(sys.modules["IPython"].get_ipython()					)

       if in_colab:
              if upgrade:
                     snake_case :     str           =   ["pip", "install", "-U", "torch"]
                     subprocess.run(UpperCamelCase__       ,      check=UpperCamelCase__					)
              # get the current version of torch
              snake_case :     Tuple           =   importlib.metadata.version("torch"					)
              snake_case :     List[Any]           =   torch_version[: torch_version.rindex("."					)]
              snake_case :     Tuple           =   f"""https://storage.googleapis.com/tpu-pytorch/wheels/colab/torch_xla-{torch_version_trunc}-cp37-cp37m-linux_x86_64.whl"""
              snake_case :     Optional[int]           =   ["pip", "install", xla_wheel]
              subprocess.run(UpperCamelCase__       ,      check=UpperCamelCase__					)
       else:
              raise RuntimeError("`install_xla` utility works only on google colab."					)







import math
from itertools import permutations


def     UpperCamelCase      (					__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     UpperCamelCase      (					__lowerCamelCase  :				int       ,      __lowerCamelCase  :				list					):
       snake_case       ,      snake_case :     List[str]           =   0, len(__lowerCamelCase					) - 1
       while left <= right:
              snake_case :     int           =   (left + right) // 2
              if prime_list[middle] == target:
                     return True
              elif prime_list[middle] < target:
                     snake_case :     Dict           =   middle + 1
              else:
                     snake_case :     Optional[int]           =   middle - 1

       return False


def     UpperCamelCase      (					):
       snake_case :     List[Any]           =   [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 :     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					)

       snake_case :     Union[str, Any]           =   []
       for candidate in candidates:
              snake_case :     Dict           =   len(__lowerCamelCase					)
              snake_case :     Any           =   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 :     Optional[Any]           =   True

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

       snake_case :     Tuple           =   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())





