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