





from __future__ import annotations

from collections import Counter


def 			lowerCamelCase_		(					lowerCAmelCase:		int )->						list[int]:
  _snake_case      : int														=		[True] * n
  _snake_case      : List[Any]														=		False
  _snake_case      : Optional[int]														=		False
  _snake_case      : Dict														=		True

  for i in range(3			,							int(n**0.5 + 1 )			,							2 ):
    _snake_case      : List[Any]														=		i * 2
    while index < n:
      _snake_case      : str														=		False
      _snake_case      : Optional[Any]														=		index + i

  _snake_case      : Union[str, Any]														=		[2]

  for i in range(3			,							lowerCAmelCase			,							2 ):
    if is_prime[i]:
      primes.append(lowerCAmelCase )

  return primes


def 			lowerCamelCase_		(					lowerCAmelCase:		int )->						list[list[int]]:
  _snake_case      : Optional[int]														=		str(lowerCAmelCase )
  _snake_case      : Dict														=		[]
  _snake_case      : List[str]														=		['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']

  for duplicate in Counter(lowerCAmelCase ) - Counter(set(lowerCAmelCase ) ):
    _snake_case      : int														=		[int(number_str.replace(lowerCAmelCase			,							lowerCAmelCase ) ) for digit in digits]
    replacements.append(lowerCAmelCase )

  return replacements


def 			lowerCamelCase_		(					lowerCAmelCase:		int = 8 )->						int:
  _snake_case      : List[Any]														=		set()

  # Filter primes with less than 3 replaceable digits
  _snake_case      : str														=		{
      x for x in set(prime_sieve(1_00_00_00 ) ) if len(str(lowerCAmelCase ) ) - len(set(str(lowerCAmelCase ) ) ) >= 3
  }

  for prime in primes:
    if prime in numbers_checked:
      continue

    _snake_case      : str														=		digit_replacements(lowerCAmelCase )

    for family in replacements:
      numbers_checked.update(lowerCAmelCase )
      _snake_case      : List[str]														=		primes.intersection(lowerCAmelCase )

      if len(lowerCAmelCase ) != family_length:
        continue

      return min(lowerCAmelCase )

  return -1


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






"""simple docstring"""

from typing import SupportsIndex

import numpy as np
from scipy.ndimage import convolve




def 			lowercase__  (    lowerCAmelCase :    np.ndarray       , lowerCAmelCase :    np.ndarray       , lowerCAmelCase :    np.ndarray       )       ->					np.ndarray:






    """simple docstring"""




    UpperCAmelCase  	=    np.stack((horizontal_flow, vertical_flow)       , 2       )

    # Create a grid of all pixel coordinates and subtract the flow to get the
    # target pixels coordinates
    UpperCAmelCase  	=    np.stack(
        np.meshgrid(np.arange(0       , image.shape[1]       )       , np.arange(0       , image.shape[0]       )       )       , 2       )
    UpperCAmelCase  	=    np.round(grid - flow       ).astype(np.intaa       )

    # Find the locations outside of the original image
    UpperCAmelCase  	=    (grid < 0) | (grid >= np.array([image.shape[1], image.shape[0]]       ))
    UpperCAmelCase  	=    0

    UpperCAmelCase  	=    image[grid[:, :, 1], grid[:, :, 0]]

    # Set pixels at invalid locations to 0
    UpperCAmelCase  	=    0

    return warped




def 			lowercase__  (    lowerCAmelCase :    np.ndarray       , lowerCAmelCase :    np.ndarray       , lowerCAmelCase :    SupportsIndex       , lowerCAmelCase :    float | None = None       , )       ->					tuple[np.ndarray, np.ndarray]:






    """simple docstring"""




    if alpha is None:
        UpperCAmelCase  	=    0.1

    # Initialize flow
    UpperCAmelCase  	=    np.zeros_like(lowerCAmelCase       )
    UpperCAmelCase  	=    np.zeros_like(lowerCAmelCase       )

    # Prepare kernels for the calculation of the derivatives and the average velocity
    UpperCAmelCase  	=    np.array([[-1, 1], [-1, 1]]       ) * 0.25
    UpperCAmelCase  	=    np.array([[-1, -1], [1, 1]]       ) * 0.25
    UpperCAmelCase  	=    np.array([[1, 1], [1, 1]]       ) * 0.25
    UpperCAmelCase  	=    np.array(
        [[1 / 12, 1 / 6, 1 / 12], [1 / 6, 0, 1 / 6], [1 / 12, 1 / 6, 1 / 12]]       )

    # Iteratively refine the flow
    for _ in range(lowerCAmelCase       ):
        UpperCAmelCase  	=    warp(lowerCAmelCase       , lowerCAmelCase       , lowerCAmelCase       )
        UpperCAmelCase  	=    convolve(lowerCAmelCase       , lowerCAmelCase       ) + convolve(lowerCAmelCase       , lowerCAmelCase       )
        UpperCAmelCase  	=    convolve(lowerCAmelCase       , lowerCAmelCase       ) + convolve(lowerCAmelCase       , lowerCAmelCase       )
        UpperCAmelCase  	=    convolve(lowerCAmelCase       , lowerCAmelCase       ) + convolve(lowerCAmelCase       , -kernel_t       )

        UpperCAmelCase  	=    convolve(lowerCAmelCase       , lowerCAmelCase       )
        UpperCAmelCase  	=    convolve(lowerCAmelCase       , lowerCAmelCase       )

        # This updates the flow as proposed in the paper (Step 12)
        UpperCAmelCase  	=    (
            derivative_x * avg_horizontal_velocity
            + derivative_y * avg_vertical_velocity
            + derivative_t
        )
        UpperCAmelCase  	=    update / (alpha**2 + derivative_x**2 + derivative_y**2)

        UpperCAmelCase  	=    avg_horizontal_velocity - derivative_x * update
        UpperCAmelCase  	=    avg_vertical_velocity - derivative_y * update

    return horizontal_flow, vertical_flow


if __name__ == "__main__":
   import doctest

   doctest.testmod()



