"""simple docstring"""






from sympy import diff, lambdify, symbols
from sympy.functions import *  # noqa: F403




def 						SCREAMING_SNAKE_CASE					(  __UpperCAmelCase  ,					__UpperCAmelCase  ,					__UpperCAmelCase = "x"  ,					__UpperCAmelCase = 10**-10  ,					__UpperCAmelCase = 1  ,					)							->   complex:
				SCREAMING_SNAKE_CASE__		  =				symbols(__UpperCAmelCase       )
				SCREAMING_SNAKE_CASE__		  =				lambdify(__UpperCAmelCase  ,					__UpperCAmelCase       )
				SCREAMING_SNAKE_CASE__		  =				lambdify(__UpperCAmelCase  ,					diff(__UpperCAmelCase  ,					__UpperCAmelCase       )       )

				SCREAMING_SNAKE_CASE__		  =				starting_point

				while True:
								if diff_function(__UpperCAmelCase       ) != 0:
												SCREAMING_SNAKE_CASE__		  =				prev_guess - multiplicity * func(__UpperCAmelCase       ) / diff_function(
												    __UpperCAmelCase       )
								else:
												raise ZeroDivisionError("Could not find root"       ) from None

								# Precision is checked by comparing the difference of consecutive guesses
								if abs(next_guess - prev_guess       ) < precision:
												return next_guess

								SCREAMING_SNAKE_CASE__		  =				next_guess


# Let's Execute
if __name__ == "__main__":
						# Find root of trigonometric function
						# Find value of pi
						print(F'The root of sin(x) = 0 is {newton_raphson("sin(x)", 2)}')

						# Find root of polynomial
						# Find fourth Root of 5
						print(F'The root of x**4 - 5 = 0 is {newton_raphson("x**4 -5", 0.4 +5J)}')

						# Find value of e
						print(
						    'The root of log(y) - 1 = 0 is ',
						    F'{newton_raphson("log(y) - 1", 2, variable="y")}',
						)

						# Exponential Roots
						print(
						    'The root of exp(x) - 1 = 0 is',
						    F'{newton_raphson("exp(x) - 1", 1_0, precision=0.005)}',
						)

						# Find root of cos(x)
						print(F'The root of cos(x) = 0 is {newton_raphson("cos(x)", 0)}')





"""simple docstring"""






def 						SCREAMING_SNAKE_CASE					(  __UpperCAmelCase       )							->   List[str]:
				if not head:
								return True
				# split the list to two parts
				SCREAMING_SNAKE_CASE__  ,       SCREAMING_SNAKE_CASE__		  =				head.next, head
				while fast and fast.next:
								SCREAMING_SNAKE_CASE__		  =				fast.next.next
								SCREAMING_SNAKE_CASE__		  =				slow.next
				SCREAMING_SNAKE_CASE__		  =				slow.next
				SCREAMING_SNAKE_CASE__		  =				None  # Don't forget here! But forget still works!
				# reverse the second part
				SCREAMING_SNAKE_CASE__		  =				None
				while second:
								SCREAMING_SNAKE_CASE__		  =				second.next
								SCREAMING_SNAKE_CASE__		  =				node
								SCREAMING_SNAKE_CASE__		  =				second
								SCREAMING_SNAKE_CASE__		  =				nxt
				# compare two parts
				# second part has the same or one less node
				while node:
								if node.val != head.val:
												return False
								SCREAMING_SNAKE_CASE__		  =				node.next
								SCREAMING_SNAKE_CASE__		  =				head.next
				return True




def 						SCREAMING_SNAKE_CASE					(  __UpperCAmelCase       )							->   str:
				if not head or not head.next:
								return True

				# 1. Get the midpoint (slow)
				SCREAMING_SNAKE_CASE__		  =				SCREAMING_SNAKE_CASE__		  =				SCREAMING_SNAKE_CASE__		  =				head
				while fast and fast.next:
								SCREAMING_SNAKE_CASE__  ,       SCREAMING_SNAKE_CASE__		  =				fast.next.next, slow.next

				# 2. Push the second half into the stack
				SCREAMING_SNAKE_CASE__		  =				[slow.val]
				while slow.next:
								SCREAMING_SNAKE_CASE__		  =				slow.next
								stack.append(slow.val       )

				# 3. Comparison
				while stack:
								if stack.pop() != cur.val:
												return False
								SCREAMING_SNAKE_CASE__		  =				cur.next

				return True




def 						SCREAMING_SNAKE_CASE					(  __UpperCAmelCase       )							->   str:
				if not head or not head.next:
								return True
				SCREAMING_SNAKE_CASE__		  =				{}
				SCREAMING_SNAKE_CASE__		  =				0
				while head:
								if head.val in d:
												d[head.val].append(__UpperCAmelCase       )
								else:
												SCREAMING_SNAKE_CASE__		  =				[pos]
								SCREAMING_SNAKE_CASE__		  =				head.next
								pos += 1
				SCREAMING_SNAKE_CASE__		  =				pos - 1
				SCREAMING_SNAKE_CASE__		  =				0
				for v in d.values():
								if len(__UpperCAmelCase       ) % 2 != 0:
												middle += 1
								else:
												SCREAMING_SNAKE_CASE__		  =				0
												for i in range(0  ,					len(__UpperCAmelCase       )       ):
																if v[i] + v[len(__UpperCAmelCase       ) - 1 - step] != checksum:
																				return False
																step += 1
								if middle > 1:
												return False
				return True




