module mdl contains recursive subroutine qsort(a,s,t) integer*8::a(:),s,t,i,j,m if(t-s<=1)return i=s j=t-1 m=a((s+t)/2) do do while(a(i)m) j=j-1 end do if(i>=j)exit a(i)=xor(a(i),a(j)) a(j)=xor(a(i),a(j)) a(i)=xor(a(i),a(j)) i=i+1 j=j-1 end do call qsort(a,s,i) call qsort(a,j+1,t) end subroutine end module program main use mdl implicit none integer*8::B,C,D,N,i,j,k,p,ans=0,arr(3),a(3) integer*8,allocatable::E(:) read(*,*)B,C,D a(1)=B a(2)=C a(3)=D call qsort(a,1_8,4_8) read*,N allocate(E(N)) read*,(E(i),i=1,N) call qsort(E,int(1,8),int(size(E)+1,8)) do i=1,lshift(1,N)-1 if(popcnt(i)<3)cycle p=1 do j=N-1,0,-1 if(mod(rshift(i,j),2)==1)then arr(p)=E(j+1) p=p+1 end if if(p==4)exit end do if(a(1)<=arr(3).and.a(2)<=arr(2).and.a(3)<=arr(1))ans=ans+1 end do print*,ans end program