program DoubleBooking integer,allocatable,dimension(:)::R integer::P1,P2,N,k,sum,X sum=0 read(*,*)P1,P2 read(*,*)N allocate(R(N)) read(*,*)R(:) do X=1,999 if(count(X==R(:))<2) cycle sum=sum+count(X==R(:))-1 end do write(*,*)sum*(P1+P2) end program DoubleBooking