program double_landscape
  implicit none
  integer(8), parameter :: md = 1000000007_8
  integer :: n, m, a(1000), b(1000), ac, bc, i
  logical :: au(1000000), bu(1000000)
  integer(8) :: x
  a = 0
  b = 0
  au = .false.
  bu = .false.
  read(*,*) n, m
  read(*,*) a(1:n)
  read(*,*) b(1:m)
  do i = 1, n
    if (au(a(i))) then
      write(*,'(i0)') 0
      stop
    end if
    au(a(i)) = .true.
  end do
  do i = 1, m
    if (bu(b(i))) then
      write(*,'(i0)') 0
      stop
    end if
    bu(b(i)) = .true.
  end do
  ac = 0
  bc = 0
  x = 1_8
  do i = n*m, 1, -1
    if (au(i).and.bu(i)) then
      ac = ac+1
      bc = bc+1
    else if (au(i)) then
      ac = ac+1
      x = mod(x*int(bc,8),md)
    else if (bu(i)) then
      bc = bc+1
      x = mod(x*int(ac,8),md)
    else
      x = mod(x*(int(ac,8)*int(bc,8)-int(n*m-i,8)),md)
    end if
  end do
  write(*,'(i0)') x
  stop
end program double_landscape
; 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 [1000 x i32] undef
@_QFEau = internal unnamed_addr global [1000000 x i32] undef
@_QFEb = internal global [1000 x i32] undef
@_QFEbu = internal unnamed_addr global [1000000 x i32] undef
@_QQcl.051563bcf4a9093dc16ee87bb84366e9 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_5129/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 {
.preheader62.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
  %3 = alloca i32, align 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(4000) @_QFEa, i8 0, i64 4000, i1 false), !tbaa !3
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(4000) @_QFEb, i8 0, i64 4000, i1 false), !tbaa !3
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(4000000) @_QFEau, i8 0, i64 4000000, i1 false), !tbaa !3
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(4000000) @_QFEbu, i8 0, i64 4000000, i1 false), !tbaa !3
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.051563bcf4a9093dc16ee87bb84366e9, i32 11)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 4)
  %6 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %2, i32 4)
  %7 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %8 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.051563bcf4a9093dc16ee87bb84366e9, i32 12)
  %9 = load i32, ptr %3, align 4, !tbaa !3
  %10 = call i32 @llvm.smax.i32(i32 %9, i32 0)
  %11 = zext i32 %10 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 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 %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 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 %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 %11, 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 4, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %12 = call i1 @_FortranAioInputDescriptor(ptr %8, ptr nonnull %1)
  %13 = call i32 @_FortranAioEndIoStatement(ptr %8)
  %14 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.051563bcf4a9093dc16ee87bb84366e9, i32 13)
  %15 = load i32, ptr %2, align 4, !tbaa !3
  %16 = call i32 @llvm.smax.i32(i32 %15, i32 0)
  %17 = zext i32 %16 to i64
  store ptr @_QFEb, ptr %0, align 8, !tbaa !7
  %.fca.1.gep30 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 1
  store i64 4, ptr %.fca.1.gep30, align 8, !tbaa !7
  %.fca.2.gep32 = 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.gep32, align 8, !tbaa !7
  %.fca.3.gep34 = 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.gep34, align 4, !tbaa !7
  %.fca.4.gep36 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 4
  store i8 9, ptr %.fca.4.gep36, align 1, !tbaa !7
  %.fca.5.gep38 = 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.gep38, align 2, !tbaa !7
  %.fca.6.gep40 = 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.gep40, align 1, !tbaa !7
  %.fca.7.0.0.gep42 = 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.gep42, align 8, !tbaa !7
  %.fca.7.0.1.gep44 = 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 %17, ptr %.fca.7.0.1.gep44, align 8, !tbaa !7
  %.fca.7.0.2.gep46 = 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 4, ptr %.fca.7.0.2.gep46, align 8, !tbaa !7
  %18 = call i1 @_FortranAioInputDescriptor(ptr %14, ptr nonnull %0)
  %19 = call i32 @_FortranAioEndIoStatement(ptr %14)
  %20 = load i32, ptr %3, align 4, !tbaa !3
  %21 = icmp sgt i32 %20, 0
  br i1 %21, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader62.preheader, %35
  %.04764 = phi i32 [ %36, %35 ], [ 1, %.preheader62.preheader ]
  %22 = sext i32 %.04764 to i64
  %23 = add nsw i64 %22, -1
  %24 = getelementptr [1000 x i32], ptr @_QFEa, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !3
  %26 = sext i32 %25 to i64
  %27 = add nsw i64 %26, -1
  %28 = getelementptr [1000000 x i32], ptr @_QFEau, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !3
  %.not60 = icmp eq i32 %29, 0
  br i1 %.not60, label %35, label %30

30:                                               ; preds = %.lr.ph
  %31 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.051563bcf4a9093dc16ee87bb84366e9, i32 16)
  %32 = call i1 @_FortranAioOutputInteger32(ptr %31, i32 0)
  %33 = call i32 @_FortranAioEndIoStatement(ptr %31)
  %34 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable

