program pr3
  implicit none
  character(len=4) :: charn
  character(len=1) :: charop(3)
  integer :: a(4), i, b(4), n
  
  read(*,*) charn
  do i = 1, 4
     read(charn(i:i),*) a(i)
  end do
  b(1) = 1
  do i = 0, 7
     call dectoopr(i,b(2:4))
     if ( dot_product(a,b) == 7 ) then
        call opr(b(2:4),charop)
        write(*,'(i1,a,i1,a,i1,a,i1,a)') a(1),charop(1),a(2),charop(2),a(3),charop(3),a(4),'=7'
     end if
  end do
  
  stop
contains
  subroutine dectoopr(n,b)
    implicit none
    integer :: n, b(3)
    select case(n)
    case(0)
       b = (/-1,-1,-1/)
    case(1)
       b = (/-1,-1,1/)
    case(2)
       b = (/-1,1,-1/)
    case(3)
       b = (/-1,1,1/)
    case(4)
       b = (/1,-1,-1/)
    case(5)
       b = (/1,-1,1/)
    case(6)
       b = (/1,1,-1/)
    case(7)
       b = (/1,1,1/)
    case default
       stop
    end select
    return
  end subroutine dectoopr


  subroutine opr(b,charop)
    implicit none
    integer :: b(3)
    character(len=1) :: charop(3)
    integer :: i
    do i = 1, 3
       if ( b(i) == 1 ) then
          charop(i) = '+'
       else
          charop(i) = '-'
       end if
    end do
    return
  end subroutine opr
end program pr3
