


'''simple docstring'''




from __future__ import annotations

def 			__UpperCamelCase    (    _A    :				list[int]					,   _A    :				int				)    ->      int:




	"""simple docstring"""





	if len(_A				) < k or k < 0:
		raise ValueError('Invalid Input'				)
	lowerCAmelCase					:    Optional[Any]      							= sum(array[:k]				)
	for i in range(len(_A				) - k				):
		lowerCAmelCase					:    str      							= current_sum - array[i] + array[i + k]
		lowerCAmelCase					:    List[Any]      							= max(_A					,   _A				)
	return max_sum


if __name__ == "__main__":
				from doctest import testmod
				from random import randint

				testmod()
				_lowerCAmelCase  :		Union[str, Any]		     =	[randint(-1000, 1000) for i in range(100)]
				_lowerCAmelCase  :		Any		     =	randint(0, 110)
				print(f"""The maximum sum of {k} consecutive elements is {max_sum_in_array(array,k)}""")




'''simple docstring'''




def 			__UpperCamelCase    (    _A    :				List[str]				)    ->      Optional[Any]:




	"""simple docstring"""





	if not head:
		return True
	# split the list to two parts
	lowerCAmelCase							,   lowerCAmelCase					:    str      							= head.next, head
	while fast and fast.next:
		lowerCAmelCase					:    Optional[int]      							= fast.next.next
		lowerCAmelCase					:    int      							= slow.next
	lowerCAmelCase					:    int      							= slow.next
	lowerCAmelCase					:    Optional[Any]      							= None  # Don't forget here! But forget still works!
	# reverse the second part
	lowerCAmelCase					:    List[Any]      							= None
	while second:
		lowerCAmelCase					:    List[Any]      							= second.next
		lowerCAmelCase					:    Union[str, Any]      							= node
		lowerCAmelCase					:    Optional[Any]      							= second
		lowerCAmelCase					:    Any      							= nxt
	# compare two parts
	# second part has the same or one less node
	while node:
		if node.val != head.val:
			return False
		lowerCAmelCase					:    Optional[Any]      							= node.next
		lowerCAmelCase					:    Tuple      							= head.next
	return True

def 			__UpperCamelCase    (    _A    :				Optional[Any]				)    ->      Optional[int]:




	"""simple docstring"""





	if not head or not head.next:
		return True

	# 1. Get the midpoint (slow)
	lowerCAmelCase					:    Optional[int]      							= head
	while fast and fast.next:
		lowerCAmelCase							,   lowerCAmelCase					:    Optional[Any]      							= fast.next.next, slow.next

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

	# 3. Comparison
	while stack:
		if stack.pop() != cur.val:
			return False
		lowerCAmelCase					:    Union[str, Any]      							= cur.next

	return True






def 			__UpperCamelCase    (    _A    :				Tuple				)    ->      Optional[int]:




	"""simple docstring"""





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