integer*8::N,i,mod2,tmp,maxvalue,value,total=0 integer*8,allocatable::a(:,:) read *,N allocate(a(1:2,1:N)) read *,a mod2 = MOD(a(1,1),2) maxvalue = a(1,1)+a(2,1)*4 total = maxvalue do i=2, N tmp = MOD(a(1,i),2) if(tmp.ne.mod2) then print '(a)','-1' return end if value = a(1,i) + 4*a(2,i) maxvalue = MAX(value, maxvalue) total = total + value end do print '(i0)', (maxvalue*N-total)/2 end program