



'''simple docstring'''




from collections import deque
from math import floor
from random import random
from time import time







class      _lowerCAmelCase							:


	def __init__(self							):
				A_     :						Dict     =					{}


	def    _a     (self	,				lowercase	,				lowercase	,				lowercase=1							):
				if self.graph.get(lowercase							):
							if self.graph[u].count([w, v]							) == 0:
										self.graph[u].append([w, v]							)
				else:
							A_     :						Dict     =					[[w, v]]
				if not self.graph.get(lowercase							):
							A_     :						Optional[int]     =					[]


	def    _a     (self							):
				return list(self.graph							)


	def    _a     (self	,				lowercase	,				lowercase							):
				if self.graph.get(lowercase							):
							for _ in self.graph[u]:
										if _[1] == v:
													self.graph[u].remove(lowercase							)


	def    _a     (self	,				lowercase=-2	,				lowercase=-1							):
				if s == d:
							return []
				A_     :						Union[str, Any]     =					[]
				A_     :						Dict     =					[]
				if s == -2:
							A_     :						Optional[int]     =					list(self.graph							)[0]
				stack.append(lowercase							)
				visited.append(lowercase							)
				A_     :						str     =					s

				while True:
							# check if there is any non isolated nodes
							if len(self.graph[s]							) != 0:
										A_     :						int     =					s
										for node in self.graph[s]:
													if visited.count(node[1]							) < 1:
																if node[1] == d:
																			visited.append(lowercase							)
																			return visited
																else:
																			stack.append(node[1]							)
																			visited.append(node[1]							)
																			A_     :						str     =					node[1]
																			break

            # check if all the children are visited
							if s == ss:
										stack.pop()
										if len(lowercase							) != 0:
													A_     :						str     =					stack[len(lowercase							) - 1]
							else:
										A_     :						Union[str, Any]     =					ss

							# check if se have reached the starting point
							if len(lowercase							) == 0:
										return visited


	def    _a     (self	,				lowercase=-1							):
				if c == -1:
							A_     :						Tuple     =					floor(random() * 10000							) + 10
				for i in range(lowercase							):
							# every vertex has max 100 edges
							for _ in range(floor(random() * 102							) + 1							):
										A_     :						Optional[int]     =					floor(random() * c							) + 1
										if n != i:
													self.add_pair(lowercase	,				lowercase	,				1							)


	def    _a     (self	,				lowercase=-2							):
				A_     :						str     =					deque()
				A_     :						Any     =					[]
				if s == -2:
							A_     :						List[str]     =					list(self.graph							)[0]
				d.append(lowercase							)
				visited.append(lowercase							)
				while d:
							A_     :						int     =					d.popleft()
							if len(self.graph[s]							) != 0:
										for node in self.graph[s]:
													if visited.count(node[1]							) < 1:
																d.append(node[1]							)
																visited.append(node[1]							)
				return visited


	def    _a     (self	,				lowercase							):
				A_     :						Any     =					0
				for x in self.graph:
							for y in self.graph[x]:
										if y[1] == u:
													count += 1
				return count


	def    _a     (self	,				lowercase							):
				return len(self.graph[u]							)


	def    _a     (self	,				lowercase=-2							):
				A_     :						Optional[int]     =					[]
				A_     :						Dict     =					[]
				if s == -2:
							A_     :						Optional[Any]     =					list(self.graph							)[0]
				stack.append(lowercase							)
				visited.append(lowercase							)
				A_     :						Union[str, Any]     =					s
				A_     :						Any     =					[]

				while True:
							# check if there is any non isolated nodes
							if len(self.graph[s]							) != 0:
										A_     :						Optional[int]     =					s
										for node in self.graph[s]:
													if visited.count(node[1]							) < 1:
																stack.append(node[1]							)
																visited.append(node[1]							)
																A_     :						Tuple     =					node[1]
																break

            # check if all the children are visited
							if s == ss:
										sorted_nodes.append(stack.pop()							)
										if len(lowercase							) != 0:
													A_     :						List[str]     =					stack[len(lowercase							) - 1]
							else:
										A_     :						List[str]     =					ss

							# check if se have reached the starting point
							if len(lowercase							) == 0:
										return sorted_nodes


	def    _a     (self							):
				A_     :						Any     =					[]
				A_     :						List[Any]     =					[]
				A_     :						str     =					list(self.graph							)[0]
				stack.append(lowercase							)
				visited.append(lowercase							)
				A_     :						Optional[Any]     =					-2
				A_     :						int     =					[]
				A_     :						Optional[Any]     =					s
				A_     :						Any     =					False
				A_     :						Dict     =					set()

				while True:
							# check if there is any non isolated nodes
							if len(self.graph[s]							) != 0:
										A_     :						List[Any]     =					s
										for node in self.graph[s]:
													if (
													    visited.count(node[1]							) > 0
													    and node[1] != parent
													    and indirect_parents.count(node[1]							) > 0
													    and not on_the_way_back
													):
																A_     :						List[str]     =					len(lowercase							) - 1
																while len_stack >= 0:
																			if stack[len_stack] == node[1]:
																						anticipating_nodes.add(node[1]							)
																						break
																			else:
																						anticipating_nodes.add(stack[len_stack]							)
																						len_stack -= 1
													if visited.count(node[1]							) < 1:
																stack.append(node[1]							)
																visited.append(node[1]							)
																A_     :						List[str]     =					node[1]
																break

            # check if all the children are visited
							if s == ss:
										stack.pop()
										A_     :						Union[str, Any]     =					True
										if len(lowercase							) != 0:
													A_     :						Dict     =					stack[len(lowercase							) - 1]
							else:
										A_     :						List[str]     =					False
										indirect_parents.append(lowercase							)
										A_     :						Optional[int]     =					s
										A_     :						str     =					ss

							# check if se have reached the starting point
							if len(lowercase							) == 0:
										return list(lowercase							)


	def    _a     (self							):
				A_     :						str     =					[]
				A_     :						int     =					[]
				A_     :						int     =					list(self.graph							)[0]
				stack.append(lowercase							)
				visited.append(lowercase							)
				A_     :						Optional[Any]     =					-2
				A_     :						int     =					[]
				A_     :						Any     =					s
				A_     :						List[Any]     =					False
				A_     :						List[str]     =					set()

				while True:
							# check if there is any non isolated nodes
							if len(self.graph[s]							) != 0:
										A_     :						Any     =					s
										for node in self.graph[s]:
													if (
													    visited.count(node[1]							) > 0
													    and node[1] != parent
													    and indirect_parents.count(node[1]							) > 0
													    and not on_the_way_back
													):
																A_     :						int     =					len(lowercase							) - 1
																while len_stack_minus_one >= 0:
																			if stack[len_stack_minus_one] == node[1]:
																						anticipating_nodes.add(node[1]							)
																						break
																			else:
																						return True
													if visited.count(node[1]							) < 1:
																stack.append(node[1]							)
																visited.append(node[1]							)
																A_     :						int     =					node[1]
																break

            # check if all the children are visited
							if s == ss:
										stack.pop()
										A_     :						str     =					True
										if len(lowercase							) != 0:
													A_     :						Optional[int]     =					stack[len(lowercase							) - 1]
							else:
										A_     :						int     =					False
										indirect_parents.append(lowercase							)
										A_     :						List[Any]     =					s
										A_     :						Dict     =					ss

							# check if se have reached the starting point
							if len(lowercase							) == 0:
										return False


	def    _a     (self	,				lowercase=-2	,				lowercase=-1							):
				A_     :						List[Any]     =					time()
				self.dfs(lowercase	,				lowercase							)
				A_     :						Optional[int]     =					time()
				return end - begin


	def    _a     (self	,				lowercase=-2							):
				A_     :						Union[str, Any]     =					time()
				self.bfs(lowercase							)
				A_     :						Optional[int]     =					time()
				return end - begin







