





import os
from typing import Any, Callable, Dict, List, Optional, Tuple, Union

import torch
from torch import nn

from ...models.controlnet import ControlNetModel, ControlNetOutput
from ...models.modeling_utils import ModelMixin
from ...utils import logging


SCREAMING_SNAKE_CASE_						       =   logging.get_logger(__name__)

class 		UpperCamelCase__			(				_SCREAMING_SNAKE_CASE       ):



     '''simple docstring'''

     def __init__(							self						:   Any						,lowerCamelCase__						:   Union[List[ControlNetModel], Tuple[ControlNetModel]]	)					->		Tuple:




           '''simple docstring'''


           super().__init__()
           SCREAMING_SNAKE_CASE		=						nn.ModuleList(lowerCamelCase__	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Dict						,lowerCamelCase__						:   torch.FloatTensor						,lowerCamelCase__						:   Union[torch.Tensor, float, int]						,lowerCamelCase__						:   torch.Tensor						,lowerCamelCase__						:   List[torch.tensor]						,lowerCamelCase__						:   List[float]						,lowerCamelCase__						:   Optional[torch.Tensor] = None						,lowerCamelCase__						:   Optional[torch.Tensor] = None						,lowerCamelCase__						:   Optional[torch.Tensor] = None						,lowerCamelCase__						:   Optional[Dict[str, Any]] = None						,lowerCamelCase__						:   bool = False						,lowerCamelCase__						:   bool = True						,)					->		Union[ControlNetOutput, Tuple]:




           '''simple docstring'''


           for i, (image, scale, controlnet) in enumerate(zip(lowerCamelCase__						,lowerCamelCase__						,self.nets	)	):
                 SCREAMING_SNAKE_CASE		=						controlnet(
                     lowerCamelCase__						,lowerCamelCase__						,lowerCamelCase__						,lowerCamelCase__						,lowerCamelCase__						,lowerCamelCase__						,lowerCamelCase__						,lowerCamelCase__						,lowerCamelCase__						,lowerCamelCase__						,lowerCamelCase__						,)

                 # merge samples
                 if i == 0:
                       SCREAMING_SNAKE_CASE		=						down_samples, mid_sample
                 else:
                       SCREAMING_SNAKE_CASE		=						[
                           samples_prev + samples_curr
                           for samples_prev, samples_curr in zip(lowerCamelCase__						,lowerCamelCase__	)
                       ]
                       mid_block_res_sample += mid_sample

           return down_block_res_samples, mid_block_res_sample






     def     SCREAMING_SNAKE_CASE__  (							self						:   Optional[Any]						,lowerCamelCase__						:   Union[str, os.PathLike]						,lowerCamelCase__						:   bool = True						,lowerCamelCase__						:   Callable = None						,lowerCamelCase__						:   bool = False						,lowerCamelCase__						:   Optional[str] = None						,)					->		List[str]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						0
           SCREAMING_SNAKE_CASE		=						save_directory
           for controlnet in self.nets:
                 controlnet.save_pretrained(
                     lowerCamelCase__						,is_main_process=lowerCamelCase__						,save_function=lowerCamelCase__						,safe_serialization=lowerCamelCase__						,variant=lowerCamelCase__						,)

                 idx += 1
                 SCREAMING_SNAKE_CASE		=						model_path_to_save + F"""_{idx}"""






     @classmethod
     def     SCREAMING_SNAKE_CASE__  (							cls						:   List[str]						,lowerCamelCase__						:   Optional[Union[str, os.PathLike]]						,**lowerCamelCase__						:   str	)					->		Any:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						0
           SCREAMING_SNAKE_CASE		=						[]

           # load controlnet and append to list until no controlnet directory exists anymore
           # first controlnet has to be saved under `./mydirectory/controlnet` to be compliant with `DiffusionPipeline.from_prertained`
           # second, third, ... controlnets have to be saved under `./mydirectory/controlnet_1`, `./mydirectory/controlnet_2`, ...
           SCREAMING_SNAKE_CASE		=						pretrained_model_path
           while os.path.isdir(lowerCamelCase__	):
                 SCREAMING_SNAKE_CASE		=						ControlNetModel.from_pretrained(lowerCamelCase__						,**lowerCamelCase__	)
                 controlnets.append(lowerCamelCase__	)

                 idx += 1
                 SCREAMING_SNAKE_CASE		=						pretrained_model_path + F"""_{idx}"""

           logger.info(F"""{len(lowerCamelCase__	)} controlnets loaded from {pretrained_model_path}."""	)

           if len(lowerCamelCase__	) == 0:
                 raise ValueError(
                     F"""No ControlNets found under {os.path.dirname(lowerCamelCase__	)}. Expected at least {pretrained_model_path + '_0'}."""	)

           return cls(lowerCamelCase__	)









from itertools import permutations



def        __lowercase       (				_SCREAMING_SNAKE_CASE     )			->       bool:


      '''simple docstring'''


      if num[3] % 2 != 0:
            return False

      if (num[2] + num[3] + num[4]) % 3 != 0:
            return False

      if num[5] % 5 != 0:
            return False

      SCREAMING_SNAKE_CASE		=						[7, 11, 13, 17]
      for i, test in enumerate(_SCREAMING_SNAKE_CASE     ):
            if (num[i + 4] * 1_00 + num[i + 5] * 10 + num[i + 6]) % test != 0:
                  return False
      return True



def        __lowercase       (				_SCREAMING_SNAKE_CASE = 10     )			->       int:


      '''simple docstring'''


      return sum(
          int("""""".join(map(_SCREAMING_SNAKE_CASE			,						_SCREAMING_SNAKE_CASE     )     )     )
          for num in permutations(range(_SCREAMING_SNAKE_CASE     )     )
          if is_substring_divisible(_SCREAMING_SNAKE_CASE     )     )


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


