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 mut 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 mut 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 mut b: Vec = b.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); r.sort(); g.sort(); b.sort(); let mut gcnts = vec![0usize; MAXVAL+1]; let mut bcnts = vec![0usize; MAXVAL+1]; for &v in g.iter() { gcnts[v] += 1; } for &v in b.iter() { bcnts[v] += 1; } let mut sum_max_dp = vec![vec![0usize; MAXVAL+1]; 2*MAXVAL+1]; for i in 0..=MAXVAL { let gcnt = gcnts[i]; for j in 0..=MAXVAL { let bcnt = bcnts[j]; sum_max_dp[i+j][i.max(j)] += gcnt * bcnt; } } for sumval in 0..=2*MAXVAL { for maxval in 0..=MAXVAL { if sumval > 0 { sum_max_dp[sumval][maxval] += sum_max_dp[sumval-1][maxval]; } if maxval > 0 { sum_max_dp[sumval][maxval] += sum_max_dp[sumval][maxval-1]; } if sumval > 0 && maxval > 0 { sum_max_dp[sumval][maxval] -= sum_max_dp[sumval-1][maxval-1]; } } } let mut result = 0usize; for &r in r.iter() { result += sum_max_dp[2*r][r]; result -= sum_max_dp[r][r]; } println!("{}", result); }