#import <stdio.h>
#import <stdlib.h>

int compare_int(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}

// 昇順に並んだ values の中で searchValue を 左から探したときに初めて上回る(order>0) / 右から探したときに初めて下回る(order<0) ような index を探す（ない場合は -1 を返す）
int binary_search(int searchValue, int *values, int minIndex, int maxIndex, int order) {
    int midIndex = (minIndex + maxIndex)/2;
    int midValue = values[midIndex];
    int maxValue = values[maxIndex];
    if (minIndex == midIndex) { // 区間の長さが2になったとき
        if (order > 0) {
            if (searchValue < midValue) { // 左がサーチ値を上回るなら左
                return midIndex;
            }
            if (searchValue < maxValue) { // 左がサーチ値以下かつ右がサーチ値を上回るなら右
                return maxIndex;
            }
        } else {
            if (searchValue > maxValue) { // 右がサーチ値を下回るなら右
                return maxIndex;
            }
            if (searchValue > midValue) { // 右がサーチ値以上かつ左がサーチ値を下回るなら左
                return midIndex;
            }
        }
        return -1; // 区間の長さが2のとき両端とも条件を満たさないなら存在しない
    }
    if (order > 0) {
        if (midValue <= searchValue) { // 中央での値がまだ上回っていないなら右半分
            return binary_search(searchValue, values, midIndex, maxIndex, order);
        } else {
            return binary_search(searchValue, values, minIndex, midIndex, order);
        }
    } else {
        if (midValue >= searchValue) { // 中央での値がまだ下回っていないなら左半分
            return binary_search(searchValue, values, minIndex, midIndex, order);
        } else {
            return binary_search(searchValue, values, midIndex, maxIndex, order);
        }
    }
}

int main(){
    int N;
    scanf("%d", &N);
    int A[200000] = {0};
    int B[200000] = {0};
    int C[200000] = {0};
    for(int i=0;i<N;i++){
        int a;
        scanf("%d", &a);
        A[i] = a;
    }
    for(int i=0;i<N;i++){
        int b;
        scanf("%d", &b);
        B[i] = b;
    }
    for(int i=0;i<N;i++){
        int c;
        scanf("%d", &c);
        C[i] = c;
    }
    qsort(A, N, sizeof(int), compare_int);
    qsort(C, N, sizeof(int), compare_int);
    if (N==1) {
        puts((A[0]<B[0] && B[0]<C[0]) ? "1" : "0");
        return 0;
    }
    long long count = 0;
    for(int j=0;j<N;j++){
        int b = B[j];
        int i = binary_search(b,A,0,N-1,-1);
        int k = binary_search(b,C,0,N-1,1);
        if (i>=0 && k>=0) {
            count += (long long)(i+1)*(N-k);
        }
    }
    printf("%lld",count);
}

; ModuleID = '/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_686/source.m'
source_filename = "/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_686/source.m"
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"

@.str = private unnamed_addr constant [3 x i8] c"%d\00", align 1
@.str.1 = private unnamed_addr constant [2 x i8] c"1\00", align 1
@.str.2 = private unnamed_addr constant [2 x i8] c"0\00", align 1
@.str.3 = private unnamed_addr constant [5 x i8] c"%lld\00", align 1

; Function Attrs: minsize mustprogress nofree norecurse nosync nounwind optsize willreturn memory(argmem: read) uwtable
define dso_local i32 @compare_int(ptr nocapture noundef readonly %a, ptr nocapture noundef readonly %b) #0 {
entry:
  %0 = load i32, ptr %a, align 4, !tbaa !5
  %1 = load i32, ptr %b, align 4, !tbaa !5
  %sub = sub nsw i32 %0, %1
  ret i32 %sub
}

; Function Attrs: minsize nofree norecurse nosync nounwind optsize memory(argmem: read) uwtable
define dso_local i32 @binary_search(i32 noundef %searchValue, ptr nocapture noundef readonly %values, i32 noundef %minIndex, i32 noundef %maxIndex, i32 noundef %order) local_unnamed_addr #1 {
entry:
  %cmp18 = icmp sgt i32 %order, 0
  br label %tailrecurse

