const MOD: usize = 998244353; 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 p2s = vec![1usize; n+1]; for i in 0..n { p2s[i+1] = p2s[i] * 2 % MOD; } let mut summary = vec![0usize; n+1]; for i in 0..n { summary[i+1] = summary[i] + p2s[i]; summary[i+1] %= MOD; } let mut result = 0usize; for i in 0..n { if i+1 < n { result += summary[n-1-i] * a[i] % MOD; result %= MOD; } if i > 0 { result += MOD - summary[i] * a[i] % MOD; result %= MOD; } } println!("{}", result); }