

from typing import Any

import numpy as np


class     lowerCamelCase_   :




	def __init__( self     ,     _UpperCAmelCase     ,     _UpperCAmelCase       ):







			if np.any(tableau[:, -1]     ,     where=tableau[:, -1] < 0       ):
					raise ValueError('RHS must be > 0'       )

			__UpperCAmelCase  :     List[str]		=    tableau
			__UpperCAmelCase  :     Any		=    tableau.shape

			# Number of decision variables x1, x2, x3...
			__UpperCAmelCase  :     List[str]		=    n_vars

			# Number of artificial variables to be minimised
			__UpperCAmelCase  :     Optional[Any]		=    len(np.where(tableau[self.n_vars : -1] == -1       )[0]       )

			# 2 if there are >= or == constraints (nonstandard), 1 otherwise (std)
			__UpperCAmelCase  :     str		=    (self.n_art_vars > 0) + 1

			# Number of slack variables added to make inequalities into equalities
			__UpperCAmelCase  :     Union[str, Any]		=    self.n_rows - self.n_stages

			# Objectives for each stage
			__UpperCAmelCase  :     int		=    ['''max''']

			# In two stage simplex, first minimise then maximise
			if self.n_art_vars:
					self.objectives.append('min'       )

			__UpperCAmelCase  :     str		=    ['''''']

			# Index of current pivot row and column
			__UpperCAmelCase  :     Dict		=    None
			__UpperCAmelCase  :     int		=    None

			# Does objective row only contain (non)-negative values?
			__UpperCAmelCase  :     Optional[int]		=    False




	@staticmethod
	def 						a					( *_UpperCAmelCase       ):







			if len(UpperCamelCase__       ) != 3:
					raise ValueError('Must provide n_vars, n_slack, and n_art_vars'       )

			if not all(x >= 0 and isinstance(UpperCamelCase__     ,     UpperCamelCase__       ) for x in args       ):
					raise ValueError('All arguments must be non-negative integers'       )

			# decision | slack | artificial
			__UpperCAmelCase  :     Tuple		=    ['''x''', '''s''', '''a''']
			__UpperCAmelCase  :     Optional[Any]		=    []
			for i in range(3       ):
					for j in range(args[i]       ):
							titles.append(string_starts[i] + str(j + 1       )       )
			titles.append('RHS'       )
			return titles




	def 						a					( self     ,     _UpperCAmelCase       ):
			__UpperCAmelCase  :     Union[str, Any]		=    self.objectives[-1]

			# Find entries of highest magnitude in objective rows
			__UpperCAmelCase  :     Tuple		=    (objective == '''min''') - (objective == '''max''')
			__UpperCAmelCase  :     Union[str, Any]		=    np.argmax(sign * tableau[0, : self.n_vars]       )

			# Choice is only valid if below 0 for maximise, and above for minimise
			if sign * self.tableau[0, col_idx] <= 0:
					__UpperCAmelCase  :     Tuple		=    True
					return 0, 0

			# Pivot row is chosen as having the lowest quotient when elements of
			# the pivot column divide the right-hand side

			# Slice excluding the objective rows
			__UpperCAmelCase  :     int		=    slice(self.n_stages     ,     self.n_rows       )

			# RHS
			__UpperCAmelCase  :     Optional[int]		=    tableau[s, -1]

			# Elements of pivot column within slice
			__UpperCAmelCase  :     Dict		=    tableau[s, col_idx]

			# Array filled with nans
			__UpperCAmelCase  :     Any		=    np.full(self.n_rows - self.n_stages     ,     np.nan       )

			# If element in pivot column is greater than zeron_stages, return
			# quotient or nan otherwise
			__UpperCAmelCase  :     Optional[int]		=    np.divide(UpperCamelCase__     ,     UpperCamelCase__     ,     out=UpperCamelCase__     ,     where=divisor > 0       )

			# Arg of minimum quotient excluding the nan values. n_stages is added
			# to compensate for earlier exclusion of objective columns
			__UpperCAmelCase  :     List[str]		=    np.nanargmin(UpperCamelCase__       ) + self.n_stages
			return row_idx, col_idx




	def 						a					( self     ,     _UpperCAmelCase     ,     _UpperCAmelCase     ,     _UpperCAmelCase       ):
			__UpperCAmelCase  :     List[str]		=    tableau[row_idx].copy()

			__UpperCAmelCase  :     Optional[Any]		=    piv_row[col_idx]

			# Entry becomes 1
			piv_row *= 1 / piv_val

			# Variable in pivot column becomes basic, ie the only non-zero entry
			for idx, coeff in enumerate(tableau[:, col_idx]       ):
					tableau[idx] += -coeff * piv_row
			__UpperCAmelCase  :     Tuple		=    piv_row
			return tableau




	def 						a					( self     ,     _UpperCAmelCase       ):
			self.objectives.pop()

			if not self.objectives:
					return tableau

			# Slice containing ids for artificial columns
			__UpperCAmelCase  :     Any		=    slice(-self.n_art_vars - 1     ,     -1       )

			# Delete the artificial variable columns
			__UpperCAmelCase  :     Union[str, Any]		=    np.delete(UpperCamelCase__     ,     UpperCamelCase__     ,     axis=1       )

			# Delete the objective row of the first stage
			__UpperCAmelCase  :     Union[str, Any]		=    np.delete(UpperCamelCase__     ,     0     ,     axis=0       )

			__UpperCAmelCase  :     str		=    1
			self.n_rows -= 1
			__UpperCAmelCase  :     str		=    0
			__UpperCAmelCase  :     int		=    False
			return tableau




	def 						a					( self       ):







			for _ in range(100       ):
					# Completion of each stage removes an objective. If both stages
					# are complete, then no objectives are left
					if not self.objectives:
							__UpperCAmelCase  :     Optional[Any]		=    self.generate_col_titles(
							    self.n_vars     ,     self.n_slack     ,     self.n_art_vars       )

							# Find the values of each variable at optimal solution
							return self.interpret_tableau(self.tableau     ,     self.col_titles       )

					__UpperCAmelCase  :     int		=    self.find_pivot(self.tableau       )

					# If there are no more negative values in objective row
					if self.stop_iter:
							# Delete artificial variable columns and rows. Update attributes
							__UpperCAmelCase  :     Optional[int]		=    self.change_stage(self.tableau       )
					else:
							__UpperCAmelCase  :     List[str]		=    self.pivot(self.tableau     ,     UpperCamelCase__     ,     UpperCamelCase__       )
			return {}




	def 						a					( self     ,     _UpperCAmelCase     ,     _UpperCAmelCase       ):
			__UpperCAmelCase  :     List[Any]		=    {'''P''': abs(tableau[0, -1]       )}

			for i in range(self.n_vars       ):
					# Gives ids of nonzero entries in the ith column
					__UpperCAmelCase  :     Dict		=    np.nonzero(tableau[:, i]       )
					__UpperCAmelCase  :     int		=    len(nonzero[0]       )

					# First entry in the nonzero ids
					__UpperCAmelCase  :     Any		=    nonzero[0][0]
					__UpperCAmelCase  :     Union[str, Any]		=    tableau[nonzero_rowidx, i]

					# If there is only one nonzero value in column, which is one
					if n_nonzero == nonzero_val == 1:
							__UpperCAmelCase  :     Dict		=    tableau[nonzero_rowidx, -1]
							__UpperCAmelCase  :     str		=    rhs_val

        # Check for basic variables
			for title in col_titles:
					# Don't add RHS or slack variables to output dict
					if title[0] not in "R-s-a":
							output_dict.setdefault(UpperCamelCase__     ,     0       )
			return output_dict


