integer N,K
integer,allocatable,dimension(:)::A
integer Asum,hantei,plus,minus
read*,N,K
allocate(A(N))
read*,A
Asum=sum(A)
do j=Asum,1,-1
  if(mod(Asum,j)==0)then
    hantei=0;plus=0;minus=0
    do i=1,N
      if(plus+mod(j-mod(A(i),j),j)>=minus+mod(A(i),j))then
        minus=minus+mod(A(i),j)
      else
        plus=plus+mod(j-mod(A(i),j),j)
      endif
    end do
    if(min(minus,plus)+abs(minus-plus)<=K)then
      print"(i0)",j
      stop
    endif
  endif
end do
end