program ABC140B
    implicit none
    integer::N,i,ans=0
    integer,allocatable::A(:),B(:),C(:)
    read*,N
    allocate(A(N))
    allocate(B(N))
    allocate(C(N-1))
    read*,A,B,C
    do i=1,N
        ans=ans+B(A(i))
        if(i>=2.and.A(i)-A(i-1)==1)ans=ans+C(A(i-1))
    end do
    print'(i0)',ans
end program ABC140B
; 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.0 = internal unnamed_addr global ptr null
@_QFEa.8 = internal unnamed_addr global i64 0
@_QFEans = internal unnamed_addr global i32 0
@_QFEb.0 = internal unnamed_addr global ptr null
@_QFEb.8 = internal unnamed_addr global i64 0
@_QFEc.0 = internal unnamed_addr global ptr null
@_QFEc.8 = internal unnamed_addr global i64 0
@_QQcl.662fc7a1ae9d6b003d69ef641b019c31 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_3293/source.f\00"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

define void @_QQmain() local_unnamed_addr {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %3 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %4 = alloca i32, align 4
  %5 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.662fc7a1ae9d6b003d69ef641b019c31, i32 5)
  %6 = call i1 @_FortranAioInputInteger(ptr %5, ptr nonnull %4, i32 4)
  %7 = call i32 @_FortranAioEndIoStatement(ptr %5)
  %8 = load i32, ptr %4, align 4, !tbaa !3
  %9 = call i32 @llvm.smax.i32(i32 %8, i32 0)
  %10 = zext i32 %9 to i64
  %11 = shl nuw nsw i64 %10, 2
  %12 = call ptr @malloc(i64 %11)
  store ptr %12, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 %10, ptr @_QFEa.8, align 8, !tbaa !7
  %13 = call ptr @malloc(i64 %11)
  store ptr %13, ptr @_QFEb.0, align 8, !tbaa !7
  store i64 %10, ptr @_QFEb.8, align 8, !tbaa !7
  %14 = add i32 %8, -1
  %15 = call i32 @llvm.smax.i32(i32 %14, i32 0)
  %16 = zext i32 %15 to i64
  %17 = shl nuw nsw i64 %16, 2
  %18 = call ptr @malloc(i64 %17)
  store ptr %18, ptr @_QFEc.0, align 8, !tbaa !7
  store i64 %16, ptr @_QFEc.8, align 8, !tbaa !7
  %19 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.662fc7a1ae9d6b003d69ef641b019c31, i32 9)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack404.unpack.unpack406 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  store ptr %.unpack, ptr %3, align 8, !tbaa !7
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %3, i64 0, i32 1
  store i64 4, 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 %3, 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 %3, 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 %3, i64 0, i32 4
  store i8 9, 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 %3, 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 %3, 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 %3, 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 %3, i64 0, i32 7, i64 0, i64 1
  store i64 %.unpack404.unpack.unpack406, 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 %3, i64 0, i32 7, i64 0, i64 2
  store i64 4, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %20 = call i1 @_FortranAioInputDescriptor(ptr %19, ptr nonnull %3)
  %.unpack409 = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  %.unpack416.unpack.unpack418 = load i64, ptr @_QFEb.8, align 8, !tbaa !7
  store ptr %.unpack409, ptr %2, align 8, !tbaa !7
  %.fca.1.gep154 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 1
  store i64 4, ptr %.fca.1.gep154, align 8, !tbaa !7
  %.fca.2.gep156 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep156, align 8, !tbaa !7
  %.fca.3.gep158 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 3
  store i8 1, ptr %.fca.3.gep158, align 4, !tbaa !7
  %.fca.4.gep160 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 4
  store i8 9, ptr %.fca.4.gep160, align 1, !tbaa !7
  %.fca.5.gep162 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep162, align 2, !tbaa !7
  %.fca.6.gep164 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep164, align 1, !tbaa !7
  %.fca.7.0.0.gep166 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 7, i64 0, i64 0
  store i64 1, ptr %.fca.7.0.0.gep166, align 8, !tbaa !7
  %.fca.7.0.1.gep168 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 7, i64 0, i64 1
  store i64 %.unpack416.unpack.unpack418, ptr %.fca.7.0.1.gep168, align 8, !tbaa !7
  %.fca.7.0.2.gep170 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, i64 0, i32 7, i64 0, i64 2
  store i64 4, ptr %.fca.7.0.2.gep170, align 8, !tbaa !7
  %21 = call i1 @_FortranAioInputDescriptor(ptr %19, ptr nonnull %2)
  %.unpack421 = load ptr, ptr @_QFEc.0, align 8, !tbaa !7
  %.unpack428.unpack.unpack430 = load i64, ptr @_QFEc.8, align 8, !tbaa !7
  store ptr %.unpack421, ptr %1, align 8, !tbaa !7
  %.fca.1.gep204 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 1
  store i64 4, ptr %.fca.1.gep204, align 8, !tbaa !7
  %.fca.2.gep206 = 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.gep206, align 8, !tbaa !7
  %.fca.3.gep208 = 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.gep208, align 4, !tbaa !7
  %.fca.4.gep210 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 4
  store i8 9, ptr %.fca.4.gep210, align 1, !tbaa !7
  %.fca.5.gep212 = 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.gep212, align 2, !tbaa !7
  %.fca.6.gep214 = 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.gep214, align 1, !tbaa !7
  %.fca.7.0.0.gep216 = 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.gep216, align 8, !tbaa !7
  %.fca.7.0.1.gep218 = 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 %.unpack428.unpack.unpack430, ptr %.fca.7.0.1.gep218, align 8, !tbaa !7
  %.fca.7.0.2.gep220 = 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 4, ptr %.fca.7.0.2.gep220, align 8, !tbaa !7
  %22 = call i1 @_FortranAioInputDescriptor(ptr %19, ptr nonnull %1)
  %23 = call i32 @_FortranAioEndIoStatement(ptr %19)
  %24 = load i32, ptr %4, align 4, !tbaa !3
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %.lr.ph, label %52

