p = input().strip() reversed_p = p[::-1] n = len(reversed_p) from collections import defaultdict # Initialize DP table. Each entry is a dictionary of possible states (carry, a_has_non_zero, b_has_non_zero) to boolean. dp = [defaultdict(bool) for _ in range(n + 1)] dp[0][(0, False, False)] = True for i in range(n): current_digit = int(reversed_p[i]) for state in list(dp[i].keys()): carry, a_has, b_has = state if not dp[i][state]: continue # Try all possible digits for a and b (0, 6, 7) for d_a in [0, 6, 7]: for d_b in [0, 6, 7]: total = d_a + d_b + carry if total % 10 != current_digit: continue new_carry = total // 10 new_a_has = a_has or (d_a != 0) new_b_has = b_has or (d_b != 0) # Update the next state dp[i + 1][(new_carry, new_a_has, new_b_has)] = True # Check if the final state is valid: carry 0, both have non-zero digits if dp[n].get((0, True, True), False): print("Yes") else: print("No")