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