class      _lowerCAmelCase							:


	def __init__(self							):
				A_     :						List[str]     =					{}


	def    _a     (self	,				lowercase	,				lowercase	,				lowercase=1							):
				# check if the u exists
				if self.graph.get(lowercase							):
							# if there already is a edge
							if self.graph[u].count([w, v]							) == 0:
										self.graph[u].append([w, v]							)
				else:
							# if u does not exist
							A_     :						Union[str, Any]     =					[[w, v]]
				# add the other way
				if self.graph.get(lowercase							):
							# if there already is a edge
							if self.graph[v].count([w, u]							) == 0:
										self.graph[v].append([w, u]							)
				else:
							# if u does not exist
							A_     :						Tuple     =					[[w, u]]


	def    _a     (self	,				lowercase	,				lowercase							):
				if self.graph.get(lowercase							):
							for _ in self.graph[u]:
										if _[1] == v:
													self.graph[u].remove(lowercase							)
        # the other way round
				if self.graph.get(lowercase							):
							for _ in self.graph[v]:
										if _[1] == u:
													self.graph[v].remove(lowercase							)


	def    _a     (self	,				lowercase=-2	,				lowercase=-1							):
				if s == d:
							return []
				A_     :						Optional[Any]     =					[]
				A_     :						Union[str, Any]     =					[]
				if s == -2:
							A_     :						Optional[int]     =					list(self.graph							)[0]
				stack.append(lowercase							)
				visited.append(lowercase							)
				A_     :						Tuple     =					s

				while True:
							# check if there is any non isolated nodes
							if len(self.graph[s]							) != 0:
										A_     :						int     =					s
										for node in self.graph[s]:
													if visited.count(node[1]							) < 1:
																if node[1] == d:
																			visited.append(lowercase							)
																			return visited
																else:
																			stack.append(node[1]							)
																			visited.append(node[1]							)
																			A_     :						Optional[Any]     =					node[1]
																			break

            # check if all the children are visited
							if s == ss:
										stack.pop()
										if len(lowercase							) != 0:
													A_     :						int     =					stack[len(lowercase							) - 1]
							else:
										A_     :						int     =					ss

							# check if se have reached the starting point
							if len(lowercase							) == 0:
										return visited


	def    _a     (self	,				lowercase=-1							):
				if c == -1:
							A_     :						str     =					floor(random() * 10000							) + 10
				for i in range(lowercase							):
							# every vertex has max 100 edges
							for _ in range(floor(random() * 102							) + 1							):
										A_     :						int     =					floor(random() * c							) + 1
										if n != i:
													self.add_pair(lowercase	,				lowercase	,				1							)


	def    _a     (self	,				lowercase=-2							):
				A_     :						Dict     =					deque()
				A_     :						str     =					[]
				if s == -2:
							A_     :						List[Any]     =					list(self.graph							)[0]
				d.append(lowercase							)
				visited.append(lowercase							)
				while d:
							A_     :						Optional[int]     =					d.popleft()
							if len(self.graph[s]							) != 0:
										for node in self.graph[s]:
													if visited.count(node[1]							) < 1:
																d.append(node[1]							)
																visited.append(node[1]							)
				return visited


	def    _a     (self	,				lowercase							):
				return len(self.graph[u]							)


	def    _a     (self							):
				A_     :						List[Any]     =					[]
				A_     :						List[str]     =					[]
				A_     :						Tuple     =					list(self.graph							)[0]
				stack.append(lowercase							)
				visited.append(lowercase							)
				A_     :						Optional[int]     =					-2
				A_     :						Tuple     =					[]
				A_     :						Union[str, Any]     =					s
				A_     :						Any     =					False
				A_     :						str     =					set()

				while True:
							# check if there is any non isolated nodes
							if len(self.graph[s]							) != 0:
										A_     :						Tuple     =					s
										for node in self.graph[s]:
													if (
													    visited.count(node[1]							) > 0
													    and node[1] != parent
													    and indirect_parents.count(node[1]							) > 0
													    and not on_the_way_back
													):
																A_     :						Optional[Any]     =					len(lowercase							) - 1
																while len_stack >= 0:
																			if stack[len_stack] == node[1]:
																						anticipating_nodes.add(node[1]							)
																						break
																			else:
																						anticipating_nodes.add(stack[len_stack]							)
																						len_stack -= 1
													if visited.count(node[1]							) < 1:
																stack.append(node[1]							)
																visited.append(node[1]							)
																A_     :						Dict     =					node[1]
																break

            # check if all the children are visited
							if s == ss:
										stack.pop()
										A_     :						Tuple     =					True
										if len(lowercase							) != 0:
													A_     :						List[str]     =					stack[len(lowercase							) - 1]
							else:
										A_     :						Optional[Any]     =					False
										indirect_parents.append(lowercase							)
										A_     :						Any     =					s
										A_     :						Any     =					ss

							# check if se have reached the starting point
							if len(lowercase							) == 0:
										return list(lowercase							)


	def    _a     (self							):
				A_     :						str     =					[]
				A_     :						str     =					[]
				A_     :						Union[str, Any]     =					list(self.graph							)[0]
				stack.append(lowercase							)
				visited.append(lowercase							)
				A_     :						Tuple     =					-2
				A_     :						Optional[int]     =					[]
				A_     :						Union[str, Any]     =					s
				A_     :						int     =					False
				A_     :						Dict     =					set()

				while True:
							# check if there is any non isolated nodes
							if len(self.graph[s]							) != 0:
										A_     :						str     =					s
										for node in self.graph[s]:
													if (
													    visited.count(node[1]							) > 0
													    and node[1] != parent
													    and indirect_parents.count(node[1]							) > 0
													    and not on_the_way_back
													):
																A_     :						Dict     =					len(lowercase							) - 1
																while len_stack_minus_one >= 0:
																			if stack[len_stack_minus_one] == node[1]:
																						anticipating_nodes.add(node[1]							)
																						break
																			else:
																						return True
													if visited.count(node[1]							) < 1:
																stack.append(node[1]							)
																visited.append(node[1]							)
																A_     :						Union[str, Any]     =					node[1]
																break

            # check if all the children are visited
							if s == ss:
										stack.pop()
										A_     :						Any     =					True
										if len(lowercase							) != 0:
													A_     :						Any     =					stack[len(lowercase							) - 1]
							else:
										A_     :						Optional[int]     =					False
										indirect_parents.append(lowercase							)
										A_     :						List[str]     =					s
										A_     :						Optional[Any]     =					ss

							# check if se have reached the starting point
							if len(lowercase							) == 0:
										return False


	def    _a     (self							):
				return list(self.graph							)


	def    _a     (self	,				lowercase=-2	,				lowercase=-1							):
				A_     :						Optional[Any]     =					time()
				self.dfs(lowercase	,				lowercase							)
				A_     :						Dict     =					time()
				return end - begin


	def    _a     (self	,				lowercase=-2							):
				A_     :						List[str]     =					time()
				self.bfs(lowercase							)
				A_     :						List[Any]     =					time()
				return end - begin








