      program answer
        implicit none
        integer :: i,N
        integer,allocatable,dimension(:) :: A,B,C
        integer :: ans
        ans = 0
        read(*,*) N
        allocate(A(N),B(N),C(N))
        read(*,*) (A(i),i=1,N)
        read(*,*) (B(i),i=1,N)
        read(*,*) (C(i),i=1,N-1)
        do i=1,N
          ans = ans + B(A(i))
          if(i .gt. 1) then
            if((A(i-1)+1) == A(i)) then
              ans = ans + C(A(i-1))
            end if
          end if
        end do
        write(*,'(I0)') ans
        stop
      end program answer

; 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
@_QFEb.0 = internal unnamed_addr global ptr null
@_QFEc.0 = internal unnamed_addr global ptr null
@_QQcl.9eb8f450cf087e88e8116d20caa6b5a1 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_3302/source.f\00"
@_QQcl.28493029 = 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

; Function Attrs: noreturn
define void @_QQmain() local_unnamed_addr #1 {
  %1 = alloca i32, align 4
  %2 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.9eb8f450cf087e88e8116d20caa6b5a1, i32 7)
  %3 = call i1 @_FortranAioInputInteger(ptr %2, ptr nonnull %1, i32 4)
  %4 = call i32 @_FortranAioEndIoStatement(ptr %2)
  %5 = load i32, ptr %1, align 4, !tbaa !3
  %6 = call i32 @llvm.smax.i32(i32 %5, i32 0)
  %7 = zext i32 %6 to i64
  %8 = shl nuw nsw i64 %7, 2
  %9 = call ptr @malloc(i64 %8)
  store ptr %9, ptr @_QFEa.0, align 8, !tbaa !7
  %10 = call ptr @malloc(i64 %8)
  store ptr %10, ptr @_QFEb.0, align 8, !tbaa !7
  %11 = call ptr @malloc(i64 %8)
  store ptr %11, ptr @_QFEc.0, align 8, !tbaa !7
  %12 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.9eb8f450cf087e88e8116d20caa6b5a1, i32 9)
  %13 = load i32, ptr %1, align 4, !tbaa !3
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %15 = zext i32 %13 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %16 = phi i64 [ %21, %.lr.ph ], [ 1, %.lr.ph.preheader ]
  %.unpack350 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %sext362 = shl i64 %16, 32
  %17 = ashr exact i64 %sext362, 32
  %18 = add nsw i64 %17, -1
  %19 = getelementptr i32, ptr %.unpack350, i64 %18
  %20 = call i1 @_FortranAioInputInteger(ptr %12, ptr %19, i32 4)
  %21 = add nuw nsw i64 %16, 1
  %exitcond.not = icmp eq i64 %16, %15
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %0
  %22 = call i32 @_FortranAioEndIoStatement(ptr %12)
  %23 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.9eb8f450cf087e88e8116d20caa6b5a1, i32 10)
  %24 = load i32, ptr %1, align 4, !tbaa !3
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %.lr.ph364.preheader, label %._crit_edge365

.lr.ph364.preheader:                              ; preds = %._crit_edge
  %26 = zext i32 %24 to i64
  br label %.lr.ph364

.lr.ph364:                                        ; preds = %.lr.ph364.preheader, %.lr.ph364
  %27 = phi i64 [ %32, %.lr.ph364 ], [ 1, %.lr.ph364.preheader ]
  %.unpack337 = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  %sext349 = shl i64 %27, 32
  %28 = ashr exact i64 %sext349, 32
  %29 = add nsw i64 %28, -1
  %30 = getelementptr i32, ptr %.unpack337, i64 %29
  %31 = call i1 @_FortranAioInputInteger(ptr %23, ptr %30, i32 4)
  %32 = add nuw nsw i64 %27, 1
  %exitcond373.not = icmp eq i64 %27, %26
  br i1 %exitcond373.not, label %._crit_edge365, label %.lr.ph364

