program main use,intrinsic :: iso_fortran_env implicit none integer(int32):: n,n2,s,ns,i,j,f integer(int32), allocatable:: a(:),dp(:) read*, n n2 = lshift(1,n)-1 allocate(a(n)) allocate(dp(0:n2), source=0) read*, a(:) do s=0,n2 do i=1,n-1 if (btest(s,i-1)) cycle do j=i+1,n if (btest(s,j-1)) cycle ns = ibset(ibset(s,i-1),j-1) f = xor(a(i),a(j)) dp(ns) = max(dp(ns), dp(s)+f) end do end do end do print'(i0)', dp(n2) end program main