      program replicate

      double precision a(10,10,10), ra(5,5,5), x
      integer i, j, n

cmf$  layout ra(:serial)

      forall (i=1:10,j=1:10,k=1:10) a(i,j,k) = i + 2*j - k

      ra = 0
      ra = a(4:8,2:6,5:9)

      n = 0
      do i = 4, 8
        do j = 2, 6
          do k = 5,9
            n = n + i + 2*j - k
          end do
        end do
      end do

      x = sum (ra)
      print *, 'Result is ', x, ' should be ', n

      end