tailrecurse:                                      ; preds = %tailrecurse.backedge, %entry
  %minIndex.tr = phi i32 [ %minIndex, %entry ], [ %minIndex.tr.be, %tailrecurse.backedge ]
  %maxIndex.tr = phi i32 [ %maxIndex, %entry ], [ %maxIndex.tr.be, %tailrecurse.backedge ]
  %add = add nsw i32 %maxIndex.tr, %minIndex.tr
  %div = sdiv i32 %add, 2
  %idxprom = sext i32 %div to i64
  %arrayidx = getelementptr inbounds i32, ptr %values, i64 %idxprom
  %0 = load i32, ptr %arrayidx, align 4, !tbaa !5
  %cmp = icmp eq i32 %div, %minIndex.tr
  br i1 %cmp, label %if.then, label %if.end17

if.then:                                          ; preds = %tailrecurse
  %idxprom1.le = sext i32 %maxIndex.tr to i64
  %arrayidx2.le = getelementptr inbounds i32, ptr %values, i64 %idxprom1.le
  %1 = load i32, ptr %arrayidx2.le, align 4, !tbaa !5
  br i1 %cmp18, label %if.then4, label %if.else

if.then4:                                         ; preds = %if.then
  %cmp5 = icmp sgt i32 %0, %searchValue
  br i1 %cmp5, label %cleanup, label %if.end

if.end:                                           ; preds = %if.then4
  %cmp7 = icmp sgt i32 %1, %searchValue
  br i1 %cmp7, label %cleanup, label %if.end16

if.else:                                          ; preds = %if.then
  %cmp10 = icmp slt i32 %1, %searchValue
  br i1 %cmp10, label %cleanup, label %if.end12

if.end12:                                         ; preds = %if.else
  %cmp13 = icmp slt i32 %0, %searchValue
  br i1 %cmp13, label %cleanup, label %if.end16

if.end16:                                         ; preds = %if.end12, %if.end
  br label %cleanup

if.end17:                                         ; preds = %tailrecurse
  br i1 %cmp18, label %if.then19, label %if.else24

if.then19:                                        ; preds = %if.end17
  %cmp20.not = icmp sgt i32 %0, %searchValue
  %minIndex.tr.div = select i1 %cmp20.not, i32 %minIndex.tr, i32 %div
  %div.maxIndex.tr = select i1 %cmp20.not, i32 %div, i32 %maxIndex.tr
  br label %tailrecurse.backedge

tailrecurse.backedge:                             ; preds = %if.then19, %if.else24
  %minIndex.tr.be = phi i32 [ %minIndex.tr.div, %if.then19 ], [ %div.minIndex.tr, %if.else24 ]
  %maxIndex.tr.be = phi i32 [ %div.maxIndex.tr, %if.then19 ], [ %maxIndex.tr.div, %if.else24 ]
  br label %tailrecurse

if.else24:                                        ; preds = %if.end17
  %cmp25.not = icmp slt i32 %0, %searchValue
  %div.minIndex.tr = select i1 %cmp25.not, i32 %div, i32 %minIndex.tr
  %maxIndex.tr.div = select i1 %cmp25.not, i32 %maxIndex.tr, i32 %div
  br label %tailrecurse.backedge

cleanup:                                          ; preds = %if.end12, %if.else, %if.end, %if.then4, %if.end16
  %retval.0 = phi i32 [ -1, %if.end16 ], [ %minIndex.tr, %if.then4 ], [ %maxIndex.tr, %if.end ], [ %maxIndex.tr, %if.else ], [ %minIndex.tr, %if.end12 ]
  ret i32 %retval.0
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: minsize nofree nounwind optsize uwtable
define dso_local i32 @main() local_unnamed_addr #3 {
entry:
  %N = alloca i32, align 4
  %A = alloca [200000 x i32], align 16
  %B = alloca [200000 x i32], align 16
  %C = alloca [200000 x i32], align 16
  %a = alloca i32, align 4
  %b = alloca i32, align 4
  %c = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %N) #8
  %call = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %N) #9
  call void @llvm.lifetime.start.p0(i64 800000, ptr nonnull %A) #8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(800000) %A, i8 0, i64 800000, i1 false)
  call void @llvm.lifetime.start.p0(i64 800000, ptr nonnull %B) #8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(800000) %B, i8 0, i64 800000, i1 false)
  call void @llvm.lifetime.start.p0(i64 800000, ptr nonnull %C) #8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(800000) %C, i8 0, i64 800000, i1 false)
  br label %for.cond

