#include #include #include #include template std::vector vec(int len, T elem) { return std::vector(len, elem); } std::vector> xss{{0}, {6, 7}, {12, 13, 14}}; void solve() { std::string n; std::cin >> n; std::reverse(n.begin(), n.end()); // carry, remain auto dp = vec(2, vec(3, false)); std::fill(dp[0].begin(), dp[0].end(), true); for (char cc : n) { int d = cc - '0'; auto ndp = vec(2, vec(3, false)); for (int c = 0; c <= 1; ++c) { for (int t = 0; t <= 2; ++t) { if (!dp[c][t]) continue; for (auto x : xss[t]) { int s = x + c; if (s % 10 != d) continue; ndp[s / 10][t] = true; } } } std::swap(dp, ndp); for (int c = 0; c <= 1; ++c) { for (int t = 1; t >= 0; --t) { if (dp[c][t + 1]) dp[c][t] = true; } } } std::cout << (dp[0][0] ? "Yes" : "No") << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }