/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author aajisaka */ #include using namespace std; void debug_out() { cerr << endl; } template void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif #define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr) #define rep(i,n) for(int i=0; i<(int)(n); i++) #define all(v) v.begin(), v.end() template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using ull = unsigned long long; using P = pair; constexpr long double PI = 3.14159265358979323846264338327950288L; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); class No1231MakeAMultipleOfTen { public: void solve(istream& cin, ostream& cout) { SPEED; int n; cin >> n; vector cnt(10); rep(i, n) { int a; cin >> a; cnt[a%10]++; } int ret = cnt[0]; for(int two=max(cnt[2]-4, 0); two<=cnt[2]; two++) { for(int three=max(cnt[3]-9, 0); three<=cnt[3]; three++) { for(int four=max(cnt[4]-4, 0); four<=cnt[4]; four++) { for(int five=max(cnt[5]-1, 0); five<=cnt[5]; five++) { for(int six=max(cnt[6]-4, 0); six<=cnt[6]; six++) { for(int seven=max(cnt[7]-9, 0); seven<=cnt[7]; seven++) { for(int eight=max(cnt[8]-4, 0); eight<=cnt[8]; eight++) { for(int nine=max(cnt[9]-9, 0); nine<=cnt[9]; nine++) { for(int one=max(cnt[0]-9, 0); one<=cnt[1]; one++) { ll now = one+two*2+three*3+four*4+five*5+six*6+seven*7+eight*8+nine*9; if (now%10==0) { chmax(ret, cnt[0]+one+two+three+four+five+six+seven+eight+nine); } } } } } } } } } } cout << ret << endl; } }; signed main() { No1231MakeAMultipleOfTen solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }