pub fn readln() -> String { let mut line = String::new(); ::std::io::stdin() .read_line(&mut line) .unwrap_or_else(|e| panic!("{}", e)); line } macro_rules !read {($($t :tt ) ,*;$n :expr ) =>{{let stdin =::std ::io ::stdin () ;let ret =::std ::io ::BufRead ::lines (stdin .lock () ) .take ($n ) .map (|line |{let line =line .unwrap () ;let mut it =line .split_whitespace () ;_read !(it ;$($t ) ,*) } ) .collect ::>() ;ret } } ;($($t :tt ) ,*) =>{{let line =readln () ;let mut it =line .split_whitespace () ;_read !(it ;$($t ) ,*) } } ;} macro_rules !_read {($it :ident ;[char ] ) =>{_read !($it ;String ) .chars () .collect ::>() } ;($it :ident ;[u8 ] ) =>{Vec ::from (_read !($it ;String ) .into_bytes () ) } ;($it :ident ;usize1 ) =>{$it .next () .unwrap_or_else (||panic !("input mismatch" ) ) .parse ::() .unwrap_or_else (|e |panic !("{}" ,e ) ) -1 } ;($it :ident ;[usize1 ] ) =>{$it .map (|s |s .parse ::() .unwrap_or_else (|e |panic !("{}" ,e ) ) -1 ) .collect ::>() } ;($it :ident ;[$t :ty ] ) =>{$it .map (|s |s .parse ::<$t >() .unwrap_or_else (|e |panic !("{}" ,e ) ) ) .collect ::>() } ;($it :ident ;$t :ty ) =>{$it .next () .unwrap_or_else (||panic !("input mismatch" ) ) .parse ::<$t >() .unwrap_or_else (|e |panic !("{}" ,e ) ) } ;($it :ident ;$($t :tt ) ,+) =>{($(_read !($it ;$t ) ) ,*) } ;} fn main() { let n = read!(usize); let mut s = read!([usize]); let mut t = read!([usize]); { let mut zero = 0; let mut two = 0; for i in 0..n { if s[i] == 0 { zero += 1; } if s[i] == 2 { two += 1; } } if zero > 0 && two > 0 { println!("{}", two * n + (n - zero - two)); return; } } { let mut zero = 0; let mut two = 0; for i in 0..n { if t[i] == 0 { zero += 1; } if t[i] == 2 { two += 1; } } if zero > 0 && two > 0 { println!("{}", two * n + (n - zero - two)); return; } } let mut a = vec![vec![0; n]; n]; for i in 0..n { for j in 0..n { if s[i] == 0 || t[j] == 0 { a[i][j] = 0; } if s[i] == 2 || t[j] == 2 { a[i][j] = 1; } } } let mut ans = 0; for i in 0..n { if s[i] == 1 { let mut f = false; for j in 0..n { if a[i][j] == 1 { f = true; break; } } if f { continue; } for j in 0..n { if t[j] == 1 { t[j] = 0; a[i][j] = 1; f = true; break; } } if !f { ans += 1; } } } for j in 0..n { if t[j] == 1 { let mut f = false; for i in 0..n { if a[i][j] == 1 { f = true; break; } } if !f { ans += 1; } } } for i in 0..n { for j in 0..n { ans += a[i][j]; } } println!("{}", ans); }