use std::cmp; use std::fs::File; use std::io::Read; // fn pow_speedt_with_mod(mut p: i64, mut q: i64, m: i64) -> i64 { // p %= m; // let mut r = p; // let mut ret: i64 = 1; // while q > 0 { // ret *= if q % 2 == 1 {r} else {1}; // r *= r; // r %= m; // q /= 2; // ret %= m; // } // return ret; // } fn main() { let inputstatus = 1; let mut buf = String::new(); let filename = "inputrust.txt"; if inputstatus == 0 { let mut f = File::open(filename).expect("file not found"); f.read_to_string(&mut buf) .expect("something went wrong reading the file"); } else { std::io::stdin().read_to_string(&mut buf).unwrap(); } let mut iter = buf.split_whitespace(); let n: usize = iter.next().unwrap().parse().unwrap(); let mut dp = vec![vec![0; n]; 2]; for i in 0..n { let p: i32 = iter.next().unwrap().parse().unwrap(); let a: i32 = iter.next().unwrap().parse().unwrap(); if i == 0 { dp[0][i] = p; dp[1][i] = a; } else { dp[0][i] = cmp::max(dp[0][i - 1] + p, dp[1][i - 1] + 2 * p); dp[1][i] = cmp::max(dp[0][i - 1] + a, dp[1][i - 1] + 2 * a); } } println!("{}", cmp::max(dp[0][n - 1], dp[1][n - 1])); }