MOD = 998244353 def solve(N): s = str(N) n = len(s) # 记忆化数组 memo = {} def dp(pos, tight, last1, last2, started): # pos: 当前位置, tight: 是否受限, last1/last2: 前两位数字, started: 是否已经开始 if pos == n: return 1 if started else 0 if (pos, tight, last1, last2, started) in memo: return memo[(pos, tight, last1, last2, started)] limit = int(s[pos]) if tight else 9 result = 0 for digit in range(0, limit + 1): # 检查是否形成404 if last2 == 4 and last1 == 0 and digit == 4: continue new_tight = tight and (digit == limit) new_started = started or (digit > 0) new_last1 = digit if new_started else -1 new_last2 = last1 if new_started else -1 result = (result + dp(pos + 1, new_tight, new_last1, new_last2, new_started)) % MOD memo[(pos, tight, last1, last2, started)] = result return result return dp(0, True, -1, -1, False) N = input().strip() print(solve(int(N)))