Problem:
Score : 200 points

Problem Statement

Snuke has N integers. Among them, the smallest is A, and the largest is B.
We are interested in the sum of those N integers. How many different possible sums there are?

Constraints

1 ≤ N,A,B ≤ 10^9

A and B are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the number of the different possible sums.

Sample Input 1

4 4 6

Sample Output 1

5

There are five possible sums: 18=4+4+4+6, 19=4+4+5+6, 20=4+5+5+6, 21=4+5+6+6 and 22=4+6+6+6.

Sample Input 2

5 4 3

Sample Output 2

0

Sample Input 3

1 7 10

Sample Output 3

0

Sample Input 4

1 3 3

Sample Output 4

1

Solution in Fortran (gfortran v4.8.4) (judge verdict: Runtime Error)

program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,k,i,nk,ans
    integer(int32), allocatable:: a(:), cnt(:), num(:)

    read*, n,k
    allocate(a(n))
    read*, a(:)
    allocate(cnt(maxval(a)), source=0)

    do i=1,n
        cnt(a(i))=cnt(a(i))+1
    end do
    deallocate(a)

    nk=0
    do i=1,size(cnt)
        if (cnt(i) /= 0) nk=nk+1
    end do

    allocate(num(nk))
    nk=0

    do i=1,size(cnt)
        if (cnt(i) /= 0) then
            nk=nk+1
            num(nk)=cnt(i)
        end if
    end do
    deallocate(cnt)
    call merge_sort(num,1,nk)
    ans=0
    i=0
    do while (nk-i > k)
        i=i+1
        ans=ans+num(i)
    end do
    print'(i0)',ans
contains
    recursive subroutine merge_sort(ar, fst, lst)
        integer(4),intent(inout):: ar(:)
        integer(4),intent(in):: fst,lst
        integer(4):: mdl

        if (lst-fst < 2) then
            if (ar(fst) > ar(lst)) call swap(ar(fst),ar(lst))
            return
        end if

        mdl = (fst+lst)/2
        call merge_sort(ar, fst, mdl)
        call merge_sort(ar, mdl+1, lst)
        call merge_(ar, fst, mdl, lst)
    end subroutine

    subroutine merge_(ar, fst, mdl, lst)
        integer(4),intent(inout):: ar(:)
        integer(4),intent(in):: fst, mdl, lst
        integer(4),allocatable:: tmp(:)
        integer(4):: li, ri, ti

        allocate(tmp(lst-fst+1))

        li=fst
        ri=mdl+1   
        ti=1

        do while (li <= mdl .and. ri <= lst)
            if (ar(li) <= ar(ri)) then
                tmp(ti) = ar(li)
                li=li+1
            else
                tmp(ti) = ar(ri)
                ri=ri+1
            end if
            ti=ti+1
        end do

        if (li <= mdl) then
            tmp(ti:) = ar(li:mdl)
        else
            tmp(ti:) = ar(ri:lst)
        end if

        ar(fst:lst) = tmp(:)
        deallocate(tmp)
    end subroutine

    subroutine swap(x,y)
        integer(4),intent(inout):: x,y
        integer(4):: tmp
        tmp = x
        x = y
        y = tmp
    end subroutine
end program name