const SIZE: usize = 3000; fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let mut r = String::new(); std::io::stdin().read_line(&mut r).ok(); let r: Vec = r.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut g = String::new(); std::io::stdin().read_line(&mut g).ok(); let g: Vec = g.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut b = String::new(); std::io::stdin().read_line(&mut b).ok(); let b: Vec = b.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let mut rcnts = vec![0usize; SIZE+1]; let mut gcnts = vec![0usize; SIZE+1]; let mut bcnts = vec![0usize; SIZE+1]; for i in 0..n { rcnts[r[i]] += 1; gcnts[g[i]] += 1; bcnts[b[i]] += 1; } let mut max2sum = vec![vec![0usize; 2*SIZE+1]; SIZE+1]; for gval in 0..=SIZE { for bval in 0..=SIZE { max2sum[gval.max(bval)][gval+bval] += gcnts[gval] * bcnts[bval]; } } for i in 0..=SIZE { for j in 0..=2*SIZE { if i > 0 { max2sum[i][j] += max2sum[i-1][j]; } if j > 0 { max2sum[i][j] += max2sum[i][j-1]; } if i > 0 && j > 0 { max2sum[i][j] -= max2sum[i-1][j-1]; } } } let mut result = 0usize; for i in 0..=SIZE { result += rcnts[i] * (max2sum[i][2*i] - max2sum[i][i]); } println!("{}", result); }