import operator def accum_dp(xs: list, f, op, e, init: dict, *, is_reset=True): dp = init.copy() for x in xs: pp = {} if is_reset else dp.copy() dp, pp = pp, dp for fm_key, fm_val in pp.items(): for to_key, to_val in f(fm_key, fm_val, x): dp[to_key] = op(dp.get(to_key, e), to_val) return dp def f(k, v, x): # 取る nk = (k + x) % 10 yield nk, v+1 # 取らない yield k, v N = int(input()) A = list(map(int, input().split())) init = {0: 0} dp = accum_dp(A, f, max, 0, init) ans = dp.get(0, 0) print(ans)