#![allow(unused_imports)] use std::cmp::*; use std::collections::*; use std::io::Write; use std::ops::Bound::*; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn main() { let n = read::(); let mut s = read_vec::(); let mut t = read_vec::(); if !s.iter().any(|&x| x == 2) && !t.iter().any(|&x| x == 2) { let ans = max( s.iter().filter(|&&x| x == 1).count(), t.iter().filter(|&&x| x == 1).count(), ); println!("{}", ans); return; } if s.iter().any(|&x| x == 2) && t.iter().any(|&x| x == 2) { let mut ans = n * s.iter().filter(|&&x| x == 2).count(); ans += (n - s.iter().filter(|&&x| x == 2).count()) * t.iter().filter(|&&x| x == 2).count(); println!("{}", ans); return; } if t.iter().any(|&x| x == 2) { std::mem::swap(&mut s, &mut t); } let mut ans = 0; for i in 0..n { if s[i] == 2 { ans += n; } else if s[i] == 1 { ans += 1; } } println!("{}", ans); } fn read() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec() -> Vec { read::() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() }