PROGRAM main
    USE double
    USE mpi
    IMPLICIT NONE
    INTEGER, PARAMETER :: procs = 4, root = 0
    INTEGER :: nprocs, myrank, count, n, error

    CALL MPI_Init(error)
    CALL MPI_Comm_size(MPI_COMM_WORLD,nprocs,error)
    CALL MPI_Comm_rank(MPI_COMM_WORLD,myrank,error)
    IF (nprocs /= procs) THEN
        PRINT *, 'Invalid number of processes'
        CALL MPI_Abort(MPI_COMM_WORLD,1,error)
    END IF
    IF (myrank == root) THEN
        READ (*,*) count
        IF (count < 1 .OR. count > 1000000) THEN
            WRITE (*,*) "Invalid count specified"
            STOP 1
        END IF
    END IF
    CALL MPI_Bcast(count,1,MPI_INTEGER,MPI_COMM_WORLD,root,error)

    DO n = 1,count
        WRITE (*,"('Process ',I0,' line ',I0)") myrank, n
    END DO
    CALL MPI_Finalize(error)

END PROGRAM main
