program two_alpinists
  implicit none
  integer(8), parameter :: md = 1000000007_8
  integer(8) :: t(100000), a(100000), m
  integer :: n, i
  t = 0_8
  a = 0_8
  read(*,*) n
  read(*,*) t(1:n)
  read(*,*) a(1:n)
  m = 1_8
  if (t(1).gt.a(1).or.t(n).lt.a(n)) m = 0_8
  do i = 2, n-1
    if (t(i).ne.t(i-1).and.a(i).ne.a(i+1)) then
      if (t(i).ne.a(i)) m = 0_8
    else if (t(i).ne.t(i-1).and.a(i).eq.a(i+1)) then
      if (t(i).gt.a(i)) m = 0_8
    else if (t(i).eq.t(i-1).and.a(i).ne.a(i+1)) then
      if (t(i).lt.a(i)) m = 0_8
    else
      m = mod(m*min(t(i),a(i)),md)
    end if
  end do
  write(*,'(i0)') m
  stop
end program two_alpinists
; 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 [100000 x i64] undef
@_QFEt = internal global [100000 x i64] undef
@_QQcl.da32d0593026bf7fbd6181703765c159 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_7798/source.f\00"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

; Function Attrs: noreturn
define void @_QQmain() local_unnamed_addr #0 {
.preheader.preheader:
  %0 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca i32, align 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(800000) @_QFEt, i8 0, i64 800000, i1 false), !tbaa !3
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(800000) @_QFEa, i8 0, i64 800000, i1 false), !tbaa !3
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.da32d0593026bf7fbd6181703765c159, i32 8)
  %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.da32d0593026bf7fbd6181703765c159, i32 9)
  %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 @_QFEt, 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 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.da32d0593026bf7fbd6181703765c159, i32 10)
  %13 = load i32, ptr %2, align 4, !tbaa !3
  %14 = call i32 @llvm.smax.i32(i32 %13, i32 0)
  %15 = zext i32 %14 to i64
  store ptr @_QFEa, ptr %0, align 8, !tbaa !7
  %.fca.1.gep13 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 1
  store i64 8, ptr %.fca.1.gep13, align 8, !tbaa !7
  %.fca.2.gep15 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep15, align 8, !tbaa !7
  %.fca.3.gep17 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 3
  store i8 1, ptr %.fca.3.gep17, align 4, !tbaa !7
  %.fca.4.gep19 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 4
  store i8 10, ptr %.fca.4.gep19, align 1, !tbaa !7
  %.fca.5.gep21 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep21, align 2, !tbaa !7
  %.fca.6.gep23 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep23, align 1, !tbaa !7
  %.fca.7.0.0.gep25 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 7, i64 0, i64 0
  store i64 1, ptr %.fca.7.0.0.gep25, align 8, !tbaa !7
  %.fca.7.0.1.gep27 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 7, i64 0, i64 1
  store i64 %15, ptr %.fca.7.0.1.gep27, align 8, !tbaa !7
  %.fca.7.0.2.gep29 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 7, i64 0, i64 2
  store i64 8, ptr %.fca.7.0.2.gep29, align 8, !tbaa !7
  %16 = call i1 @_FortranAioInputDescriptor(ptr %12, ptr nonnull %0)
  %17 = call i32 @_FortranAioEndIoStatement(ptr %12)
  %18 = load i64, ptr @_QFEt, align 16, !tbaa !3
  %19 = load i64, ptr @_QFEa, align 16, !tbaa !3
  %20 = icmp sle i64 %18, %19
  %21 = load i32, ptr %2, align 4, !tbaa !3
  %22 = sext i32 %21 to i64
  %23 = add nsw i64 %22, -1
  %24 = getelementptr [100000 x i64], ptr @_QFEt, i64 0, i64 %23
  %25 = load i64, ptr %24, align 8, !tbaa !3
  %26 = getelementptr [100000 x i64], ptr @_QFEa, i64 0, i64 %23
  %27 = load i64, ptr %26, align 8, !tbaa !3
  %28 = icmp sge i64 %25, %27
  %.not44 = and i1 %20, %28
  %spec.select = zext i1 %.not44 to i64
  %29 = add i32 %21, -1
  %30 = icmp sgt i32 %29, 1
  br i1 %30, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader.preheader
  %31 = zext i32 %29 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %60
  %32 = phi i64 [ %18, %.lr.ph.preheader ], [ %35, %60 ]
  %indvars.iv = phi i64 [ 2, %.lr.ph.preheader ], [ %indvars.iv.next, %60 ]
  %.145 = phi i64 [ %spec.select, %.lr.ph.preheader ], [ %.2, %60 ]
  %33 = add nsw i64 %indvars.iv, -1
  %34 = getelementptr [100000 x i64], ptr @_QFEt, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !3
  %36 = icmp ne i64 %35, %32
  %37 = getelementptr [100000 x i64], ptr @_QFEa, i64 0, i64 %33
  %38 = load i64, ptr %37, align 8, !tbaa !3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %sext = shl i64 %indvars.iv.next, 32
  %39 = ashr exact i64 %sext, 32
  %40 = add nsw i64 %39, -1
  %41 = getelementptr [100000 x i64], ptr @_QFEa, i64 0, i64 %40
  %42 = load i64, ptr %41, align 8, !tbaa !3
  %43 = icmp ne i64 %38, %42
  %44 = and i1 %36, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %.lr.ph
  %.not = icmp eq i64 %35, %38
  %spec.select39 = select i1 %.not, i64 %.145, i64 0
  br label %60

46:                                               ; preds = %.lr.ph
  %47 = icmp eq i64 %38, %42
  %48 = and i1 %36, %47
  br i1 %48, label %49, label %51

49:                                               ; preds = %46
  %50 = icmp sgt i64 %35, %38
  %spec.select40 = select i1 %50, i64 0, i64 %.145
  br label %60

51:                                               ; preds = %46
  %52 = icmp eq i64 %35, %32
  %53 = and i1 %52, %43
  br i1 %53, label %54, label %56

54:                                               ; preds = %51
  %55 = icmp slt i64 %32, %38
  %spec.select41 = select i1 %55, i64 0, i64 %.145
  br label %60

56:                                               ; preds = %51
  %57 = call i64 @llvm.smin.i64(i64 %35, i64 %38)
  %58 = mul i64 %57, %.145
  %59 = srem i64 %58, 1000000007
  br label %60

60:                                               ; preds = %54, %49, %45, %56
  %.2 = phi i64 [ %59, %56 ], [ %spec.select39, %45 ], [ %spec.select40, %49 ], [ %spec.select41, %54 ]
  %exitcond.not = icmp eq i64 %indvars.iv, %31
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %60, %.preheader.preheader
  %.1.lcssa = phi i64 [ %spec.select, %.preheader.preheader ], [ %.2, %60 ]
  %61 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.da32d0593026bf7fbd6181703765c159, i32 24)
  %62 = call i1 @_FortranAioOutputInteger64(ptr %61, i64 %.1.lcssa)
  %63 = call i32 @_FortranAioEndIoStatement(ptr %61)
  %64 = 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 i1 @_FortranAioInputDescriptor(ptr, ptr) local_unnamed_addr

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

declare i1 @_FortranAioOutputInteger64(ptr, i64) 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) #1

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { noreturn }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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}
