


import math
from itertools import permutations

def       _a	(					SCREAMING_SNAKE_CASE						:					int  ):







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

def       _a	(					SCREAMING_SNAKE_CASE						:					int     ,			SCREAMING_SNAKE_CASE						:					list  ):







 """simple docstring"""



 UpperCamelCase__       :     Tuple 							= 0, len(_a  ) - 1
 while left <= right:
  UpperCamelCase__       :     List[Any] 							= (left + right) // 2
  if prime_list[middle] == target:
   return True
  elif prime_list[middle] < target:
   UpperCamelCase__       :     str 							= middle + 1
  else:
   UpperCamelCase__       :     Union[str, Any] 							= middle - 1

 return False

def       _a	(					):







 """simple docstring"""



 UpperCamelCase__       :     Optional[Any] 							= [n for n in range(1001     ,			10000     ,			2  ) if is_prime(_a  )]
 UpperCamelCase__       :     Tuple 							= []

 for number in prime_list:
  UpperCamelCase__       :     int 							= []

  for prime_member in permutations(list(str(_a  )  )  ):
   UpperCamelCase__       :     List[str] 							= int(''''''.join(_a  )  )

   if prime % 2 == 0:
    continue

   if search(_a     ,			_a  ):
    tmp_numbers.append(_a  )

  tmp_numbers.sort()
  if len(_a  ) >= 3:
   candidates.append(_a  )

 UpperCamelCase__       :     List[str] 							= []
 for candidate in candidates:
  UpperCamelCase__       :     Optional[Any] 							= len(_a  )
  UpperCamelCase__       :     int 							= False

  for i in range(_a  ):
   for j in range(i + 1     ,			_a  ):
    for k in range(j + 1     ,			_a  ):
     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__       :     int 							= True

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

 UpperCamelCase__       :     Optional[int] 							= set()
 for seq in passed:
  answer.add(''''''.join([str(_a  ) for i in seq]  )  )

 return max(int(_a  ) for x in answer  )


if __name__ == "__main__":
       print(solution())







import getopt
import json
import os

# import numpy as np
import sys
from collections import OrderedDict

import datasets
import numpy as np
import torch
from modeling_frcnn import GeneralizedRCNN
from processing_image import Preprocess

from utils import Config
UpperCamelCase_									=   False
UpperCamelCase_									=   Config.from_pretrained('''unc-nlp/frcnn-vg-finetuned''')
UpperCamelCase_									=   datasets.Features(
    OrderedDict(
        {
            '''attr_ids''': datasets.Sequence(length=CONFIG.MAX_DETECTIONS, feature=datasets.Value('''float32''')),
            '''attr_probs''': datasets.Sequence(length=CONFIG.MAX_DETECTIONS, feature=datasets.Value('''float32''')),
            '''boxes''': datasets.ArrayaD((CONFIG.MAX_DETECTIONS, 4), dtype='''float32'''),
            '''img_id''': datasets.Value('''int32'''),
            '''obj_ids''': datasets.Sequence(length=CONFIG.MAX_DETECTIONS, feature=datasets.Value('''float32''')),
            '''obj_probs''': datasets.Sequence(length=CONFIG.MAX_DETECTIONS, feature=datasets.Value('''float32''')),
            '''roi_features''': datasets.ArrayaD((CONFIG.MAX_DETECTIONS, 2048), dtype='''float32'''),
            '''sizes''': datasets.Sequence(length=2, feature=datasets.Value('''float32''')),
            '''preds_per_image''': datasets.Value(dtype='''int32'''),
        }
    )
)







