#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(100000000); dp[n] = 1; rep(i, 0, 7) { vector ndp(100000000); int x; cin >> x; auto xs = f(x); rep(j, 0, 100000000) { if (dp[j] == 0) continue; rep(k, 0, 8) { if (j >= xs[k]) { ndp[j - xs[k]] = 1; } } } swap(dp, ndp); } cout << (dp[0] ? "Yes" : "No") << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(12); int t = 1; while (t--) solve(); }