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