const MAXVAL: 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 gcnts = vec![0usize; MAXVAL+1]; let mut bcnts = vec![0usize; MAXVAL+1]; let mut sum2max = vec![vec![0usize; MAXVAL+1]; 2*MAXVAL+1]; for &v in g.iter() { gcnts[v] += 1; } for &v in b.iter() { bcnts[v] += 1; } for i in 0..=MAXVAL { for j in 0..=MAXVAL { sum2max[i+j][i.max(j)] += gcnts[i] * bcnts[j]; } } for sumval in 0..=2*MAXVAL { for maxval in 0..=MAXVAL { if sumval > 0 { sum2max[sumval][maxval] += sum2max[sumval-1][maxval]; } if maxval > 0 { sum2max[sumval][maxval] += sum2max[sumval][maxval-1]; } if sumval > 0 && maxval > 0 { sum2max[sumval][maxval] -= sum2max[sumval-1][maxval-1]; } } } let mut result = 0usize; for &v in r.iter() { result += sum2max[2*v][v] - sum2max[v][v]; } println!("{}", result); }