import sys, time, random from collections import deque, Counter, defaultdict import logging from logging import debug, error, info, warning logging.basicConfig(level=logging.DEBUG) input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 61 - 1 mod = 998244353 n = ii() a = li() a.sort() dp = [[[-inf] * 7001 for _ in range(n + 1)] for _ in range(2)] dp[0][0][0] = 0 for i in range(n): for j in range(7001): dp[0][i + 1][j] = max(dp[0][i + 1][j], dp[0][i][j] + a[i]) dp[1][i + 1][j] = max(dp[1][i + 1][j], dp[1][i][j] + a[i]) dp[1][i + 1][abs(j - a[i])] = max(dp[1][i + 1][abs(j - a[i])], dp[1][i][j]) dp[1][i + 1][abs(j - a[i])] = max(dp[1][i + 1][abs(j - a[i])], dp[0][i][j]) if j + a[i] <= 7000: dp[1][i + 1][j + a[i]] = max(dp[1][i + 1][j + a[i]], dp[1][i][j]) dp[1][i + 1][j + a[i]] = max(dp[1][i + 1][j + a[i]], dp[0][i][j]) print(-1 if dp[1][n][0] <= 0 else dp[1][n][0])