use proconio::input; fn main() { input! { n: usize, a: [usize; n], b: [usize; n], } let mut g = vec![vec![]; 1_000_001]; for (i, j) in a.into_iter().zip(b.into_iter()) { g[i].push(i + j); } let mut ans = 1; let mut stack = vec![1]; let mut vis = vec![false; 1_000_001]; while let Some(u) = stack.pop() { vis[u] = true; ans = ans.max(u); for &v in &g[u] { if !vis[v] { stack.push(v); } } } println!("{ans}"); }