n=int(input()) price=[int(input()) for _ in range(n)] INF = 10**9 dp=[INF]*(1<>j)&1: x+=price[j] discount[s]=x for s in range(1<>v)&1==0: x=max(0,price[v]-(discount[s]%1000)) dp[s|(1<