can   0   3(3+can[0])  6(3+can[1]/6+can[0])  9(3+can[2]/6+can[1])   10(10+can[0])   12(3+can[3]/6+can[2])
3   idx[0]   0  1                    2                                   3                                    3                         4
6   idx[1]   0  0                    1                                   2                                    2                         3
10 idx[2]   0  0                    0                                   0                                    1                         1

/*
ID:qcx97811
LANG:C++
PROG:nuggets
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int n;
int num[16];
int idx[16],total_idx;
int can[2000000];
int cmp(const void *a,const void *b)
{//快速排序从小到大模板
int *c = (int *)a;
int *d = (int *)b;
if(*c > *d)
return 1;
if(*c == *d)
return 0;
return -1;
}
int gcd(int a,int b)
{//公约数
int tmp;
if(a < b)
{
tmp = a;
a = b;
b =tmp;
}
while(b)
{
tmp = a;
a = b;
b = tmp%b;
}
return a;
}
int main(void)
{
freopen("nuggets.in","r",stdin);
freopen("nuggets.out","w",stdout);
int i,j;
int k,tmp;
scanf("%d",&n);
for(i = 0;i < n;i++)
{//scanf
scanf("%d",&num[i]);
}
qsort(num,n,sizeof(num[0]),cmp);//sort the number
if((1 == num[0]) || (1 == n))
{//only one num or an one in the num
printf("0\n");
return 0;
}
else
{
memset(idx,0,sizeof(idx));
memset(can,0,sizeof(can));
if(2 == n)
{//2个数的话可以直接算出来
if(1 == gcd(num[0],num[1]))
{//如果互素的话
printf("%d\n",num[0]*num[1]-num[0]-num[1]);
return 0;
}
else
{//不互素 肯定无
printf("0\n");
return 0;
}
}
tmp = num[1] - num[0];
for(i = 2;i < n;i++)
{//看是否为等差数列
if(num[i]-num[i-1] != tmp)
break;
}
if(i == n)
{//如果是等差数列的话 也不可能有
printf("0\n");
return 0;
}
can[0] = 0;
total_idx = 0;
for(i = num[0];i < 2000000;i++ )
{//下标是为了不超过内存16M 同时最大
j = 0;
for(k = 1;k < n;k++)
{//增大能表示的数
if(num[k]+can[idx[k]]<num[j]+can[idx[j]])
j = k;
}
tmp = num[j]+can[idx[j]];
can[++total_idx] = tmp;
if(total_idx > num[0]-1 && (can[total_idx]-can[total_idx-num[0]+1] == num[0]-1))
{//如果已经找到最大数,因为后面的数都连续了
tmp = total_idx-num[0]+1;
while(can[tmp] - can[tmp-1] == 1)
{//寻找最大的数
tmp--
}
printf("%d\n",can[tmp]-1);//输出最大数
return 0;
}
for(k = 0;k < n;k++)
{//改变相应的下标
if(num[k]+can[idx[k]] == tmp)
idx[k]++;
}
}
//            for(i = 0;i <= total_idx;i++)
//              printf("%d\n",can[i]);
printf("0\n");
}
return 0;
}