program meow
implicit none

integer(8) :: i,j,k,n,a(300000),bits(0:300000,50)=0,test(50),ans=0,last_success=0

read(*,*) n
read(*,*) (a(i),i=1,n)

do i= 1,n
	do j= 1,50
		if(BTEST(a(i),j-1)) then
			bits(i,j) = bits(i-1,j) + 1
		else
			bits(i,j) = bits(i-1,j)
		endif
	enddo
enddo

i=1
j=1
do
	do
		test(1:50) = bits(j,1:50) - bits(i-1,1:50)
		if(maxval(test(1:50))<=1) then
!			write(*,*) i,j,"o"
			last_success = 1
			if(j==n) then
				!スコア加算
				ans = ans + (j-i+1)
				if(i==n) then
					goto 100
				else
					i = i+1
				endif
			else
				j=j+1
			endif
		else
!			write(*,*) i,j,"x"
			if(last_success==1) then
				ans = ans + (j-i)
			endif
			i=i+1
		endif
	enddo
enddo

100 continue
write(*,*) ans

end program
; 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 [300000 x i64] undef
@_QFEans = internal unnamed_addr global i64 0
@_QFEbits = internal unnamed_addr global [50 x [300001 x i64]] zeroinitializer
@_QFElast_success = internal unnamed_addr global i1 false
@_QFEtest = internal unnamed_addr global [50 x i64] undef
@_QQcl.3ff642319b05ed3fc8adfb41958e362e = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_5940/source.f\00"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.3ff642319b05ed3fc8adfb41958e362e, i32 6)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 8)
  %6 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %7 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.3ff642319b05ed3fc8adfb41958e362e, i32 7)
  %8 = load i64, ptr %3, align 8, !tbaa !3
  %9 = icmp sgt i64 %8, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %10 = phi i64 [ %14, %.lr.ph ], [ 1, %0 ]
  %11 = add nsw i64 %10, -1
  %12 = getelementptr [300000 x i64], ptr @_QFEa, i64 0, i64 %11
  %13 = call i1 @_FortranAioInputInteger(ptr %7, ptr %12, i32 8)
  %14 = add nuw i64 %10, 1
  %exitcond.not = icmp eq i64 %10, %8
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %0
  %15 = call i32 @_FortranAioEndIoStatement(ptr %7)
  %16 = load i64, ptr %3, align 8, !tbaa !3
  %17 = icmp sgt i64 %16, 0
  br i1 %17, label %.lr.ph31, label %._crit_edge32

.lr.ph31:                                         ; preds = %._crit_edge, %38
  %18 = phi i64 [ %39, %38 ], [ 1, %._crit_edge ]
  %19 = add i64 %18, -1
  %20 = getelementptr [300000 x i64], ptr @_QFEa, i64 0, i64 %19
  %21 = load i64, ptr %20, align 8, !tbaa !3
  br label %22

22:                                               ; preds = %22, %.lr.ph31
  %23 = phi i64 [ 1, %.lr.ph31 ], [ %37, %22 ]
  %24 = add nsw i64 %23, -1
  %sext = shl i64 %24, 32
  %25 = ashr exact i64 %sext, 32
  %26 = getelementptr [50 x [300001 x i64]], ptr @_QFEbits, i64 0, i64 %24, i64 %19
  %27 = load i64, ptr %26, align 8, !tbaa !3
  %28 = lshr i64 %21, %25
  %29 = and i64 %28, 1
  %.sink = add i64 %27, %29
  %30 = getelementptr [50 x [300001 x i64]], ptr @_QFEbits, i64 0, i64 %24, i64 %18
  store i64 %.sink, ptr %30, align 8
  %sext.1 = shl i64 %23, 32
  %31 = ashr exact i64 %sext.1, 32
  %32 = getelementptr [50 x [300001 x i64]], ptr @_QFEbits, i64 0, i64 %23, i64 %19
  %33 = load i64, ptr %32, align 8, !tbaa !3
  %34 = lshr i64 %21, %31
  %35 = and i64 %34, 1
  %.sink.1 = add i64 %33, %35
  %36 = getelementptr [50 x [300001 x i64]], ptr @_QFEbits, i64 0, i64 %23, i64 %18
  store i64 %.sink.1, ptr %36, align 8
  %37 = add nuw nsw i64 %23, 2
  %exitcond42.not.1 = icmp eq i64 %37, 51
  br i1 %exitcond42.not.1, label %38, label %22

