pub mod procon_input { use std::{str::FromStr, iter::FromIterator}; pub fn read_line() -> String { let mut input = String::new(); std::io::stdin().read_line(&mut input).ok(); input } pub fn parse(s: &str) -> T { s.parse().ok().unwrap() } pub fn read() -> T { parse(read_line().trim_end()) } pub fn read_collection>() -> C { read_line().split_whitespace().map(parse).collect() } #[macro_export] macro_rules! read_tuple { ( $( $t:ty ),* ) => {{ let input = read_line(); let mut iter = input.split_whitespace(); ( $( parse::<$t>(iter.next().unwrap()) ),* ) }}; } } struct FenwickTree { n: usize, init: T, data: Vec, } impl FenwickTree { fn new(n: usize, init: T) -> FenwickTree { FenwickTree { n, init, data: vec![init; n] } } fn add(&mut self, mut p: usize, x: T) { p += 1; while p <= self.n { self.data[p - 1] += x; p += p & (!p + 1); } } fn sum(&self, mut r: usize) -> T { let mut res = self.init; while r > 0 { res += self.data[r - 1]; r -= r & (!r + 1); } res } } use procon_input::*; fn solve(writer: &mut std::io::BufWriter) { use std::io::Write; let n: usize = read(); let mut a: Vec = read_collection(); a.sort(); let b: Vec = read_collection(); let mut v: Vec = a.iter().chain(b.iter()).cloned().collect(); v.sort(); v.dedup(); let a: Vec = { a.into_iter().map(|x| v.binary_search(&x).unwrap()).collect() }; let b: Vec = { b.into_iter().map(|x| v.binary_search(&x).unwrap()).collect() }; let mut ans: i64 = 0; let mut ft = FenwickTree::new(2 * n, 0); for i in 0..n { ft.add(b[i], 1); ans += ft.sum(a[i]); } writeln!(writer, "{}", ans).ok(); } fn main() { let stdout = std::io::stdout(); let mut writer = std::io::BufWriter::new(stdout.lock()); solve(&mut writer); }