for.cond:                                         ; preds = %for.body, %entry
  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
  %0 = load i32, ptr %N, align 4, !tbaa !5
  %1 = sext i32 %0 to i64
  %cmp = icmp slt i64 %indvars.iv, %1
  br i1 %cmp, label %for.body, label %for.cond3

for.body:                                         ; preds = %for.cond
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %a) #8
  %call1 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %a) #9
  %2 = load i32, ptr %a, align 4, !tbaa !5
  %arrayidx = getelementptr inbounds [200000 x i32], ptr %A, i64 0, i64 %indvars.iv
  store i32 %2, ptr %arrayidx, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %a) #8
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br label %for.cond

for.cond3:                                        ; preds = %for.cond, %for.body6
  %3 = phi i32 [ %.pre, %for.body6 ], [ %0, %for.cond ]
  %indvars.iv82 = phi i64 [ %indvars.iv.next83, %for.body6 ], [ 0, %for.cond ]
  %4 = sext i32 %3 to i64
  %cmp4 = icmp slt i64 %indvars.iv82, %4
  br i1 %cmp4, label %for.body6, label %for.cond14

for.body6:                                        ; preds = %for.cond3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %b) #8
  %call7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %b) #9
  %5 = load i32, ptr %b, align 4, !tbaa !5
  %arrayidx9 = getelementptr inbounds [200000 x i32], ptr %B, i64 0, i64 %indvars.iv82
  store i32 %5, ptr %arrayidx9, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %b) #8
  %indvars.iv.next83 = add nuw nsw i64 %indvars.iv82, 1
  %.pre = load i32, ptr %N, align 4, !tbaa !5
  br label %for.cond3

for.cond14:                                       ; preds = %for.cond3, %for.body17
  %6 = phi i32 [ %.pre91, %for.body17 ], [ %3, %for.cond3 ]
  %indvars.iv85 = phi i64 [ %indvars.iv.next86, %for.body17 ], [ 0, %for.cond3 ]
  %7 = sext i32 %6 to i64
  %cmp15 = icmp slt i64 %indvars.iv85, %7
  br i1 %cmp15, label %for.body17, label %for.cond.cleanup16

for.cond.cleanup16:                               ; preds = %for.cond14
  call void @qsort(ptr noundef nonnull %A, i64 noundef %7, i64 noundef 4, ptr noundef nonnull @compare_int) #10
  %8 = load i32, ptr %N, align 4, !tbaa !5
  %conv25 = sext i32 %8 to i64
  call void @qsort(ptr noundef nonnull %C, i64 noundef %conv25, i64 noundef 4, ptr noundef nonnull @compare_int) #10
  %9 = load i32, ptr %N, align 4, !tbaa !5
  %cmp26 = icmp eq i32 %9, 1
  br i1 %cmp26, label %if.then, label %for.cond37.preheader

for.cond37.preheader:                             ; preds = %for.cond.cleanup16
  %sub = add nsw i32 %9, -1
  %smax = call i32 @llvm.smax.i32(i32 %9, i32 0)
  %wide.trip.count = zext i32 %smax to i64
  br label %for.cond37

for.body17:                                       ; preds = %for.cond14
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %c) #8
  %call18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %c) #9
  %10 = load i32, ptr %c, align 4, !tbaa !5
  %arrayidx20 = getelementptr inbounds [200000 x i32], ptr %C, i64 0, i64 %indvars.iv85
  store i32 %10, ptr %arrayidx20, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %c) #8
  %indvars.iv.next86 = add nuw nsw i64 %indvars.iv85, 1
  %.pre91 = load i32, ptr %N, align 4, !tbaa !5
  br label %for.cond14