38:                                               ; preds = %22
  %39 = add nuw i64 %18, 1
  %exitcond43.not = icmp eq i64 %18, %16
  br i1 %exitcond43.not, label %._crit_edge32, label %.lr.ph31

._crit_edge32:                                    ; preds = %38, %._crit_edge
  store i64 1, ptr %1, align 8, !tbaa !3
  store i64 1, ptr %2, align 8, !tbaa !3
  %_QFElast_success.promoted = load i1, ptr @_QFElast_success, align 1
  %_QFEans.promoted = load i64, ptr @_QFEans, align 8, !tbaa !3
  %40 = add i64 %16, 1
  br label %41

41:                                               ; preds = %.backedge, %._crit_edge32
  %.0..0..0.8 = phi i64 [ %.0..0..0.8.pre, %.backedge ], [ 1, %._crit_edge32 ]
  %.0..0..0. = phi i64 [ %.0..0..0..0..pre, %.backedge ], [ 1, %._crit_edge32 ]
  %42 = phi i64 [ %187, %.backedge ], [ %_QFEans.promoted, %._crit_edge32 ]
  %.b36 = phi i1 [ %.b35, %.backedge ], [ %_QFElast_success.promoted, %._crit_edge32 ]
  %43 = add i64 %.0..0..0.8, -1
  br label %44

44:                                               ; preds = %44, %41
  %45 = phi i64 [ 0, %41 ], [ %56, %44 ]
  %46 = or i64 %45, 1
  %47 = mul nuw nsw i64 %45, 300001
  %48 = add i64 %47, %.0..0..0.
  %49 = getelementptr i64, ptr @_QFEbits, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !3
  %51 = add i64 %43, %47
  %52 = getelementptr i64, ptr @_QFEbits, i64 %51
  %53 = load i64, ptr %52, align 8, !tbaa !3
  %54 = sub i64 %50, %53
  %55 = getelementptr i64, ptr @_QFEtest, i64 %45
  store i64 %54, ptr %55, align 16, !tbaa !3
  %56 = add nuw nsw i64 %45, 2
  %57 = mul nuw nsw i64 %46, 300001
  %58 = add i64 %57, %.0..0..0.
  %59 = getelementptr i64, ptr @_QFEbits, i64 %58
  %60 = load i64, ptr %59, align 8, !tbaa !3
  %61 = add i64 %43, %57
  %62 = getelementptr i64, ptr @_QFEbits, i64 %61
  %63 = load i64, ptr %62, align 8, !tbaa !3
  %64 = sub i64 %60, %63
  %65 = getelementptr i64, ptr @_QFEtest, i64 %46
  store i64 %64, ptr %65, align 8, !tbaa !3
  %exitcond44.not.1 = icmp eq i64 %56, 50
  br i1 %exitcond44.not.1, label %.lr.ph.i.preheader, label %44

