module answeroutput
contains
subroutine YNoutput(TF,ch)
  implicit none
  logical,intent(in)::TF
  character,intent(in),optional::ch
  if(present(ch))then
  select case(ch)
    case('Y')
      if(TF)then
        print"(A)","YES"
      else
        print"(A)","NO"
      endif
    case('y')
      if(TF)then
        print"(A)","yes"
      else
        print"(A)","no"
      endif
    case default
      if(TF)then
        print"(A)","Yes"
      else
        print"(A)","No"
      endif
    end select
  else
    if(TF)then
      print"(A)","Yes"
    else
      print"(A)","No"
    endif
  endif
  return
end subroutine
end module
use answeroutput
integer N
integer,allocatable,dimension(:)::A
integer x,y,z
integer xcnt,ycnt,zcnt
logical TF
read*,N
allocate(A(N))
read*,A
x=-1;y=-1;z=-1
xcnt=0;ycnt=0;zcnt=0
do i=1,N
  if((A(i)-x)*(A(i)-y)*(A(i)-z)/=0)then
    if(x==-1)then
      x=A(i)
      xcnt=1
    else if(y==-1)then
      y=A(i)
      ycnt=1
    else if(z==-1)then
      z=A(I)
      zcnt=1
    else
      call YNoutput(1==-1)
      stop
    endif
  else
    if(x==A(i))xcnt=xcnt+1
    if(y==A(i))ycnt=ycnt+1
    if(z==A(i))zcnt=zcnt+1
  endif
end do

TF=.False.
if((xcnt==ycnt.and.ycnt==zcnt).and.xor(xor(x,y),z)==0)TF=.TRUE.
if((x==0.and.xcnt==(N/3)).and.(ycnt==2*xcnt).and.zcnt==0)TF=.TRUE.
if((y==0.and.ycnt==(N/3)).and.(xcnt==2*ycnt).and.zcnt==0)TF=.TRUE.

call YNoutput(TF)
end