module fast_prime_sieve
  implicit none
contains
  subroutine primes(p, m, n)
    integer, allocatable, intent(inout) :: p(:)
    integer, intent(inout) :: m
    integer, intent(in) :: n
    integer :: lp(n), pr(n), i, j
    lp(n) = 0
    m = 0
    do i = 2, n
      if (lp(i) == 0) then
        lp(i) = i
        m = m + 1
        pr(m) = i
      end if
      j = 1
      do j = 1, m
        if (pr(j) > lp(i) .or. i * pr(j) > n) exit
        lp(i * pr(j)) = pr(j)
      end do
    end do
    allocate(p(m))
    p = pr(1:m)
  end
end module fast_prime_sieve
program coprime
  use fast_prime_sieve
  implicit none
  integer :: n, m, i, j
  integer, allocatable :: a(:), b(:), p(:)
  character(8), parameter :: x = 'pairwise', y = 'setwise ', z = 'not     '
  read(*,*) n
  allocate(a(n))
  read(*,*) a
  call primes(p, m, maxval(a(1:n)))
  allocate(b(m))
  b = 0
  do i = 1, n
    do j = 1, m
      if (p(j) > a(i)) exit
      if (mod(a(i), p(j)) == 0) b(j) = b(j) + 1
    end do
  end do
  write(*,'(a)') trim(merge(x, merge(y, z, all(b < n)), all(b < 2))) // ' coprime'
end program coprime