.lr.ph.i.preheader:                               ; preds = %44
  %66 = load i64, ptr @_QFEtest, align 16, !tbaa !3
  %67 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 1), align 8, !tbaa !3
  %68 = call i64 @llvm.smax.i64(i64 %67, i64 %66)
  %69 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 2), align 16, !tbaa !3
  %70 = call i64 @llvm.smax.i64(i64 %69, i64 %68)
  %71 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 3), align 8, !tbaa !3
  %72 = call i64 @llvm.smax.i64(i64 %71, i64 %70)
  %73 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 4), align 16, !tbaa !3
  %74 = call i64 @llvm.smax.i64(i64 %73, i64 %72)
  %75 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 5), align 8, !tbaa !3
  %76 = call i64 @llvm.smax.i64(i64 %75, i64 %74)
  %77 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 6), align 16, !tbaa !3
  %78 = call i64 @llvm.smax.i64(i64 %77, i64 %76)
  %79 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 7), align 8, !tbaa !3
  %80 = call i64 @llvm.smax.i64(i64 %79, i64 %78)
  %81 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 8), align 16, !tbaa !3
  %82 = call i64 @llvm.smax.i64(i64 %81, i64 %80)
  %83 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 9), align 8, !tbaa !3
  %84 = call i64 @llvm.smax.i64(i64 %83, i64 %82)
  %85 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 10), align 16, !tbaa !3
  %86 = call i64 @llvm.smax.i64(i64 %85, i64 %84)
  %87 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 11), align 8, !tbaa !3
  %88 = call i64 @llvm.smax.i64(i64 %87, i64 %86)
  %89 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 12), align 16, !tbaa !3
  %90 = call i64 @llvm.smax.i64(i64 %89, i64 %88)
  %91 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 13), align 8, !tbaa !3
  %92 = call i64 @llvm.smax.i64(i64 %91, i64 %90)
  %93 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 14), align 16, !tbaa !3
  %94 = call i64 @llvm.smax.i64(i64 %93, i64 %92)
  %95 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 15), align 8, !tbaa !3
  %96 = call i64 @llvm.smax.i64(i64 %95, i64 %94)
  %97 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 16), align 16, !tbaa !3
  %98 = call i64 @llvm.smax.i64(i64 %97, i64 %96)
  %99 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 17), align 8, !tbaa !3
  %100 = call i64 @llvm.smax.i64(i64 %99, i64 %98)
  %101 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 18), align 16, !tbaa !3
  %102 = call i64 @llvm.smax.i64(i64 %101, i64 %100)
  %103 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 19), align 8, !tbaa !3
  %104 = call i64 @llvm.smax.i64(i64 %103, i64 %102)
  %105 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 20), align 16, !tbaa !3
  %106 = call i64 @llvm.smax.i64(i64 %105, i64 %104)
  %107 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 21), align 8, !tbaa !3
  %108 = call i64 @llvm.smax.i64(i64 %107, i64 %106)
  %109 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 22), align 16, !tbaa !3
  %110 = call i64 @llvm.smax.i64(i64 %109, i64 %108)
  %111 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 23), align 8, !tbaa !3
  %112 = call i64 @llvm.smax.i64(i64 %111, i64 %110)
  %113 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 24), align 16, !tbaa !3
  %114 = call i64 @llvm.smax.i64(i64 %113, i64 %112)
  %115 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 25), align 8, !tbaa !3
  %116 = call i64 @llvm.smax.i64(i64 %115, i64 %114)
  %117 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 26), align 16, !tbaa !3
  %118 = call i64 @llvm.smax.i64(i64 %117, i64 %116)
  %119 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 27), align 8, !tbaa !3
  %120 = call i64 @llvm.smax.i64(i64 %119, i64 %118)
  %121 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 28), align 16, !tbaa !3
  %122 = call i64 @llvm.smax.i64(i64 %121, i64 %120)
  %123 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 29), align 8, !tbaa !3
  %124 = call i64 @llvm.smax.i64(i64 %123, i64 %122)
  %125 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 30), align 16, !tbaa !3
  %126 = call i64 @llvm.smax.i64(i64 %125, i64 %124)
  %127 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 31), align 8, !tbaa !3
  %128 = call i64 @llvm.smax.i64(i64 %127, i64 %126)
  %129 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 32), align 16, !tbaa !3
  %130 = call i64 @llvm.smax.i64(i64 %129, i64 %128)
  %131 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 33), align 8, !tbaa !3
  %132 = call i64 @llvm.smax.i64(i64 %131, i64 %130)
  %133 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 34), align 16, !tbaa !3
  %134 = call i64 @llvm.smax.i64(i64 %133, i64 %132)
  %135 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 35), align 8, !tbaa !3
  %136 = call i64 @llvm.smax.i64(i64 %135, i64 %134)
  %137 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 36), align 16, !tbaa !3
  %138 = call i64 @llvm.smax.i64(i64 %137, i64 %136)
  %139 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 37), align 8, !tbaa !3
  %140 = call i64 @llvm.smax.i64(i64 %139, i64 %138)
  %141 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 38), align 16, !tbaa !3
  %142 = call i64 @llvm.smax.i64(i64 %141, i64 %140)
  %143 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 39), align 8, !tbaa !3
  %144 = call i64 @llvm.smax.i64(i64 %143, i64 %142)
  %145 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 40), align 16, !tbaa !3
  %146 = call i64 @llvm.smax.i64(i64 %145, i64 %144)
  %147 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 41), align 8, !tbaa !3
  %148 = call i64 @llvm.smax.i64(i64 %147, i64 %146)
  %149 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 42), align 16, !tbaa !3
  %150 = call i64 @llvm.smax.i64(i64 %149, i64 %148)
  %151 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 43), align 8, !tbaa !3
  %152 = call i64 @llvm.smax.i64(i64 %151, i64 %150)
  %153 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 44), align 16, !tbaa !3
  %154 = call i64 @llvm.smax.i64(i64 %153, i64 %152)
  %155 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 45), align 8, !tbaa !3
  %156 = call i64 @llvm.smax.i64(i64 %155, i64 %154)
  %157 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 46), align 16, !tbaa !3
  %158 = call i64 @llvm.smax.i64(i64 %157, i64 %156)
  %159 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 47), align 8, !tbaa !3
  %160 = call i64 @llvm.smax.i64(i64 %159, i64 %158)
  %161 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 48), align 16, !tbaa !3
  %162 = call i64 @llvm.smax.i64(i64 %161, i64 %160)
  %163 = load i64, ptr getelementptr inbounds ([50 x i64], ptr @_QFEtest, i64 0, i64 49), align 8, !tbaa !3
  %164 = call i64 @llvm.smax.i64(i64 %163, i64 %162)
  %165 = icmp slt i64 %164, 2
  br i1 %165, label %166, label %182

