fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n: usize = n.trim().parse().unwrap(); let mut a = String::new(); std::io::stdin().read_line(&mut a).ok(); let a: Vec = a.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 result = 0usize; let mut ok = vec![false; n-1]; for i in 0..n-1 { let minval = b[i].min(b[i+1]); let maxval = b[i].max(b[i+1]); ok[i] = a[i] + maxval < a[i+1] + minval; if ok[i] { result += 1; } } let mut idx = 0usize; for i in 0..n-1 { if !ok[i] { continue; } idx = idx.max(i+1); while idx < n { let minval = b[i].min(b[idx]); let maxval = b[i].max(b[idx]); if a[i] + maxval < a[idx] + minval { idx += 1; } else { break; } } result += idx - i - 2; } println!("{}", result); }