'''simple docstring'''




from __future__ import annotations

from collections.abc import Callable

lowerCamelCase							:List[Any]       = list[list[float | int]]



def      a      (			lowerCamelCase__						,				lowerCamelCase__   ):
			'''simple docstring'''





			A_     :						int     =					len(lowerCamelCase__   )
			A_     :						Matrix     =					[[0 for _ in range(size + 1   )] for _ in range(lowerCamelCase__   )]
			A_     :						int
			A_     :						int
			A_     :						int
			A_     :						int
			A_     :						int
			A_     :						float

			for row in range(lowerCamelCase__   ):
						for col in range(lowerCamelCase__   ):
									A_     :						List[str]     =					matrix[row][col]

						A_     :						Optional[int]     =					vector[row][0]

			A_     :						Tuple     =					0
			A_     :						Tuple     =					0
			while row < size and col < size:
						# pivoting
						A_     :						Dict     =					max((abs(augmented[rowa][col]   ), rowa) for rowa in range(lowerCamelCase__						,				lowerCamelCase__   )   )[
						    1
						]
						if augmented[pivot_row][col] == 0:
									col += 1
									continue
						else:
									A_,   A_     :						Optional[Any]     =					augmented[pivot_row], augmented[row]

						for rowa in range(row + 1						,				lowerCamelCase__   ):
									A_     :						int     =					augmented[rowa][col] / augmented[row][col]
									A_     :						Union[str, Any]     =					0
									for cola in range(col + 1						,				size + 1   ):
												augmented[rowa][cola] -= augmented[row][cola] * ratio

						row += 1
						col += 1

			# back substitution
			for col in range(1						,				lowerCamelCase__   ):
						for row in range(lowerCamelCase__   ):
									A_     :						Tuple     =					augmented[row][col] / augmented[col][col]
									for cola in range(lowerCamelCase__						,				size + 1   ):
												augmented[row][cola] -= augmented[col][cola] * ratio

    # round to get rid of numbers like 2.000000000000004
			return [
			    [round(augmented[row][size] / augmented[row][row]						,				10   )] for row in range(lowerCamelCase__   )
			]