._crit_edge365:                                   ; preds = %.lr.ph364, %._crit_edge
  %33 = call i32 @_FortranAioEndIoStatement(ptr %23)
  %34 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.9eb8f450cf087e88e8116d20caa6b5a1, i32 11)
  %35 = load i32, ptr %1, align 4, !tbaa !3
  %36 = add i32 %35, -1
  %37 = icmp sgt i32 %36, 0
  br i1 %37, label %.lr.ph367.preheader, label %._crit_edge368

.lr.ph367.preheader:                              ; preds = %._crit_edge365
  %38 = zext i32 %36 to i64
  br label %.lr.ph367

.lr.ph367:                                        ; preds = %.lr.ph367.preheader, %.lr.ph367
  %39 = phi i64 [ %44, %.lr.ph367 ], [ 1, %.lr.ph367.preheader ]
  %.unpack325 = load ptr, ptr @_QFEc.0, align 8, !tbaa !7
  %sext = shl i64 %39, 32
  %40 = ashr exact i64 %sext, 32
  %41 = add nsw i64 %40, -1
  %42 = getelementptr i32, ptr %.unpack325, i64 %41
  %43 = call i1 @_FortranAioInputInteger(ptr %34, ptr %42, i32 4)
  %44 = add nuw nsw i64 %39, 1
  %exitcond374.not = icmp eq i64 %39, %38
  br i1 %exitcond374.not, label %._crit_edge368, label %.lr.ph367

._crit_edge368:                                   ; preds = %.lr.ph367, %._crit_edge365
  %45 = call i32 @_FortranAioEndIoStatement(ptr %34)
  %46 = load i32, ptr %1, align 4, !tbaa !3
  %47 = icmp sgt i32 %46, 0
  br i1 %47, label %48, label %._crit_edge372

48:                                               ; preds = %._crit_edge368
  %49 = zext i32 %46 to i64
  %.unpack = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  %.unpack301 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack313 = load ptr, ptr @_QFEc.0, align 8
  %50 = load i32, ptr %.unpack301, align 4, !tbaa !3
  %51 = sext i32 %50 to i64
  %52 = add nsw i64 %51, -1
  %53 = getelementptr i32, ptr %.unpack, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !3
  %exitcond376.peel.not = icmp eq i32 %46, 1
  br i1 %exitcond376.peel.not, label %._crit_edge372, label %.peel.next

.peel.next:                                       ; preds = %48, %74
  %indvars.iv = phi i64 [ %indvars.iv.next, %74 ], [ 2, %48 ]
  %.0369 = phi i32 [ %.1, %74 ], [ %54, %48 ]
  %55 = add nsw i64 %indvars.iv, -1
  %56 = getelementptr i32, ptr %.unpack301, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !3
  %58 = sext i32 %57 to i64
  %59 = add nsw i64 %58, -1
  %60 = getelementptr i32, ptr %.unpack, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !3
  %62 = add i32 %61, %.0369
  %63 = add nsw i64 %indvars.iv, -2
  %64 = getelementptr i32, ptr %.unpack301, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !3
  %66 = add i32 %65, 1
  %67 = icmp eq i32 %66, %57
  br i1 %67, label %68, label %74

68:                                               ; preds = %.peel.next
  %69 = sext i32 %65 to i64
  %70 = add nsw i64 %69, -1
  %71 = getelementptr i32, ptr %.unpack313, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !3
  %73 = add i32 %72, %62
  br label %74

74:                                               ; preds = %68, %.peel.next
  %.1 = phi i32 [ %73, %68 ], [ %62, %.peel.next ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond376.not = icmp eq i64 %indvars.iv, %49
  br i1 %exitcond376.not, label %._crit_edge372, label %.peel.next, !llvm.loop !9

._crit_edge372:                                   ; preds = %74, %48, %._crit_edge368
  %.0.lcssa = phi i32 [ 0, %._crit_edge368 ], [ %54, %48 ], [ %.1, %74 ]
  %75 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28493029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.9eb8f450cf087e88e8116d20caa6b5a1, i32 20)
  %76 = call i1 @_FortranAioOutputInteger32(ptr %75, i32 %.0.lcssa)
  %77 = call i32 @_FortranAioEndIoStatement(ptr %75)
  %78 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable
}

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 @_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

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

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { noreturn }
attributes #2 = { 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}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.peeled.count", i32 1}