.lr.ph:                                           ; preds = %0
  %26 = zext i32 %24 to i64
  %_QFEans.promoted = load i32, ptr @_QFEans, align 4, !tbaa !3
  %.unpack433 = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  %.unpack445 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack469 = load ptr, ptr @_QFEc.0, align 8
  br label %27

27:                                               ; preds = %.lr.ph, %50
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %50 ]
  %28 = phi i32 [ %_QFEans.promoted, %.lr.ph ], [ %51, %50 ]
  %29 = add nsw i64 %indvars.iv, -1
  %30 = getelementptr i32, ptr %.unpack445, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !3
  %32 = sext i32 %31 to i64
  %33 = add nsw i64 %32, -1
  %34 = getelementptr i32, ptr %.unpack433, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !3
  %36 = add i32 %35, %28
  %37 = icmp ugt i64 %indvars.iv, 1
  %38 = add nsw i64 %indvars.iv, -2
  %39 = getelementptr i32, ptr %.unpack445, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !3
  %41 = sub i32 %31, %40
  %42 = icmp eq i32 %41, 1
  %43 = and i1 %37, %42
  br i1 %43, label %44, label %50

44:                                               ; preds = %27
  %45 = sext i32 %40 to i64
  %46 = add nsw i64 %45, -1
  %47 = getelementptr i32, ptr %.unpack469, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !3
  %49 = add i32 %48, %36
  br label %50

50:                                               ; preds = %44, %27
  %51 = phi i32 [ %49, %44 ], [ %36, %27 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv, %26
  br i1 %exitcond.not, label %._crit_edge, label %27

._crit_edge:                                      ; preds = %50
  store i32 %51, ptr @_QFEans, align 4, !tbaa !3
  br label %52

52:                                               ; preds = %._crit_edge, %0
  %53 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.662fc7a1ae9d6b003d69ef641b019c31, i32 14)
  %54 = load i32, ptr @_QFEans, align 4, !tbaa !3
  %55 = call i1 @_FortranAioOutputInteger32(ptr %53, i32 %54)
  %56 = call i32 @_FortranAioEndIoStatement(ptr %53)
  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

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

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { 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"}
!7 = !{!8, !8, i64 0}
!8 = !{!"descriptor member", !5, i64 0}