if.then:                                          ; preds = %for.cond.cleanup16
  %11 = load i32, ptr %A, align 16, !tbaa !5
  %12 = load i32, ptr %B, align 16
  %cmp30 = icmp slt i32 %11, %12
  %13 = load i32, ptr %C, align 16
  %cmp34 = icmp slt i32 %12, %13
  %14 = select i1 %cmp30, i1 %cmp34, i1 false
  %cond = select i1 %14, ptr @.str.1, ptr @.str.2
  %call36 = call i32 @puts(ptr noundef nonnull dereferenceable(1) %cond) #9
  br label %cleanup

for.cond37:                                       ; preds = %for.cond37.preheader, %if.end60
  %indvars.iv88 = phi i64 [ 0, %for.cond37.preheader ], [ %indvars.iv.next89, %if.end60 ]
  %count.0 = phi i64 [ 0, %for.cond37.preheader ], [ %count.1, %if.end60 ]
  %exitcond.not = icmp eq i64 %indvars.iv88, %wide.trip.count
  br i1 %exitcond.not, label %for.cond.cleanup40, label %for.body41

for.cond.cleanup40:                               ; preds = %for.cond37
  %call64 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef %count.0) #9
  br label %cleanup

for.body41:                                       ; preds = %for.cond37
  %arrayidx44 = getelementptr inbounds [200000 x i32], ptr %B, i64 0, i64 %indvars.iv88
  %15 = load i32, ptr %arrayidx44, align 4, !tbaa !5
  %call47 = call i32 @binary_search(i32 noundef %15, ptr noundef nonnull %A, i32 noundef 0, i32 noundef %sub, i32 noundef -1) #9
  %call50 = call i32 @binary_search(i32 noundef %15, ptr noundef nonnull %C, i32 noundef 0, i32 noundef %sub, i32 noundef 1) #9
  %cmp51 = icmp sgt i32 %call47, -1
  %cmp53 = icmp sgt i32 %call50, -1
  %or.cond = select i1 %cmp51, i1 %cmp53, i1 false
  br i1 %or.cond, label %if.then55, label %if.end60

if.then55:                                        ; preds = %for.body41
  %add = add nuw nsw i32 %call47, 1
  %conv56 = zext i32 %add to i64
  %sub57 = sub nsw i32 %9, %call50
  %conv58 = sext i32 %sub57 to i64
  %mul = mul nsw i64 %conv58, %conv56
  %add59 = add nsw i64 %mul, %count.0
  br label %if.end60

if.end60:                                         ; preds = %if.then55, %for.body41
  %count.1 = phi i64 [ %add59, %if.then55 ], [ %count.0, %for.body41 ]
  %indvars.iv.next89 = add nuw nsw i64 %indvars.iv88, 1
  br label %for.cond37

cleanup:                                          ; preds = %for.cond.cleanup40, %if.then
  call void @llvm.lifetime.end.p0(i64 800000, ptr nonnull %C) #8
  call void @llvm.lifetime.end.p0(i64 800000, ptr nonnull %B) #8
  call void @llvm.lifetime.end.p0(i64 800000, ptr nonnull %A) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %N) #8
  ret i32 0
}

; Function Attrs: minsize nofree nounwind optsize
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #4

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

; Function Attrs: minsize nofree optsize
declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #6

; Function Attrs: minsize nofree nounwind optsize
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #4

; Function Attrs: minsize nofree nounwind optsize
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #4

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

attributes #0 = { minsize mustprogress nofree norecurse nosync nounwind optsize willreturn memory(argmem: read) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { minsize nofree norecurse nosync nounwind optsize memory(argmem: read) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { minsize nofree nounwind optsize uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { minsize nofree nounwind optsize "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { minsize nofree optsize "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #7 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #8 = { nounwind }
attributes #9 = { minsize optsize }
attributes #10 = { minsize nounwind optsize }

!llvm.linker.options = !{}
!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"Ubuntu clang version 18.0.0 (++20231007042255+8abb2ace888b-1~exp1~20231007042414.1230)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