class       _snake_case				:






   '''simple docstring'''






   def __init__(    self:     Dict  ,lowerCamelCase_:     Optional[Any]=sys.argv[1:]							)	->      Optional[int]:
       UpperCAmelCase_     :       Union[str, Any]  		=					None
       UpperCAmelCase_     :       Any  		=					None
       UpperCAmelCase_     :       List[str]  		=					None
       UpperCAmelCase_     :       List[str]  		=					1
       UpperCAmelCase_		, UpperCAmelCase_     :       str  		=					getopt.getopt(lowerCamelCase_  ,"""i:o:b:s"""  ,["""inputdir=""", """outfile=""", """batch_size=""", """subset_list="""]							)
       for opt, arg in opts:
           if opt in ("-i", "--inputdir"):
               UpperCAmelCase_     :       List[Any]  		=					arg
           elif opt in ("-o", "--outfile"):
               UpperCAmelCase_     :       Optional[int]  		=					arg
           elif opt in ("-b", "--batch_size"):
               UpperCAmelCase_     :       Tuple  		=					int(lowerCamelCase_							)
           elif opt in ("-s", "--subset_list"):
               UpperCAmelCase_     :       Dict  		=					arg

       assert inputdir is not None  # and os.path.isdir(inputdir), f"{inputdir}"
       assert outputfile is not None and not os.path.isfile(lowerCamelCase_							), F'''{outputfile}'''
       if subset_list is not None:
           with open(os.path.realpath(lowerCamelCase_							)							) as f:
               UpperCAmelCase_     :       Union[str, Any]  		=					{self._vqa_file_split()[0] for x in tryload(lowerCamelCase_							)}
       else:
           UpperCAmelCase_     :       Optional[Any]  		=					None

       UpperCAmelCase_     :       Optional[int]  		=					CONFIG
       if torch.cuda.is_available():
           UpperCAmelCase_     :       Any  		=					"""cuda"""
       UpperCAmelCase_     :       str  		=					os.path.realpath(lowerCamelCase_							)
       UpperCAmelCase_     :       Any  		=					os.path.realpath(lowerCamelCase_							)
       UpperCAmelCase_     :       Optional[Any]  		=					Preprocess(self.config							)
       UpperCAmelCase_     :       List[str]  		=					GeneralizedRCNN.from_pretrained("""unc-nlp/frcnn-vg-finetuned"""  ,config=self.config							)
       UpperCAmelCase_     :       Optional[Any]  		=					batch_size if batch_size != 0 else 1
       UpperCAmelCase_     :       Optional[int]  		=					DEFAULT_SCHEMA


   def       A__    (    self:     str  ,lowerCamelCase_:     Dict							)	->      Union[str, Any]:
       UpperCAmelCase_     :       List[str]  		=					int(file.split("""."""							)[0].split("""_"""							)[-1]							)
       UpperCAmelCase_     :       int  		=					os.path.join(self.inputdir  ,lowerCamelCase_							)
       return (img_id, filepath)


   @property
   def       A__    (    self:     Tuple							)	->      List[str]:
       UpperCAmelCase_     :       int  		=					[]
       for i, file in enumerate(os.listdir(self.inputdir							)							):
           if self.subset_list is not None and i not in self.subset_list:
               continue
           batch.append(self._vqa_file_split(lowerCamelCase_							)							)
           if len(lowerCamelCase_							) == self.batch:
               UpperCAmelCase_     :       Tuple  		=					batch
               UpperCAmelCase_     :       Union[str, Any]  		=					[]
               yield list(map(lowerCamelCase_  ,zip(*lowerCamelCase_							)							)							)

       for i in range(1							):
           yield list(map(lowerCamelCase_  ,zip(*lowerCamelCase_							)							)							)






   def __call__(    self:     Any							)	->      Optional[Any]:
       # make writer
       if not TEST:
           UpperCAmelCase_     :       Tuple  		=					datasets.ArrowWriter(features=self.schema  ,path=self.outputfile							)
       # do file generator
       for i, (img_ids, filepaths) in enumerate(self.file_generator							):
           UpperCAmelCase_		, UpperCAmelCase_		, UpperCAmelCase_     :       str  		=					self.preprocess(lowerCamelCase_							)
           UpperCAmelCase_     :       Any  		=					self.model(
               lowerCamelCase_  ,lowerCamelCase_  ,scales_yx=lowerCamelCase_  ,padding="""max_detections"""  ,max_detections=self.config.MAX_DETECTIONS  ,pad_value=0  ,return_tensors="""np"""  ,location="""cpu"""  ,)
           UpperCAmelCase_     :       Dict  		=					output_dict.pop("""normalized_boxes"""							)
           if not TEST:
               UpperCAmelCase_     :       str  		=					np.array(lowerCamelCase_							)
               UpperCAmelCase_     :       int  		=					self.schema.encode_batch(lowerCamelCase_							)
               writer.write_batch(lowerCamelCase_							)
           if TEST:
               break
           # finalizer the writer
       if not TEST:
           UpperCAmelCase_		, UpperCAmelCase_     :       Dict  		=					writer.finalize()
           print(F'''Success! You wrote {num_examples} entry(s) and {num_bytes >> 20} mb'''							)







def       lowerCamelCase_  (    _a       :						int    ):



    '''simple docstring'''




    try:
        UpperCAmelCase_     :       Optional[int]  		=					json.load(_a    )
        try:
            UpperCAmelCase_     :       List[Any]  		=					list(data.keys()    )
        except Exception:
            UpperCAmelCase_     :       List[Any]  		=					[d["""img_id"""] for d in data]
    except Exception:
        try:
            UpperCAmelCase_     :       str  		=					eval(stream.read()    )
        except Exception:
            UpperCAmelCase_     :       List[Any]  		=					stream.read().split("""\n"""    )
    return data


if __name__ == "__main__":
      UpperCamelCase_									=   Extract(sys.argv[1:])
      extract()
      if not TEST:
            UpperCamelCase_									=   datasets.Dataset.from_file(extract.outputfile)
            # wala!
            # print(np.array(dataset[0:2]["roi_features"]).shape)
