




"""simple docstring"""






lowercase__     						=						range(2, 20 + 1)
lowercase__     						=						[10**k for k in range(ks[-1] + 1)]
lowercase__     						=						{}







def      _snake_case			(				lowercase__							,    lowercase__							,    lowercase__							,    lowercase__		):
				_lowerCamelCase     :			Optional[Any]    =    sum(a_i[j] for j in range(lowercase__							,    len(lowercase__		)		)		)
				_lowerCamelCase     :			Dict    =    sum(a_i[j] * base[j] for j in range(min(len(lowercase__		)							,    lowercase__		)		)		)

				_lowerCamelCase, _lowerCamelCase     :			Dict    =    0, 0
				_lowerCamelCase     :			List[str]    =    n - i

				_lowerCamelCase     :			Optional[int]    =    memo.get(lowercase__		)

				if sub_memo is not None:
								_lowerCamelCase     :			Tuple    =    sub_memo.get(lowercase__		)

								if jumps is not None and len(lowercase__		) > 0:
												# find and make the largest jump without going over
												_lowerCamelCase     :			Optional[Any]    =    -1
												for _k in range(len(lowercase__		) - 1							,    -1							,    -1		):
																if jumps[_k][2] <= k and jumps[_k][1] <= max_dn:
																				_lowerCamelCase     :			Dict    =    _k
																				break

												if max_jump >= 0:
																_lowerCamelCase, _lowerCamelCase, _lowerCamelCase     :			Dict    =    jumps[max_jump]
																# since the difference between jumps is cached, add c
																_lowerCamelCase     :			Any    =    diff + c
																for j in range(min(lowercase__							,    len(lowercase__		)		)		):
																				_lowerCamelCase, _lowerCamelCase     :			Tuple    =    divmod(lowercase__							,    10		)
																if new_c > 0:
																				add(lowercase__							,    lowercase__							,    lowercase__		)

								else:
												_lowerCamelCase     :			List[Any]    =    []
				else:
								_lowerCamelCase     :			List[str]    =    {c: []}
								_lowerCamelCase     :			str    =    sub_memo

				if dn >= max_dn or c + diff >= base[k]:
								return diff, dn

				if k > ks[0]:
								while True:
												# keep doing smaller jumps
												_lowerCamelCase, _lowerCamelCase     :			Any    =    next_term(lowercase__							,    k - 1							,    i + dn							,    lowercase__		)
												diff += _diff
												dn += terms_jumped

												if dn >= max_dn or c + diff >= base[k]:
																break
				else:
								# would be too small a jump, just compute sequential terms instead
								_lowerCamelCase, _lowerCamelCase     :			str    =    compute(lowercase__							,    lowercase__							,    i + dn							,    lowercase__		)
								diff += _diff
								dn += terms_jumped

				_lowerCamelCase     :			Union[str, Any]    =    sub_memo[c]

				# keep jumps sorted by # of terms skipped
				_lowerCamelCase     :			Dict    =    0
				while j < len(lowercase__		):
								if jumps[j][1] > dn:
												break
								j += 1

				# cache the jump for this value digitsum(b) and c
				sub_memo[c].insert(lowercase__							,    (diff, dn, k)		)
				return (diff, dn)







def      _snake_case			(				lowercase__							,    lowercase__							,    lowercase__							,    lowercase__		):
				if i >= n:
								return 0, i
				if k > len(lowercase__		):
								a_i.extend([0 for _ in range(k - len(lowercase__		)		)]		)

				# note: a_i -> b * 10^k + c
				# ds_b -> digitsum(b)
				# ds_c -> digitsum(c)
				_lowerCamelCase     :			int    =    i
				_lowerCamelCase, _lowerCamelCase, _lowerCamelCase     :			int    =    0, 0, 0
				for j in range(len(lowercase__		)		):
								if j >= k:
												ds_b += a_i[j]
								else:
												ds_c += a_i[j]

				while i < n:
								i += 1
								_lowerCamelCase     :			int    =    ds_c + ds_b
								diff += addend
								_lowerCamelCase     :			Optional[int]    =    0
								for j in range(lowercase__		):
												_lowerCamelCase     :			Dict    =    a_i[j] + addend
												_lowerCamelCase, _lowerCamelCase     :			List[Any]    =    divmod(lowercase__							,    10		)

												ds_c += a_i[j]

								if addend > 0:
												break

				if addend > 0:
								add(lowercase__							,    lowercase__							,    lowercase__		)
				return diff, i - start_i







def      _snake_case			(				lowercase__							,    lowercase__							,    lowercase__		):
				for j in range(lowercase__							,    len(lowercase__		)		):
								_lowerCamelCase     :			int    =    digits[j] + addend
								if s >= 10:
												_lowerCamelCase, _lowerCamelCase     :			Dict    =    divmod(lowercase__							,    10		)
												_lowerCamelCase     :			Union[str, Any]    =    addend // 10 + quotient
								else:
												_lowerCamelCase     :			Dict    =    s
												_lowerCamelCase     :			Optional[Any]    =    addend // 10

								if addend == 0:
												break

				while addend > 0:
								_lowerCamelCase, _lowerCamelCase     :			Dict    =    divmod(lowercase__							,    10		)
								digits.append(lowercase__		)