35:                                               ; preds = %.lr.ph
  store i32 1, ptr %28, align 4, !tbaa !3
  %36 = add nuw i32 %.04764, 1
  %exitcond.not = icmp eq i32 %.04764, %20
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %35, %.preheader62.preheader
  %37 = load i32, ptr %2, align 4, !tbaa !3
  %38 = icmp sgt i32 %37, 0
  br i1 %38, label %.lr.ph68, label %._crit_edge69

.lr.ph68:                                         ; preds = %._crit_edge, %52
  %.14866 = phi i32 [ %53, %52 ], [ 1, %._crit_edge ]
  %39 = sext i32 %.14866 to i64
  %40 = add nsw i64 %39, -1
  %41 = getelementptr [1000 x i32], ptr @_QFEb, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !3
  %43 = sext i32 %42 to i64
  %44 = add nsw i64 %43, -1
  %45 = getelementptr [1000000 x i32], ptr @_QFEbu, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !3
  %.not = icmp eq i32 %46, 0
  br i1 %.not, label %52, label %47

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

52:                                               ; preds = %.lr.ph68
  store i32 1, ptr %45, align 4, !tbaa !3
  %53 = add nuw i32 %.14866, 1
  %exitcond76.not = icmp eq i32 %.14866, %37
  br i1 %exitcond76.not, label %._crit_edge69, label %.lr.ph68

._crit_edge69:                                    ; preds = %52, %._crit_edge
  %54 = mul i32 %37, %20
  %55 = icmp sgt i32 %54, 0
  br i1 %55, label %.lr.ph74.preheader, label %._crit_edge75

.lr.ph74.preheader:                               ; preds = %._crit_edge69
  %56 = zext i32 %54 to i64
  br label %.lr.ph74

.lr.ph74:                                         ; preds = %.lr.ph74.preheader, %91
  %57 = phi i64 [ %92, %91 ], [ %56, %.lr.ph74.preheader ]
  %.072 = phi i64 [ %.1, %91 ], [ 1, %.lr.ph74.preheader ]
  %.04971 = phi i32 [ %.150, %91 ], [ 0, %.lr.ph74.preheader ]
  %.05170 = phi i32 [ %.152, %91 ], [ 0, %.lr.ph74.preheader ]
  %indvars77 = trunc i64 %57 to i32
  %sext = shl i64 %57, 32
  %58 = ashr exact i64 %sext, 32
  %59 = add nsw i64 %58, -1
  %60 = getelementptr [1000000 x i32], ptr @_QFEau, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !3
  %62 = getelementptr [1000000 x i32], ptr @_QFEbu, i64 0, i64 %59
  %63 = load i32, ptr %62, align 4, !tbaa !3
  %64 = icmp ne i32 %61, 0
  %65 = icmp ne i32 %63, 0
  %66 = and i1 %64, %65
  br i1 %66, label %67, label %70

67:                                               ; preds = %.lr.ph74
  %68 = add i32 %.05170, 1
  %69 = add i32 %.04971, 1
  br label %91

70:                                               ; preds = %.lr.ph74
  br i1 %64, label %71, label %76

71:                                               ; preds = %70
  %72 = add i32 %.05170, 1
  %73 = sext i32 %.04971 to i64
  %74 = mul i64 %.072, %73
  %75 = srem i64 %74, 1000000007
  br label %91

76:                                               ; preds = %70
  br i1 %65, label %77, label %82

77:                                               ; preds = %76
  %78 = add i32 %.04971, 1
  %79 = sext i32 %.05170 to i64
  %80 = mul i64 %.072, %79
  %81 = srem i64 %80, 1000000007
  br label %91

82:                                               ; preds = %76
  %83 = sext i32 %.05170 to i64
  %84 = sext i32 %.04971 to i64
  %85 = mul nsw i64 %84, %83
  %86 = sub i32 %54, %indvars77
  %87 = sext i32 %86 to i64
  %88 = sub nsw i64 %85, %87
  %89 = mul i64 %88, %.072
  %90 = srem i64 %89, 1000000007
  br label %91

91:                                               ; preds = %67, %71, %77, %82
  %.152 = phi i32 [ %68, %67 ], [ %72, %71 ], [ %.05170, %77 ], [ %.05170, %82 ]
  %.150 = phi i32 [ %69, %67 ], [ %.04971, %71 ], [ %78, %77 ], [ %.04971, %82 ]
  %.1 = phi i64 [ %.072, %67 ], [ %75, %71 ], [ %81, %77 ], [ %90, %82 ]
  %92 = add nsw i64 %57, -1
  %93 = icmp sgt i64 %57, 1
  br i1 %93, label %.lr.ph74, label %._crit_edge75

._crit_edge75:                                    ; preds = %91, %._crit_edge69
  %.0.lcssa = phi i64 [ 1, %._crit_edge69 ], [ %.1, %91 ]
  %94 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.051563bcf4a9093dc16ee87bb84366e9, i32 45)
  %95 = call i1 @_FortranAioOutputInteger64(ptr %94, i64 %.0.lcssa)
  %96 = call i32 @_FortranAioEndIoStatement(ptr %94)
  %97 = 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 @_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) #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}
