import java.util.Arrays; import java.util.Scanner; public class Yuki_528 { int[] data; int totalMoney(int bit) { int total = 0; for (int i = 0; bit >> i > 0; i++) { if (((1 << i) & bit) > 0) { total += data[i]; } } return total; } public Yuki_528() { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); data = new int[N]; for (int i = 0; i < N; i++) { data[i] = scanner.nextInt(); } int[] dp = new int[(1 << N)]; Arrays.fill(dp, Integer.MAX_VALUE); dp[0] = 0; for (int mask = 0; mask < 1 << N; mask++) { for (int i = 0; i < N; i++) { if ((mask & (1 << i)) == 0) { int nextMask = mask | (1 << i); int buy = data[i] - Math.min(data[i], (totalMoney(mask) % 1000)); dp[nextMask] = Math.min(dp[nextMask], buy + dp[mask]); } } } System.out.println(dp[(1 << N) - 1]); } public static void main(String[] args) { Yuki_528 hoge = new Yuki_528(); } }