if __name__ == "__main__":
						import doctest

						doctest.testmod()








import math
from itertools import permutations





def    _snake_case		(snake_case_				:    int     )       ->		bool:

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





def    _snake_case		(snake_case_				:    int						,					snake_case_				:    list     )       ->		bool:
  __UpperCAmelCase, __UpperCAmelCase  :     Any		=    0, len(snake_case_     ) - 1
  while left <= right:
    __UpperCAmelCase  :     List[str]		=    (left + right) // 2
    if prime_list[middle] == target:
      return True
    elif prime_list[middle] < target:
      __UpperCAmelCase  :     Tuple		=    middle + 1
    else:
      __UpperCAmelCase  :     Tuple		=    middle - 1

  return False





def    _snake_case		()       ->		str:
  __UpperCAmelCase  :     List[Any]		=    [n for n in range(1001						,					1_0000						,					2     ) if is_prime(snake_case_     )]
  __UpperCAmelCase  :     Tuple		=    []

  for number in prime_list:
    __UpperCAmelCase  :     List[str]		=    []

    for prime_member in permutations(list(str(snake_case_     )     )     ):
      __UpperCAmelCase  :     Dict		=    int(''.join(snake_case_     )     )

      if prime % 2 == 0:
        continue

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

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

  __UpperCAmelCase  :     Optional[int]		=    []
  for candidate in candidates:
    __UpperCAmelCase  :     int		=    len(snake_case_     )
    __UpperCAmelCase  :     List[Any]		=    False

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

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

  __UpperCAmelCase  :     Dict		=    set()
  for seq in passed:
    answer.add(''.join([str(snake_case_     ) for i in seq]     )     )

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


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





