#include //sort,二分探索,など #include //固定長bit集合 #include //pow,logなど #include //複素数 #include //両端アクセスのキュー #include //ファイルストリーム(標準入力変更用) #include //sortのgreater #include //setprecision(浮動小数点の出力の誤差) #include //入出力 #include //集合演算(積集合,和集合,差集合など) #include //map(辞書) #include //iota(整数列の生成),gcdとlcm(c++17) #include //キュー #include //集合 #include //スタック #include //文字列 #include //イテレータあるけど順序保持しないmap #include //イテレータあるけど順序保持しないset #include //pair #include //可変長配列 //名前 using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef map msi; typedef map msll; typedef pair pii; typedef pair pllll; typedef vector vi; typedef vector vll; typedef vector vs; typedef vector vb; typedef vector> vvi; typedef vector> vvll; typedef vector> vvs; typedef vector> vvb; //定数 const ll MOD = 1000000007; const ll INF = 1000000000000000000; //マクロ #define rep(i,n) for(int i=0;i=0;i--) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define in1(x1) cin >> x1 #define in2(x1, x2) cin >> x1 >> x2 #define in3(x1, x2, x3) cin >> x1 >> x2 >> x3 #define inN(x, N) rep(i, N) in1(x[i]) #define outl(x) cout << x << endl #define out2l(x, y) cout << x << " " << y << endl //よく使う関数 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; } class C { public: int r; ll count; int i; C(int r, ll count, int i) { this->r = r; this->count = count; this->i = i; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); //標準入力をファイルに変更 //std::ifstream in("input.txt"); //std::cin.rdbuf(in.rdbuf()); int N; in1(N); vll A(N); inN(A, N); vll r(10); rep(i, N) r[A[i] % 10]++; ll sum = accumulate(all(A), 0LL); sum %= 10; //dp[i][j] := i - 1まで選んであまりをjにするために必要な枚数の最小値 vvll dp(11, vll(10, INF)); rep(i, 11) dp[i][0] = 0; rep(i, 10) { rep(j, 10) { chmin(dp[i + 1][j], dp[i][j]); repse(k, 1, r[i]) chmin(dp[i + 1][(j + k * i) % 10], dp[i][j] + k); } } if (dp[10][sum] != INF) { outl(N - dp[10][sum]); } else { outl(0); } return 0; }