






"""simple docstring"""





UpperCamelCase			=      float("""inf""")







class 		_a       :





   '''simple docstring'''






   def __init__(   self			,				UpperCAmelCase_)	-> Optional[int]:




          '''simple docstring'''




          lowercase__:    Any        =      [0] * n
          lowercase__:    List[str]        =      [0] * n
          lowercase__:    Optional[int]        =      [0] * n
          lowercase__:    int        =      [[] for _ in range(UpperCAmelCase_)]





   def __lowercase    (   self			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_=0)	-> Tuple:




          '''simple docstring'''




          self.adj[a].append([b, len(self.adj[b]), c, 0])
          self.adj[b].append([a, len(self.adj[a]) - 1, rcap, 0])





   def __lowercase    (   self			,				UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_)	-> Optional[Any]:




          '''simple docstring'''




          if vertex == sink or not flow:
                 return flow

          for i in range(self.ptr[vertex]			,				len(self.adj[vertex])):
                 lowercase__:    Tuple        =      self.adj[vertex][i]
                 if self.lvl[e[0]] == self.lvl[vertex] + 1:
                        lowercase__:    Optional[Any]        =      self.depth_first_search(e[0]			,				UpperCAmelCase_			,				min(UpperCAmelCase_			,				e[2] - e[3]))
                        if p:
                               self.adj[vertex][i][3] += p
                               self.adj[e[0]][e[1]][3] -= p
                               return p
                 lowercase__:    int        =      self.ptr[vertex] + 1
          return 0





   def __lowercase    (   self			,				UpperCAmelCase_			,				UpperCAmelCase_)	-> List[Any]:




          '''simple docstring'''




          lowercase__  ,     lowercase__:    Optional[Any]        =      0, source
          for l in range(31):  # noqa: E741  l = 30 maybe faster for random data
                 while True:
                        lowercase__  ,     lowercase__:    int        =      [0] * len(self.q), [0] * len(self.q)
                        lowercase__  ,     lowercase__  ,     lowercase__:    Any        =      0, 1, 1
                        while qi < qe and not self.lvl[sink]:
                               lowercase__:    Optional[Any]        =      self.q[qi]
                               qi += 1
                               for e in self.adj[v]:
                                      if not self.lvl[e[0]] and (e[2] - e[3]) >> (30 - l):
                                             lowercase__:    str        =      e[0]
                                             qe += 1
                                             lowercase__:    List[Any]        =      self.lvl[v] + 1

                        lowercase__:    Dict        =      self.depth_first_search(UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_)
                        while p:
                               flow += p
                               lowercase__:    List[str]        =      self.depth_first_search(UpperCAmelCase_			,				UpperCAmelCase_			,				UpperCAmelCase_)

                        if not self.lvl[sink]:
                               break

          return flow
UpperCamelCase			=      Dinic(10)
UpperCamelCase			=      0
UpperCamelCase			=      9
for vertex in range(1, 5):
  graph.add_edge(source, vertex, 1)
for vertex in range(5, 9):
  graph.add_edge(vertex, sink, 1)
for vertex in range(1, 5):
  graph.add_edge(vertex, vertex + 4, 1)

# Now we can know that is the maximum flow(source -> sink)
print(graph.max_flow(source, sink))














"""simple docstring"""





UpperCamelCase			=      {
    """0""": 1,
    """1""": 1,
    """2""": 2,
    """3""": 6,
    """4""": 24,
    """5""": 1_20,
    """6""": 7_20,
    """7""": 50_40,
    """8""": 4_03_20,
    """9""": 36_28_80,
}

UpperCamelCase			=      {1_45: 1_45}

UpperCamelCase			=      {
    1_45: 0,
    1_69: 3,
    3_63_01: 3,
    14_54: 3,
    8_71: 2,
    4_53_61: 2,
    8_72: 2,
}






def     A(  snake_case_		):
       """simple docstring"""





       if n in CACHE_SUM_DIGIT_FACTORIALS:
              return CACHE_SUM_DIGIT_FACTORIALS[n]
       lowercase__:    Any        =      sum(DIGIT_FACTORIALS[let] for let in str(snake_case_		)		)
       lowercase__:    Optional[Any]        =      ret
       return ret






def     A(  snake_case_						,       snake_case_ = None		):
       """simple docstring"""





       lowercase__:    Optional[int]        =      previous or set()
       if n in CHAIN_LENGTH_CACHE:
              return CHAIN_LENGTH_CACHE[n]
       lowercase__:    Tuple        =      sum_digit_factorials(snake_case_		)
       if next_number in previous:
              lowercase__:    List[Any]        =      0
              return 0
       else:
              previous.add(snake_case_		)
              lowercase__:    Optional[int]        =      1 + chain_length(snake_case_						,       snake_case_		)
              lowercase__:    Any        =      ret
              return ret






def     A(  snake_case_ = 60						,       snake_case_ = 1000000		):
       """simple docstring"""





       return sum(1 for i in range(1						,       snake_case_		) if chain_length(snake_case_		) == num_terms		)


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






