#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MOD = 700000;
int main() {
int n;
cin >> n;
vector<int> powerUps(n);
for (int i = 0; i < n; i++) {
cin >> powerUps[i];
}
vector<bool> dp(MOD + 1, false);
dp[0] = true;
for (int i = 0; i < n; i++) {
vector<bool> new_dp(dp);
for (int j = 0; j <= MOD; j++) {
if (dp[j]) {
int new_power = (j + powerUps[i]) % MOD;
new_dp[new_power] = true;
if (new_power == 0) {
new_dp[MOD] = true;
}
}
}
dp = new_dp;
}
int maxPower = 0;
for (int i = 0; i <= MOD; i++) {
if (dp[i]) {
maxPower = max(maxPower, i);
}
}
cout << maxPower << endl;
return 0;
}