program main
  use, intrinsic :: iso_fortran_env
  implicit none
  integer, parameter :: n = 100
  integer :: i, s[*]
  real :: a(n)[*]
  type (team_type) :: odd_even
  form team (mod(this_image(), 2) + 1, odd_even)
  change team (odd_even)
    select case (team_number())
    case (1)
      s = this_image()
      sync all
      if (this_image() == 1) then
        do i = 2, num_images()
          s = s + s[i]
        end do
        print *, "The sum of integers from 1 to", num_images(), "is", s
      end if
    case (2)
      call random_number(a)
      sync all
      if (this_image() == 1) then
        do i = 2, num_images()
          a = a + a(:)[i]
        end do
       print *, "Mean :", sum(a) / (n * num_images())
      end if
    end select
  end team
end program
