





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





def lowerCAmelCase__(__snake_case       ,__snake_case       ,__snake_case       ,__snake_case							)				->      int:







	'''simple docstring'''







	lowerCamelCase__								=		sum(a_i[j] for j in range(_UpperCAmelCase       ,len(_UpperCAmelCase							)							)							)
	lowerCamelCase__								=		sum(a_i[j] * base[j] for j in range(min(len(_UpperCAmelCase							)       ,_UpperCAmelCase							)							)							)

	lowerCamelCase__								=		0, 0
	lowerCamelCase__								=		n - i

	lowerCamelCase__								=		memo.get(_UpperCAmelCase							)

	if sub_memo is not None:
		lowerCamelCase__								=		sub_memo.get(_UpperCAmelCase							)

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

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

		else:
			lowerCamelCase__								=		[]
	else:
		lowerCamelCase__								=		{c: []}
		lowerCamelCase__								=		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__								=		next_term(_UpperCAmelCase       ,k - 1       ,i + dn       ,_UpperCAmelCase							)
			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__								=		compute(_UpperCAmelCase       ,_UpperCAmelCase       ,i + dn       ,_UpperCAmelCase							)
		diff += _diff
		dn += terms_jumped

	lowerCamelCase__								=		sub_memo[c]

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

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





def lowerCAmelCase__(__snake_case       ,__snake_case       ,__snake_case       ,__snake_case							)				->      List[str]:







	'''simple docstring'''







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

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

	while i < n:
		i += 1
		lowerCamelCase__								=		ds_c + ds_b
		diff += addend
		lowerCamelCase__								=		0
		for j in range(_UpperCAmelCase							):
			lowerCamelCase__								=		a_i[j] + addend
			lowerCamelCase__								=		divmod(_UpperCAmelCase       ,10							)

			ds_c += a_i[j]

		if addend > 0:
			break

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





def lowerCAmelCase__(__snake_case       ,__snake_case       ,__snake_case							)				->      List[str]:







	'''simple docstring'''







	for j in range(_UpperCAmelCase       ,len(_UpperCAmelCase							)							):
		lowerCamelCase__								=		digits[j] + addend
		if s >= 10:
			lowerCamelCase__								=		divmod(_UpperCAmelCase       ,10							)
			lowerCamelCase__								=		addend // 10 + quotient
		else:
			lowerCamelCase__								=		s
			lowerCamelCase__								=		addend // 10

		if addend == 0:
			break

	while addend > 0:
		lowerCamelCase__								=		divmod(_UpperCAmelCase       ,10							)
		digits.append(_UpperCAmelCase							)





def lowerCAmelCase__(__snake_case = 10**15							)				->      List[Any]:







	'''simple docstring'''







	lowerCamelCase__								=		[1]
	lowerCamelCase__								=		1
	lowerCamelCase__								=		0
	while True:
		lowerCamelCase__								=		next_term(_UpperCAmelCase       ,20       ,i + dn       ,_UpperCAmelCase							)
		dn += terms_jumped
		if dn == n - i:
			break

	lowerCamelCase__								=		0
	for j in range(len(_UpperCAmelCase							)							):
		a_n += digits[j] * 10**j
	return a_n


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










"""simple docstring"""




from typing import Optional, Union

import torch
from torch import nn

from ...configuration_utils import ConfigMixin, register_to_config
from ...models.modeling_utils import ModelMixin

class  _UpperCAmelCase  (   UpperCAmelCase__			,   UpperCAmelCase__		):



      '''simple docstring'''

      @register_to_config
      def __init__(     self					,      snake_case_ = 7_6_8					,      ):

        """simple docstring"""

        super().__init__()

        A_  :       Optional[int]										=  nn.Parameter(torch.zeros(1					,      snake_case_  )  )
        A_  :       Optional[int]										=  nn.Parameter(torch.ones(1					,      snake_case_  )  )

      def 					lowerCamelCase_			(     self					,      snake_case_ = None					,      snake_case_ = None					,      ):

        """simple docstring"""

        A_  :       str										=  nn.Parameter(self.mean.to(snake_case_  ).to(snake_case_  )  )
        A_  :       Optional[int]										=  nn.Parameter(self.std.to(snake_case_  ).to(snake_case_  )  )
        return self

      def 					lowerCamelCase_			(     self					,      snake_case_  ):

        """simple docstring"""

        A_  :       Tuple										=  (embeds - self.mean) * 1.0 / self.std
        return embeds

      def 					lowerCamelCase_			(     self					,      snake_case_  ):

        """simple docstring"""

        A_  :       List[str]										=  (embeds * self.std) + self.mean
        return embeds