

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

def 							__SCREAMING_SNAKE_CASE							(			lowerCAmelCase:					Optional[Any]					, lowerCAmelCase:					str					, lowerCAmelCase:					Optional[Any]					, lowerCAmelCase:					Optional[int]	)				->    Tuple:
				_UpperCAmelCase    :						Union[str, Any]							=      sum(a_i[j] for j in range(lowerCAmelCase					, len(lowerCAmelCase	)	)	)
				_UpperCAmelCase    :						List[str]							=      sum(a_i[j] * base[j] for j in range(min(len(lowerCAmelCase	)					, lowerCAmelCase	)	)	)

				_UpperCAmelCase						,							_UpperCAmelCase    :						Union[str, Any]							=      0, 0
				_UpperCAmelCase    :						Dict							=      n - i

				_UpperCAmelCase    :						Dict							=      memo.get(lowerCAmelCase	)

				if sub_memo is not None:
								_UpperCAmelCase    :						Optional[int]							=      sub_memo.get(lowerCAmelCase	)

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

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

								else:
												_UpperCAmelCase    :						Union[str, Any]							=      []
				else:
								_UpperCAmelCase    :						List[str]							=      {c: []}
								_UpperCAmelCase    :						Optional[int]							=      sub_memo

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

				if k > ks[0]:
								while True:
												# keep doing smaller jumps
												_UpperCAmelCase						,							_UpperCAmelCase    :						Optional[int]							=      next_term(lowerCAmelCase					, k - 1					, i + dn					, lowerCAmelCase	)
												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
								_UpperCAmelCase						,							_UpperCAmelCase    :						Dict							=      compute(lowerCAmelCase					, lowerCAmelCase					, i + dn					, lowerCAmelCase	)
								diff += _diff
								dn += terms_jumped

				_UpperCAmelCase    :						List[Any]							=      sub_memo[c]

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

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

def 							__SCREAMING_SNAKE_CASE							(			lowerCAmelCase:					Optional[Any]					, lowerCAmelCase:					str					, lowerCAmelCase:					str					, lowerCAmelCase:					Tuple	)				->    Optional[Any]:
				if i >= n:
								return 0, i
				if k > len(lowerCAmelCase	):
								a_i.extend([0 for _ in range(k - len(lowerCAmelCase	)	)]	)

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

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

												ds_c += a_i[j]

								if addend > 0:
												break

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

def 							__SCREAMING_SNAKE_CASE							(			lowerCAmelCase:					Optional[int]					, lowerCAmelCase:					str					, lowerCAmelCase:					Dict	)				->    int:
				for j in range(lowerCAmelCase					, len(lowerCAmelCase	)	):
								_UpperCAmelCase    :						Optional[Any]							=      digits[j] + addend
								if s >= 10:
												_UpperCAmelCase						,							_UpperCAmelCase    :						Any							=      divmod(lowerCAmelCase					, 10	)
												_UpperCAmelCase    :						List[str]							=      addend // 10 + quotient
								else:
												_UpperCAmelCase    :						Tuple							=      s
												_UpperCAmelCase    :						Dict							=      addend // 10

								if addend == 0:
												break

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

def 							__SCREAMING_SNAKE_CASE							(			lowerCAmelCase:					int = 10**15	)				->    int:
				_UpperCAmelCase    :						Union[str, Any]							=      [1]
				_UpperCAmelCase    :						str							=      1
				_UpperCAmelCase    :						Optional[int]							=      0
				while True:
								_UpperCAmelCase						,							_UpperCAmelCase    :						Tuple							=      next_term(lowerCAmelCase					, 20					, i + dn					, lowerCAmelCase	)
								dn += terms_jumped
								if dn == n - i:
												break

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


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





def 							__SCREAMING_SNAKE_CASE							(			lowerCAmelCase:					str					, lowerCAmelCase:					str	)				->    bool:
				_UpperCAmelCase    :						Optional[Any]							=      len(lowerCAmelCase	) + 1
				_UpperCAmelCase    :						Optional[int]							=      len(lowerCAmelCase	) + 1

				# dp is a 2d matrix where dp[i][j] denotes whether prefix string of
				# length i of input_string matches with prefix string of length j of
				# given pattern.
				# "dp" stands for dynamic programming.
				_UpperCAmelCase    :						List[str]							=      [[0 for i in range(lowerCAmelCase	)] for j in range(lowerCAmelCase	)]

				# since string of zero length match pattern of zero length
				_UpperCAmelCase    :						List[Any]							=      1

				# since pattern of zero length will never match with string of non-zero length
				for i in range(1					, lowerCAmelCase	):
								_UpperCAmelCase    :						Dict							=      0

				# since string of zero length will match with pattern where there
				# is at least one * alternatively
				for j in range(1					, lowerCAmelCase	):
								_UpperCAmelCase    :						Tuple							=      dp[0][j - 2] if pattern[j - 1] == "*" else 0

				# now using bottom-up approach to find for all remaining lengths
				for i in range(1					, lowerCAmelCase	):
								for j in range(1					, lowerCAmelCase	):
												if input_string[i - 1] == pattern[j - 1] or pattern[j - 1] == ".":
																_UpperCAmelCase    :						Optional[Any]							=      dp[i - 1][j - 1]

												elif pattern[j - 1] == "*":
																if dp[i][j - 2] == 1:
																				_UpperCAmelCase    :						List[str]							=      1
																elif pattern[j - 2] in (input_string[i - 1], "."):
																				_UpperCAmelCase    :						str							=      dp[i - 1][j]
																else:
																				_UpperCAmelCase    :						int							=      0
												else:
																_UpperCAmelCase    :						List[Any]							=      0

				return bool(dp[-1][-1]	)


if __name__ == "__main__":
					import doctest

					doctest.testmod()
					# inputing the strings
					# input_string = input("input a string :")
					# pattern = input("input a pattern :")

					SCREAMING_SNAKE_CASE_            = 'aab'
					SCREAMING_SNAKE_CASE_            = 'c*a*b'

					# using function to check whether given string matches the given pattern
					if match_pattern(input_string, pattern):
										print(F'''{input_string} matches the given pattern {pattern}''')
					else:
										print(F'''{input_string} does not match with the given pattern {pattern}''')