166:                                              ; preds = %.lr.ph.i.preheader
  %167 = icmp eq i64 %.0..0..0., %16
  br i1 %167, label %168, label %177

168:                                              ; preds = %166
  %169 = sub i64 %40, %.0..0..0.8
  %170 = add i64 %169, %42
  %171 = icmp eq i64 %.0..0..0.8, %16
  br i1 %171, label %172, label %177

172:                                              ; preds = %168
  store i1 true, ptr @_QFElast_success, align 1
  store i64 %170, ptr @_QFEans, align 8, !tbaa !3
  %173 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.3ff642319b05ed3fc8adfb41958e362e, i32 49)
  %174 = load i64, ptr @_QFEans, align 8, !tbaa !3
  %175 = call i1 @_FortranAioOutputInteger64(ptr %173, i64 %174)
  %176 = call i32 @_FortranAioEndIoStatement(ptr %173)
  ret void

177:                                              ; preds = %168, %166
  %178 = phi i64 [ %170, %168 ], [ %42, %166 ]
  %179 = phi ptr [ %1, %168 ], [ %2, %166 ]
  %180 = load i64, ptr %179, align 8, !tbaa !3
  %181 = add i64 %180, 1
  store i64 %181, ptr %179, align 8, !tbaa !3
  %.0..0..0..0.8.pre.pre = load i64, ptr %1, align 8, !tbaa !3
  br label %.backedge

182:                                              ; preds = %.lr.ph.i.preheader
  %183 = sub i64 %.0..0..0., %.0..0..0.8
  %184 = select i1 %.b36, i64 %183, i64 0
  %185 = add i64 %42, %184
  %186 = add i64 %.0..0..0.8, 1
  store i64 %186, ptr %1, align 8, !tbaa !3
  br label %.backedge

.backedge:                                        ; preds = %182, %177
  %.0..0..0.8.pre = phi i64 [ %186, %182 ], [ %.0..0..0..0.8.pre.pre, %177 ]
  %187 = phi i64 [ %185, %182 ], [ %178, %177 ]
  %.b35 = phi i1 [ %.b36, %182 ], [ true, %177 ]
  %.0..0..0..0..pre = load i64, ptr %2, align 8, !tbaa !3
  br label %41
}

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 ptr @_FortranAioBeginExternalListOutput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable 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"}