def      a      (			lowerCamelCase__   ):
			'''simple docstring'''





			A_     :						int     =					len(lowerCamelCase__   )
			A_     :						Matrix     =					[[0 for _ in range(lowerCamelCase__   )] for _ in range(lowerCamelCase__   )]
			A_     :						Matrix     =					[[0] for _ in range(lowerCamelCase__   )]
			A_     :						Matrix
			A_     :						int
			A_     :						int
			A_     :						int

			for x_val, y_val in enumerate(lowerCamelCase__   ):
						for col in range(lowerCamelCase__   ):
									A_     :						Dict     =					(x_val + 1) ** (size - col - 1)
						A_     :						Any     =					y_val

			A_     :						Dict     =					solve(lowerCamelCase__						,				lowerCamelCase__   )

			def interpolated_func(lowerCamelCase__   ) -> int:
						return sum(
						    round(coeffs[x_val][0]   ) * (var ** (size - x_val - 1))
						    for x_val in range(lowerCamelCase__   )   )

			return interpolated_func



def      a      (			lowerCamelCase__   ):
			'''simple docstring'''





			return (
			    1
			    - variable
			    + variable**2
			    - variable**3
			    + variable**4
			    - variable**5
			    + variable**6
			    - variable**7
			    + variable**8
			    - variable**9
			    + variable**10
			)



def      a      (			lowerCamelCase__ = question_function						,				lowerCamelCase__ = 10   ):
			'''simple docstring'''





			A_     :						list[int]     =					[func(lowerCamelCase__   ) for x_val in range(1						,				order + 1   )]

			A_     :						list[Callable[[int], int]]     =					[
			    interpolate(data_points[:max_coeff]   ) for max_coeff in range(1						,				order + 1   )
			]

			A_     :						int     =					0
			A_     :						Callable[[int], int]
			A_     :						int

			for poly in polynomials:
						A_     :						int     =					1
						while func(lowerCamelCase__   ) == poly(lowerCamelCase__   ):
									x_val += 1

						ret += poly(lowerCamelCase__   )

			return ret


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