ll@N,@K,@A[N],D[1d6],L,a=0,c;rep(i,N){L=Divisor(A[i],D);rep[D](d,L)a>?=d*(K>=sum[j,0,N](min(A[j]%d,-a%d+d)));}wt(a);