def      _snake_case			(				lowercase__ = 10**15		):
				_lowerCamelCase     :			Optional[Any]    =    [1]
				_lowerCamelCase     :			int    =    1
				_lowerCamelCase     :			Any    =    0
				while True:
								_lowerCamelCase, _lowerCamelCase     :			Dict    =    next_term(lowercase__							,    20							,    i + dn							,    lowercase__		)
								dn += terms_jumped
								if dn == n - i:
												break

				_lowerCamelCase     :			int    =    0
				for j in range(len(lowercase__		)		):
								a_n += digits[j] * 10**j
				return a_n


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





"""simple docstring"""






from __future__ import annotations

from collections.abc import Iterator
from typing import Any






class lowerCAmelCase__	:






			'''simple docstring'''



			def __init__(  self  ,      lowercase  ):
							_lowerCamelCase     :			Any    =    data
							_lowerCamelCase     :			Node | None    =    None






class lowerCAmelCase__	:






			'''simple docstring'''



			def __init__(  self  ):
							_lowerCamelCase     :			str    =    None
							_lowerCamelCase     :			str    =    None
			def __iter__(  self  ):
							_lowerCamelCase     :			List[str]    =    self.head
							while self.head:
											yield node.data
											_lowerCamelCase     :			Optional[int]    =    node.next
											if node == self.head:
															break
			def __len__(  self  ):
							return sum(1 for _ in self  )
			def __repr__(  self  ):
							return "->".join(str(lowercase  ) for item in iter(self  )  )
			def 					A_    (  self  ,      lowercase  ):
							self.insert_nth(len(self  )  ,      lowercase  )
			def 					A_    (  self  ,      lowercase  ):
							self.insert_nth(0  ,      lowercase  )
			def 					A_    (  self  ,      lowercase  ,      lowercase  ):
							if index < 0 or index > len(self  ):
											raise IndexError('list index out of range.'  )
							_lowerCamelCase     :			List[Any]    =    Node(lowercase  )
							if self.head is None:
											_lowerCamelCase     :			str    =    new_node  # first node points itself
											_lowerCamelCase     :			Union[str, Any]    =    new_node
							elif index == 0:  # insert at head
											_lowerCamelCase     :			List[str]    =    self.head
											_lowerCamelCase     :			str    =    new_node
							else:
											_lowerCamelCase     :			Union[str, Any]    =    self.head
											for _ in range(index - 1  ):
															_lowerCamelCase     :			List[Any]    =    temp.next
											_lowerCamelCase     :			Union[str, Any]    =    temp.next
											_lowerCamelCase     :			List[str]    =    new_node
											if index == len(self  ) - 1:  # insert at tail
															_lowerCamelCase     :			Any    =    new_node
			def 					A_    (  self  ):
							return self.delete_nth(0  )
			def 					A_    (  self  ):
							return self.delete_nth(len(self  ) - 1  )
			def 					A_    (  self  ,      lowercase = 0  ):
							if not 0 <= index < len(self  ):
											raise IndexError('list index out of range.'  )
							_lowerCamelCase     :			Any    =    self.head
							if self.head == self.tail:  # just one node
											_lowerCamelCase     :			List[str]    =    None
							elif index == 0:  # delete head node
											_lowerCamelCase     :			List[str]    =    self.tail.next.next
											_lowerCamelCase     :			Optional[int]    =    self.head.next
							else:
											_lowerCamelCase     :			Dict    =    self.head
											for _ in range(index - 1  ):
															_lowerCamelCase     :			List[Any]    =    temp.next
											_lowerCamelCase     :			int    =    temp.next
											_lowerCamelCase     :			Optional[int]    =    temp.next.next
											if index == len(self  ) - 1:  # delete at tail
															_lowerCamelCase     :			List[Any]    =    temp
							return delete_node.data






			def 					A_    (  self  ):
							return len(self  ) == 0







def      _snake_case			(				):
				_lowerCamelCase     :			Union[str, Any]    =    CircularLinkedList()
				assert len(lowercase__		) == 0
				assert circular_linked_list.is_empty() is True
				assert str(lowercase__		) == ""

				try:
								circular_linked_list.delete_front()
								raise AssertionError  # This should not happen
				except IndexError:
								assert True  # This should happen

				try:
								circular_linked_list.delete_tail()
								raise AssertionError  # This should not happen
				except IndexError:
								assert True  # This should happen

				try:
								circular_linked_list.delete_nth(-1		)
								raise AssertionError
				except IndexError:
								assert True

				try:
								circular_linked_list.delete_nth(0		)
								raise AssertionError
				except IndexError:
								assert True

				assert circular_linked_list.is_empty() is True
				for i in range(5		):
								assert len(lowercase__		) == i
								circular_linked_list.insert_nth(lowercase__							,    i + 1		)
				assert str(lowercase__		) == "->".join(str(lowercase__		) for i in range(1							,    6		)		)

				circular_linked_list.insert_tail(6		)
				assert str(lowercase__		) == "->".join(str(lowercase__		) for i in range(1							,    7		)		)
				circular_linked_list.insert_head(0		)
				assert str(lowercase__		) == "->".join(str(lowercase__		) for i in range(0							,    7		)		)

				assert circular_linked_list.delete_front() == 0
				assert circular_linked_list.delete_tail() == 6
				assert str(lowercase__		) == "->".join(str(lowercase__		) for i in range(1							,    6		)		)
				assert circular_linked_list.delete_nth(2		) == 3

				circular_linked_list.insert_nth(2							,    3		)
				assert str(lowercase__		) == "->".join(str(lowercase__		) for i in range(1							,    6		)		)

				assert circular_linked_list.is_empty() is False


if __name__ == "__main__":
			import doctest

			doctest.testmod()