use std::collections::HashMap; fn getline() -> String{ let mut __ret=String::new(); std::io::stdin().read_line(&mut __ret).ok(); return __ret; } fn main() { let n=getline(); let n:Vec<_>=n.trim().split(' ').collect(); let n:i64=n[0].parse().unwrap(); let r=getline(); let r:Vec<_>=r.trim().split(' ').collect(); let r:Vec=r.iter().map(|v| v.parse().unwrap()).collect(); let g=getline(); let g:Vec<_>=g.trim().split(' ').collect(); let g:Vec=g.iter().map(|v| v.parse().unwrap()).collect(); let mut ag = vec![0; 3001]; for i in 0..n { ag[g[i as usize] as usize] = ag[g[i as usize] as usize] + 1; } let b=getline(); let b:Vec<_>=b.trim().split(' ').collect(); let b:Vec=b.iter().map(|v| v.parse().unwrap()).collect(); let mut ab = vec![0; 3001]; for i in 0..n { ab[b[i as usize] as usize] = ab[b[i as usize] as usize] + 1; } let mut ans:i64=0; let mut ar = vec![0; 3001]; for i in 0..n { ar[r[i as usize] as usize] = ar[r[i as usize] as usize] + 1; } let mut aar = vec![0; 3001]; aar[0] = ar[0]; for i in 1..3001 { aar[i as usize] = aar[(i-1) as usize] + ar[i]; } for j in 1..3001 { for k in 1..3001 { let bi = std::cmp::min(j + k -1, 3000); let si = std::cmp::max(j,k) -1; let add = (aar[bi] - aar[si]) * ag[j as usize] * ab[k as usize]; ans = ans + add; } } println!("{}", ans) }