fn g() -> Vec { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.split_whitespace().flat_map(str::parse).collect() } fn main() { g(); let mut a = g(); let mut t = a.iter().fold(0, |t, a| t + a * a); let q = g()[0]; for _ in 0..q { let v = g(); t -= a[v[0] - 1].pow(2) + a[v[2] - 1].pow(2); a[v[0] - 1] -= v[1]; a[v[2] - 1] += v[1]; t += a[v[0] - 1].pow(2) + a[v[2] - 1].pow(2); println!("{t}") } }