N = int(input()) M = [int(input()) for _ in range(N)] dp = [10**18]*(1<>i)&1: c += M[i] bonus = c%1000 for i in range(N): if not (S>>i)&1: dp[S|(1<