program unfair_nim
  implicit none
  integer :: n, i
  integer(8) :: a(300) = 0, s, x = 0, d, y = 0
  read(*,*) n
  read(*,*) a(1:n)
  s = a(1) + a(2)
  do i = 3, n
    x = xor(x, a(i))
  end do
  if (s - x < 0 .or. mod(s - x, 2) /= 0) then
    write(*,'(i0)') -1
    stop
  end if
  d = (s - x) / 2
  if (and(d, x) /= 0 .or. d > a(1)) then
    write(*,'(i0)') -1
    stop
  end if
  do i = 62, 0, -1
    if (.not.btest(x, i)) cycle
    y = ibset(y, i)
    if (xor(d, y) > a(1)) y = ibclr(y, i)
  end do
  write(*,'(i0)') merge(-1_8, a(1) - xor(d, y), xor(d, y) == 0)
end program unfair_nim
; ModuleID = 'FIRModule'
source_filename = "FIRModule"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

@_QFEa = internal global [300 x i64] zeroinitializer
@_QFEx = internal unnamed_addr global i64 0
@_QFEy = internal unnamed_addr global i64 0
@_QQcl.73dab905498bf64a3bdbf9dc22116c37 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_1094/source.f\00"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca i32, align 4
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.73dab905498bf64a3bdbf9dc22116c37, i32 5)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 4)
  %5 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %6 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.73dab905498bf64a3bdbf9dc22116c37, i32 6)
  %7 = load i32, ptr %2, align 4, !tbaa !3
  %8 = call i32 @llvm.smax.i32(i32 %7, i32 0)
  %9 = zext i32 %8 to i64
  store ptr @_QFEa, ptr %1, align 8, !tbaa !7
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 1
  store i64 8, ptr %.fca.1.gep, align 8, !tbaa !7
  %.fca.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep, align 8, !tbaa !7
  %.fca.3.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 3
  store i8 1, ptr %.fca.3.gep, align 4, !tbaa !7
  %.fca.4.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 4
  store i8 10, ptr %.fca.4.gep, align 1, !tbaa !7
  %.fca.5.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep, align 2, !tbaa !7
  %.fca.6.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep, align 1, !tbaa !7
  %.fca.7.0.0.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 0
  store i64 1, ptr %.fca.7.0.0.gep, align 8, !tbaa !7
  %.fca.7.0.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 1
  store i64 %9, ptr %.fca.7.0.1.gep, align 8, !tbaa !7
  %.fca.7.0.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 2
  store i64 8, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %10 = call i1 @_FortranAioInputDescriptor(ptr %6, ptr nonnull %1)
  %11 = call i32 @_FortranAioEndIoStatement(ptr %6)
  %12 = load i64, ptr @_QFEa, align 16, !tbaa !3
  %13 = load i64, ptr getelementptr inbounds ([300 x i64], ptr @_QFEa, i64 0, i64 1), align 8, !tbaa !3
  %14 = add i64 %13, %12
  %15 = load i32, ptr %2, align 4, !tbaa !3
  %_QFEx.promoted = load i64, ptr @_QFEx, align 8, !tbaa !3
  %16 = icmp sgt i32 %15, 2
  br i1 %16, label %.lr.ph.preheader, label %32

.lr.ph.preheader:                                 ; preds = %0
  %17 = zext i32 %15 to i64
  %18 = add nsw i64 %17, -2
  %min.iters.check = icmp ult i64 %18, 4
  br i1 %min.iters.check, label %.lr.ph.preheader20, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %18, -4
  %ind.end = or i64 %18, 3
  %19 = insertelement <2 x i64> <i64 poison, i64 0>, i64 %_QFEx.promoted, i64 0
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i64> [ %19, %vector.ph ], [ %23, %vector.body ]
  %vec.phi18 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %24, %vector.body ]
  %20 = or i64 %index, 2
  %21 = getelementptr [300 x i64], ptr @_QFEa, i64 0, i64 %20
  %wide.load = load <2 x i64>, ptr %21, align 16, !tbaa !3
  %22 = getelementptr i64, ptr %21, i64 2
  %wide.load19 = load <2 x i64>, ptr %22, align 16, !tbaa !3
  %23 = xor <2 x i64> %wide.load, %vec.phi
  %24 = xor <2 x i64> %wide.load19, %vec.phi18
  %index.next = add nuw i64 %index, 4
  %25 = icmp eq i64 %index.next, %n.vec
  br i1 %25, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = xor <2 x i64> %24, %23
  %26 = call i64 @llvm.vector.reduce.xor.v2i64(<2 x i64> %bin.rdx)
  %cmp.n = icmp eq i64 %18, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader20

