# ABC281Dと近い # 2次元dp # dp[i][j] i番目まで見て、j mod 10、の最大枚数 N = int(input()) A = list(map(int, input().split())) INF = 10**10 dp = [[-INF]*10 for i in range(N+1)] dp[0][0] = 0 for i in range(1, N+1): num = A[i-1] for j in range(10): # not using i-th dp[i][j] = max(dp[i][j], dp[i-1][j]) # using i-th dp[i][(j+num)%10] = max(dp[i][(j+num)%10], dp[i-1][j]+1) #print(dp[i]) ans = dp[N][0] print(ans)