#include #include #include #include #include #include #include #include #include static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using u64 = unsigned long long; using namespace std; template constexpr T INF = ::numeric_limits::max()/32*15+208; template vector make_v(U size, const T& init){ return vector(static_cast(size), init); } template auto make_v(U size, Ts... rest) { return vector(static_cast(size), make_v(rest...)); } template void chmin(T &a, const T &b){ a = (a < b ? a : b); } template void chmax(T &a, const T &b){ a = (a > b ? a : b); } int main() { int n; cin >> n; vector v(n); for (auto &&i : v) scanf("%d", &i); vector cnt(10); int S = 0; for (int i = 0; i < n; ++i) { S += v[i]%10; cnt[v[i]%10]++; } vector dp(10, INF), dp2; dp[S%10] = 0; for (int i = 1; i < 10; ++i) { dp2 = dp; for (int j = 0; j < 10; ++j) { for (int k = 1; k <= min(9, cnt[i]); ++k) { chmin(dp2[(j+k*(10-i))%10], dp[j]+k); } } swap(dp, dp2); } cout << n-dp[0] << "\n"; return 0; }