.lr.ph.preheader20:                               ; preds = %.lr.ph.preheader, %middle.block
  %indvars.iv.ph = phi i64 [ 3, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %.ph = phi i64 [ %_QFEx.promoted, %.lr.ph.preheader ], [ %26, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader20, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader20 ]
  %27 = phi i64 [ %31, %.lr.ph ], [ %.ph, %.lr.ph.preheader20 ]
  %28 = add nsw i64 %indvars.iv, -1
  %29 = getelementptr [300 x i64], ptr @_QFEa, i64 0, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !3
  %31 = xor i64 %30, %27
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv, %17
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %middle.block
  %.lcssa = phi i64 [ %26, %middle.block ], [ %31, %.lr.ph ]
  store i64 %.lcssa, ptr @_QFEx, align 8, !tbaa !3
  br label %32

32:                                               ; preds = %._crit_edge, %0
  %33 = phi i64 [ %.lcssa, %._crit_edge ], [ %_QFEx.promoted, %0 ]
  %34 = sub i64 %14, %33
  %35 = and i64 %34, -9223372036854775807
  %.not = icmp eq i64 %35, 0
  br i1 %.not, label %41, label %36

36:                                               ; preds = %32
  %37 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.73dab905498bf64a3bdbf9dc22116c37, i32 12)
  %38 = call i1 @_FortranAioOutputInteger32(ptr %37, i32 -1)
  %39 = call i32 @_FortranAioEndIoStatement(ptr %37)
  %40 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable

41:                                               ; preds = %32
  %42 = lshr i64 %34, 1
  %43 = and i64 %42, %33
  %44 = icmp ne i64 %43, 0
  %45 = icmp sgt i64 %42, %12
  %46 = or i1 %45, %44
  br i1 %46, label %47, label %.preheader

.preheader:                                       ; preds = %41
  %_QFEy.promoted = load i64, ptr @_QFEy, align 8, !tbaa !3
  br label %52

47:                                               ; preds = %41
  %48 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.73dab905498bf64a3bdbf9dc22116c37, i32 17)
  %49 = call i1 @_FortranAioOutputInteger32(ptr %48, i32 -1)
  %50 = call i32 @_FortranAioEndIoStatement(ptr %48)
  %51 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable

52:                                               ; preds = %.preheader, %64
  %indvars.iv15 = phi i64 [ 62, %.preheader ], [ %indvars.iv.next16, %64 ]
  %53 = phi i64 [ 63, %.preheader ], [ %66, %64 ]
  %54 = phi i64 [ %_QFEy.promoted, %.preheader ], [ %65, %64 ]
  %55 = shl nuw i64 1, %indvars.iv15
  %56 = and i64 %55, %33
  %.not13 = icmp eq i64 %56, 0
  br i1 %.not13, label %64, label %57

57:                                               ; preds = %52
  %58 = or i64 %54, %55
  store i64 %58, ptr @_QFEy, align 8, !tbaa !3
  %59 = xor i64 %58, %42
  %60 = icmp sgt i64 %59, %12
  br i1 %60, label %61, label %64

61:                                               ; preds = %57
  %62 = xor i64 %55, -1
  %63 = and i64 %54, %62
  store i64 %63, ptr @_QFEy, align 8, !tbaa !3
  br label %64

64:                                               ; preds = %61, %57, %52
  %65 = phi i64 [ %63, %61 ], [ %58, %57 ], [ %54, %52 ]
  %indvars.iv.next16 = add nsw i64 %indvars.iv15, -1
  %66 = add nsw i64 %53, -1
  %67 = icmp ugt i64 %53, 1
  br i1 %67, label %52, label %68

68:                                               ; preds = %64
  %69 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.73dab905498bf64a3bdbf9dc22116c37, i32 25)
  %70 = load i64, ptr @_QFEa, align 16, !tbaa !3
  %71 = load i64, ptr @_QFEy, align 8, !tbaa !3
  %72 = xor i64 %71, %42
  %73 = sub i64 %70, %72
  %74 = icmp eq i64 %72, 0
  %75 = select i1 %74, i64 -1, i64 %73
  %76 = call i1 @_FortranAioOutputInteger64(ptr %69, i64 %75)
  %77 = call i32 @_FortranAioEndIoStatement(ptr %69)
  ret void
}

declare ptr @_FortranAioBeginExternalListInput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioInputInteger(ptr, ptr, i32) local_unnamed_addr

declare i32 @_FortranAioEndIoStatement(ptr) local_unnamed_addr

declare i1 @_FortranAioInputDescriptor(ptr, ptr) local_unnamed_addr

declare ptr @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

declare {} @_FortranAStopStatement(i32, i1, i1) local_unnamed_addr

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.vector.reduce.xor.v2i64(<2 x i64>) #1

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) }

!llvm.module.flags = !{!0, !1, !2}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{!4, !4, i64 0}
!4 = !{!"any data access", !5, i64 0}
!5 = !{!"any access", !6, i64 0}
!6 = !{!"Flang Type TBAA Root"}
!7 = !{!8, !8, i64 0}
!8 = !{!"descriptor member", !5, i64 0}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = distinct !{!12, !11, !10}
