#include #include #define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) using namespace atcoder; using namespace std; typedef long long ll; vector f(int x) { vector ret; rep(i, 0, 8) { x = (x % 10) * 10000000 + (x / 10); ret.push_back(x); } return ret; } void solve() { int n; cin >> n; vector dp(2, vector(100000000)); dp[0][n] = 1; rep(i, 0, 7) { int x; cin >> x; auto xs = f(x); rep(j, 0, 100000000) { if (dp[0][j] == 0) continue; rep(k, 0, 8) { if (j >= xs[k]) { dp[1][j - xs[k]] = 1; } } } swap(dp[0], dp[1]); rep(j, 0, 100000000) dp[1][j] = 0; } cout << (dp[0][0] ? "Yes" : "No") << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(12); int t = 1; while (t--) solve(); }