






import math
from itertools import permutations

def     lowerCAmelCase__  (  UpperCamelCase__       ):



  '''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__  (  UpperCamelCase__  ,     UpperCamelCase__       ):



  '''simple docstring'''
  _a						: int    =			0, len(__lowerCAmelCase       ) - 1
  while left <= right:
    _a						: Optional[Any]    =			(left + right) // 2
    if prime_list[middle] == target:
      return True
    elif prime_list[middle] < target:
      _a						: List[Any]    =			middle + 1
    else:
      _a						: Any    =			middle - 1

  return False

def     lowerCAmelCase__  (  ):



  '''simple docstring'''
  _a						: Optional[Any]    =			[n for n in range(1_0_0_1  ,     1_0_0_0_0  ,     2       ) if is_prime(__lowerCAmelCase       )]
  _a						: Any    =			[]

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

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

  _a						: List[Any]    =			[]
  for candidate in candidates:
    _a						: Any    =			len(__lowerCAmelCase       )
    _a						: 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]]       )       )
            _a						: Any    =			True

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

  _a						: int    =			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 math
from itertools import permutations

def     lowerCAmelCase__  (  UpperCamelCase__       ):



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

def     lowerCAmelCase__  (  UpperCamelCase__ = 7       ):



  '''simple docstring'''
  _a						: Tuple    =			"""""".join(str(UpperCamelCase__       ) for i in range(1  ,     n + 1       )       )
  _a						: str    =			[int("""""".join(UpperCamelCase__       )       ) for i in permutations(UpperCamelCase__  ,     UpperCamelCase__       )]
  _a						: Union[str, Any]    =			[num for num in perm_list if is_prime(UpperCamelCase__       )]
  return max(UpperCamelCase__       ) if pandigitals else 0


if __name__ == "__main__":
 print(F'''{solution() = }''')

