
'''simple docstring'''



from __future__ import annotations

from collections import deque
from collections.abc import Iterator
from dataclasses import dataclass




@dataclass
class     UpperCAmelCase_	:






						'''simple docstring'''






						_lowercase						: int
						_lowercase						: int






class     UpperCAmelCase_	:






						'''simple docstring'''






						def __init__(   self       ,  _lowercase ):

												"""simple docstring"""



												_lowerCAmelCase    		=					[[] for _ in range(_lowercase )]
												_lowerCAmelCase    		=					size




						def __getitem__(   self       ,  _lowercase ):

												"""simple docstring"""



												return iter(self._graph[vertex] )




						@property
						def    _lowercase      (   self ):

												"""simple docstring"""



												return self._size




						def    _lowercase      (   self       ,  _lowercase       ,  _lowercase       ,  _lowercase ):

												"""simple docstring"""



												if weight not in (0, 1):
																		raise ValueError("""Edge weight must be either 0 or 1.""" )

												if to_vertex < 0 or to_vertex >= self.size:
																		raise ValueError("""Vertex indexes must be in [0; size).""" )

												self._graph[from_vertex].append(Edge(_lowercase       ,  _lowercase ) )




						def    _lowercase      (   self       ,  _lowercase       ,  _lowercase ):

												"""simple docstring"""



												_lowerCAmelCase    		=					deque([start_vertex] )
												_lowerCAmelCase    		=					[None] * self.size
												_lowerCAmelCase    		=					0

												while queue:
																		_lowerCAmelCase    		=					queue.popleft()
																		_lowerCAmelCase    		=					distances[current_vertex]
																		if current_distance is None:
																								continue

																		for edge in self[current_vertex]:
																								_lowerCAmelCase    		=					current_distance + edge.weight
																								_lowerCAmelCase    		=					distances[edge.destination_vertex]
																								if (
																								    isinstance(_lowercase       ,  _lowercase )
																								    and new_distance >= dest_vertex_distance
																								):
																														continue
																								_lowerCAmelCase    		=					new_distance
																								if edge.weight == 0:
																														queue.appendleft(edge.destination_vertex )
																								else:
																														queue.append(edge.destination_vertex )

												if distances[finish_vertex] is None:
																		raise ValueError("""No path from start_vertex to finish_vertex.""" )

												return distances[finish_vertex]


if __name__ == "__main__":
						import doctest

						doctest.testmod()


'''simple docstring'''



import functools


def A (__lowerCamelCase :list[int]					,      __lowerCamelCase :list[int]						):

						# Validation
						if not isinstance(__lowerCamelCase					,      __lowerCamelCase						) or not all(isinstance(__lowerCamelCase					,      __lowerCamelCase						) for day in days						):
												raise ValueError("""The parameter days should be a list of integers"""						)

						if len(__lowerCamelCase						) != 3 or not all(isinstance(__lowerCamelCase					,      __lowerCamelCase						) for cost in costs						):
												raise ValueError("""The parameter costs should be a list of three integers"""						)

						if len(__lowerCamelCase						) == 0:
												return 0

						if min(__lowerCamelCase						) <= 0:
												raise ValueError("""All days elements should be greater than 0"""						)

						if max(__lowerCamelCase						) >= 366:
												raise ValueError("""All days elements should be less than 366"""						)

						_lowerCAmelCase    		=					set(__lowerCamelCase						)

						@functools.cache
						def dynamic_programming(__lowerCamelCase :int						) -> int:
												if index > 365:
																		return 0

												if index not in days_set:
																		return dynamic_programming(index + 1						)

												return min(
												    costs[0] + dynamic_programming(index + 1						)					,      costs[1] + dynamic_programming(index + 7						)					,      costs[2] + dynamic_programming(index + 30						)					,      )

						return dynamic_programming(1						)


if __name__ == "__main__":
						import doctest

						doctest.testmod()
