N = int(input()) A = list(map(int, input().split())) inf = 10 ** 18 pre = [-inf] * 10 pre[0] = 0 for i in range(N): dp = [-inf] * 10 for j in range(10): dp[j] = max(dp[j], pre[j]) dp[(j + A[i])%10] = max(dp[(j + A[i])%10], pre[j] + 1) dp, pre = pre, dp print(pre[0])